LLVM  3.7.0
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 #include "llvm/Transforms/IPO.h"
19 #include "llvm/IR/CallSite.h"
20 #include "llvm/IR/CallingConv.h"
21 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/Instructions.h"
23 #include "llvm/IR/IntrinsicInst.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/IR/Type.h"
27 
28 using namespace llvm;
29 
30 #define DEBUG_TYPE "inline"
31 
32 namespace {
33 
34 /// \brief Actual inliner pass implementation.
35 ///
36 /// The common implementation of the inlining logic is shared between this
37 /// inliner pass and the always inliner pass. The two passes use different cost
38 /// analyses to determine when to inline.
39 class SimpleInliner : public Inliner {
40  InlineCostAnalysis *ICA;
41 
42 public:
43  SimpleInliner() : Inliner(ID), ICA(nullptr) {
45  }
46 
47  SimpleInliner(int Threshold)
48  : Inliner(ID, Threshold, /*InsertLifetime*/ true), ICA(nullptr) {
50  }
51 
52  static char ID; // Pass identification, replacement for typeid
53 
54  InlineCost getInlineCost(CallSite CS) override {
55  return ICA->getInlineCost(CS, getInlineThreshold(CS));
56  }
57 
58  bool runOnSCC(CallGraphSCC &SCC) override;
59  void getAnalysisUsage(AnalysisUsage &AU) const override;
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 }
72 
73 } // end anonymous namespace
74 
75 char SimpleInliner::ID = 0;
76 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline",
77  "Function Integration/Inlining", false, false)
82 INITIALIZE_PASS_END(SimpleInliner, "inline",
83  "Function Integration/Inlining", false, false)
84 
85 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
86 
88  return new SimpleInliner(Threshold);
89 }
90 
92  unsigned SizeOptLevel) {
93  return new SimpleInliner(
94  computeThresholdFromOptLevels(OptLevel, SizeOptLevel));
95 }
96 
97 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
98  ICA = &getAnalysis<InlineCostAnalysis>();
99  return Inliner::runOnSCC(SCC);
100 }
101 
102 void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
105 }
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:82
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Function Integration Inlining
void initializeSimpleInlinerPass(PassRegistry &)
An immutable pass that tracks lazily created AssumptionCache objects.
Represents the cost of inlining a function.
Definition: InlineCost.h:51
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:70
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:75
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
Definition: Inliner.cpp:78
inline
Inliner - This class contains all of the helper code which is used to perform the inlining operations...
Definition: InlinerPass.h:32
The ModulePass which wraps up a CallGraph and the logic to build it.
Definition: CallGraph.h:316
Cost analyzer used by inliner.
Definition: InlineCost.h:102
Represent the analysis usage information of a pass.
Function Integration false
#define INITIALIZE_AG_DEPENDENCY(depName)
Definition: PassSupport.h:72
bool runOnSCC(CallGraphSCC &SCC) override
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
Definition: Inliner.cpp:431
Module.h This file contains the declarations for the Module class.
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
INITIALIZE_PASS_BEGIN(SimpleInliner,"inline","Function Integration/Inlining", false, false) INITIALIZE_PASS_END(SimpleInliner