This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Make rethrow take an except_ref type argument
ClosedPublic

Authored by aheejin on Mar 14 2019, 3:38 AM.

Details

Summary

In the new wasm EH proposal, rethrow takes an except_ref argument.
This change was missing in D57134 (r352598).

This patch adds llvm.wasm.rethrow.in.catch intrinsic. This is an
intrinsic that's gonna eventually be lowered to wasm rethrow
instruction, but this intrinsic can appear only within a catchpad or a
cleanuppad scope. Also this intrinsic needs to be invokable - otherwise
EH pad successor for it will not be correctly generated in clang.

This also adds lowering logic for this intrinsic in
SelectionDAGBuilder::visitInvoke. This routine is basically a
specialized and simplified version of
SelectionDAGBuilder::visitTargetIntrinsic, but we can't use it
because if is only for CallInsts.

This deletes the previous llvm.wasm.rethrow intrinsic and related
tests, which was meant to be used within a __cxa_rethrow library
function. Turned out this needs some more logic, so the intrinsic for
this purpose will be added later.

LateEHPrepare takes a result value of catch and inserts it into
matching rethrow as an argument.

RETHROW_IN_CATCH is a pseudo instruction that serves as a link between
llvm.wasm.rethrow.in.catch and the real wasm rethrow instruction. To
generate a rethrow instruction, we need an except_ref argument,
which is generated from catch instruction. But catch instrutions are
added in LateEHPrepare pass, so we use RETHROW_IN_CATCH, which takes
no argument, until we are able to correctly lower it to rethrow in
LateEHPrepare.

Diff Detail

Repository
rL LLVM

Event Timeline

aheejin created this revision.Mar 14 2019, 3:38 AM
aheejin updated this revision to Diff 190588.Mar 14 2019, 3:42 AM

Comment fix

dschuff accepted this revision.Mar 14 2019, 2:28 PM

otherwise LGTM

lib/CodeGen/WasmEHPrepare.cpp
180 ↗(On Diff #190588)

Update the comment too.

test/CodeGen/WebAssembly/cfg-stackify-eh.ll
36 ↗(On Diff #190588)

Here you are trying to match the $ but below you are not. I guess the reason you are not checking the value (in catch or rethrow) is because these tests are only intended to verify the control flow?

test/CodeGen/WebAssembly/wasmehprepare.ll
399 ↗(On Diff #190588)

You've removed this test; should we also remove the code that it's testing?

This revision is now accepted and ready to land.Mar 14 2019, 2:28 PM
aheejin updated this revision to Diff 190945.Mar 15 2019, 10:28 PM
aheejin marked 6 inline comments as done.
  • Address comments
  • Change rethrow definition from NRI to I
aheejin added inline comments.Mar 15 2019, 10:28 PM
lib/CodeGen/WasmEHPrepare.cpp
180 ↗(On Diff #190588)

Done.

You've removed this test; should we also remove the code that it's testing?

This is the part where I removed the code for that. Note I deleted the line

for (auto L : {ThrowF->users(), RethrowF->users()}) {

and now the User *U only refers to ThrowF->users().

test/CodeGen/WebAssembly/cfg-stackify-eh.ll
36 ↗(On Diff #190588)

Yes, I didn't try to check if the argument is correct in this file because this is for CFG ctackify pass checking. But I wasn't gonna make this different from other occurrences in this file by checking $ here only; I will change this to `{{.*}} like others.

test/CodeGen/WebAssembly/wasmehprepare.ll
399 ↗(On Diff #190588)

I've already done that; please see the comment above in WasmEHPrepare.cpp.

This revision was automatically updated to reflect the committed changes.