llvm.org GIT mirror llvm / 69f0407
[PM] Port LowerInvoke to the new pass manager git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278531 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Kuperstein 3 years ago
7 changed file(s) with 67 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
204204 void initializeLowerExpectIntrinsicPass(PassRegistry&);
205205 void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry&);
206206 void initializeLowerIntrinsicsPass(PassRegistry&);
207 void initializeLowerInvokePass(PassRegistry&);
207 void initializeLowerInvokeLegacyPassPass(PassRegistry&);
208208 void initializeLowerSwitchPass(PassRegistry&);
209209 void initializeLowerTypeTestsPass(PassRegistry&);
210210 void initializeMIRPrintingPassPass(PassRegistry&);
0 //===- LowerInvoke.h - Eliminate Invoke instructions ----------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This transformation is designed for use by code generators which do not yet
10 // support stack unwinding. This pass converts 'invoke' instructions to 'call'
11 // instructions, so that any exception-handling 'landingpad' blocks become dead
12 // code (which can be removed by running the '-simplifycfg' pass afterwards).
13 //
14 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_UTILS_LOWERINVOKE_H
16 #define LLVM_TRANSFORMS_UTILS_LOWERINVOKE_H
17
18 #include "llvm/IR/PassManager.h"
19
20 namespace llvm {
21
22 class LowerInvokePass : public PassInfoMixin {
23 public:
24 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
25 };
26
27 }
28
29 #endif // LLVM_TRANSFORMS_UTILS_LOWERINVOKE_H
118118 #include "llvm/Transforms/Utils/BreakCriticalEdges.h"
119119 #include "llvm/Transforms/Utils/LCSSA.h"
120120 #include "llvm/Transforms/Utils/LoopSimplify.h"
121 #include "llvm/Transforms/Utils/LowerInvoke.h"
121122 #include "llvm/Transforms/Utils/Mem2Reg.h"
122123 #include "llvm/Transforms/Utils/MemorySSA.h"
123124 #include "llvm/Transforms/Utils/NameAnonFunctions.h"
150150 FUNCTION_PASS("guard-widening", GuardWideningPass())
151151 FUNCTION_PASS("gvn", GVN())
152152 FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
153 FUNCTION_PASS("lowerinvoke", LowerInvokePass())
153154 FUNCTION_PASS("mem2reg", PromotePass())
154155 FUNCTION_PASS("memcpyopt", MemCpyOptPass())
155156 FUNCTION_PASS("mldst-motion", MergedLoadStoreMotionPass())
1313 //
1414 //===----------------------------------------------------------------------===//
1515
16 #include "llvm/Transforms/Utils/LowerInvoke.h"
1617 #include "llvm/ADT/SmallVector.h"
1718 #include "llvm/ADT/Statistic.h"
1819 #include "llvm/IR/Instructions.h"
2728 STATISTIC(NumInvokes, "Number of invokes replaced");
2829
2930 namespace {
30 class LowerInvoke : public FunctionPass {
31 class LowerInvokeLegacyPass : public FunctionPass {
3132 public:
3233 static char ID; // Pass identification, replacement for typeid
33 explicit LowerInvoke() : FunctionPass(ID) {
34 initializeLowerInvokePass(*PassRegistry::getPassRegistry());
34 explicit LowerInvokeLegacyPass() : FunctionPass(ID) {
35 initializeLowerInvokeLegacyPassPass(*PassRegistry::getPassRegistry());
3536 }
3637 bool runOnFunction(Function &F) override;
3738 };
3839 }
3940
40 char LowerInvoke::ID = 0;
41 INITIALIZE_PASS(LowerInvoke, "lowerinvoke",
41 char LowerInvokeLegacyPass::ID = 0;
42 INITIALIZE_PASS(LowerInvokeLegacyPass, "lowerinvoke",
4243 "Lower invoke and unwind, for unwindless code generators",
4344 false, false)
4445
45 char &llvm::LowerInvokePassID = LowerInvoke::ID;
46
47 // Public Interface To the LowerInvoke pass.
48 FunctionPass *llvm::createLowerInvokePass() {
49 return new LowerInvoke();
50 }
51
52 bool LowerInvoke::runOnFunction(Function &F) {
46 static bool runImpl(Function &F) {
5347 bool Changed = false;
5448 for (BasicBlock &BB : F)
5549 if (InvokeInst *II = dyn_cast(BB.getTerminator())) {
56 SmallVector*,16> CallArgs(II->op_begin(), II->op_end() - 3);
50 SmallVector *, 16> CallArgs(II->op_begin(), II->op_end() - 3);
5751 // Insert a normal call instruction...
58 CallInst *NewCall = CallInst::Create(II->getCalledValue(),
59 CallArgs, "", II);
52 CallInst *NewCall =
53 CallInst::Create(II->getCalledValue(), CallArgs, "", II);
6054 NewCall->takeName(II);
6155 NewCall->setCallingConv(II->getCallingConv());
6256 NewCall->setAttributes(II->getAttributes());
7266 // Remove the invoke instruction now.
7367 BB.getInstList().erase(II);
7468
75 ++NumInvokes; Changed = true;
69 ++NumInvokes;
70 Changed = true;
7671 }
7772 return Changed;
7873 }
74
75 bool LowerInvokeLegacyPass::runOnFunction(Function &F) {
76 return runImpl(F);
77 }
78
79 namespace llvm {
80 char &LowerInvokePassID = LowerInvokeLegacyPass::ID;
81
82 // Public Interface To the LowerInvoke pass.
83 FunctionPass *createLowerInvokePass() { return new LowerInvokeLegacyPass(); }
84
85 PreservedAnalyses LowerInvokePass::run(Function &F,
86 FunctionAnalysisManager &AM) {
87 bool Changed = runImpl(F);
88 if (!Changed)
89 return PreservedAnalyses::all();
90
91 return PreservedAnalyses::none();
92 }
93 }
2525 initializeInstNamerPass(Registry);
2626 initializeLCSSAWrapperPassPass(Registry);
2727 initializeLoopSimplifyPass(Registry);
28 initializeLowerInvokePass(Registry);
28 initializeLowerInvokeLegacyPassPass(Registry);
2929 initializeLowerSwitchPass(Registry);
3030 initializeNameAnonFunctionLegacyPassPass(Registry);
3131 initializePromoteLegacyPassPass(Registry);
0 ; RUN: opt < %s -lowerinvoke -S | FileCheck %s
1 ; RUN: opt < %s -passes='lowerinvoke' -S | FileCheck %s
12
23 declare i32 @external_func(i64 %arg)
34