Mercurial > hg > Members > tobaru > cbc > CbC_llvm
comparison lib/Transforms/IPO/InlineSimple.cpp @ 80:67baa08a3894
update to LLVM 3.6
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 25 Sep 2014 16:56:18 +0900 |
parents | 54457678186b |
children | 60c9769439b8 |
comparison
equal
deleted
inserted
replaced
76:9e74acfe8c42 | 80:67baa08a3894 |
---|---|
9 // | 9 // |
10 // This file implements bottom-up inlining of functions into callees. | 10 // This file implements bottom-up inlining of functions into callees. |
11 // | 11 // |
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 #define DEBUG_TYPE "inline" | |
15 #include "llvm/Transforms/IPO.h" | 14 #include "llvm/Transforms/IPO.h" |
15 #include "llvm/Analysis/AliasAnalysis.h" | |
16 #include "llvm/Analysis/AssumptionTracker.h" | |
16 #include "llvm/Analysis/CallGraph.h" | 17 #include "llvm/Analysis/CallGraph.h" |
17 #include "llvm/Analysis/InlineCost.h" | 18 #include "llvm/Analysis/InlineCost.h" |
19 #include "llvm/IR/CallSite.h" | |
18 #include "llvm/IR/CallingConv.h" | 20 #include "llvm/IR/CallingConv.h" |
19 #include "llvm/IR/DataLayout.h" | 21 #include "llvm/IR/DataLayout.h" |
20 #include "llvm/IR/Instructions.h" | 22 #include "llvm/IR/Instructions.h" |
21 #include "llvm/IR/IntrinsicInst.h" | 23 #include "llvm/IR/IntrinsicInst.h" |
22 #include "llvm/IR/Module.h" | 24 #include "llvm/IR/Module.h" |
23 #include "llvm/IR/Type.h" | 25 #include "llvm/IR/Type.h" |
24 #include "llvm/Support/CallSite.h" | |
25 #include "llvm/Transforms/IPO/InlinerPass.h" | 26 #include "llvm/Transforms/IPO/InlinerPass.h" |
26 | 27 |
27 using namespace llvm; | 28 using namespace llvm; |
29 | |
30 #define DEBUG_TYPE "inline" | |
28 | 31 |
29 namespace { | 32 namespace { |
30 | 33 |
31 /// \brief Actual inliner pass implementation. | 34 /// \brief Actual inliner pass implementation. |
32 /// | 35 /// |
35 /// analyses to determine when to inline. | 38 /// analyses to determine when to inline. |
36 class SimpleInliner : public Inliner { | 39 class SimpleInliner : public Inliner { |
37 InlineCostAnalysis *ICA; | 40 InlineCostAnalysis *ICA; |
38 | 41 |
39 public: | 42 public: |
40 SimpleInliner() : Inliner(ID), ICA(0) { | 43 SimpleInliner() : Inliner(ID), ICA(nullptr) { |
41 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); | 44 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); |
42 } | 45 } |
43 | 46 |
44 SimpleInliner(int Threshold) | 47 SimpleInliner(int Threshold) |
45 : Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(0) { | 48 : Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(nullptr) { |
46 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); | 49 initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); |
47 } | 50 } |
48 | 51 |
49 static char ID; // Pass identification, replacement for typeid | 52 static char ID; // Pass identification, replacement for typeid |
50 | 53 |
51 InlineCost getInlineCost(CallSite CS) { | 54 InlineCost getInlineCost(CallSite CS) override { |
52 return ICA->getInlineCost(CS, getInlineThreshold(CS)); | 55 return ICA->getInlineCost(CS, getInlineThreshold(CS)); |
53 } | 56 } |
54 | 57 |
55 virtual bool runOnSCC(CallGraphSCC &SCC); | 58 bool runOnSCC(CallGraphSCC &SCC) override; |
56 virtual void getAnalysisUsage(AnalysisUsage &AU) const; | 59 void getAnalysisUsage(AnalysisUsage &AU) const override; |
57 }; | 60 }; |
61 | |
62 static int computeThresholdFromOptLevels(unsigned OptLevel, | |
63 unsigned SizeOptLevel) { | |
64 if (OptLevel > 2) | |
65 return 275; | |
66 if (SizeOptLevel == 1) // -Os | |
67 return 75; | |
68 if (SizeOptLevel == 2) // -Oz | |
69 return 25; | |
70 return 225; | |
71 } | |
58 | 72 |
59 } // end anonymous namespace | 73 } // end anonymous namespace |
60 | 74 |
61 char SimpleInliner::ID = 0; | 75 char SimpleInliner::ID = 0; |
62 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", | 76 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", |
63 "Function Integration/Inlining", false, false) | 77 "Function Integration/Inlining", false, false) |
78 INITIALIZE_AG_DEPENDENCY(AliasAnalysis) | |
79 INITIALIZE_PASS_DEPENDENCY(AssumptionTracker) | |
64 INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass) | 80 INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass) |
65 INITIALIZE_PASS_DEPENDENCY(InlineCostAnalysis) | 81 INITIALIZE_PASS_DEPENDENCY(InlineCostAnalysis) |
66 INITIALIZE_PASS_END(SimpleInliner, "inline", | 82 INITIALIZE_PASS_END(SimpleInliner, "inline", |
67 "Function Integration/Inlining", false, false) | 83 "Function Integration/Inlining", false, false) |
68 | 84 |
70 | 86 |
71 Pass *llvm::createFunctionInliningPass(int Threshold) { | 87 Pass *llvm::createFunctionInliningPass(int Threshold) { |
72 return new SimpleInliner(Threshold); | 88 return new SimpleInliner(Threshold); |
73 } | 89 } |
74 | 90 |
91 Pass *llvm::createFunctionInliningPass(unsigned OptLevel, | |
92 unsigned SizeOptLevel) { | |
93 return new SimpleInliner( | |
94 computeThresholdFromOptLevels(OptLevel, SizeOptLevel)); | |
95 } | |
96 | |
75 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) { | 97 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) { |
76 ICA = &getAnalysis<InlineCostAnalysis>(); | 98 ICA = &getAnalysis<InlineCostAnalysis>(); |
77 return Inliner::runOnSCC(SCC); | 99 return Inliner::runOnSCC(SCC); |
78 } | 100 } |
79 | 101 |