Skip to content

Commit aecbc92

Browse files
authored
[WebAssembly] Rename CATCH/CATCH_ALL to *_LEGACY (#107187)
This renames MIR instruction `CATCH` and `CATCH_ALL` to `CATCH_LEGACY` and `CATCH_ALL_LEGACY` respectively. 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 `_LEGACY` prefix to the old names. This also rearranges `WebAssemblyInstrControl.td` so that the old legacy instructions are listed all together at the end.
1 parent 9efe377 commit aecbc92

11 files changed

+66
-56
lines changed

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
166166
}
167167
return;
168168

169-
case WebAssembly::CATCH:
170-
case WebAssembly::CATCH_S:
171-
case WebAssembly::CATCH_ALL:
172-
case WebAssembly::CATCH_ALL_S:
169+
case WebAssembly::CATCH_LEGACY:
170+
case WebAssembly::CATCH_LEGACY_S:
171+
case WebAssembly::CATCH_ALL_LEGACY:
172+
case WebAssembly::CATCH_ALL_LEGACY_S:
173173
// There can be multiple catch instructions for one try instruction, so
174174
// we print a label only for the first 'catch' label.
175175
if (EHInstStack.empty()) {
176176
printAnnotation(OS, "try-catch mismatch!");
177-
} else if (EHInstStack.back() == CATCH_ALL) {
177+
} else if (EHInstStack.back() == CATCH_ALL_LEGACY) {
178178
printAnnotation(OS, "catch/catch_all cannot occur after catch_all");
179179
} else if (EHInstStack.back() == TRY) {
180180
if (TryStack.empty()) {
@@ -183,10 +183,11 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
183183
printAnnotation(OS, "catch" + utostr(TryStack.pop_back_val()) + ':');
184184
}
185185
EHInstStack.pop_back();
186-
if (Opc == WebAssembly::CATCH || Opc == WebAssembly::CATCH_S) {
187-
EHInstStack.push_back(CATCH);
186+
if (Opc == WebAssembly::CATCH_LEGACY ||
187+
Opc == WebAssembly::CATCH_LEGACY_S) {
188+
EHInstStack.push_back(CATCH_LEGACY);
188189
} else {
189-
EHInstStack.push_back(CATCH_ALL);
190+
EHInstStack.push_back(CATCH_ALL_LEGACY);
190191
}
191192
}
192193
return;

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class WebAssemblyInstPrinter final : public MCInstPrinter {
2828
SmallVector<std::pair<uint64_t, bool>, 4> ControlFlowStack;
2929
SmallVector<uint64_t, 4> TryStack;
3030

31-
enum EHInstKind { TRY, CATCH, CATCH_ALL };
31+
enum EHInstKind { TRY, CATCH_LEGACY, CATCH_ALL_LEGACY };
3232
SmallVector<EHInstKind, 4> EHInstStack;
3333

3434
public:

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ inline bool isMarker(unsigned Opc) {
470470

471471
inline bool isCatch(unsigned Opc) {
472472
switch (Opc) {
473-
case WebAssembly::CATCH:
474-
case WebAssembly::CATCH_S:
475-
case WebAssembly::CATCH_ALL:
476-
case WebAssembly::CATCH_ALL_S:
473+
case WebAssembly::CATCH_LEGACY:
474+
case WebAssembly::CATCH_LEGACY_S:
475+
case WebAssembly::CATCH_ALL_LEGACY:
476+
case WebAssembly::CATCH_ALL_LEGACY_S:
477477
return true;
478478
default:
479479
return false;

llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ bool WebAssemblyCFGStackify::fixCatchUnwindMismatches(MachineFunction &MF) {
13051305

13061306
// catch_all always catches an exception, so we don't need to do
13071307
// anything
1308-
if (MI.getOpcode() == WebAssembly::CATCH_ALL) {
1308+
if (MI.getOpcode() == WebAssembly::CATCH_ALL_LEGACY) {
13091309
}
13101310

13111311
// This can happen when the unwind dest was removed during the
@@ -1448,8 +1448,8 @@ void WebAssemblyCFGStackify::recalculateScopeTops(MachineFunction &MF) {
14481448
case WebAssembly::DELEGATE:
14491449
updateScopeTops(EndToBegin[&MI]->getParent(), &MBB);
14501450
break;
1451-
case WebAssembly::CATCH:
1452-
case WebAssembly::CATCH_ALL:
1451+
case WebAssembly::CATCH_LEGACY:
1452+
case WebAssembly::CATCH_ALL_LEGACY:
14531453
updateScopeTops(EHPadToTry[&MBB]->getParent(), &MBB);
14541454
break;
14551455
}
@@ -1698,8 +1698,8 @@ void WebAssemblyCFGStackify::rewriteDepthImmediates(MachineFunction &MF) {
16981698
Stack.push_back(std::make_pair(EndToBegin[&MI]->getParent(), &MI));
16991699
break;
17001700

1701-
case WebAssembly::CATCH:
1702-
case WebAssembly::CATCH_ALL:
1701+
case WebAssembly::CATCH_LEGACY:
1702+
case WebAssembly::CATCH_ALL_LEGACY:
17031703
EHPadStack.pop_back();
17041704
break;
17051705

llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void WebAssemblyDAGToDAGISel::Select(SDNode *Node) {
212212
int Tag = Node->getConstantOperandVal(2);
213213
SDValue SymNode = getTagSymNode(Tag, CurDAG);
214214
MachineSDNode *Catch =
215-
CurDAG->getMachineNode(WebAssembly::CATCH, DL,
215+
CurDAG->getMachineNode(WebAssembly::CATCH_LEGACY, DL,
216216
{
217217
PtrVT, // exception pointer
218218
MVT::Other // outchain type

llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,27 @@ defm DEBUG_UNREACHABLE : NRI<(outs), (ins), [(debugtrap)], "unreachable", 0x00>;
127127

128128
let Predicates = [HasExceptionHandling] in {
129129

130-
// Throwing an exception: throw / rethrow
130+
// Throwing an exception: throw
131131
let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
132132
defm THROW : I<(outs), (ins tag_op:$tag, variable_ops),
133133
(outs), (ins tag_op:$tag), [],
134134
"throw \t$tag", "throw \t$tag", 0x08>;
135+
} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
136+
137+
// Pseudo instructions: cleanupret / catchret
138+
let isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
139+
isPseudo = 1, isEHScopeReturn = 1 in {
140+
defm CLEANUPRET : NRI<(outs), (ins), [(cleanupret)], "cleanupret", 0>;
141+
defm CATCHRET : NRI<(outs), (ins bb_op:$dst, bb_op:$from),
142+
[(catchret bb:$dst, bb:$from)], "catchret", 0>;
143+
} // isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
144+
// isPseudo = 1, isEHScopeReturn = 1
145+
146+
// Below are instructions from the legacy EH proposal. Could be deprecated if
147+
// usage gets low enough.
148+
149+
// Rethrowing an exception: rethrow
150+
let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
135151
defm RETHROW : NRI<(outs), (ins i32imm:$depth), [], "rethrow \t$depth", 0x09>;
136152
} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
137153
// 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>;
147163
// Catching an exception: catch / catch_all
148164
let hasCtrlDep = 1, hasSideEffects = 1 in {
149165
let variadicOpsAreDefs = 1 in
150-
defm CATCH : I<(outs), (ins tag_op:$tag, variable_ops),
151-
(outs), (ins tag_op:$tag), [],
152-
"catch", "catch \t$tag", 0x07>;
153-
defm CATCH_ALL : NRI<(outs), (ins), [], "catch_all", 0x19>;
166+
defm CATCH_LEGACY : I<(outs), (ins tag_op:$tag, variable_ops),
167+
(outs), (ins tag_op:$tag), [],
168+
"catch", "catch \t$tag", 0x07>;
169+
defm CATCH_ALL_LEGACY : NRI<(outs), (ins), [], "catch_all", 0x19>;
154170
}
155171

156172
// Delegating an exception: delegate
157173
let isTerminator = 1, hasCtrlDep = 1, hasSideEffects = 1 in
158174
defm DELEGATE : NRI<(outs), (ins bb_op:$dst), [], "delegate \t $dst", 0x18>;
159175

160-
// Pseudo instructions: cleanupret / catchret
161-
let isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
162-
isPseudo = 1, isEHScopeReturn = 1 in {
163-
defm CLEANUPRET : NRI<(outs), (ins), [(cleanupret)], "cleanupret", 0>;
164-
defm CATCHRET : NRI<(outs), (ins bb_op:$dst, bb_op:$from),
165-
[(catchret bb:$dst, bb:$from)], "catchret", 0>;
166-
} // isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
167-
// isPseudo = 1, isEHScopeReturn = 1
168176
} // Predicates = [HasExceptionHandling]

llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ bool WebAssemblyLateEHPrepare::addCatchAlls(MachineFunction &MF) {
216216
Changed = true;
217217
BuildMI(MBB, InsertPos,
218218
InsertPos == MBB.end() ? DebugLoc() : InsertPos->getDebugLoc(),
219-
TII.get(WebAssembly::CATCH_ALL));
219+
TII.get(WebAssembly::CATCH_ALL_LEGACY));
220220
}
221221
}
222222
return Changed;

llvm/test/CodeGen/WebAssembly/cfg-stackify-eh-legacy.mir

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,23 @@ body: |
3131
bb.1 (landing-pad):
3232
successors: %bb.2
3333
; CHECK: bb.1 (landing-pad):
34-
; CHECK: CATCH
34+
; CHECK: CATCH_LEGACY
3535
; CHECK: TRY
36-
; This RETHROW rethrows the exception caught by this BB's CATCH, but after
37-
; CFGStackify a TRY is placed between the CATCH and this RETHROW, so after
38-
; CFGStackify its immediate argument should become not 0, but 1.
36+
; This RETHROW rethrows the exception caught by this BB's CATCH_LEGACY, but
37+
; after CFGStackify a TRY is placed between the CATCH_LEGACY and this
38+
; RETHROW, so after CFGStackify its immediate argument should become not 0,
39+
; but 1.
3940
; CHECK: RETHROW 1
4041
EH_LABEL <mcsymbol .Ltmp2>
41-
%0:i32 = CATCH &__cpp_exception, implicit-def dead $arguments
42+
%0:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments
4243
RETHROW 0, implicit-def dead $arguments
4344
4445
bb.2 (landing-pad):
4546
; CHECK: bb.2 (landing-pad):
46-
; CHECK: CATCH
47+
; CHECK: CATCH_LEGACY
4748
; CHECK: RETHROW 0
4849
EH_LABEL <mcsymbol .Ltmp3>
49-
%1:i32 = CATCH &__cpp_exception, implicit-def dead $arguments
50+
%1:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments
5051
RETHROW 0, implicit-def dead $arguments
5152
5253
bb.3:
@@ -78,13 +79,13 @@ body: |
7879
; CHECK: CALL @foo
7980
; CHECK: DELEGATE
8081
; CHECK: RETURN
81-
; CHECK: CATCH
82+
; CHECK: CATCH_LEGACY
8283
;; This TRY should have the return type i32 (127)
8384
; CHECK: TRY 127
8485
; CHECK: RETHROW
8586
; CHECK: DELEGATE
8687
; CHECK: END_TRY
87-
; CHECK: CATCH
88+
; CHECK: CATCH_LEGACY
8889
; CHECK: RETHROW
8990
; CHECK: END_TRY
9091
bb.0:
@@ -105,11 +106,11 @@ body: |
105106
106107
bb.3 (landing-pad):
107108
EH_LABEL <mcsymbol .Ltmp4>
108-
%0:i32 = CATCH &__cpp_exception, implicit-def dead $arguments
109+
%0:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments
109110
RETHROW 0, implicit-def dead $arguments
110111
111112
bb.4 (landing-pad):
112113
EH_LABEL <mcsymbol .Ltmp5>
113-
%1:i32 = CATCH &__cpp_exception, implicit-def dead $arguments
114+
%1:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments
114115
RETHROW 0, implicit-def dead $arguments
115116
...

llvm/test/CodeGen/WebAssembly/exception-legacy.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ body: |
4242
bb.1 (landing-pad):
4343
; predecessors: %bb.0
4444
successors: %bb.2
45-
; CATCH_ALL should be after EH_LABELs in the beginning of an EH pad.
45+
; CATCH_ALL_LEGACY should be after EH_LABELs in the beginning of an EH pad.
4646
; (Sometimes there are multiple EH_LABELs in an EH pad. This test tests
4747
; that.) GLOBAL_SET should follow right after that.
4848
; CHECK: bb.1
4949
; CHECK: EH_LABEL
5050
; CHECK: EH_LABEL
51-
; CHECK-NEXT: CATCH_ALL
51+
; CHECK-NEXT: CATCH_ALL_LEGACY
5252
; CHECK-NEXT: GLOBAL_SET_I32
5353
EH_LABEL <mcsymbol .Ltmp2>
5454
EH_LABEL <mcsymbol .Ltmp2>

llvm/test/CodeGen/WebAssembly/function-info.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ body: |
6161
6262
bb.2 (landing-pad):
6363
successors: %bb.1, %bb.3
64-
%0:i32 = CATCH &__cpp_exception, implicit-def dead $arguments
64+
%0:i32 = CATCH_LEGACY &__cpp_exception, implicit-def dead $arguments
6565
CALL @foo, implicit-def dead $arguments, implicit $sp32, implicit $sp64, implicit-def dead $arguments, implicit $sp32, implicit $sp64
6666
BR %bb.1, implicit-def $arguments
6767
6868
bb.3 (landing-pad):
69-
CATCH_ALL implicit-def $arguments
69+
CATCH_ALL_LEGACY implicit-def $arguments
7070
RETHROW 0, implicit-def $arguments
7171
...
7272

llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ body: |
101101
; predecessors: %bb.0
102102
successors: %bb.3, %bb.9
103103
liveins: $value_stack
104-
CATCH_ALL implicit-def $arguments
104+
CATCH_ALL_LEGACY implicit-def $arguments
105105
RETHROW 0, implicit-def dead $arguments
106106
107107
bb.3 (landing-pad):
108108
; predecessors: %bb.2
109109
successors: %bb.4, %bb.6
110110
liveins: $value_stack
111-
%1:i32 = CATCH &__cpp_exception, implicit-def $arguments
111+
%1:i32 = CATCH_LEGACY &__cpp_exception, implicit-def $arguments
112112
BR_IF %bb.4, %58:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack
113113
BR %bb.6, implicit-def $arguments
114114
@@ -139,13 +139,13 @@ body: |
139139
; predecessors: %bb.4
140140
successors: %bb.9
141141
liveins: $value_stack
142-
CATCH_ALL implicit-def $arguments
142+
CATCH_ALL_LEGACY implicit-def $arguments
143143
RETHROW 0, implicit-def dead $arguments
144144
145145
bb.9 (landing-pad):
146146
; predecessors: %bb.2, %bb.6, %bb.8
147147
liveins: $value_stack
148-
CATCH_ALL implicit-def $arguments
148+
CATCH_ALL_LEGACY implicit-def $arguments
149149
RETHROW 0, implicit-def dead $arguments
150150
151151
bb.10:
@@ -257,7 +257,7 @@ body: |
257257
; predecessors: %bb.0
258258
successors: %bb.2, %bb.8
259259
liveins: $value_stack
260-
%0:i32 = CATCH &__cpp_exception, implicit-def $arguments
260+
%0:i32 = CATCH_LEGACY &__cpp_exception, implicit-def $arguments
261261
BR_IF %bb.2, %32:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack
262262
BR %bb.8, implicit-def $arguments
263263
@@ -271,7 +271,7 @@ body: |
271271
; predecessors: %bb.2
272272
successors: %bb.4, %bb.6
273273
liveins: $value_stack
274-
%1:i32 = CATCH &__cpp_exception, implicit-def $arguments
274+
%1:i32 = CATCH_LEGACY &__cpp_exception, implicit-def $arguments
275275
BR_IF %bb.4, %43:i32, implicit-def $arguments, implicit-def $value_stack, implicit $value_stack
276276
BR %bb.6, implicit-def $arguments
277277
@@ -313,13 +313,13 @@ body: |
313313
; predecessors: %bb.4
314314
successors: %bb.11
315315
liveins: $value_stack
316-
CATCH_ALL implicit-def $arguments
316+
CATCH_ALL_LEGACY implicit-def $arguments
317317
RETHROW 0, implicit-def dead $arguments
318318
319319
bb.11 (landing-pad):
320320
; predecessors: %bb.2, %bb.6, %bb.10
321321
liveins: $value_stack
322-
CATCH_ALL implicit-def $arguments
322+
CATCH_ALL_LEGACY implicit-def $arguments
323323
RETHROW 0, implicit-def dead $arguments
324324
325325
bb.12:

0 commit comments

Comments
 (0)