diff options
author | Heejin Ahn <aheejin@gmail.com> | 2018-06-25 01:07:11 +0000 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2018-06-25 01:07:11 +0000 |
commit | 4934f76b58403059e810a4559dcbde27bfab65d4 (patch) | |
tree | 5634e7b743721663806483d28d752e1aa9be2a3d /llvm/lib/Target/WebAssembly/WebAssemblyExceptionPrepare.cpp | |
parent | 3b18bdc46d667c91f38f39b1d237119d1a473158 (diff) | |
download | bcm5719-llvm-4934f76b58403059e810a4559dcbde27bfab65d4.tar.gz bcm5719-llvm-4934f76b58403059e810a4559dcbde27bfab65d4.zip |
[WebAssembly] Add WebAssemblyLateEHPrepare pass
Summary:
Add WebAssemblyLateEHPrepare pass that does several small jobs for
exception handling. This runs before CFGSort, and is different from
WasmEHPrepare pass that runs before ISel, even though the names are
similar.
Reviewers: dschuff, majnemer
Subscribers: sbc100, jgravelle-google, sunfish, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D46803
llvm-svn: 335438
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyExceptionPrepare.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyExceptionPrepare.cpp | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyExceptionPrepare.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyExceptionPrepare.cpp deleted file mode 100644 index 837e9576c85..00000000000 --- a/llvm/lib/Target/WebAssembly/WebAssemblyExceptionPrepare.cpp +++ /dev/null @@ -1,88 +0,0 @@ -//=== WebAssemblyExceptionPrepare.cpp - WebAssembly Exception Preparation -===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// \brief Does various transformations for exception handling. -/// -//===----------------------------------------------------------------------===// - -#include "MCTargetDesc/WebAssemblyMCTargetDesc.h" -#include "WebAssembly.h" -#include "WebAssemblySubtarget.h" -#include "llvm/CodeGen/MachineInstrBuilder.h" -using namespace llvm; - -#define DEBUG_TYPE "wasm-exception-prepare" - -namespace { -class WebAssemblyExceptionPrepare final : public MachineFunctionPass { - StringRef getPassName() const override { - return "WebAssembly Prepare Exception"; - } - - bool runOnMachineFunction(MachineFunction &MF) override; - - bool replaceFuncletReturns(MachineFunction &MF); - -public: - static char ID; // Pass identification, replacement for typeid - WebAssemblyExceptionPrepare() : MachineFunctionPass(ID) {} -}; -} // end anonymous namespace - -char WebAssemblyExceptionPrepare::ID = 0; -INITIALIZE_PASS(WebAssemblyExceptionPrepare, DEBUG_TYPE, - "WebAssembly Exception Preparation", false, false) - -FunctionPass *llvm::createWebAssemblyExceptionPrepare() { - return new WebAssemblyExceptionPrepare(); -} - -bool WebAssemblyExceptionPrepare::runOnMachineFunction(MachineFunction &MF) { - bool Changed = false; - if (!MF.getFunction().hasPersonalityFn()) - return false; - Changed |= replaceFuncletReturns(MF); - // TODO More transformations will be added - return Changed; -} - -bool WebAssemblyExceptionPrepare::replaceFuncletReturns(MachineFunction &MF) { - bool Changed = false; - const auto &TII = *MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo(); - - for (auto &MBB : MF) { - auto Pos = MBB.getFirstTerminator(); - if (Pos == MBB.end()) - continue; - MachineInstr *TI = &*Pos; - - switch (TI->getOpcode()) { - case WebAssembly::CATCHRET: { - // Replace a catchret with a branch - MachineBasicBlock *TBB = TI->getOperand(0).getMBB(); - if (!MBB.isLayoutSuccessor(TBB)) - BuildMI(MBB, TI, TI->getDebugLoc(), TII.get(WebAssembly::BR)) - .addMBB(TBB); - TI->eraseFromParent(); - Changed = true; - break; - } - case WebAssembly::CLEANUPRET: { - // Replace a cleanupret with a rethrow - BuildMI(MBB, TI, TI->getDebugLoc(), TII.get(WebAssembly::RETHROW)) - .addImm(0); - TI->eraseFromParent(); - Changed = true; - break; - } - } - } - return Changed; -} |