This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Place 'try' and 'catch' correctly wrt EH_LABELs
ClosedPublic

Authored by aheejin on Mar 4 2019, 10:49 AM.

Details

Summary

After instruction selection phase, possibly-throwing calls, which were
previously invoke, are wrapped in EH_LABEL instructions. For example:

EH_LABEL <mcsymbol .Ltmp0>
CALL_VOID @foo ...
EH_LABEL <mcsymbol .Ltmp1>

EH_LABEL is placed also in the beginning of EH pads:

bb.1 (landing-pad):
  EH_LABEL <mcsymbol .Ltmp2>
  ...

And we'd like to maintian this relationship, so when we place a try,

TRY ...
EH_LABEL <mcsymbol .Ltmp0>
CALL_VOID @foo ...
EH_LABEL <mcsymbol .Ltmp1>

When we place a catch,

bb.1 (landing-pad):
  EH_LABEL <mcsymbol .Ltmp2>
  %0:except_ref = CATCH ...
  ...

Previously we didn't treat EH_LABELs specially, so try was placed
right before a call, and catch was placed in the beginning of an EH
pad.

Diff Detail

Repository
rL LLVM

Event Timeline

aheejin created this revision.Mar 4 2019, 10:49 AM
aheejin updated this revision to Diff 189171.Mar 4 2019, 11:00 AM

Add comments on the test case

dschuff accepted this revision.Mar 12 2019, 11:00 AM

So by "correctly" you mean that the TRY goes before the EH_LABEL rather than between the label and the call, and the CATCH goes after the label rather than at the top of the BB?

test/CodeGen/WebAssembly/eh-labels.mir
25 ↗(On Diff #189171)

Should this be CHECK: EH_LABEL? (also below)

This revision is now accepted and ready to land.Mar 12 2019, 11:00 AM
aheejin marked an inline comment as done.Mar 12 2019, 5:35 PM

So by "correctly" you mean that the TRY goes before the EH_LABEL rather than between the label and the call, and the CATCH goes after the label rather than at the top of the BB?

Yes. We currently don't really use these labels (there are platforms who do), but they are generated anyway, so I'd respect their semantics for now.

aheejin updated this revision to Diff 190364.Mar 12 2019, 5:35 PM
  • Test fix
This revision was automatically updated to reflect the committed changes.