LLVM  14.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 
18 #include "llvm/IR/PassManager.h"
19 #include <utility>
20 
21 namespace llvm {
22 
23 class AssumptionCacheTracker;
24 class CallGraph;
25 class ProfileSummaryInfo;
26 
27 /// This class contains all of the helper code which is used to perform the
28 /// inlining operations that do not depend on the policy. It contains the core
29 /// bottom-up inlining infrastructure that specific inliner passes use.
31  explicit LegacyInlinerBase(char &ID);
32  explicit LegacyInlinerBase(char &ID, bool InsertLifetime);
33 
34  /// For this class, we declare that we require and preserve the call graph.
35  /// If the derived class implements this method, it should always explicitly
36  /// call the implementation here.
37  void getAnalysisUsage(AnalysisUsage &Info) const override;
38 
40 
41  bool doInitialization(CallGraph &CG) override;
42 
43  /// Main run interface method, this implements the interface required by the
44  /// Pass class.
45  bool runOnSCC(CallGraphSCC &SCC) override;
46 
48 
49  /// Remove now-dead linkonce functions at the end of processing to avoid
50  /// breaking the SCC traversal.
51  bool doFinalization(CallGraph &CG) override;
52 
53  /// This method must be implemented by the subclass to determine the cost of
54  /// inlining the specified call site. If the cost returned is greater than
55  /// the current inline threshold, the call site is not inlined.
56  virtual InlineCost getInlineCost(CallBase &CB) = 0;
57 
58  /// Remove dead functions.
59  ///
60  /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
61  /// which restricts it to deleting functions with an 'AlwaysInline'
62  /// attribute. This is useful for the InlineAlways pass that only wants to
63  /// deal with that subset of the functions.
64  bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
65 
66  /// This function performs the main work of the pass. The default of
67  /// Inlinter::runOnSCC() calls skipSCC() before calling this method, but
68  /// derived classes which cannot be skipped can override that method and call
69  /// this function unconditionally.
71 
72 private:
73  // Insert @llvm.lifetime intrinsics.
74  bool InsertLifetime = true;
75 
76 protected:
81 };
82 
83 /// The inliner pass for the new pass manager.
84 ///
85 /// This pass wires together the inlining utilities and the inline cost
86 /// analysis into a CGSCC pass. It considers every call in every function in
87 /// the SCC and tries to inline if profitable. It can be tuned with a number of
88 /// parameters to control what cost model is used and what tradeoffs are made
89 /// when making the decision.
90 ///
91 /// It should be noted that the legacy inliners do considerably more than this
92 /// inliner pass does. They provide logic for manually merging allocas, and
93 /// doing considerable DCE including the DCE of dead functions. This pass makes
94 /// every attempt to be simpler. DCE of functions requires complex reasoning
95 /// about comdat groups, etc. Instead, it is expected that other more focused
96 /// passes be composed to achieve the same end result.
97 class InlinerPass : public PassInfoMixin<InlinerPass> {
98 public:
99  InlinerPass(bool OnlyMandatory = false) : OnlyMandatory(OnlyMandatory) {}
100  InlinerPass(InlinerPass &&Arg) = default;
101 
104 
105  void printPipeline(raw_ostream &OS,
106  function_ref<StringRef(StringRef)> MapClassName2PassName);
107 
108 private:
111  std::unique_ptr<InlineAdvisor> OwnedAdvisor;
112  const bool OnlyMandatory;
113 };
114 
115 /// Module pass, wrapping the inliner pass. This works in conjunction with the
116 /// InlineAdvisorAnalysis to facilitate inlining decisions taking into account
117 /// module-wide state, that need to keep track of inter-inliner pass runs, for
118 /// a given module. An InlineAdvisor is configured and kept alive for the
119 /// duration of the ModuleInlinerWrapperPass::run.
121  : public PassInfoMixin<ModuleInlinerWrapperPass> {
122 public:
124  InlineParams Params = getInlineParams(), bool MandatoryFirst = true,
126  unsigned MaxDevirtIterations = 0);
128 
130 
131  /// Allow adding more CGSCC passes, besides inlining. This should be called
132  /// before run is called, as part of pass pipeline building.
133  CGSCCPassManager &getPM() { return PM; }
134 
135  /// Allow adding module-level passes benefiting the contained CGSCC passes.
136  template <class T> void addModulePass(T Pass) {
137  MPM.addPass(std::move(Pass));
138  }
139 
140  void printPipeline(raw_ostream &OS,
141  function_ref<StringRef(StringRef)> MapClassName2PassName);
142 
143 private:
144  const InlineParams Params;
145  const InliningAdvisorMode Mode;
146  const unsigned MaxDevirtIterations;
147  CGSCCPassManager PM;
148  ModulePassManager MPM;
149 };
150 } // end namespace llvm
151 
152 #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
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::ModuleInlinerWrapperPass::ModuleInlinerWrapperPass
ModuleInlinerWrapperPass(InlineParams Params=getInlineParams(), bool MandatoryFirst=true, InliningAdvisorMode Mode=InliningAdvisorMode::Default, unsigned MaxDevirtIterations=0)
Definition: Inliner.cpp:1024
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:62
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:553
llvm::LegacyInlinerBase::inlineCalls
bool inlineCalls(CallGraphSCC &SCC)
This function performs the main work of the pass.
Definition: Inliner.cpp:550
llvm::LegacyInlinerBase::GetTLI
std::function< const TargetLibraryInfo &(Function &)> GetTLI
Definition: Inliner.h:79
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
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::InlineParams
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:185
llvm::LegacyInlinerBase::LegacyInlinerBase
LegacyInlinerBase(char &ID)
Definition: Inliner.cpp:119
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::ModuleInlinerWrapperPass
Module pass, wrapping the inliner pass.
Definition: Inliner.h:120
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:422
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ModuleInlinerWrapperPass::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: Inliner.cpp:1080
MAM
ModuleAnalysisManager MAM
Definition: PassBuilderBindings.cpp:61
llvm::ModuleInlinerWrapperPass::getPM
CGSCCPassManager & getPM()
Allow adding more CGSCC passes, besides inlining.
Definition: Inliner.h:133
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:82
InlineAdvisor.h
llvm::OuterAnalysisManagerProxy::Result
Result proxy object for OuterAnalysisManagerProxy.
Definition: PassManager.h:1070
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
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:3072
LazyCallGraph.h
llvm::LegacyInlinerBase::ACT
AssumptionCacheTracker * ACT
Definition: Inliner.h:77
llvm::LegacyInlinerBase::removeDeadFunctions
bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly=false)
Remove dead functions.
Definition: Inliner.cpp:576
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
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:308
llvm::LegacyInlinerBase
This class contains all of the helper code which is used to perform the inlining operations that do n...
Definition: Inliner.h:30
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:78
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:295
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::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::InlineAdvisor
Interface for deciding whether to inline a call site or not.
Definition: InlineAdvisor.h:139
llvm::InlinerPass::printPipeline
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: Inliner.cpp:1072
CallGraphSCCPass.h
llvm::ModuleInlinerWrapperPass::addModulePass
void addModulePass(T Pass)
Allow adding module-level passes benefiting the contained CGSCC passes.
Definition: Inliner.h:136
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:238
llvm::InlinerPass::InlinerPass
InlinerPass(bool OnlyMandatory=false)
Definition: Inliner.h:99
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:221
llvm::ModuleInlinerWrapperPass::run
PreservedAnalyses run(Module &, ModuleAnalysisManager &)
Definition: Inliner.cpp:1040
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:97
llvm::InlinerPass::run
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Definition: Inliner.cpp:690
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:568
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:127
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1161
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:113
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:302
llvm::LegacyInlinerBase::ImportedFunctionsStats
ImportedFunctionsInliningStatistics ImportedFunctionsStats
Definition: Inliner.h:80
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37