diff options
| author | Heejin Ahn <aheejin@gmail.com> | 2019-03-16 05:38:57 +0000 | 
|---|---|---|
| committer | Heejin Ahn <aheejin@gmail.com> | 2019-03-16 05:38:57 +0000 | 
| commit | 66ce419468ced9196d9e6586eea6522744ae184d (patch) | |
| tree | 468e6d1a06e1179cfac854a2bd20df9385da3f0e /llvm/lib/Target/WebAssembly | |
| parent | b47a18cd4bec55c4a4aba8ad398982b997f7fbc9 (diff) | |
| download | bcm5719-llvm-66ce419468ced9196d9e6586eea6522744ae184d.tar.gz bcm5719-llvm-66ce419468ced9196d9e6586eea6522744ae184d.zip  | |
[WebAssembly] Make rethrow take an except_ref type argument
Summary:
In the new wasm EH proposal, `rethrow` takes an `except_ref` argument.
This change was missing in 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 `CallInst`s.
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.
Reviewers: dschuff
Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59352
llvm-svn: 356316
Diffstat (limited to 'llvm/lib/Target/WebAssembly')
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td | 8 | ||||
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp | 19 | 
2 files changed, 21 insertions, 6 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td index d44458f790a..574cb09ff33 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td @@ -144,7 +144,13 @@ defm THROW : I<(outs), (ins event_op:$tag, variable_ops),                 (outs), (ins event_op:$tag),                 [(WebAssemblythrow (WebAssemblywrapper texternalsym:$tag))],                 "throw   \t$tag", "throw   \t$tag", 0x08>; -defm RETHROW : NRI<(outs), (ins), [(int_wasm_rethrow)], "rethrow", 0x09>; +defm RETHROW : I<(outs), (ins EXCEPT_REF:$exn), (outs), (ins), +                 [], "rethrow \t$exn", "rethrow", 0x09>; +// Pseudo instruction to be the lowering target of int_wasm_rethrow_in_catch +// intrinsic. Will be converted to the real rethrow instruction later. +let isPseudo = 1 in +defm RETHROW_IN_CATCH : NRI<(outs), (ins), [(int_wasm_rethrow_in_catch)], +                            "rethrow_in_catch", 0>;  } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1  // Region within which an exception is caught: try / end_try diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp index 5b6fdb86c6d..f365aa73792 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp @@ -161,9 +161,17 @@ bool WebAssemblyLateEHPrepare::replaceFuncletReturns(MachineFunction &MF) {        Changed = true;        break;      } -    case WebAssembly::CLEANUPRET: { -      // Replace a cleanupret with a rethrow -      BuildMI(MBB, TI, TI->getDebugLoc(), TII.get(WebAssembly::RETHROW)); +    case WebAssembly::CLEANUPRET: +    case WebAssembly::RETHROW_IN_CATCH: { +      // Replace a cleanupret/rethrow_in_catch with a rethrow +      auto *EHPad = getMatchingEHPad(TI); +      auto CatchPos = EHPad->begin(); +      if (CatchPos->isEHLabel()) // EH pad starts with an EH label +        ++CatchPos; +      MachineInstr *Catch = &*CatchPos; +      unsigned ExnReg = Catch->getOperand(0).getReg(); +      BuildMI(MBB, TI, TI->getDebugLoc(), TII.get(WebAssembly::RETHROW)) +          .addReg(ExnReg);        TI->eraseFromParent();        Changed = true;        break; @@ -191,7 +199,8 @@ bool WebAssemblyLateEHPrepare::removeUnnecessaryUnreachables(        SmallVector<MachineBasicBlock *, 8> Succs(MBB.succ_begin(),                                                  MBB.succ_end());        for (auto *Succ : Succs) -        MBB.removeSuccessor(Succ); +        if (!Succ->isEHPad()) +          MBB.removeSuccessor(Succ);        eraseDeadBBsAndChildren(Succs);      }    } @@ -337,7 +346,7 @@ bool WebAssemblyLateEHPrepare::addExceptionExtraction(MachineFunction &MF) {        BuildMI(ElseMBB, DL, TII.get(WebAssembly::UNREACHABLE));      } else { -      BuildMI(ElseMBB, DL, TII.get(WebAssembly::RETHROW)); +      BuildMI(ElseMBB, DL, TII.get(WebAssembly::RETHROW)).addReg(ExnReg);        if (EHInfo->hasEHPadUnwindDest(EHPad))          ElseMBB->addSuccessor(EHInfo->getEHPadUnwindDest(EHPad));      }  | 

