LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InlineSimple.cpp
Go to the documentation of this file.
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/Transforms/IPO.h"
18 #include "llvm/IR/CallingConv.h"
19 #include "llvm/IR/DataLayout.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/IR/IntrinsicInst.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/IR/Type.h"
24 #include "llvm/Support/CallSite.h"
26 
27 using namespace llvm;
28 
29 namespace {
30 
31 /// \brief Actual inliner pass implementation.
32 ///
33 /// The common implementation of the inlining logic is shared between this
34 /// inliner pass and the always inliner pass. The two passes use different cost
35 /// analyses to determine when to inline.
36 class SimpleInliner : public Inliner {
37  InlineCostAnalysis *ICA;
38 
39 public:
40  SimpleInliner() : Inliner(ID), ICA(0) {
42  }
43 
44  SimpleInliner(int Threshold)
45  : Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(0) {
47  }
48 
49  static char ID; // Pass identification, replacement for typeid
50 
51  InlineCost getInlineCost(CallSite CS) {
52  return ICA->getInlineCost(CS, getInlineThreshold(CS));
53  }
54 
55  virtual bool runOnSCC(CallGraphSCC &SCC);
56  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
57 };
58 
59 } // end anonymous namespace
60 
61 char SimpleInliner::ID = 0;
62 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline",
63  "Function Integration/Inlining", false, false)
66 INITIALIZE_PASS_END(SimpleInliner, "inline",
67  "Function Integration/Inlining", false, false)
68 
69 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
70 
72  return new SimpleInliner(Threshold);
73 }
74 
75 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
76  ICA = &getAnalysis<InlineCostAnalysis>();
77  return Inliner::runOnSCC(SCC);
78 }
79 
80 void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
83 }
static PassRegistry * getPassRegistry()
Function Integration Inlining
void initializeSimpleInlinerPass(PassRegistry &)
Represents the cost of inlining a function.
Definition: InlineCost.h:50
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:167
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:172
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
inline
Cost analyzer used by inliner.
Definition: InlineCost.h:101
Function Integration false
virtual void getAnalysisUsage(AnalysisUsage &Info) const
Definition: Inliner.cpp:67
static int const Threshold
Pass * createFunctionInliningPass()
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
virtual bool runOnSCC(CallGraphSCC &SCC)
Definition: Inliner.cpp:397
INITIALIZE_PASS_BEGIN(SimpleInliner,"inline","Function Integration/Inlining", false, false) INITIALIZE_PASS_END(SimpleInliner