LLVM  13.0.0git
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/CallingConv.h"
19 #include "llvm/IR/DataLayout.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/IR/Type.h"
23 #include "llvm/InitializePasses.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(CallBase &CB) override {
56  TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
57 
58  bool RemarksEnabled = false;
59  const auto &BBs = CB.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(CB, Params, TTI, GetAssumptionCache, GetTLI,
72  /*GetBFI=*/nullptr, PSI,
73  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",
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>();
119 }
120 
121 void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
124 }
AssumptionCache.h
llvm
Definition: AllocatorList.h:23
Inliner.h
llvm::Function::getBasicBlockList
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:755
llvm::Function
Definition: Function.h:61
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:167
Module.h
llvm::InlineParams
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:160
llvm::initializeSimpleInlinerPass
void initializeSimpleInlinerPass(PassRegistry &)
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::CallGraphSCC
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
Definition: CallGraphSCCPass.h:87
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::getInlineCost
InlineCost getInlineCost(CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI, function_ref< AssumptionCache &(Function &)> GetAssumptionCache, function_ref< const TargetLibraryInfo &(Function &)> GetTLI, function_ref< BlockFrequencyInfo &(Function &)> GetBFI=nullptr, ProfileSummaryInfo *PSI=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Get an InlineCost object representing the cost of inlining this callsite.
Definition: InlineCost.cpp:2473
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1396
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", "Function Integration/Inlining", false, false) INITIALIZE_PASS_END(SimpleInliner
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::InlineCost
Represents the cost of inlining a function.
Definition: InlineCost.h:67
Param
Value * Param
Definition: NVPTXLowerArgs.cpp:163
TargetLibraryInfo.h
false
Definition: StackSlotColoring.cpp:142
llvm::getInlineParams
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options.
Definition: InlineCost.cpp:2743
Type.h
llvm::CallBase::getCaller
Function * getCaller()
Helper to get the caller (the parent function).
Definition: Instructions.cpp:278
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::createFunctionInliningPass
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
Definition: InlineSimple.cpp:97
llvm::LegacyInlinerBase::runOnSCC
bool runOnSCC(CallGraphSCC &SCC) override
Main run interface method, this implements the interface required by the Pass class.
Definition: Inliner.cpp:291
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:446
ProfileSummaryInfo.h
llvm::LegacyInlinerBase
This class contains all of the helper code which is used to perform the inlining operations that do n...
Definition: Inliner.h:31
llvm::TargetTransformInfoWrapperPass
Wrapper pass for TargetTransformInfo.
Definition: TargetTransformInfo.h:2375
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
IPO.h
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::CallGraphWrapperPass
The ModulePass which wraps up a CallGraph and the logic to build it.
Definition: CallGraph.h:337
llvm::ProfileSummaryInfoWrapperPass
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Definition: ProfileSummaryInfo.h:185
inline
inline
Definition: InlineSimple.cpp:94
InlineCost.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::AMDGPU::CPol::SCC
@ SCC
Definition: SIDefines.h:285
llvm::AssumptionCacheTracker
An immutable pass that tracks lazily created AssumptionCache objects.
Definition: AssumptionCache.h:200
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
DataLayout.h
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:41
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:205
CallingConv.h
llvm::OptimizationRemark
Diagnostic information for applied optimization remarks.
Definition: DiagnosticInfo.h:684
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
Instructions.h
TargetTransformInfo.h
Threshold
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
Inlining
Function Integration Inlining
Definition: InlineSimple.cpp:94
llvm::LegacyInlinerBase::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &Info) const override
For this class, we declare that we require and preserve the call graph.
Definition: Inliner.cpp:110
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1164
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
DEBUG_TYPE
#define DEBUG_TYPE
Definition: InlineSimple.cpp:29
InitializePasses.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38