Rip out support for 'llvm.noinline'. This thing has a strange history...
[oota-llvm.git] / lib / Transforms / IPO / InlineSimple.cpp
1 //===- InlineSimple.cpp - Code to perform simple function inlining --------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements bottom-up inlining of functions into callees.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "inline"
15 #include "llvm/CallingConv.h"
16 #include "llvm/Instructions.h"
17 #include "llvm/IntrinsicInst.h"
18 #include "llvm/Module.h"
19 #include "llvm/Type.h"
20 #include "llvm/Analysis/CallGraph.h"
21 #include "llvm/Analysis/InlineCost.h"
22 #include "llvm/Support/CallSite.h"
23 #include "llvm/Transforms/IPO.h"
24 #include "llvm/Transforms/IPO/InlinerPass.h"
25 #include "llvm/Target/TargetData.h"
26
27 using namespace llvm;
28
29 namespace {
30
31   class SimpleInliner : public Inliner {
32     InlineCostAnalyzer CA;
33   public:
34     SimpleInliner() : Inliner(ID) {
35       initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
36     }
37     SimpleInliner(int Threshold) : Inliner(ID, Threshold,
38                                            /*InsertLifetime*/true) {
39       initializeSimpleInlinerPass(*PassRegistry::getPassRegistry());
40     }
41     static char ID; // Pass identification, replacement for typeid
42     InlineCost getInlineCost(CallSite CS) {
43       return CA.getInlineCost(CS);
44     }
45     float getInlineFudgeFactor(CallSite CS) {
46       return CA.getInlineFudgeFactor(CS);
47     }
48     void resetCachedCostInfo(Function *Caller) {
49       CA.resetCachedCostInfo(Caller);
50     }
51     void growCachedCostInfo(Function* Caller, Function* Callee) {
52       CA.growCachedCostInfo(Caller, Callee);
53     }
54     virtual bool doInitialization(CallGraph &CG);
55     void releaseMemory() {
56       CA.clear();
57     }
58   };
59 }
60
61 char SimpleInliner::ID = 0;
62 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline",
63                 "Function Integration/Inlining", false, false)
64 INITIALIZE_AG_DEPENDENCY(CallGraph)
65 INITIALIZE_PASS_END(SimpleInliner, "inline",
66                 "Function Integration/Inlining", false, false)
67
68 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
69
70 Pass *llvm::createFunctionInliningPass(int Threshold) {
71   return new SimpleInliner(Threshold);
72 }
73
74 // doInitialization - Initializes the vector of functions that have been
75 // annotated with the noinline attribute.
76 bool SimpleInliner::doInitialization(CallGraph &CG) {
77   CA.setTargetData(getAnalysisIfAvailable<TargetData>());
78   return false;
79 }
80