[PATCH] D58474: [WebAssembly] Fix WasmEHInfo updating in LateEHPrepare
Heejin Ahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 20 13:37:25 PST 2019
aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: llvm-commits, sunfish, jgravelle-google, sbc100.
Herald added a project: LLVM.
When adding a 'br_on_exn' instruction, we transform code as follows:
- Before:
ehpad:
%exnref:except_ref = catch
%exn:i32 = extract_exception
...
call @foo() // can throw
- After:
ehpad:
%exnref:except_ref = catch
br_on_exn %thenbb, $__cpp_exception, %exnref
br %elsebb
elsebb:
rethrow
thenbb:
%exn:i32 = extract_exception
...
call @foo() // can throw
So if an ehpad ends with an instruction that can throw, there is a
ThrowUnwindDest mapping of <ehpad, otherbb>, which means if an
instruction in 'ehpad' throws it should go to 'otherbb'. In that case,
we should've updated it to <thenbb, otherbb>. This fixes the bug, and
also adds member functions to erase mappings in WasmEHFuncInfo.
It's hard to add a test for this because target-specific
MachineFunctionInfo is not serialized at the moment.
Repository:
rL LLVM
https://reviews.llvm.org/D58474
Files:
include/llvm/CodeGen/WasmEHFuncInfo.h
lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
Index: lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
+++ lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
@@ -289,6 +289,11 @@
.addReg(ExnRefReg);
BuildMI(EHPad, DL, TII.get(WebAssembly::BR)).addMBB(ElseMBB);
+ if (EHInfo->hasThrowUnwindDest(EHPad)) {
+ EHInfo->setThrowUnwindDest(ThenMBB, EHInfo->getThrowUnwindDest(EHPad));
+ EHInfo->eraseThrowUnwindDest(EHPad);
+ }
+
// When this is a terminate pad with __clang_call_terminate() call, we don't
// rethrow it anymore and call __clang_call_terminate() with a nullptr
// argument, which will call std::terminate().
@@ -325,8 +330,11 @@
} else {
BuildMI(ElseMBB, DL, TII.get(WebAssembly::RETHROW));
- if (EHInfo->hasEHPadUnwindDest(EHPad))
- EHInfo->setThrowUnwindDest(ElseMBB, EHInfo->getEHPadUnwindDest(EHPad));
+ if (EHInfo->hasEHPadUnwindDest(EHPad)) {
+ auto *DestMBB = EHInfo->getEHPadUnwindDest(EHPad);
+ EHInfo->setThrowUnwindDest(ElseMBB, DestMBB);
+ ElseMBB->addSuccessor(DestMBB);
+ }
}
}
Index: include/llvm/CodeGen/WasmEHFuncInfo.h
===================================================================
--- include/llvm/CodeGen/WasmEHFuncInfo.h
+++ include/llvm/CodeGen/WasmEHFuncInfo.h
@@ -52,6 +52,12 @@
bool hasThrowUnwindDest(const BasicBlock *BB) const {
return ThrowUnwindMap.count(BB);
}
+ void eraseEHPadUnwindDest(const BasicBlock *BB) {
+ EHPadUnwindMap.erase(BB);
+ }
+ void eraseThrowUnwindDest(const BasicBlock *BB) {
+ ThrowUnwindMap.erase(BB);
+ }
MachineBasicBlock *getEHPadUnwindDest(MachineBasicBlock *MBB) const {
return EHPadUnwindMap.lookup(MBB).get<MachineBasicBlock *>();
@@ -71,6 +77,12 @@
bool hasThrowUnwindDest(MachineBasicBlock *MBB) const {
return ThrowUnwindMap.count(MBB);
}
+ void eraseEHPadUnwindDest(MachineBasicBlock *MBB) {
+ EHPadUnwindMap.erase(MBB);
+ }
+ void eraseThrowUnwindDest(MachineBasicBlock *MBB) {
+ ThrowUnwindMap.erase(MBB);
+ }
};
// Analyze the IR in the given function to build WasmEHFuncInfo.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58474.187665.patch
Type: text/x-patch
Size: 2211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190220/931a2fb2/attachment.bin>
More information about the llvm-commits
mailing list