LLVM 17.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
20namespace llvm {
21
22class AssumptionCacheTracker;
23class CallGraph;
24class ProfileSummaryInfo;
25
26/// This class contains all of the helper code which is used to perform the
27/// inlining operations that do not depend on the policy. It contains the core
28/// bottom-up inlining infrastructure that specific inliner passes use.
30 explicit LegacyInlinerBase(char &ID);
31 explicit LegacyInlinerBase(char &ID, bool InsertLifetime);
32
33 /// For this class, we declare that we require and preserve the call graph.
34 /// If the derived class implements this method, it should always explicitly
35 /// call the implementation here.
36 void getAnalysisUsage(AnalysisUsage &Info) const override;
37
39
40 bool doInitialization(CallGraph &CG) override;
41
42 /// Main run interface method, this implements the interface required by the
43 /// Pass class.
44 bool runOnSCC(CallGraphSCC &SCC) override;
45
47
48 /// Remove now-dead linkonce functions at the end of processing to avoid
49 /// breaking the SCC traversal.
50 bool doFinalization(CallGraph &CG) override;
51
52 /// This method must be implemented by the subclass to determine the cost of
53 /// inlining the specified call site. If the cost returned is greater than
54 /// the current inline threshold, the call site is not inlined.
56
57 /// Remove dead functions.
58 ///
59 /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
60 /// which restricts it to deleting functions with an 'AlwaysInline'
61 /// attribute. This is useful for the InlineAlways pass that only wants to
62 /// deal with that subset of the functions.
63 bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
64
65 /// This function performs the main work of the pass. The default of
66 /// Inlinter::runOnSCC() calls skipSCC() before calling this method, but
67 /// derived classes which cannot be skipped can override that method and call
68 /// this function unconditionally.
69 bool inlineCalls(CallGraphSCC &SCC);
70
71private:
72 // Insert @llvm.lifetime intrinsics.
73 bool InsertLifetime = true;
74
75protected:
78 std::function<const TargetLibraryInfo &(Function &)> GetTLI;
80};
81
82/// The inliner pass for the new pass manager.
83///
84/// This pass wires together the inlining utilities and the inline cost
85/// analysis into a CGSCC pass. It considers every call in every function in
86/// the SCC and tries to inline if profitable. It can be tuned with a number of
87/// parameters to control what cost model is used and what tradeoffs are made
88/// when making the decision.
89///
90/// It should be noted that the legacy inliners do considerably more than this
91/// inliner pass does. They provide logic for manually merging allocas, and
92/// doing considerable DCE including the DCE of dead functions. This pass makes
93/// every attempt to be simpler. DCE of functions requires complex reasoning
94/// about comdat groups, etc. Instead, it is expected that other more focused
95/// passes be composed to achieve the same end result.
96class InlinerPass : public PassInfoMixin<InlinerPass> {
97public:
98 InlinerPass(bool OnlyMandatory = false,
100 : OnlyMandatory(OnlyMandatory), LTOPhase(LTOPhase) {}
102
105
106 void printPipeline(raw_ostream &OS,
107 function_ref<StringRef(StringRef)> MapClassName2PassName);
108
109private:
112 std::unique_ptr<InlineAdvisor> OwnedAdvisor;
113 const bool OnlyMandatory;
114 const ThinOrFullLTOPhase LTOPhase;
115};
116
117/// Module pass, wrapping the inliner pass. This works in conjunction with the
118/// InlineAdvisorAnalysis to facilitate inlining decisions taking into account
119/// module-wide state, that need to keep track of inter-inliner pass runs, for
120/// a given module. An InlineAdvisor is configured and kept alive for the
121/// duration of the ModuleInlinerWrapperPass::run.
123 : public PassInfoMixin<ModuleInlinerWrapperPass> {
124public:
126 InlineParams Params = getInlineParams(), bool MandatoryFirst = true,
127 InlineContext IC = {},
129 unsigned MaxDevirtIterations = 0);
131
133
134 /// Allow adding more CGSCC passes, besides inlining. This should be called
135 /// before run is called, as part of pass pipeline building.
136 CGSCCPassManager &getPM() { return PM; }
137
138 /// Add a module pass that runs before the CGSCC passes.
139 template <class T> void addModulePass(T Pass) {
140 MPM.addPass(std::move(Pass));
141 }
142
143 /// Add a module pass that runs after the CGSCC passes.
144 template <class T> void addLateModulePass(T Pass) {
145 AfterCGMPM.addPass(std::move(Pass));
146 }
147
148 void printPipeline(raw_ostream &OS,
149 function_ref<StringRef(StringRef)> MapClassName2PassName);
150
151private:
152 const InlineParams Params;
153 const InlineContext IC;
154 const InliningAdvisorMode Mode;
155 const unsigned MaxDevirtIterations;
156 // TODO: Clean this up so we only have one ModulePassManager.
159 ModulePassManager AfterCGMPM;
160};
161} // end namespace llvm
162
163#endif // LLVM_TRANSFORMS_IPO_INLINER_H
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
This header provides classes for managing passes over SCCs of the call graph.
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
Implements a lazy call graph analysis and related passes for the new pass manager.
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
This header defines various interfaces for pass management in LLVM.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
Represent the analysis usage information of a pass.
An immutable pass that tracks lazily created AssumptionCache objects.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1184
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:72
Calculate and dump ThinLTO specific inliner stats.
Interface for deciding whether to inline a call site or not.
Represents the cost of inlining a function.
Definition: InlineCost.h:89
The inliner pass for the new pass manager.
Definition: Inliner.h:96
InlinerPass(bool OnlyMandatory=false, ThinOrFullLTOPhase LTOPhase=ThinOrFullLTOPhase::None)
Definition: Inliner.h:98
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: Inliner.cpp:1181
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Definition: Inliner.cpp:743
InlinerPass(InlinerPass &&Arg)=default
An SCC of the call graph.
A lazily constructed view of the call graph of a module.
Module pass, wrapping the inliner pass.
Definition: Inliner.h:123
void addModulePass(T Pass)
Add a module pass that runs before the CGSCC passes.
Definition: Inliner.h:139
PreservedAnalyses run(Module &, ModuleAnalysisManager &)
Definition: Inliner.cpp:1142
CGSCCPassManager & getPM()
Allow adding more CGSCC passes, besides inlining.
Definition: Inliner.h:136
void addLateModulePass(T Pass)
Add a module pass that runs after the CGSCC passes.
Definition: Inliner.h:144
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: Inliner.cpp:1189
ModuleInlinerWrapperPass(ModuleInlinerWrapperPass &&Arg)=default
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Result proxy object for OuterAnalysisManagerProxy.
Definition: PassManager.h:1061
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:544
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:116
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:120
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
Analysis providing profile information.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Provides information about what library functions are available for the current target.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
InliningAdvisorMode
There are 4 scenarios we can use the InlineAdvisor:
Definition: InlineAdvisor.h:44
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition: Pass.h:73
@ None
No LTO/ThinLTO behavior needed.
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options.
cl::opt< unsigned > MaxDevirtIterations("max-devirt-iterations", cl::ReallyHidden, cl::init(4))
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...
Definition: InlineAdvisor.h:60
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:205
This class contains all of the helper code which is used to perform the inlining operations that do n...
Definition: Inliner.h:29
bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly=false)
Remove dead functions.
Definition: Inliner.cpp:623
ProfileSummaryInfo * PSI
Definition: Inliner.h:77
ImportedFunctionsInliningStatistics ImportedFunctionsStats
Definition: Inliner.h:79
std::function< const TargetLibraryInfo &(Function &)> GetTLI
Definition: Inliner.h:78
AssumptionCacheTracker * ACT
Definition: Inliner.h:76
virtual InlineCost getInlineCost(CallBase &CB)=0
This method must be implemented by the subclass to determine the cost of inlining the specified call ...
bool doFinalization(CallGraph &CG) override
Remove now-dead linkonce functions at the end of processing to avoid breaking the SCC traversal.
Definition: Inliner.cpp:615
bool inlineCalls(CallGraphSCC &SCC)
This function performs the main work of the pass.
Definition: Inliner.cpp:597
bool doInitialization(CallGraph &CG) override
doInitialization - This method is called before the SCC's of the program has been processed,...
Definition: Inliner.cpp:349
void getAnalysisUsage(AnalysisUsage &Info) const override
For this class, we declare that we require and preserve the call graph.
Definition: Inliner.cpp:174
bool runOnSCC(CallGraphSCC &SCC) override
Main run interface method, this implements the interface required by the Pass class.
Definition: Inliner.cpp:355
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:371