diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp index bf6d6dce1f8ac..b85ed1d93593b 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp @@ -166,15 +166,15 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address, } return; - case WebAssembly::CATCH: - case WebAssembly::CATCH_S: - case WebAssembly::CATCH_ALL: - case WebAssembly::CATCH_ALL_S: + case WebAssembly::CATCH_LEGACY: + case WebAssembly::CATCH_LEGACY_S: + case WebAssembly::CATCH_ALL_LEGACY: + case WebAssembly::CATCH_ALL_LEGACY_S: // There can be multiple catch instructions for one try instruction, so // we print a label only for the first 'catch' label. if (EHInstStack.empty()) { printAnnotation(OS, "try-catch mismatch!"); - } else if (EHInstStack.back() == CATCH_ALL) { + } else if (EHInstStack.back() == CATCH_ALL_LEGACY) { printAnnotation(OS, "catch/catch_all cannot occur after catch_all"); } else if (EHInstStack.back() == TRY) { if (TryStack.empty()) { @@ -183,10 +183,11 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address, printAnnotation(OS, "catch" + utostr(TryStack.pop_back_val()) + ':'); } EHInstStack.pop_back(); - if (Opc == WebAssembly::CATCH || Opc == WebAssembly::CATCH_S) { - EHInstStack.push_back(CATCH); + if (Opc == WebAssembly::CATCH_LEGACY || + Opc == WebAssembly::CATCH_LEGACY_S) { + EHInstStack.push_back(CATCH_LEGACY); } else { - EHInstStack.push_back(CATCH_ALL); + EHInstStack.push_back(CATCH_ALL_LEGACY); } } return; diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h index f3c0124fd7f1f..8fd54d1640905 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h @@ -28,7 +28,7 @@ class WebAssemblyInstPrinter final : public MCInstPrinter { SmallVector, 4> ControlFlowStack; SmallVector TryStack; - enum EHInstKind { TRY, CATCH, CATCH_ALL }; + enum EHInstKind { TRY, CATCH_LEGACY, CATCH_ALL_LEGACY }; SmallVector EHInstStack; public: diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h index eb3087dafed2a..00f15e1db5e13 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h @@ -470,10 +470,10 @@ inline bool isMarker(unsigned Opc) { inline bool isCatch(unsigned Opc) { switch (Opc) { - case WebAssembly::CATCH: - case WebAssembly::CATCH_S: - case WebAssembly::CATCH_ALL: - case WebAssembly::CATCH_ALL_S: + case WebAssembly::CATCH_LEGACY: + case WebAssembly::CATCH_LEGACY_S: + case WebAssembly::CATCH_ALL_LEGACY: + case WebAssembly::CATCH_ALL_LEGACY_S: return true; default: return false; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp index 6fd882f62f3f0..3362ea5316e45 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp @@ -1305,7 +1305,7 @@ bool WebAssemblyCFGStackify::fixCatchUnwindMismatches(MachineFunction &MF) { // catch_all always catches an exception, so we don't need to do // anything - if (MI.getOpcode() == WebAssembly::CATCH_ALL) { + if (MI.getOpcode() == WebAssembly::CATCH_ALL_LEGACY) { } // This can happen when the unwind dest was removed during the @@ -1448,8 +1448,8 @@ void WebAssemblyCFGStackify::recalculateScopeTops(MachineFunction &MF) { case WebAssembly::DELEGATE: updateScopeTops(EndToBegin[&MI]->getParent(), &MBB); break; - case WebAssembly::CATCH: - case WebAssembly::CATCH_ALL: + case WebAssembly::CATCH_LEGACY: + case WebAssembly::CATCH_ALL_LEGACY: updateScopeTops(EHPadToTry[&MBB]->getParent(), &MBB); break; } @@ -1698,8 +1698,8 @@ void WebAssemblyCFGStackify::rewriteDepthImmediates(MachineFunction &MF) { Stack.push_back(std::make_pair(EndToBegin[&MI]->getParent(), &MI)); break; - case WebAssembly::CATCH: - case WebAssembly::CATCH_ALL: + case WebAssembly::CATCH_LEGACY: + case WebAssembly::CATCH_ALL_LEGACY: EHPadStack.pop_back(); break; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp index 0f06f54f219f9..60c5e18fbb0cd 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp @@ -212,7 +212,7 @@ void WebAssemblyDAGToDAGISel::Select(SDNode *Node) { int Tag = Node->getConstantOperandVal(2); SDValue SymNode = getTagSymNode(Tag, CurDAG); MachineSDNode *Catch = - CurDAG->getMachineNode(WebAssembly::CATCH, DL, + CurDAG->getMachineNode(WebAssembly::CATCH_LEGACY, DL, { PtrVT, // exception pointer MVT::Other // outchain type diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td index be6547007aaf7..dd40015577fd7 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td @@ -127,11 +127,27 @@ defm DEBUG_UNREACHABLE : NRI<(outs), (ins), [(debugtrap)], "unreachable", 0x00>; let Predicates = [HasExceptionHandling] in { -// Throwing an exception: throw / rethrow +// Throwing an exception: throw let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { defm THROW : I<(outs), (ins tag_op:$tag, variable_ops), (outs), (ins tag_op:$tag), [], "throw \t$tag", "throw \t$tag", 0x08>; +} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 + +// Pseudo instructions: cleanupret / catchret +let isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1, + isPseudo = 1, isEHScopeReturn = 1 in { + defm CLEANUPRET : NRI<(outs), (ins), [(cleanupret)], "cleanupret", 0>; + defm CATCHRET : NRI<(outs), (ins bb_op:$dst, bb_op:$from), + [(catchret bb:$dst, bb:$from)], "catchret", 0>; +} // isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1, + // isPseudo = 1, isEHScopeReturn = 1 + +// Below are instructions from the legacy EH proposal. Could be deprecated if +// usage gets low enough. + +// Rethrowing an exception: rethrow +let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in { defm RETHROW : NRI<(outs), (ins i32imm:$depth), [], "rethrow \t$depth", 0x09>; } // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 // The depth argument will be computed in CFGStackify. We set it to 0 here for @@ -147,22 +163,14 @@ defm END_TRY : NRI<(outs), (ins), [], "end_try", 0x0b>; // Catching an exception: catch / catch_all let hasCtrlDep = 1, hasSideEffects = 1 in { let variadicOpsAreDefs = 1 in -defm CATCH : I<(outs), (ins tag_op:$tag, variable_ops), - (outs), (ins tag_op:$tag), [], - "catch", "catch \t$tag", 0x07>; -defm CATCH_ALL : NRI<(outs), (ins), [], "catch_all", 0x19>; +defm CATCH_LEGACY : I<(outs), (ins tag_op:$tag, variable_ops), + (outs), (ins tag_op:$tag), [], + "catch", "catch \t$tag", 0x07>; +defm CATCH_ALL_LEGACY : NRI<(outs), (ins), [], "catch_all", 0x19>; } // Delegating an exception: delegate let isTerminator = 1, hasCtrlDep = 1, hasSideEffects = 1 in defm DELEGATE : NRI<(outs), (ins bb_op:$dst), [], "delegate \t $dst", 0x18>; -// Pseudo instructions: cleanupret / catchret -let isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1, - isPseudo = 1, isEHScopeReturn = 1 in { - defm CLEANUPRET : NRI<(outs), (ins), [(cleanupret)], "cleanupret", 0>; - defm CATCHRET : NRI<(outs), (ins bb_op:$dst, bb_op:$from), - [(catchret bb:$dst, bb:$from)], "catchret", 0>; -} // isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1, - // isPseudo = 1, isEHScopeReturn = 1 } // Predicates = [HasExceptionHandling] diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp index 94037b9ab189d..f0c205cdb6aeb 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp @@ -216,7 +216,7 @@ bool WebAssemblyLateEHPrepare::addCatchAlls(MachineFunction &MF) { Changed = true; BuildMI(MBB, InsertPos, InsertPos == MBB.end() ? DebugLoc() : InsertPos->getDebugLoc(), - TII.get(WebAssembly::CATCH_ALL)); + TII.get(WebAssembly::CATCH_ALL_LEGACY)); } } return Changed; diff --git a/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh-legacy.mir b/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh-legacy.mir index 0386410d1b612..c37a82fe80826 100644 --- a/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh-legacy.mir +++ b/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh-legacy.mir @@ -31,22 +31,23 @@ body: | bb.1 (landing-pad): successors: %bb.2 ; CHECK: bb.1 (landing-pad): - ; CHECK: CATCH + ; CHECK: CATCH_LEGACY ; CHECK: TRY - ; This RETHROW rethrows the exception caught by this BB's CATCH, but after - ; CFGStackify a TRY is placed between the CATCH and this RETHROW, so after - ; CFGStackify its immediate argument should become not 0, but 1. + ; This RETHROW rethrows the exception caught by this BB's CATCH_LEGACY, but + ; after CFGStackify a TRY is placed between the CATCH_LEGACY and this + ; RETHROW, so after CFGStackify its immediate argument should become not 0, + ; but 1. ; CHECK: RETHROW 1 EH_LABEL - %0:i32 = CATCH &__cpp_exception, implicit-def dead $arguments + %0:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments RETHROW 0, implicit-def dead $arguments bb.2 (landing-pad): ; CHECK: bb.2 (landing-pad): - ; CHECK: CATCH + ; CHECK: CATCH_LEGACY ; CHECK: RETHROW 0 EH_LABEL - %1:i32 = CATCH &__cpp_exception, implicit-def dead $arguments + %1:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments RETHROW 0, implicit-def dead $arguments bb.3: @@ -78,13 +79,13 @@ body: | ; CHECK: CALL @foo ; CHECK: DELEGATE ; CHECK: RETURN - ; CHECK: CATCH + ; CHECK: CATCH_LEGACY ;; This TRY should have the return type i32 (127) ; CHECK: TRY 127 ; CHECK: RETHROW ; CHECK: DELEGATE ; CHECK: END_TRY - ; CHECK: CATCH + ; CHECK: CATCH_LEGACY ; CHECK: RETHROW ; CHECK: END_TRY bb.0: @@ -105,11 +106,11 @@ body: | bb.3 (landing-pad): EH_LABEL - %0:i32 = CATCH &__cpp_exception, implicit-def dead $arguments + %0:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments RETHROW 0, implicit-def dead $arguments bb.4 (landing-pad): EH_LABEL - %1:i32 = CATCH &__cpp_exception, implicit-def dead $arguments + %1:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments RETHROW 0, implicit-def dead $arguments ... diff --git a/llvm/test/CodeGen/WebAssembly/exception-legacy.mir b/llvm/test/CodeGen/WebAssembly/exception-legacy.mir index 895e8d8864ea2..f9eb40bb03cc7 100644 --- a/llvm/test/CodeGen/WebAssembly/exception-legacy.mir +++ b/llvm/test/CodeGen/WebAssembly/exception-legacy.mir @@ -42,13 +42,13 @@ body: | bb.1 (landing-pad): ; predecessors: %bb.0 successors: %bb.2 - ; CATCH_ALL should be after EH_LABELs in the beginning of an EH pad. + ; CATCH_ALL_LEGACY should be after EH_LABELs in the beginning of an EH pad. ; (Sometimes there are multiple EH_LABELs in an EH pad. This test tests ; that.) GLOBAL_SET should follow right after that. ; CHECK: bb.1 ; CHECK: EH_LABEL ; CHECK: EH_LABEL - ; CHECK-NEXT: CATCH_ALL + ; CHECK-NEXT: CATCH_ALL_LEGACY ; CHECK-NEXT: GLOBAL_SET_I32 EH_LABEL EH_LABEL diff --git a/llvm/test/CodeGen/WebAssembly/function-info.mir b/llvm/test/CodeGen/WebAssembly/function-info.mir index 2971d234c9b2d..d241d59b67a39 100644 --- a/llvm/test/CodeGen/WebAssembly/function-info.mir +++ b/llvm/test/CodeGen/WebAssembly/function-info.mir @@ -61,12 +61,12 @@ body: | bb.2 (landing-pad): successors: %bb.1, %bb.3 - %0:i32 = CATCH &__cpp_exception, implicit-def dead $arguments + %0:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments CALL @foo, implicit-def dead $arguments, implicit $sp32, implicit $sp64, implicit-def dead $arguments, implicit $sp32, implicit $sp64 BR %bb.1, implicit-def $arguments bb.3 (landing-pad): - CATCH_ALL implicit-def $arguments + CATCH_ALL_LEGACY implicit-def $arguments RETHROW 0, implicit-def $arguments ... diff --git a/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp b/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp index 55caaf5d13b6c..073beb9446ffb 100644 --- a/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp +++ b/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp @@ -101,14 +101,14 @@ body: | ; predecessors: %bb.0 successors: %bb.3, %bb.9 liveins: $value_stack - CATCH_ALL implicit-def $arguments + CATCH_ALL_LEGACY implicit-def $arguments RETHROW 0, implicit-def dead $arguments bb.3 (landing-pad): ; predecessors: %bb.2 successors: %bb.4, %bb.6 liveins: $value_stack - %1:i32 = CATCH &__cpp_exception, implicit-def $arguments + %1:i32 = CATCH_LEGACY &__cpp_exception, implicit-def $arguments BR_IF %bb.4, %58:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack BR %bb.6, implicit-def $arguments @@ -139,13 +139,13 @@ body: | ; predecessors: %bb.4 successors: %bb.9 liveins: $value_stack - CATCH_ALL implicit-def $arguments + CATCH_ALL_LEGACY implicit-def $arguments RETHROW 0, implicit-def dead $arguments bb.9 (landing-pad): ; predecessors: %bb.2, %bb.6, %bb.8 liveins: $value_stack - CATCH_ALL implicit-def $arguments + CATCH_ALL_LEGACY implicit-def $arguments RETHROW 0, implicit-def dead $arguments bb.10: @@ -257,7 +257,7 @@ body: | ; predecessors: %bb.0 successors: %bb.2, %bb.8 liveins: $value_stack - %0:i32 = CATCH &__cpp_exception, implicit-def $arguments + %0:i32 = CATCH_LEGACY &__cpp_exception, implicit-def $arguments BR_IF %bb.2, %32:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack BR %bb.8, implicit-def $arguments @@ -271,7 +271,7 @@ body: | ; predecessors: %bb.2 successors: %bb.4, %bb.6 liveins: $value_stack - %1:i32 = CATCH &__cpp_exception, implicit-def $arguments + %1:i32 = CATCH_LEGACY &__cpp_exception, implicit-def $arguments BR_IF %bb.4, %43:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack BR %bb.6, implicit-def $arguments @@ -313,13 +313,13 @@ body: | ; predecessors: %bb.4 successors: %bb.11 liveins: $value_stack - CATCH_ALL implicit-def $arguments + CATCH_ALL_LEGACY implicit-def $arguments RETHROW 0, implicit-def dead $arguments bb.11 (landing-pad): ; predecessors: %bb.2, %bb.6, %bb.10 liveins: $value_stack - CATCH_ALL implicit-def $arguments + CATCH_ALL_LEGACY implicit-def $arguments RETHROW 0, implicit-def dead $arguments bb.12: