This is an archive of the discontinued LLVM Phabricator instance.

WebAssembly: Remove MachineFunction reference from MFI
ClosedPublic

Authored by arsenm on Nov 2 2022, 3:18 PM.

Details

Summary

The MachineFunctionInfo here is a bit awkward because
WasmEHInfo is in the MachineFunction but handled from
the target code. Either everything should move into WebAssembly
or into the MachineFunction for MIR serialization.

Diff Detail

Event Timeline

arsenm created this revision.Nov 2 2022, 3:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 3:18 PM
arsenm requested review of this revision.Nov 2 2022, 3:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 3:18 PM
Herald added a subscriber: wdng. · View Herald Transcript
aheejin added a comment.EditedNov 2 2022, 9:37 PM

It's been a while and I don't remember why I put a pointer to MF as a member in WebAssemblyFunctionInfo, but if things work without it, it should be fine. But I don't understand some comments, about which I asked questions below.

I think the reason I put WasmEHInfo in MachineFunction is, Wasm is not only a target but an exception mode (even though it is only being used by WebAssembly target), and also WinEHInfo, which contains info for WinEH EH mode, is there too.

llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
31–35

What does this mean by "if WasmEHFuncInfo from the block reference"?

164

Why? Which link?

pmatos added inline comments.Nov 3 2022, 12:01 AM
llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
34

Back in https://github.com/llvm/llvm-project/commit/cc5a1b3dd9039d50f6b9caa679d60398f0cec65f you changed this from a reference to a pointer. Apparently this is not needed at all and you are removing it. I am happy with it. Looking through the code I get the feeling that this was an artifact from doing similar things as other backends. Some of which have ended up removing MF, while others still have it.

arsenm added inline comments.Nov 3 2022, 10:08 AM
llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
31–35

Ultimately WasmEHFuncInfo has a bunch of MachineBasicBlock pointers in it. When cloned to a new machine function, those need to be updated to point to the blocks in the new function which isn't handled

164

This is the layering violation where this field is stored in the MachineFunction, but all the handling is done here in target code. Either everything should be done here, or done in the generic MIR handling

llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
34

I purged this from all targets last time I posted this patch; this one was added back in at some point since then

aheejin added inline comments.Nov 3 2022, 4:33 PM
llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
31–35

Apparently I'm not familiar with the cloning functionality you added a while ago. What is that for? Is that creating an in-memory copy of a while function, including BBs and instructions? Then what's src BB and what's dst BB?

And how does WinEHFuncInfo handle it currently?

164

As I said, WinEHFuncInfo is also within MachineFunction. Also this WasmEHFuncInfo is not only for MIR handling. It is referenced throughout our compilation passes.

arsenm added inline comments.Nov 3 2022, 4:36 PM
llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
31–35

It's for llvm-reduce; it's just unhandled now. If you try to reduce a function with EH info it won't faithfully reproduce

164

Right, it's a well spread out layering violation. The handling should be consistently in webassembly only, or consistently in the generic MachineFunction handling

aheejin added inline comments.Nov 3 2022, 6:38 PM
llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
31–35
  • Then what are src and dst BBs? If you are cloning a given parameter, how do you know what the dst BB will be? Are BBs cloned first and supplied here?
  • How about changing this to TODO? TODO: Implement cloning for WasmEHFuncInfo or something.
164

I think the reason both of them are in MachineFunction is, as noted above, they are for exception handling conventions, not for specific targets. (Well, WinEHFuncInfo kind of happens to be only used in x86, and WasmEHFuncInfo only in WebAssembly... but anyway)

As we don't have a plan atm to restructure this, how about removing this FIXME, or elaborating more on what the suggestion could be? "This link should be removed" doesn't explain much on why for future readers.

arsenm updated this revision to Diff 474868.Nov 11 2022, 3:05 PM

Better comments and fail clone if EH info is used

aheejin accepted this revision.Nov 11 2022, 3:54 PM
This revision is now accepted and ready to land.Nov 11 2022, 3:54 PM
arsenm closed this revision.Nov 11 2022, 4:41 PM

ff2b60bbcb28701c86b200b0c03439a2e6ef6b44 (except I dropped the MF check from the clone since it didn't actually work)