This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Make result of 'catch' inst variadic
ClosedPublic

Authored by aheejin on Aug 3 2021, 9:06 PM.

Details

Summary

catch instruction can have any number of result values depending on
its tag, but so far we have only needed a single i32 return value for
C++ exception so the instruction was specified that way. But using the
instruction for SjLj handling requires multiple return values.

This makes catch instruction's results variadic and moves selection of
throw and catch instruction from ISelLowering to ISelDAGToDAG.
Moving catch to ISelDAGToDAG is necessary because I am not aware of
a good way to do instruction selection for variadic output instructions
in TableGen. This also moves throw because 1. throw and catch
share the same utility function and 2. there is really no reason we
should do that in ISelLowering in the first place. What we do is mostly
the same in both places, and moving them to ISelDAGToDAG allows us to
remove unnecessary mid-level nodes for throw and catch in
WebAssemblyISD.def and WebAssemblyInstrInfo.td.

This also adds handling for new catch instruction to AsmTypeCheck.

Diff Detail

Event Timeline

aheejin created this revision.Aug 3 2021, 9:06 PM
aheejin requested review of this revision.Aug 3 2021, 9:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2021, 9:06 PM
dschuff added inline comments.Aug 4 2021, 11:25 AM
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
201

The order of these is different compared to what you had in ISelLowering. Likewise below for throw. I assume that's intentional, but why is it different?

tlively accepted this revision.Aug 4 2021, 12:38 PM

LGTM, but I share Derek's question.

llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
211
214–215
This revision is now accepted and ready to land.Aug 4 2021, 12:38 PM
aheejin updated this revision to Diff 364236.Aug 4 2021, 1:34 PM
aheejin marked 2 inline comments as done.

Addres comments + clang-tidy fixes

aheejin added inline comments.Aug 4 2021, 1:41 PM
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
201

The short answer is I don't know. I first copied the code but instruction selection errored out saying the chain should be the last node, so I changed the order, and it worked. (In the current ISelLowering version, if I change the order, it doesn't work either.) My guess is the expected order of chain is different in ISelLowering vs. instruction selection or something.. but I didn't specify the order of chain in WebAssemblyISD::CATCH myself, so I'm not sure how the expected order is determined, and I didn't spend more time to check.

aheejin updated this revision to Diff 364240.Aug 4 2021, 1:44 PM

One more use of getConstantOperandVal

dschuff accepted this revision.Aug 4 2021, 1:50 PM

LGTM too FTR

This revision was landed with ongoing or failed builds.Aug 4 2021, 2:05 PM
This revision was automatically updated to reflect the committed changes.