LLVM  13.0.0git
Inliner.h
Go to the documentation of this file.
1 //===- Inliner.h - Inliner pass and infrastructure --------------*- C++ -*-===//
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 #ifndef LLVM_TRANSFORMS_IPO_INLINER_H
10 #define LLVM_TRANSFORMS_IPO_INLINER_H
11 
19 #include "llvm/IR/PassManager.h"
20 #include <utility>
21 
22 namespace llvm {
23 
24 class AssumptionCacheTracker;
25 class CallGraph;
26 class ProfileSummaryInfo;
27 
28 /// This class contains all of the helper code which is used to perform the
29 /// inlining operations that do not depend on the policy. It contains the core
30 /// bottom-up inlining infrastructure that specific inliner passes use.
32  explicit LegacyInlinerBase(char &ID);
33  explicit LegacyInlinerBase(char &ID, bool InsertLifetime);
34 
35  /// For this class, we declare that we require and preserve the call graph.
36  /// If the derived class implements this method, it should always explicitly
37  /// call the implementation here.
38  void getAnalysisUsage(AnalysisUsage &Info) const override;
39 
41 
42  bool doInitialization(CallGraph &CG) override;
43 
44  /// Main run interface method, this implements the interface required by the
45  /// Pass class.
46  bool runOnSCC(CallGraphSCC &SCC) override;
47 
49 
50  /// Remove now-dead linkonce functions at the end of processing to avoid
51  /// breaking the SCC traversal.
52  bool doFinalization(CallGraph &CG) override;
53 
54  /// This method must be implemented by the subclass to determine the cost of
55  /// inlining the specified call site. If the cost returned is greater than
56  /// the current inline threshold, the call site is not inlined.
57  virtual InlineCost getInlineCost(CallBase &CB) = 0;
58 
59  /// Remove dead functions.
60  ///
61  /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
62  /// which restricts it to deleting functions with an 'AlwaysInline'
63  /// attribute. This is useful for the InlineAlways pass that only wants to
64  /// deal with that subset of the functions.
65  bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
66 
67  /// This function performs the main work of the pass. The default of
68  /// Inlinter::runOnSCC() calls skipSCC() before calling this method, but
69  /// derived classes which cannot be skipped can override that method and call
70  /// this function unconditionally.
72 
73 private:
74  // Insert @llvm.lifetime intrinsics.
75  bool InsertLifetime = true;
76 
77 protected:
82 };
83 
84 /// The inliner pass for the new pass manager.
85 ///
86 /// This pass wires together the inlining utilities and the inline cost
87 /// analysis into a CGSCC pass. It considers every call in every function in
88 /// the SCC and tries to inline if profitable. It can be tuned with a number of
89 /// parameters to control what cost model is used and what tradeoffs are made
90 /// when making the decision.
91 ///
92 /// It should be noted that the legacy inliners do considerably more than this
93 /// inliner pass does. They provide logic for manually merging allocas, and
94 /// doing considerable DCE including the DCE of dead functions. This pass makes
95 /// every attempt to be simpler. DCE of functions requires complex reasoning
96 /// about comdat groups, etc. Instead, it is expected that other more focused
97 /// passes be composed to achieve the same end result.
98 class InlinerPass : public PassInfoMixin<InlinerPass> {
99 public:
100  InlinerPass(bool OnlyMandatory = false) : OnlyMandatory(OnlyMandatory) {}
101  InlinerPass(InlinerPass &&Arg) = default;
102 
105 
106 private:
109  std::unique_ptr<InlineAdvisor> OwnedAdvisor;
110  const bool OnlyMandatory;
111 };
112 
113 /// Module pass, wrapping the inliner pass. This works in conjunction with the
114 /// InlineAdvisorAnalysis to facilitate inlining decisions taking into account
115 /// module-wide state, that need to keep track of inter-inliner pass runs, for
116 /// a given module. An InlineAdvisor is configured and kept alive for the
117 /// duration of the ModuleInlinerWrapperPass::run.
119  : public PassInfoMixin<ModuleInlinerWrapperPass> {
120 public:
122  InlineParams Params = getInlineParams(), bool MandatoryFirst = true,
124  unsigned MaxDevirtIterations = 0);
126 
128 
129  /// Allow adding more CGSCC passes, besides inlining. This should be called
130  /// before run is called, as part of pass pipeline building.
131  CGSCCPassManager &getPM() { return PM; }
132 
133  /// Allow adding module-level passes benefiting the contained CGSCC passes.
134  template <class T> void addModulePass(T Pass) {
135  MPM.addPass(std::move(Pass));
136  }
137 
138 private:
139  const InlineParams Params;
140  const InliningAdvisorMode Mode;
141  const unsigned MaxDevirtIterations;
142  CGSCCPassManager PM;
143  ModulePassManager MPM;
144 };
145 } // end namespace llvm
146 
147 #endif // LLVM_TRANSFORMS_IPO_INLINER_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
Definition: AllocatorList.h:23
llvm::ModuleInlinerWrapperPass::ModuleInlinerWrapperPass
ModuleInlinerWrapperPass(InlineParams Params=getInlineParams(), bool MandatoryFirst=true, InliningAdvisorMode Mode=InliningAdvisorMode::Default, unsigned MaxDevirtIterations=0)
Definition: Inliner.cpp:1006
llvm::LegacyInlinerBase::getInlineCost
virtual InlineCost getInlineCost(CallBase &CB)=0
This method must be implemented by the subclass to determine the cost of inlining the specified call ...
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:374
llvm::Function
Definition: Function.h:61
llvm::LegacyInlinerBase::inlineCalls
bool inlineCalls(CallGraphSCC &SCC)
This function performs the main work of the pass.
Definition: Inliner.cpp:533
llvm::LegacyInlinerBase::GetTLI
std::function< const TargetLibraryInfo &(Function &)> GetTLI
Definition: Inliner.h:80
llvm::ImportedFunctionsInliningStatistics
Calculate and dump ThinLTO specific inliner stats.
Definition: ImportedFunctionsInliningStatistics.h:44
llvm::CallGraph
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:73
llvm::InlineParams
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:160
llvm::LegacyInlinerBase::LegacyInlinerBase
LegacyInlinerBase(char &ID)
Definition: Inliner.cpp:102
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:205
llvm::ModuleInlinerWrapperPass
Module pass, wrapping the inliner pass.
Definition: Inliner.h:118
ImportedFunctionsInliningStatistics.h
llvm::CallGraphSCC
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
Definition: CallGraphSCCPass.h:87
llvm::LazyCallGraph::SCC
An SCC of the call graph.
Definition: LazyCallGraph.h:421
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ModuleInlinerWrapperPass::getPM
CGSCCPassManager & getPM()
Allow adding more CGSCC passes, besides inlining.
Definition: Inliner.h:131
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
InlineAdvisor.h
llvm::OuterAnalysisManagerProxy::Result
Result proxy object for OuterAnalysisManagerProxy.
Definition: PassManager.h:1056
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::getInlineParams
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options.
Definition: InlineCost.cpp:2743
LazyCallGraph.h
llvm::LegacyInlinerBase::ACT
AssumptionCacheTracker * ACT
Definition: Inliner.h:78
llvm::LegacyInlinerBase::removeDeadFunctions
bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly=false)
Remove dead functions.
Definition: Inliner.cpp:559
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
ReplayInlineAdvisor.h
llvm::InliningAdvisorMode
InliningAdvisorMode
There are 3 scenarios we can use the InlineAdvisor:
Definition: InlineAdvisor.h:39
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::LegacyInlinerBase
This class contains all of the helper code which is used to perform the inlining operations that do n...
Definition: Inliner.h:31
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
CGSCCPassManager.h
llvm::LegacyInlinerBase::PSI
ProfileSummaryInfo * PSI
Definition: Inliner.h:79
InlineCost.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::AMDGPU::CPol::SCC
@ SCC
Definition: SIDefines.h:285
llvm::Pass::doFinalization
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:120
llvm::AssumptionCacheTracker
An immutable pass that tracks lazily created AssumptionCache objects.
Definition: AssumptionCache.h:200
llvm::Pass::doInitialization
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:116
llvm::InlineAdvisor
Interface for deciding whether to inline a call site or not.
Definition: InlineAdvisor.h:140
CallGraphSCCPass.h
llvm::ModuleInlinerWrapperPass::addModulePass
void addModulePass(T Pass)
Allow adding module-level passes benefiting the contained CGSCC passes.
Definition: Inliner.h:134
llvm::PassManager< LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, CGSCCUpdateResult & >
llvm::CGSCCUpdateResult
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
Definition: CGSCCPassManager.h:232
llvm::InlinerPass::InlinerPass
InlinerPass(bool OnlyMandatory=false)
Definition: Inliner.h:100
llvm::CallGraphSCCPass
Definition: CallGraphSCCPass.h:34
PassManager.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:208
llvm::ModuleInlinerWrapperPass::run
PreservedAnalyses run(Module &, ModuleAnalysisManager &)
Definition: Inliner.cpp:1022
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::InliningAdvisorMode::Default
@ Default
llvm::InlinerPass
The inliner pass for the new pass manager.
Definition: Inliner.h:98
llvm::InlinerPass::run
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Definition: Inliner.cpp:673
llvm::LegacyInlinerBase::doFinalization
bool doFinalization(CallGraph &CG) override
Remove now-dead linkonce functions at the end of processing to avoid breaking the SCC traversal.
Definition: Inliner.cpp:551
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::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::LazyCallGraph
A lazily constructed view of the call graph of a module.
Definition: LazyCallGraph.h:112
llvm::PassManager::addPass
std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT Pass)
Definition: PassManager.h:542
llvm::LegacyInlinerBase::doInitialization
bool doInitialization(CallGraph &CG) override
doInitialization - This method is called before the SCC's of the program has been processed,...
Definition: Inliner.cpp:285
llvm::LegacyInlinerBase::ImportedFunctionsStats
ImportedFunctionsInliningStatistics ImportedFunctionsStats
Definition: Inliner.h:81
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38