[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)
Heejin Ahn via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 8 23:26:24 PST 2024
================
@@ -1291,19 +1327,29 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function &F) {
Type *IntPtrTy = getAddrIntType(&M);
Constant *size = ConstantInt::get(IntPtrTy, 40);
IRB.SetInsertPoint(SetjmpTableSize);
- auto *SetjmpTable = IRB.CreateMalloc(IntPtrTy, IRB.getInt32Ty(), size,
- nullptr, nullptr, "setjmpTable");
- SetjmpTable->setDebugLoc(FirstDL);
- // CallInst::CreateMalloc may return a bitcast instruction if the result types
- // mismatch. We need to set the debug loc for the original call too.
- auto *MallocCall = SetjmpTable->stripPointerCasts();
- if (auto *MallocCallI = dyn_cast<Instruction>(MallocCall)) {
- MallocCallI->setDebugLoc(FirstDL);
+ Instruction *SetjmpTable;
+ if (EnableWasmAltSjLj) {
+ // This alloca'ed pointer is used by the runtime to identify function
+ // inovactions. It's just for pointer comparisons. It will never
+ // be dereferenced.
+ SetjmpTable = IRB.CreateAlloca(IRB.getInt32Ty());
+ SetjmpTable->setDebugLoc(FirstDL);
+ SetjmpTableInsts.push_back(SetjmpTable);
+ } else {
----------------
aheejin wrote:
https://github.com/llvm/llvm-project/blob/578e66ac45dfcc5c739f3525bfb82d71282d925c/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp#L1278-L1293
This can be moved into this `else` part too. Also we don't need to create `SetjmpTableSize`, in which case we should do something like `IRB.setInsertPoint(Entry.getTerminator()` instead.
https://github.com/llvm/llvm-project/pull/84137
More information about the cfe-commits
mailing list