[llvm] [WebAssembly] Rename CATCH/CATCH_ALL to *_LEGACY (PR #107187)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 11:42:22 PDT 2024
https://github.com/aheejin updated https://github.com/llvm/llvm-project/pull/107187
>From 2bea4931527f5a83bbed42580ed4f311f205b5bc Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Wed, 4 Sep 2024 05:49:17 +0000
Subject: [PATCH 1/6] [WebAssembly] Rename CATCH/CATCH_ALL to *_P3
This renames MIR instruction `CATCH` and `CATCH_ALL` to `CATCH_P3` and
`CATCH_ALL_P3` respectively. `P3` means Phase 3.
Follow-up PRs for the new EH (exnref) implementation will use `CATCH`,
`CATCH_REF`, `CATCH_ALL`, and `CATCH_ALL_REF` as pseudo-instructions
that return extracted values or `exnref` or both, because we don't
currently support block return values in LLVM. So to give the old
(real) `CATCH`es and the new (pseudo) `CATCH`es different names, this
attaches `_P3` prefix to the names. This is what we did in Binaryen, but
in this case they were `enum` values:
https://github.com/WebAssembly/binaryen/blob/952286421a19fb8358d645f49d455b75bfbd1d19/src/wasm-binary.h#L1111-L1112
This also rearranges `WebAssemblyInstrControl.td` so that the old Phase
3 instructions are listed all together at the end.
---
.../MCTargetDesc/WebAssemblyInstPrinter.cpp | 16 ++++-----
.../MCTargetDesc/WebAssemblyInstPrinter.h | 2 +-
.../MCTargetDesc/WebAssemblyMCTargetDesc.h | 8 ++---
.../WebAssembly/WebAssemblyCFGStackify.cpp | 10 +++---
.../WebAssembly/WebAssemblyISelDAGToDAG.cpp | 2 +-
.../WebAssembly/WebAssemblyInstrControl.td | 33 +++++++++++--------
.../WebAssembly/WebAssemblyLateEHPrepare.cpp | 2 +-
.../CodeGen/WebAssembly/cfg-stackify-eh.mir | 22 ++++++-------
llvm/test/CodeGen/WebAssembly/exception.mir | 4 +--
.../CodeGen/WebAssembly/function-info.mir | 4 +--
10 files changed, 55 insertions(+), 48 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
index bf6d6dce1f8ac2..ca3dfb900becde 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_P3:
+ case WebAssembly::CATCH_P3_S:
+ case WebAssembly::CATCH_ALL_P3:
+ case WebAssembly::CATCH_ALL_P3_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_P3) {
printAnnotation(OS, "catch/catch_all cannot occur after catch_all");
} else if (EHInstStack.back() == TRY) {
if (TryStack.empty()) {
@@ -183,10 +183,10 @@ 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_P3 || Opc == WebAssembly::CATCH_P3_S) {
+ EHInstStack.push_back(CATCH_P3);
} else {
- EHInstStack.push_back(CATCH_ALL);
+ EHInstStack.push_back(CATCH_ALL_P3);
}
}
return;
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h
index f3c0124fd7f1f9..4f409fd9b9c070 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<std::pair<uint64_t, bool>, 4> ControlFlowStack;
SmallVector<uint64_t, 4> TryStack;
- enum EHInstKind { TRY, CATCH, CATCH_ALL };
+ enum EHInstKind { TRY, CATCH_P3, CATCH_ALL_P3 };
SmallVector<EHInstKind, 4> EHInstStack;
public:
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
index eb3087dafed2af..86f9fb9fac1e90 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_P3:
+ case WebAssembly::CATCH_P3_S:
+ case WebAssembly::CATCH_ALL_P3:
+ case WebAssembly::CATCH_ALL_P3_S:
return true;
default:
return false;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
index c7001ef2b33e62..45e536921c9166 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
@@ -1309,7 +1309,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_P3) {
}
// This can happen when the unwind dest was removed during the
@@ -1454,8 +1454,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_P3:
+ case WebAssembly::CATCH_ALL_P3:
updateScopeTops(EHPadToTry[&MBB]->getParent(), &MBB);
break;
}
@@ -1687,8 +1687,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_P3:
+ case WebAssembly::CATCH_ALL_P3:
EHPadStack.pop_back();
break;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
index 0f06f54f219f9a..4d50794e500329 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_P3, 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 be6547007aaf7a..6075dcb6a8a419 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
@@ -127,11 +127,26 @@ 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 old Phase 3 exception. Can be deprecated.
+
+// 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 +162,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_P3 : I<(outs), (ins tag_op:$tag, variable_ops),
+ (outs), (ins tag_op:$tag), [],
+ "catch", "catch \t$tag", 0x07>;
+defm CATCH_ALL_P3 : 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 94037b9ab189db..12d23ccfd9adb6 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_P3));
}
}
return Changed;
diff --git a/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.mir b/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.mir
index 0386410d1b6120..eae4bc4e842484 100644
--- a/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.mir
+++ b/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.mir
@@ -31,22 +31,22 @@ body: |
bb.1 (landing-pad):
successors: %bb.2
; CHECK: bb.1 (landing-pad):
- ; CHECK: CATCH
+ ; CHECK: CATCH_P3
; 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_P3, but
+ ; after CFGStackify a TRY is placed between the CATCH_P3 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_P3 &__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_P3
; CHECK: RETHROW 0
EH_LABEL <mcsymbol .Ltmp3>
- %1:i32 = CATCH &__cpp_exception, implicit-def dead $arguments
+ %1:i32 = CATCH_P3 &__cpp_exception, implicit-def dead $arguments
RETHROW 0, implicit-def dead $arguments
bb.3:
@@ -78,13 +78,13 @@ body: |
; CHECK: CALL @foo
; CHECK: DELEGATE
; CHECK: RETURN
- ; CHECK: CATCH
+ ; CHECK: CATCH_P3
;; This TRY should have the return type i32 (127)
; CHECK: TRY 127
; CHECK: RETHROW
; CHECK: DELEGATE
; CHECK: END_TRY
- ; CHECK: CATCH
+ ; CHECK: CATCH_P3
; CHECK: RETHROW
; CHECK: END_TRY
bb.0:
@@ -105,11 +105,11 @@ body: |
bb.3 (landing-pad):
EH_LABEL <mcsymbol .Ltmp4>
- %0:i32 = CATCH &__cpp_exception, implicit-def dead $arguments
+ %0:i32 = CATCH_P3 &__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_P3 &__cpp_exception, implicit-def dead $arguments
RETHROW 0, implicit-def dead $arguments
...
diff --git a/llvm/test/CodeGen/WebAssembly/exception.mir b/llvm/test/CodeGen/WebAssembly/exception.mir
index 895e8d8864ea25..405a4660045739 100644
--- a/llvm/test/CodeGen/WebAssembly/exception.mir
+++ b/llvm/test/CodeGen/WebAssembly/exception.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_P3 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_P3
; CHECK-NEXT: GLOBAL_SET_I32
EH_LABEL <mcsymbol .Ltmp2>
EH_LABEL <mcsymbol .Ltmp2>
diff --git a/llvm/test/CodeGen/WebAssembly/function-info.mir b/llvm/test/CodeGen/WebAssembly/function-info.mir
index 2971d234c9b2d7..33f10a4428e23e 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_P3 &__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_P3 implicit-def $arguments
RETHROW 0, implicit-def $arguments
...
>From f747310d680cefbe76e5502769c5c1741c4d8a43 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Wed, 4 Sep 2024 16:04:40 +0000
Subject: [PATCH 2/6] Fix unittests
---
.../WebAssembly/WebAssemblyExceptionInfoTest.cpp | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp b/llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp
index 55caaf5d13b6c8..643c90d5a51a9a 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_P3 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_P3 &__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_P3 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_P3 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_P3 &__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_P3 &__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_P3 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_P3 implicit-def $arguments
RETHROW 0, implicit-def dead $arguments
bb.12:
>From e29c5c4fcc4674f69f63ce1f3b20aac9793eb558 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Wed, 4 Sep 2024 16:57:18 +0000
Subject: [PATCH 3/6] CATCH_(ALL_)P3 -> CATCH_(ALL_)LEGACY
---
.../MCTargetDesc/WebAssemblyInstPrinter.cpp | 17 +++++++-------
.../MCTargetDesc/WebAssemblyInstPrinter.h | 2 +-
.../MCTargetDesc/WebAssemblyMCTargetDesc.h | 8 +++----
.../WebAssembly/WebAssemblyCFGStackify.cpp | 10 ++++----
.../WebAssembly/WebAssemblyISelDAGToDAG.cpp | 2 +-
.../WebAssembly/WebAssemblyInstrControl.td | 8 +++----
.../WebAssembly/WebAssemblyLateEHPrepare.cpp | 2 +-
.../WebAssembly/cfg-stackify-eh-legacy.mir | 23 ++++++++++---------
.../CodeGen/WebAssembly/exception-legacy.mir | 4 ++--
.../CodeGen/WebAssembly/function-info.mir | 4 ++--
.../WebAssemblyExceptionInfoTest.cpp | 16 ++++++-------
11 files changed, 49 insertions(+), 47 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
index ca3dfb900becde..b85ed1d93593bd 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_P3:
- case WebAssembly::CATCH_P3_S:
- case WebAssembly::CATCH_ALL_P3:
- case WebAssembly::CATCH_ALL_P3_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_P3) {
+ } 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_P3 || Opc == WebAssembly::CATCH_P3_S) {
- EHInstStack.push_back(CATCH_P3);
+ if (Opc == WebAssembly::CATCH_LEGACY ||
+ Opc == WebAssembly::CATCH_LEGACY_S) {
+ EHInstStack.push_back(CATCH_LEGACY);
} else {
- EHInstStack.push_back(CATCH_ALL_P3);
+ 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 4f409fd9b9c070..8fd54d16409059 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<std::pair<uint64_t, bool>, 4> ControlFlowStack;
SmallVector<uint64_t, 4> TryStack;
- enum EHInstKind { TRY, CATCH_P3, CATCH_ALL_P3 };
+ enum EHInstKind { TRY, CATCH_LEGACY, CATCH_ALL_LEGACY };
SmallVector<EHInstKind, 4> EHInstStack;
public:
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
index 86f9fb9fac1e90..00f15e1db5e13a 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_P3:
- case WebAssembly::CATCH_P3_S:
- case WebAssembly::CATCH_ALL_P3:
- case WebAssembly::CATCH_ALL_P3_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 dd087c9d4a2e5f..3362ea5316e452 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_P3) {
+ 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_P3:
- case WebAssembly::CATCH_ALL_P3:
+ 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_P3:
- case WebAssembly::CATCH_ALL_P3:
+ 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 4d50794e500329..60c5e18fbb0cd7 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_P3, 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 6075dcb6a8a419..ac16f95d3e5cfc 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
@@ -162,10 +162,10 @@ 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_P3 : I<(outs), (ins tag_op:$tag, variable_ops),
- (outs), (ins tag_op:$tag), [],
- "catch", "catch \t$tag", 0x07>;
-defm CATCH_ALL_P3 : 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
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
index 12d23ccfd9adb6..f0c205cdb6aebc 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_P3));
+ 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 eae4bc4e842484..c37a82fe80826d 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_P3
+ ; CHECK: CATCH_LEGACY
; CHECK: TRY
- ; This RETHROW rethrows the exception caught by this BB's CATCH_P3, but
- ; after CFGStackify a TRY is placed between the CATCH_P3 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_P3 &__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_P3
+ ; CHECK: CATCH_LEGACY
; CHECK: RETHROW 0
EH_LABEL <mcsymbol .Ltmp3>
- %1:i32 = CATCH_P3 &__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_P3
+ ; CHECK: CATCH_LEGACY
;; This TRY should have the return type i32 (127)
; CHECK: TRY 127
; CHECK: RETHROW
; CHECK: DELEGATE
; CHECK: END_TRY
- ; CHECK: CATCH_P3
+ ; CHECK: CATCH_LEGACY
; CHECK: RETHROW
; CHECK: END_TRY
bb.0:
@@ -105,11 +106,11 @@ body: |
bb.3 (landing-pad):
EH_LABEL <mcsymbol .Ltmp4>
- %0:i32 = CATCH_P3 &__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_P3 &__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 405a4660045739..f9eb40bb03cc7a 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_P3 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_P3
+ ; CHECK-NEXT: CATCH_ALL_LEGACY
; CHECK-NEXT: GLOBAL_SET_I32
EH_LABEL <mcsymbol .Ltmp2>
EH_LABEL <mcsymbol .Ltmp2>
diff --git a/llvm/test/CodeGen/WebAssembly/function-info.mir b/llvm/test/CodeGen/WebAssembly/function-info.mir
index 33f10a4428e23e..d241d59b67a391 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_P3 &__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_P3 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 643c90d5a51a9a..073beb9446ffb2 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_P3 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_P3 &__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_P3 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_P3 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_P3 &__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_P3 &__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_P3 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_P3 implicit-def $arguments
+ CATCH_ALL_LEGACY implicit-def $arguments
RETHROW 0, implicit-def dead $arguments
bb.12:
>From 7130c37a345670b86410117969364cabac6ed952 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Wed, 4 Sep 2024 17:02:03 +0000
Subject: [PATCH 4/6] Comment fix (phase 3 -> legacy)
---
llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
index ac16f95d3e5cfc..a2d589e0c7b439 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
@@ -143,7 +143,7 @@ let isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
} // isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
// isPseudo = 1, isEHScopeReturn = 1
-// Below are instructions from the old Phase 3 exception. Can be deprecated.
+// Below are instructions from the legacy EH proposal. Can be deprecated.
// Rethrowing an exception: rethrow
let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
>From 00caa5ab336b794cdd823ef52da42a092bbeac6e Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Wed, 4 Sep 2024 11:41:22 -0700
Subject: [PATCH 5/6] Update
llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
Co-authored-by: Derek Schuff <dschuff at chromium.org>
---
llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
index a2d589e0c7b439..dd068cce6b2ac0 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
@@ -143,7 +143,7 @@ let isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
} // isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
// isPseudo = 1, isEHScopeReturn = 1
-// Below are instructions from the legacy EH proposal. Can be deprecated.
+// 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 {
>From 1df718692872e03a31e3e6db823f2c7eb5eb5fd9 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Wed, 4 Sep 2024 18:42:03 +0000
Subject: [PATCH 6/6] 80 col wrapping
---
llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
index dd068cce6b2ac0..dd40015577fd75 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
@@ -143,7 +143,8 @@ let isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
} // 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.
+// 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 {
More information about the llvm-commits
mailing list