LLVM  10.0.0svn
InlineSimple.cpp
Go to the documentation of this file.
1 //===- InlineSimple.cpp - Code to perform simple function inlining --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements bottom-up inlining of functions into callees.
10 //
11 //===----------------------------------------------------------------------===//
12 
18 #include "llvm/IR/CallSite.h"
19 #include "llvm/IR/CallingConv.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Instructions.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/IR/Type.h"
24 #include "llvm/Transforms/IPO.h"
26 
27 using namespace llvm;
28 
29 #define DEBUG_TYPE "inline"
30 
31 namespace {
32 
33 /// Actual inliner pass implementation.
34 ///
35 /// The common implementation of the inlining logic is shared between this
36 /// inliner pass and the always inliner pass. The two passes use different cost
37 /// analyses to determine when to inline.
38 class SimpleInliner : public LegacyInlinerBase {
39 
40  InlineParams Params;
41 
42 public:
43  SimpleInliner() : LegacyInlinerBase(ID), Params(llvm::getInlineParams()) {
45  }
46 
47  explicit SimpleInliner(InlineParams Params)
48  : LegacyInlinerBase(ID), Params(std::move(Params)) {
50  }
51 
52  static char ID; // Pass identification, replacement for typeid
53 
54  InlineCost getInlineCost(CallSite CS) override {
56  TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
57 
58  bool RemarksEnabled = false;
59  const auto &BBs = CS.getCaller()->getBasicBlockList();
60  if (!BBs.empty()) {
61  auto DI = OptimizationRemark(DEBUG_TYPE, "", DebugLoc(), &BBs.front());
62  if (DI.isEnabled())
63  RemarksEnabled = true;
64  }
66 
67  std::function<AssumptionCache &(Function &)> GetAssumptionCache =
68  [&](Function &F) -> AssumptionCache & {
69  return ACT->getAssumptionCache(F);
70  };
71  return llvm::getInlineCost(
72  cast<CallBase>(*CS.getInstruction()), Params, TTI, GetAssumptionCache,
73  /*GetBFI=*/None, PSI, RemarksEnabled ? &ORE : nullptr);
74  }
75 
76  bool runOnSCC(CallGraphSCC &SCC) override;
77  void getAnalysisUsage(AnalysisUsage &AU) const override;
78 
79 private:
81 
82 };
83 
84 } // end anonymous namespace
85 
86 char SimpleInliner::ID = 0;
87 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", "Function Integration/Inlining",
88  false, false)
94 INITIALIZE_PASS_END(SimpleInliner, "inline", "Function Integration/Inlining",
95  false, false)
96 
97 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
98 
100  return new SimpleInliner(llvm::getInlineParams(Threshold));
101 }
102 
104  unsigned SizeOptLevel,
105  bool DisableInlineHotCallSite) {
106  auto Param = llvm::getInlineParams(OptLevel, SizeOptLevel);
107  if (DisableInlineHotCallSite)
108  Param.HotCallSiteThreshold = 0;
109  return new SimpleInliner(Param);
110 }
111 
113  return new SimpleInliner(Params);
114 }
115 
116 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
117  TTIWP = &getAnalysis<TargetTransformInfoWrapperPass>();
118  return LegacyInlinerBase::runOnSCC(SCC);
119 }
120 
121 void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
124 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:153
InlineCost getInlineCost(CallBase &Call, 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.
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:23
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:33
F(f)
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:111
Represents the cost of inlining a function.
Definition: InlineCost.h:63
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
bool runOnSCC(CallGraphSCC &SCC) override
Main run interface method, this implements the interface required by the Pass class.
Definition: Inliner.cpp:501
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:30
InstrTy * getInstruction() const
Definition: CallSite.h:96
inline
void getAnalysisUsage(AnalysisUsage &Info) const override
For this class, we declare that we require and preserve the call graph.
Definition: Inliner.cpp:131
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
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.
amdgpu Simplify well known AMD library false FunctionCallee Callee
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
#define DEBUG_TYPE
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:662
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.
FunTy * getCaller() const
Return the caller function for this call site.
Definition: CallSite.h:275