LLVM  6.0.0svn
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 
20 #include "llvm/IR/CallSite.h"
21 #include "llvm/IR/CallingConv.h"
22 #include "llvm/IR/DataLayout.h"
23 #include "llvm/IR/Instructions.h"
24 #include "llvm/IR/IntrinsicInst.h"
25 #include "llvm/IR/Module.h"
26 #include "llvm/IR/Type.h"
27 #include "llvm/Transforms/IPO.h"
29 
30 using namespace llvm;
31 
32 #define DEBUG_TYPE "inline"
33 
34 namespace {
35 
36 /// \brief Actual inliner pass implementation.
37 ///
38 /// The common implementation of the inlining logic is shared between this
39 /// inliner pass and the always inliner pass. The two passes use different cost
40 /// analyses to determine when to inline.
41 class SimpleInliner : public LegacyInlinerBase {
42 
43  InlineParams Params;
44 
45 public:
46  SimpleInliner() : LegacyInlinerBase(ID), Params(llvm::getInlineParams()) {
48  }
49 
50  explicit SimpleInliner(InlineParams Params)
51  : LegacyInlinerBase(ID), Params(std::move(Params)) {
53  }
54 
55  static char ID; // Pass identification, replacement for typeid
56 
57  InlineCost getInlineCost(CallSite CS) override {
59  TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
60 
61  bool RemarksEnabled = false;
62  const auto &BBs = CS.getCaller()->getBasicBlockList();
63  if (!BBs.empty()) {
64  auto DI = OptimizationRemark(DEBUG_TYPE, "", DebugLoc(), &BBs.front());
65  if (DI.isEnabled())
66  RemarksEnabled = true;
67  }
69 
70  std::function<AssumptionCache &(Function &)> GetAssumptionCache =
71  [&](Function &F) -> AssumptionCache & {
72  return ACT->getAssumptionCache(F);
73  };
74  return llvm::getInlineCost(CS, Params, TTI, GetAssumptionCache,
75  /*GetBFI=*/None, PSI,
76  RemarksEnabled ? &ORE : nullptr);
77  }
78 
79  bool runOnSCC(CallGraphSCC &SCC) override;
80  void getAnalysisUsage(AnalysisUsage &AU) const override;
81 
82 private:
84 
85 };
86 
87 } // end anonymous namespace
88 
89 char SimpleInliner::ID = 0;
90 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", "Function Integration/Inlining",
91  false, false)
97 INITIALIZE_PASS_END(SimpleInliner, "inline", "Function Integration/Inlining",
98  false, false)
99 
100 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
101 
103  return new SimpleInliner(llvm::getInlineParams(Threshold));
104 }
105 
107  unsigned SizeOptLevel,
108  bool DisableInlineHotCallSite) {
109  auto Param = llvm::getInlineParams(OptLevel, SizeOptLevel);
110  if (DisableInlineHotCallSite)
111  Param.HotCallSiteThreshold = 0;
112  return new SimpleInliner(Param);
113 }
114 
116  return new SimpleInliner(Params);
117 }
118 
119 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
120  TTIWP = &getAnalysis<TargetTransformInfoWrapperPass>();
121  return LegacyInlinerBase::runOnSCC(SCC);
122 }
123 
124 void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
127 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:130
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Function Integration Inlining
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void initializeSimpleInlinerPass(PassRegistry &)
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of .assume calls within a function.
A debug info location.
Definition: DebugLoc.h:34
F(f)
Represents the cost of inlining a function.
Definition: InlineCost.h:65
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
bool runOnSCC(CallGraphSCC &SCC) override
Main run interface method, this implements the interface required by the Pass class.
Definition: Inliner.cpp:458
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
This class contains all of the helper code which is used to perform the inlining operations that do n...
Definition: Inliner.h:31
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
inline
amdgpu Simplify well known AMD library false Value * Callee
void getAnalysisUsage(AnalysisUsage &Info) const override
For this class, we declare that we require and preserve the call graph.
Definition: Inliner.cpp:123
Wrapper pass for TargetTransformInfo.
The ModulePass which wraps up a CallGraph and the logic to build it.
Definition: CallGraph.h:324
Diagnostic information for applied optimization remarks.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", "Function Integration/Inlining", false, false) INITIALIZE_PASS_END(SimpleInliner
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
InlineCost getInlineCost(CallSite CS, const InlineParams &Params, TargetTransformInfo &CalleeTTI, std::function< AssumptionCache &(Function &)> &GetAssumptionCache, Optional< function_ref< BlockFrequencyInfo &(Function &)>> GetBFI, ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE=nullptr)
Get an InlineCost object representing the cost of inlining this callsite.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options...
Module.h This file contains the declarations for the Module class.
FunTy * getCaller() const
Return the caller function for this call site.
Definition: CallSite.h:267
#define DEBUG_TYPE
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:565
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it&#39;s an indirect...
Definition: CallSite.h:107
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.
This pass exposes codegen information to IR-level passes.
The optimization diagnostic interface.