@@ -353,7 +353,8 @@ class WebAssemblyLowerEmscriptenEHSjLj final : public ModulePass {
353
353
InstVector &SetjmpTableSizeInsts,
354
354
SmallVectorImpl<PHINode *> &SetjmpRetPHIs);
355
355
void
356
- handleLongjmpableCallsForWasmSjLj (Function &F, InstVector &SetjmpTableInsts,
356
+ handleLongjmpableCallsForWasmSjLj (Function &F,
357
+ Instruction *FunctionInvocationId,
357
358
SmallVectorImpl<PHINode *> &SetjmpRetPHIs);
358
359
Function *getFindMatchingCatch (Module &M, unsigned NumClauses);
359
360
@@ -1309,14 +1310,14 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function &F) {
1309
1310
1310
1311
BinaryOperator *SetjmpTableSize;
1311
1312
Instruction *SetjmpTable;
1313
+ Instruction *FunctionInvocationId;
1312
1314
if (EnableWasmSjLj) {
1313
1315
IRB.SetInsertPoint (Entry->getTerminator ());
1314
1316
// This alloca'ed pointer is used by the runtime to identify function
1315
1317
// inovactions. It's just for pointer comparisons. It will never
1316
1318
// 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);
1320
1321
} else {
1321
1322
// This instruction effectively means %setjmpTableSize = 4.
1322
1323
// We create this as an instruction intentionally, and we don't want to fold
@@ -1411,7 +1412,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function &F) {
1411
1412
handleLongjmpableCallsForEmscriptenSjLj (
1412
1413
F, SetjmpTableInsts, SetjmpTableSizeInsts, SetjmpRetPHIs);
1413
1414
else // EnableWasmSjLj
1414
- handleLongjmpableCallsForWasmSjLj (F, SetjmpTableInsts , SetjmpRetPHIs);
1415
+ handleLongjmpableCallsForWasmSjLj (F, FunctionInvocationId , SetjmpRetPHIs);
1415
1416
1416
1417
// Erase everything we no longer need in this function
1417
1418
for (Instruction *I : ToErase)
@@ -1705,7 +1706,7 @@ static BasicBlock *getCleanupRetUnwindDest(const CleanupPadInst *CPI) {
1705
1706
// BBs. Refer to 4) of "Wasm setjmp/longjmp handling" section in the comments at
1706
1707
// top of the file for details.
1707
1708
void WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj (
1708
- Function &F, InstVector &SetjmpTableInsts ,
1709
+ Function &F, Instruction *FunctionInvocationId ,
1709
1710
SmallVectorImpl<PHINode *> &SetjmpRetPHIs) {
1710
1711
Module &M = *F.getParent ();
1711
1712
LLVMContext &C = F.getContext ();
@@ -1729,10 +1730,6 @@ void WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj(
1729
1730
DebugLoc FirstDL = getOrCreateDebugLoc (&*Entry->begin (), F.getSubprogram ());
1730
1731
IRB.SetCurrentDebugLocation (FirstDL);
1731
1732
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
-
1736
1733
// Add setjmp.dispatch BB right after the entry block. Because we have
1737
1734
// initialized setjmpTable/setjmpTableSize in the entry block and split the
1738
1735
// rest into another BB, here 'OrigEntry' is the function's original entry
@@ -1777,14 +1774,14 @@ void WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj(
1777
1774
// int val = __wasm_longjmp_args.val;
1778
1775
Instruction *Val = IRB.CreateLoad (IRB.getInt32Ty (), ValField, " val" );
1779
1776
1780
- // %label = testSetjmp(mem[ %env], setjmpTable, setjmpTableSize );
1777
+ // %label = __wasm_setjmp_test( %env, functionInvocatinoId );
1781
1778
// if (%label == 0)
1782
1779
// __wasm_longjmp(%env, %val)
1783
1780
// catchret to %setjmp.dispatch
1784
1781
BasicBlock *ThenBB = BasicBlock::Create (C, " if.then" , &F);
1785
1782
BasicBlock *EndBB = BasicBlock::Create (C, " if.end" , &F);
1786
1783
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 },
1788
1785
OperandBundleDef (" funclet" , CatchPad), " label" );
1789
1786
Value *Cmp = IRB.CreateICmpEQ (Label, IRB.getInt32 (0 ));
1790
1787
IRB.CreateCondBr (Cmp, ThenBB, EndBB);
0 commit comments