comparison lib/Transforms/IPO/InlineAlways.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
10 // This file implements a custom inliner that handles only functions that 10 // This file implements a custom inliner that handles only functions that
11 // are marked as "always inline". 11 // are marked as "always inline".
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #define DEBUG_TYPE "inline"
16 #include "llvm/Transforms/IPO.h" 15 #include "llvm/Transforms/IPO.h"
17 #include "llvm/ADT/SmallPtrSet.h" 16 #include "llvm/ADT/SmallPtrSet.h"
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/Analysis/AssumptionTracker.h"
18 #include "llvm/Analysis/CallGraph.h" 19 #include "llvm/Analysis/CallGraph.h"
19 #include "llvm/Analysis/InlineCost.h" 20 #include "llvm/Analysis/InlineCost.h"
21 #include "llvm/IR/CallSite.h"
20 #include "llvm/IR/CallingConv.h" 22 #include "llvm/IR/CallingConv.h"
21 #include "llvm/IR/DataLayout.h" 23 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/Instructions.h" 24 #include "llvm/IR/Instructions.h"
23 #include "llvm/IR/IntrinsicInst.h" 25 #include "llvm/IR/IntrinsicInst.h"
24 #include "llvm/IR/Module.h" 26 #include "llvm/IR/Module.h"
25 #include "llvm/IR/Type.h" 27 #include "llvm/IR/Type.h"
26 #include "llvm/Support/CallSite.h"
27 #include "llvm/Transforms/IPO/InlinerPass.h" 28 #include "llvm/Transforms/IPO/InlinerPass.h"
28 29
29 using namespace llvm; 30 using namespace llvm;
31
32 #define DEBUG_TYPE "inline"
30 33
31 namespace { 34 namespace {
32 35
33 /// \brief Inliner pass which only handles "always inline" functions. 36 /// \brief Inliner pass which only handles "always inline" functions.
34 class AlwaysInliner : public Inliner { 37 class AlwaysInliner : public Inliner {
35 InlineCostAnalysis *ICA; 38 InlineCostAnalysis *ICA;
36 39
37 public: 40 public:
38 // Use extremely low threshold. 41 // Use extremely low threshold.
39 AlwaysInliner() : Inliner(ID, -2000000000, /*InsertLifetime*/ true), ICA(0) { 42 AlwaysInliner() : Inliner(ID, -2000000000, /*InsertLifetime*/ true),
43 ICA(nullptr) {
40 initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry()); 44 initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry());
41 } 45 }
42 46
43 AlwaysInliner(bool InsertLifetime) 47 AlwaysInliner(bool InsertLifetime)
44 : Inliner(ID, -2000000000, InsertLifetime), ICA(0) { 48 : Inliner(ID, -2000000000, InsertLifetime), ICA(nullptr) {
45 initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry()); 49 initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry());
46 } 50 }
47 51
48 static char ID; // Pass identification, replacement for typeid 52 static char ID; // Pass identification, replacement for typeid
49 53
50 virtual InlineCost getInlineCost(CallSite CS); 54 InlineCost getInlineCost(CallSite CS) override;
51 55
52 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 56 void getAnalysisUsage(AnalysisUsage &AU) const override;
53 virtual bool runOnSCC(CallGraphSCC &SCC); 57 bool runOnSCC(CallGraphSCC &SCC) override;
54 58
55 using llvm::Pass::doFinalization; 59 using llvm::Pass::doFinalization;
56 virtual bool doFinalization(CallGraph &CG) { 60 bool doFinalization(CallGraph &CG) override {
57 return removeDeadFunctions(CG, /*AlwaysInlineOnly=*/ true); 61 return removeDeadFunctions(CG, /*AlwaysInlineOnly=*/ true);
58 } 62 }
59 }; 63 };
60 64
61 } 65 }
62 66
63 char AlwaysInliner::ID = 0; 67 char AlwaysInliner::ID = 0;
64 INITIALIZE_PASS_BEGIN(AlwaysInliner, "always-inline", 68 INITIALIZE_PASS_BEGIN(AlwaysInliner, "always-inline",
65 "Inliner for always_inline functions", false, false) 69 "Inliner for always_inline functions", false, false)
70 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
71 INITIALIZE_PASS_DEPENDENCY(AssumptionTracker)
66 INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass) 72 INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
67 INITIALIZE_PASS_DEPENDENCY(InlineCostAnalysis) 73 INITIALIZE_PASS_DEPENDENCY(InlineCostAnalysis)
68 INITIALIZE_PASS_END(AlwaysInliner, "always-inline", 74 INITIALIZE_PASS_END(AlwaysInliner, "always-inline",
69 "Inliner for always_inline functions", false, false) 75 "Inliner for always_inline functions", false, false)
70 76
91 97
92 // Only inline direct calls to functions with always-inline attributes 98 // Only inline direct calls to functions with always-inline attributes
93 // that are viable for inlining. FIXME: We shouldn't even get here for 99 // that are viable for inlining. FIXME: We shouldn't even get here for
94 // declarations. 100 // declarations.
95 if (Callee && !Callee->isDeclaration() && 101 if (Callee && !Callee->isDeclaration() &&
96 Callee->getAttributes().hasAttribute(AttributeSet::FunctionIndex, 102 CS.hasFnAttr(Attribute::AlwaysInline) &&
97 Attribute::AlwaysInline) &&
98 ICA->isInlineViable(*Callee)) 103 ICA->isInlineViable(*Callee))
99 return InlineCost::getAlways(); 104 return InlineCost::getAlways();
100 105
101 return InlineCost::getNever(); 106 return InlineCost::getNever();
102 } 107 }