diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-12-27 03:02:22 -0800 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2021-01-11 17:54:28 -0800 |
commit | 9f8b25769efa409ffc3b85f1c8043d2fcb4f185e (patch) | |
tree | 75e1c3bf622cc910ec6df6704c6a6bd966787996 /llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp | |
parent | 70474dfebcd9babf2e3af5fb002b40417fd6cf88 (diff) | |
download | llvm-9f8b25769efa409ffc3b85f1c8043d2fcb4f185e.zip llvm-9f8b25769efa409ffc3b85f1c8043d2fcb4f185e.tar.gz llvm-9f8b25769efa409ffc3b85f1c8043d2fcb4f185e.tar.bz2 |
[WebAssembly] Ensure terminate pads are a single BB
This ensures every single terminate pad is a single BB in the form of:
```
%exn = catch $__cpp_exception
call @__clang_call_terminate(%exn)
unreachable
```
This is a preparation for HandleEHTerminatePads pass, which will be
added in a later CL and will run after CFGStackify. That pass duplicates
terminate pads with a `catch_all` instruction, and duplicating it
becomes simpler if we can ensure every terminate pad is a single BB.
Reviewed By: dschuff, tlively
Differential Revision: https://reviews.llvm.org/D94045
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp index 7a56c58..dbf0f92 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp @@ -178,27 +178,6 @@ getLatestInsertPos(MachineBasicBlock *MBB, return InsertPos; } -// Find a catch instruction and its destination register within an EH pad. -static MachineInstr *findCatch(MachineBasicBlock *EHPad, Register &ExnReg) { - assert(EHPad->isEHPad()); - MachineInstr *Catch = nullptr; - for (auto &MI : *EHPad) { - if (WebAssembly::isCatch(MI.getOpcode())) { - Catch = &MI; - ExnReg = Catch->getOperand(0).getReg(); - break; - } - } - assert(Catch && "EH pad does not have a catch"); - assert(ExnReg != 0 && "Invalid register"); - return Catch; -} - -static MachineInstr *findCatch(MachineBasicBlock *EHPad) { - Register Dummy; - return findCatch(EHPad, Dummy); -} - void WebAssemblyCFGStackify::registerScope(MachineInstr *Begin, MachineInstr *End) { BeginToEnd[Begin] = End; @@ -874,7 +853,10 @@ void WebAssemblyCFGStackify::fixEndsAtEndOfFunction(MachineFunction &MF) { // instructions before its corresponding 'catch' too. auto *EHPad = TryToEHPad.lookup(EndToBegin[&MI]); assert(EHPad); - Worklist.push_back(std::next(findCatch(EHPad)->getReverseIterator())); + auto NextIt = + std::next(WebAssembly::findCatch(EHPad)->getReverseIterator()); + if (NextIt != EHPad->rend()) + Worklist.push_back(NextIt); LLVM_FALLTHROUGH; } case WebAssembly::END_BLOCK: |