Skip to content

Commit dcc0220

Browse files
aheejinPhilippRados
authored andcommitted
[WebAssembly] Fix comments in CFGStackify (NFC) (llvm#114362)
This fixes comments in CFGStackify and renames a variable to be clearer.
1 parent 06d0108 commit dcc0220

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,8 @@ static void unstackifyVRegsUsedInSplitBB(MachineBasicBlock &MBB,
10921092
}
10931093
}
10941094

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.
10971097
void WebAssemblyCFGStackify::addNestedTryDelegate(
10981098
MachineInstr *RangeBegin, MachineInstr *RangeEnd,
10991099
MachineBasicBlock *UnwindDest) {
@@ -1141,23 +1141,24 @@ void WebAssemblyCFGStackify::addNestedTryDelegate(
11411141
} else {
11421142
// When the split pos is in the middle of a BB, we split the BB into two and
11431143
// 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;
11491150
if (EndBB->isEHPad()) {
11501151
for (auto I = MachineBasicBlock::iterator(SplitPos), E = EndBB->end();
11511152
I != E; ++I) {
11521153
if (WebAssembly::isCatch(I->getOpcode())) {
1153-
PostSplit = false;
1154+
CatchAfterSplit = true;
11541155
break;
11551156
}
11561157
}
11571158
}
11581159

11591160
MachineBasicBlock *PreBB = nullptr, *PostBB = nullptr;
1160-
if (PostSplit) {
1161+
if (!CatchAfterSplit) {
11611162
// If the range's end instruction is in the middle of the BB, we split the
11621163
// BB into two and insert the delegate BB in between.
11631164
// - Before:
@@ -1208,7 +1209,7 @@ void WebAssemblyCFGStackify::addNestedTryDelegate(
12081209
PreBB->addSuccessor(PostBB);
12091210
}
12101211

1211-
// Add 'delegate' instruction in the delegate BB created above.
1212+
// Add a 'delegate' instruction in the delegate BB created above.
12121213
MachineInstr *Delegate = BuildMI(DelegateBB, RangeEnd->getDebugLoc(),
12131214
TII.get(WebAssembly::DELEGATE))
12141215
.addMBB(UnwindDest);
@@ -1243,7 +1244,7 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
12431244
// catch ;; N == 3
12441245
// end
12451246
// ;; N == 4 (to caller)
1246-
1247+
//
12471248
// 1. When an instruction may throw, but the EH pad it will unwind to can be
12481249
// different from the original CFG.
12491250
//
@@ -1272,9 +1273,9 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
12721273
// ...
12731274
// end_try
12741275
//
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
12781279
// 'catch'.
12791280
//
12801281
// try
@@ -1312,7 +1313,7 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
13121313
// ...
13131314
// end_try
13141315
//
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
13161317
// throw up to the caller. We solve this problem in the same way, but in this
13171318
// case 'delegate's immediate argument is the number of block depths + 1,
13181319
// which means it rethrows to the caller.
@@ -1336,7 +1337,7 @@ bool WebAssemblyCFGStackify::fixCallUnwindMismatches(MachineFunction &MF) {
13361337
// invoke within a BB.)
13371338

13381339
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
13401341
// exists in a single BB and does not span multiple BBs.
13411342
using TryRange = std::pair<MachineInstr *, MachineInstr *>;
13421343
// In original CFG, <unwind destination BB, a vector of try ranges>
@@ -1522,14 +1523,15 @@ bool WebAssemblyCFGStackify::fixCatchUnwindMismatches(MachineFunction &MF) {
15221523
// throws a foreign exception that is not caught by ehpad A, and its next
15231524
// destination should be the caller. But after control flow linearization,
15241525
// 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.
15291530
//
15301531
// There is no specific 'call' or 'throw' instruction to wrap with a
15311532
// 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:
15331535
// try
15341536
// try ;; (new)
15351537
// try

0 commit comments

Comments
 (0)