LLVM  16.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 
17 #include "llvm/InitializePasses.h"
18 #include "llvm/Transforms/IPO.h"
20 
21 using namespace llvm;
22 
23 #define DEBUG_TYPE "inline"
24 
25 namespace {
26 
27 /// Actual inliner pass implementation.
28 ///
29 /// The common implementation of the inlining logic is shared between this
30 /// inliner pass and the always inliner pass. The two passes use different cost
31 /// analyses to determine when to inline.
32 class SimpleInliner : public LegacyInlinerBase {
33 
34  InlineParams Params;
35 
36 public:
37  SimpleInliner() : LegacyInlinerBase(ID), Params(llvm::getInlineParams()) {
39  }
40 
41  explicit SimpleInliner(InlineParams Params)
42  : LegacyInlinerBase(ID), Params(std::move(Params)) {
44  }
45 
46  static char ID; // Pass identification, replacement for typeid
47 
48  InlineCost getInlineCost(CallBase &CB) override {
50  TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
51 
52  bool RemarksEnabled = false;
53  const auto &BBs = CB.getCaller()->getBasicBlockList();
54  if (!BBs.empty()) {
55  auto DI = OptimizationRemark(DEBUG_TYPE, "", DebugLoc(), &BBs.front());
56  if (DI.isEnabled())
57  RemarksEnabled = true;
58  }
60 
61  std::function<AssumptionCache &(Function &)> GetAssumptionCache =
62  [&](Function &F) -> AssumptionCache & {
63  return ACT->getAssumptionCache(F);
64  };
65  return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache, GetTLI,
66  /*GetBFI=*/nullptr, PSI,
67  RemarksEnabled ? &ORE : nullptr);
68  }
69 
70  bool runOnSCC(CallGraphSCC &SCC) override;
71  void getAnalysisUsage(AnalysisUsage &AU) const override;
72 
73 private:
75 
76 };
77 
78 } // end anonymous namespace
79 
80 char SimpleInliner::ID = 0;
81 INITIALIZE_PASS_BEGIN(SimpleInliner, "inline", "Function Integration/Inlining",
82  false, false)
88 INITIALIZE_PASS_END(SimpleInliner, "inline", "Function Integration/Inlining",
90 
91 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
92 
94  return new SimpleInliner(llvm::getInlineParams(Threshold));
95 }
96 
98  unsigned SizeOptLevel,
99  bool DisableInlineHotCallSite) {
100  auto Param = llvm::getInlineParams(OptLevel, SizeOptLevel);
101  if (DisableInlineHotCallSite)
102  Param.HotCallSiteThreshold = 0;
103  return new SimpleInliner(Param);
104 }
105 
107  return new SimpleInliner(Params);
108 }
109 
110 bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
111  TTIWP = &getAnalysis<TargetTransformInfoWrapperPass>();
113 }
114 
115 void SimpleInliner::getAnalysisUsage(AnalysisUsage &AU) const {
118 }
AssumptionCache.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::AArch64PACKey::ID
ID
Definition: AArch64BaseInfo.h:818
Inliner.h
llvm::Function::getBasicBlockList
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:684
llvm::Function
Definition: Function.h:60
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:173
OptimizationRemarkEmitter.h
llvm::InlineParams
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:204
llvm::initializeSimpleInlinerPass
void initializeSimpleInlinerPass(PassRegistry &)
F
#define F(x, y, z)
Definition: MD5.cpp:55
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:24
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:2822
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1397
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:90
Param
Value * Param
Definition: NVPTXLowerArgs.cpp:165
false
Definition: StackSlotColoring.cpp:141
llvm::getInlineParams
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options.
Definition: InlineCost.cpp:3101
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::CallBase::getCaller
Function * getCaller()
Helper to get the caller (the parent function).
Definition: Instructions.cpp:284
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:91
llvm::LegacyInlinerBase::runOnSCC
bool runOnSCC(CallGraphSCC &SCC) override
Main run interface method, this implements the interface required by the Pass class.
Definition: Inliner.cpp:356
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:475
llvm::LegacyInlinerBase
This class contains all of the helper code which is used to perform the inlining operations that do n...
Definition: Inliner.h:29
llvm::TargetTransformInfoWrapperPass
Wrapper pass for TargetTransformInfo.
Definition: TargetTransformInfo.h:2642
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:347
llvm::ProfileSummaryInfoWrapperPass
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Definition: ProfileSummaryInfo.h:194
inline
inline
Definition: InlineSimple.cpp:88
InlineCost.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::AMDGPU::CPol::SCC
@ SCC
Definition: SIDefines.h:307
llvm::AssumptionCacheTracker
An immutable pass that tracks lazily created AssumptionCache objects.
Definition: AssumptionCache.h:202
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:42
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:187
llvm::OptimizationRemark
Diagnostic information for applied optimization remarks.
Definition: DiagnosticInfo.h:689
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
TargetTransformInfo.h
Inlining
Function Integration Inlining
Definition: InlineSimple.cpp:88
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:175
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1175
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:23
InitializePasses.h