LLVM  8.0.1
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 
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/Module.h"
24 #include "llvm/IR/Type.h"
25 #include "llvm/Transforms/IPO.h"
27 
28 using namespace llvm;
29 
30 #define DEBUG_TYPE "inline"
31 
32 namespace {
33 
34 /// 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 LegacyInlinerBase {
40 
41  InlineParams Params;
42 
43 public:
44  SimpleInliner() : LegacyInlinerBase(ID), Params(llvm::getInlineParams()) {
46  }
47 
48  explicit SimpleInliner(InlineParams Params)
49  : LegacyInlinerBase(ID), Params(std::move(Params)) {
51  }
52 
53  static char ID; // Pass identification, replacement for typeid
54 
55  InlineCost getInlineCost(CallSite CS) override {
57  TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
58 
59  bool RemarksEnabled = false;
60  const auto &BBs = CS.getCaller()->getBasicBlockList();
61  if (!BBs.empty()) {
62  auto DI = OptimizationRemark(DEBUG_TYPE, "", DebugLoc(), &BBs.front());
63  if (DI.isEnabled())
64  RemarksEnabled = true;
65  }
67 
68  std::function<AssumptionCache &(Function &)> GetAssumptionCache =
69  [&](Function &F) -> AssumptionCache & {
70  return ACT->getAssumptionCache(F);
71  };
72  return llvm::getInlineCost(CS, Params, TTI, GetAssumptionCache,
73  /*GetBFI=*/None, PSI,
74  RemarksEnabled ? &ORE : nullptr);
75  }
76 
77  bool runOnSCC(CallGraphSCC &SCC) override;
78  void getAnalysisUsage(AnalysisUsage &AU) const override;
79 
80 private:
82 
83 };
84 
85 } // end anonymous namespace
86 
87 char SimpleInliner::ID = 0;
88 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", "Function Integration/Inlining",
89  false, false)
95 INITIALIZE_PASS_END(SimpleInliner, "inline", "Function Integration/Inlining",
96  false, false)
97 
98 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
99 
101  return new SimpleInliner(llvm::getInlineParams(Threshold));
102 }
103 
105  unsigned SizeOptLevel,
106  bool DisableInlineHotCallSite) {
107  auto Param = llvm::getInlineParams(OptLevel, SizeOptLevel);
108  if (DisableInlineHotCallSite)
109  Param.HotCallSiteThreshold = 0;
110  return new SimpleInliner(Param);
111 }
112 
114  return new SimpleInliner(Params);
115 }
116 
117 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
118  TTIWP = &getAnalysis<TargetTransformInfoWrapperPass>();
119  return LegacyInlinerBase::runOnSCC(SCC);
120 }
121 
122 void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
125 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:154
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Function Integration Inlining
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void initializeSimpleInlinerPass(PassRegistry &)
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of @llvm.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:64
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:502
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
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:132
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.
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
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:633
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
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.