Skip to content

Commit 210c437

Browse files
committed
handleLongjmpableCallsForWasmSjLj: simplify a bit
1 parent 9c21d8e commit 210c437

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ class WebAssemblyLowerEmscriptenEHSjLj final : public ModulePass {
353353
InstVector &SetjmpTableSizeInsts,
354354
SmallVectorImpl<PHINode *> &SetjmpRetPHIs);
355355
void
356-
handleLongjmpableCallsForWasmSjLj(Function &F, InstVector &SetjmpTableInsts,
356+
handleLongjmpableCallsForWasmSjLj(Function &F,
357+
Instruction *FunctionInvocationId,
357358
SmallVectorImpl<PHINode *> &SetjmpRetPHIs);
358359
Function *getFindMatchingCatch(Module &M, unsigned NumClauses);
359360

@@ -1309,14 +1310,14 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function &F) {
13091310

13101311
BinaryOperator *SetjmpTableSize;
13111312
Instruction *SetjmpTable;
1313+
Instruction *FunctionInvocationId;
13121314
if (EnableWasmSjLj) {
13131315
IRB.SetInsertPoint(Entry->getTerminator());
13141316
// This alloca'ed pointer is used by the runtime to identify function
13151317
// inovactions. It's just for pointer comparisons. It will never
13161318
// be dereferenced.
1317-
SetjmpTable = IRB.CreateAlloca(IRB.getInt32Ty());
1318-
SetjmpTable->setDebugLoc(FirstDL);
1319-
SetjmpTableInsts.push_back(SetjmpTable);
1319+
FunctionInvocationId = IRB.CreateAlloca(IRB.getInt32Ty());
1320+
FunctionInvocationId->setDebugLoc(FirstDL);
13201321
} else {
13211322
// This instruction effectively means %setjmpTableSize = 4.
13221323
// We create this as an instruction intentionally, and we don't want to fold
@@ -1411,7 +1412,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function &F) {
14111412
handleLongjmpableCallsForEmscriptenSjLj(
14121413
F, SetjmpTableInsts, SetjmpTableSizeInsts, SetjmpRetPHIs);
14131414
else // EnableWasmSjLj
1414-
handleLongjmpableCallsForWasmSjLj(F, SetjmpTableInsts, SetjmpRetPHIs);
1415+
handleLongjmpableCallsForWasmSjLj(F, FunctionInvocationId, SetjmpRetPHIs);
14151416

14161417
// Erase everything we no longer need in this function
14171418
for (Instruction *I : ToErase)
@@ -1705,7 +1706,7 @@ static BasicBlock *getCleanupRetUnwindDest(const CleanupPadInst *CPI) {
17051706
// BBs. Refer to 4) of "Wasm setjmp/longjmp handling" section in the comments at
17061707
// top of the file for details.
17071708
void WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj(
1708-
Function &F, InstVector &SetjmpTableInsts,
1709+
Function &F, Instruction *FunctionInvocationId,
17091710
SmallVectorImpl<PHINode *> &SetjmpRetPHIs) {
17101711
Module &M = *F.getParent();
17111712
LLVMContext &C = F.getContext();
@@ -1729,10 +1730,6 @@ void WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj(
17291730
DebugLoc FirstDL = getOrCreateDebugLoc(&*Entry->begin(), F.getSubprogram());
17301731
IRB.SetCurrentDebugLocation(FirstDL);
17311732

1732-
// Arbitrarily use the ones defined in the beginning of the function.
1733-
// SSAUpdater will later update them to the correct values.
1734-
Instruction *SetjmpTable = *SetjmpTableInsts.begin();
1735-
17361733
// Add setjmp.dispatch BB right after the entry block. Because we have
17371734
// initialized setjmpTable/setjmpTableSize in the entry block and split the
17381735
// rest into another BB, here 'OrigEntry' is the function's original entry
@@ -1777,14 +1774,14 @@ void WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj(
17771774
// int val = __wasm_longjmp_args.val;
17781775
Instruction *Val = IRB.CreateLoad(IRB.getInt32Ty(), ValField, "val");
17791776

1780-
// %label = testSetjmp(mem[%env], setjmpTable, setjmpTableSize);
1777+
// %label = __wasm_setjmp_test(%env, functionInvocatinoId);
17811778
// if (%label == 0)
17821779
// __wasm_longjmp(%env, %val)
17831780
// catchret to %setjmp.dispatch
17841781
BasicBlock *ThenBB = BasicBlock::Create(C, "if.then", &F);
17851782
BasicBlock *EndBB = BasicBlock::Create(C, "if.end", &F);
17861783
Value *EnvP = IRB.CreateBitCast(Env, getAddrPtrType(&M), "env.p");
1787-
Value *Label = IRB.CreateCall(TestSetjmpF, {EnvP, SetjmpTable},
1784+
Value *Label = IRB.CreateCall(TestSetjmpF, {EnvP, FunctionInvocationId},
17881785
OperandBundleDef("funclet", CatchPad), "label");
17891786
Value *Cmp = IRB.CreateICmpEQ(Label, IRB.getInt32(0));
17901787
IRB.CreateCondBr(Cmp, ThenBB, EndBB);

0 commit comments

Comments
 (0)