Skip to content

[WebAssembly] Rename CATCH/CATCH_ALL to *_LEGACY #107187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WebAssemblyInstPrinter final : public MCInstPrinter {
SmallVector<std::pair<uint64_t, bool>, 4> ControlFlowStack;
SmallVector<uint64_t, 4> TryStack;

enum EHInstKind { TRY, CATCH, CATCH_ALL };
enum EHInstKind { TRY, CATCH_LEGACY, CATCH_ALL_LEGACY };
SmallVector<EHInstKind, 4> EHInstStack;

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 21 additions & 13 deletions llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
2 changes: 1 addition & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 12 additions & 11 deletions llvm/test/CodeGen/WebAssembly/cfg-stackify-eh-legacy.mir
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mcsymbol .Ltmp2>
%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 <mcsymbol .Ltmp3>
%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:
Expand Down Expand Up @@ -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:
Expand All @@ -105,11 +106,11 @@ body: |

bb.3 (landing-pad):
EH_LABEL <mcsymbol .Ltmp4>
%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 <mcsymbol .Ltmp5>
%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
...
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/WebAssembly/exception-legacy.mir
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mcsymbol .Ltmp2>
EH_LABEL <mcsymbol .Ltmp2>
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/WebAssembly/function-info.mir
Original file line number Diff line number Diff line change
Expand Up @@ -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
...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
Loading