@@ -1092,8 +1092,8 @@ static void unstackifyVRegsUsedInSplitBB(MachineBasicBlock &MBB,
1092
1092
}
1093
1093
}
1094
1094
1095
- // Wrap the given range of instruction with try-delegate. RangeBegin and
1096
- // RangeEnd are inclusive.
1095
+ // Wrap the given range of instructions with a try-delegate that targets
1096
+ // 'UnwindDest'. RangeBegin and RangeEnd are inclusive.
1097
1097
void WebAssemblyCFGStackify::addNestedTryDelegate (
1098
1098
MachineInstr *RangeBegin, MachineInstr *RangeEnd,
1099
1099
MachineBasicBlock *UnwindDest) {
@@ -1141,23 +1141,24 @@ void WebAssemblyCFGStackify::addNestedTryDelegate(
1141
1141
} else {
1142
1142
// When the split pos is in the middle of a BB, we split the BB into two and
1143
1143
// put the 'delegate' BB in between. We normally create a split BB and make
1144
- // it a successor of the original BB (PostSplit == true), but in case the BB
1145
- // is an EH pad and the split pos is before 'catch', we should preserve the
1146
- // BB's property, including that it is an EH pad, in the later part of the
1147
- // BB, where 'catch' is. In this case we set PostSplit to false.
1148
- bool PostSplit = true ;
1144
+ // it a successor of the original BB (CatchAfterSplit == false), but in case
1145
+ // the BB is an EH pad and there is a 'catch' after the split pos
1146
+ // (CatchAfterSplit == true), we should preserve the BB's property,
1147
+ // including that it is an EH pad, in the later part of the BB, where the
1148
+ // 'catch' is.
1149
+ bool CatchAfterSplit = false ;
1149
1150
if (EndBB->isEHPad ()) {
1150
1151
for (auto I = MachineBasicBlock::iterator (SplitPos), E = EndBB->end ();
1151
1152
I != E; ++I) {
1152
1153
if (WebAssembly::isCatch (I->getOpcode ())) {
1153
- PostSplit = false ;
1154
+ CatchAfterSplit = true ;
1154
1155
break ;
1155
1156
}
1156
1157
}
1157
1158
}
1158
1159
1159
1160
MachineBasicBlock *PreBB = nullptr , *PostBB = nullptr ;
1160
- if (PostSplit ) {
1161
+ if (!CatchAfterSplit ) {
1161
1162
// If the range's end instruction is in the middle of the BB, we split the
1162
1163
// BB into two and insert the delegate BB in between.
1163
1164
// - Before:
@@ -1208,7 +1209,7 @@ void WebAssemblyCFGStackify::addNestedTryDelegate(
1208
1209
PreBB->addSuccessor (PostBB);
1209
1210
}
1210
1211
1211
- // Add 'delegate' instruction in the delegate BB created above.
1212
+ // Add a 'delegate' instruction in the delegate BB created above.
1212
1213
MachineInstr *Delegate = BuildMI (DelegateBB, RangeEnd->getDebugLoc (),
1213
1214
TII.get (WebAssembly::DELEGATE))
1214
1215
.addMBB (UnwindDest);
@@ -1243,7 +1244,7 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
1243
1244
// catch ;; N == 3
1244
1245
// end
1245
1246
// ;; N == 4 (to caller)
1246
-
1247
+ //
1247
1248
// 1. When an instruction may throw, but the EH pad it will unwind to can be
1248
1249
// different from the original CFG.
1249
1250
//
@@ -1272,9 +1273,9 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
1272
1273
// ...
1273
1274
// end_try
1274
1275
//
1275
- // Now if bar() throws, it is going to end up ip in bb2, not bb3, where it
1276
- // is supposed to end up. We solve this problem by wrapping the mismatching
1277
- // call with an inner try-delegate that rethrows the exception to the right
1276
+ // Now if bar() throws, it is going to end up in bb2, not bb3, where it is
1277
+ // supposed to end up. We solve this problem by wrapping the mismatching call
1278
+ // with an inner try-delegate that rethrows the exception to the right
1278
1279
// 'catch'.
1279
1280
//
1280
1281
// try
@@ -1312,7 +1313,7 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
1312
1313
// ...
1313
1314
// end_try
1314
1315
//
1315
- // Now if bar() throws, it is going to end up ip in bb2, when it is supposed
1316
+ // Now if bar() throws, it is going to end up in bb2, when it is supposed
1316
1317
// throw up to the caller. We solve this problem in the same way, but in this
1317
1318
// case 'delegate's immediate argument is the number of block depths + 1,
1318
1319
// which means it rethrows to the caller.
@@ -1336,7 +1337,7 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
1336
1337
// invoke within a BB.)
1337
1338
1338
1339
SmallVector<const MachineBasicBlock *, 8 > EHPadStack;
1339
- // Range of intructions to be wrapped in a new nested try/catch . A range
1340
+ // Range of intructions to be wrapped in a new nested try~delegate . A range
1340
1341
// exists in a single BB and does not span multiple BBs.
1341
1342
using TryRange = std::pair<MachineInstr *, MachineInstr *>;
1342
1343
// In original CFG, <unwind destination BB, a vector of try ranges>
@@ -1522,14 +1523,15 @@ bool WebAssemblyCFGStackify::fixCatchUnwindMismatches(MachineFunction &MF) {
1522
1523
// throws a foreign exception that is not caught by ehpad A, and its next
1523
1524
// destination should be the caller. But after control flow linearization,
1524
1525
// another EH pad can be placed in between (e.g. ehpad B here), making the
1525
- // next unwind destination incorrect. In this case, the foreign exception
1526
- // will instead go to ehpad B and will be caught there instead. In this
1527
- // example the correct next unwind destination is the caller, but it can be
1528
- // another outer catch in other cases.
1526
+ // next unwind destination incorrect. In this case, the foreign exception will
1527
+ // instead go to ehpad B and will be caught there instead. In this example the
1528
+ // correct next unwind destination is the caller, but it can be another outer
1529
+ // catch in other cases.
1529
1530
//
1530
1531
// There is no specific 'call' or 'throw' instruction to wrap with a
1531
1532
// try-delegate, so we wrap the whole try-catch-end with a try-delegate and
1532
- // make it rethrow to the right destination, as in the example below:
1533
+ // make it rethrow to the right destination, which is the caller in the
1534
+ // example below:
1533
1535
// try
1534
1536
// try ;; (new)
1535
1537
// try
0 commit comments