LLVM  11.0.0git
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 //===----------------------------------------------------------------------===//
17 #include "llvm/IR/PassManager.h"
19 #include <utility>
21 namespace llvm {
23 class AssumptionCacheTracker;
24 class CallGraph;
25 class ProfileSummaryInfo;
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);
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;
41  bool doInitialization(CallGraph &CG) override;
43  /// Main run interface method, this implements the interface required by the
44  /// Pass class.
45  bool runOnSCC(CallGraphSCC &SCC) override;
49  /// Remove now-dead linkonce functions at the end of processing to avoid
50  /// breaking the SCC traversal.
51  bool doFinalization(CallGraph &CG) override;
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;
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);
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.
70  bool inlineCalls(CallGraphSCC &SCC);
72 private:
73  // Insert @llvm.lifetime intrinsics.
74  bool InsertLifetime = true;
76 protected:
79  std::function<const TargetLibraryInfo &(Function &)> GetTLI;
81 };
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() = default;
100  ~InlinerPass();
107 private:
110  std::unique_ptr<ImportedFunctionsInliningStatistics> ImportedFunctionsStats;
111  Optional<DefaultInlineAdvisor> OwnedDefaultAdvisor;
112 };
114 /// Module pass, wrapping the inliner pass. This works in conjunction with the
115 /// InlineAdvisorAnalysis to facilitate inlining decisions taking into account
116 /// module-wide state, that need to keep track of inter-inliner pass runs, for
117 /// a given module. An InlineAdvisor is configured and kept alive for the
118 /// duration of the ModuleInlinerWrapperPass::run.
120  : public PassInfoMixin<ModuleInlinerWrapperPass> {
121 public:
123  InlineParams Params = getInlineParams(), bool Debugging = false,
125  unsigned MaxDevirtIterations = 0);
130  /// Allow adding more CGSCC passes, besides inlining. This should be called
131  /// before run is called, as part of pass pipeline building.
132  CGSCCPassManager &getPM() { return PM; }
134  /// Allow adding module-level analyses benefiting the contained CGSCC passes.
135  template <class T> void addRequiredModuleAnalysis() {
136  MPM.addPass(RequireAnalysisPass<T, Module>());
137  }
139 private:
140  const InlineParams Params;
142  const unsigned MaxDevirtIterations;
143  CGSCCPassManager PM;
144  ModulePassManager MPM;
145 };
146 } // end namespace llvm
InlinerPass(InlinerPass &&Arg)
Definition: Inliner.h:101
uint64_t CallInst * C
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:157
bool doFinalization(CallGraph &CG) override
Remove now-dead linkonce functions at the end of processing to avoid breaking the SCC traversal...
Definition: Inliner.cpp:572
SI Whole Quad Mode
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:67
Analysis providing profile information.
Implements a lazy call graph analysis and related passes for the new pass manager.
An immutable pass that tracks lazily created AssumptionCache objects.
There are 3 scenarios we can use the InlineAdvisor:
Definition: InlineAdvisor.h:39
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1098
Calculate and dump ThinLTO specific inliner stats.
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1286
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
Represents the cost of inlining a function.
Definition: InlineCost.h:64
Interface for deciding whether to inline a call site or not.
bool runOnSCC(CallGraphSCC &SCC) override
Main run interface method, this implements the interface required by the Pass class.
Definition: Inliner.cpp:312
Definition: BitVector.h:959
This class contains all of the helper code which is used to perform the inlining operations that do n...
Definition: Inliner.h:30
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:106
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:373
A lazily constructed view of the call graph of a module.
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:102
static cl::opt< unsigned > MaxDevirtIterations("pm-max-devirt-iterations", cl::ReallyHidden, cl::init(4))
void getAnalysisUsage(AnalysisUsage &Info) const override
For this class, we declare that we require and preserve the call graph.
Definition: Inliner.cpp:121
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
bool inlineCalls(CallGraphSCC &SCC)
This function performs the main work of the pass.
Definition: Inliner.cpp:554
std::function< const TargetLibraryInfo &(Function &)> GetTLI
Definition: Inliner.h:79
Represent the analysis usage information of a pass.
The inliner pass for the new pass manager.
Definition: Inliner.h:97
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
void addRequiredModuleAnalysis()
Allow adding module-level analyses benefiting the contained CGSCC passes.
Definition: Inliner.h:135
virtual InlineCost getInlineCost(CallBase &CB)=0
This method must be implemented by the subclass to determine the cost of inlining the specified call ...
bool doInitialization(CallGraph &CG) override
doInitialization - This method is called before the SCC&#39;s of the program has been processed...
Definition: Inliner.cpp:306
Result proxy object for OuterAnalysisManagerProxy.
Definition: PassManager.h:1073
ImportedFunctionsInliningStatistics ImportedFunctionsStats
Definition: Inliner.h:80
CGSCCPassManager & getPM()
Allow adding more CGSCC passes, besides inlining.
Definition: Inliner.h:132
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options...
AssumptionCacheTracker * ACT
Definition: Inliner.h:77
bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly=false)
Remove dead functions.
Definition: Inliner.cpp:580
Module pass, wrapping the inliner pass.
Definition: Inliner.h:119
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:73
LegacyInlinerBase(char &ID)
Definition: Inliner.cpp:113
ProfileSummaryInfo * PSI
Definition: Inliner.h:78
This header provides classes for managing passes over SCCs of the call graph.
An SCC of the call graph.
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
PassManager< LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, CGSCCUpdateResult & > CGSCCPassManager
The CGSCC pass manager.
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.