LLVM  9.0.0svn
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 
16 #include "llvm/IR/CallSite.h"
17 #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 
39  bool doInitialization(CallGraph &CG) override;
40 
41  /// Main run interface method, this implements the interface required by the
42  /// Pass class.
43  bool runOnSCC(CallGraphSCC &SCC) override;
44 
46 
47  /// Remove now-dead linkonce functions at the end of processing to avoid
48  /// breaking the SCC traversal.
49  bool doFinalization(CallGraph &CG) override;
50 
51  /// This method must be implemented by the subclass to determine the cost of
52  /// inlining the specified call site. If the cost returned is greater than
53  /// the current inline threshold, the call site is not inlined.
54  virtual InlineCost getInlineCost(CallSite CS) = 0;
55 
56  /// Remove dead functions.
57  ///
58  /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
59  /// which restricts it to deleting functions with an 'AlwaysInline'
60  /// attribute. This is useful for the InlineAlways pass that only wants to
61  /// deal with that subset of the functions.
62  bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
63 
64  /// This function performs the main work of the pass. The default of
65  /// Inlinter::runOnSCC() calls skipSCC() before calling this method, but
66  /// derived classes which cannot be skipped can override that method and call
67  /// this function unconditionally.
68  bool inlineCalls(CallGraphSCC &SCC);
69 
70 private:
71  // Insert @llvm.lifetime intrinsics.
72  bool InsertLifetime = true;
73 
74 protected:
78 };
79 
80 /// The inliner pass for the new pass manager.
81 ///
82 /// This pass wires together the inlining utilities and the inline cost
83 /// analysis into a CGSCC pass. It considers every call in every function in
84 /// the SCC and tries to inline if profitable. It can be tuned with a number of
85 /// parameters to control what cost model is used and what tradeoffs are made
86 /// when making the decision.
87 ///
88 /// It should be noted that the legacy inliners do considerably more than this
89 /// inliner pass does. They provide logic for manually merging allocas, and
90 /// doing considerable DCE including the DCE of dead functions. This pass makes
91 /// every attempt to be simpler. DCE of functions requires complex reasoning
92 /// about comdat groups, etc. Instead, it is expected that other more focused
93 /// passes be composed to achieve the same end result.
94 class InlinerPass : public PassInfoMixin<InlinerPass> {
95 public:
97  : Params(std::move(Params)) {}
98  ~InlinerPass();
100  : Params(std::move(Arg.Params)),
102 
105 
106 private:
107  InlineParams Params;
108  std::unique_ptr<ImportedFunctionsInliningStatistics> ImportedFunctionsStats;
109 };
110 
111 } // end namespace llvm
112 
113 #endif // LLVM_TRANSFORMS_IPO_INLINER_H
InlinerPass(InlinerPass &&Arg)
Definition: Inliner.h:99
uint64_t CallInst * C
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:153
bool doFinalization(CallGraph &CG) override
Remove now-dead linkonce functions at the end of processing to avoid breaking the SCC traversal...
Definition: Inliner.cpp:771
This class represents lattice values for constants.
Definition: AllocatorList.h:23
virtual InlineCost getInlineCost(CallSite CS)=0
This method must be implemented by the subclass to determine the cost of inlining the specified call ...
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.
Calculate and dump ThinLTO specific inliner stats.
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:63
bool runOnSCC(CallGraphSCC &SCC) override
Main run interface method, this implements the interface required by the Pass class.
Definition: Inliner.cpp:501
Definition: BitVector.h:937
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:109
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:365
A lazily constructed view of the call graph of a module.
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
void getAnalysisUsage(AnalysisUsage &Info) const override
For this class, we declare that we require and preserve the call graph.
Definition: Inliner.cpp:131
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
bool inlineCalls(CallGraphSCC &SCC)
This function performs the main work of the pass.
Definition: Inliner.cpp:756
Represent the analysis usage information of a pass.
The inliner pass for the new pass manager.
Definition: Inliner.h:94
bool doInitialization(CallGraph &CG) override
doInitialization - This method is called before the SCC&#39;s of the program has been processed...
Definition: Inliner.cpp:495
ImportedFunctionsInliningStatistics ImportedFunctionsStats
Definition: Inliner.h:77
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options...
AssumptionCacheTracker * ACT
Definition: Inliner.h:75
bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly=false)
Remove dead functions.
Definition: Inliner.cpp:779
InlinerPass(InlineParams Params=getInlineParams())
Definition: Inliner.h:96
amdgpu Simplify well known AMD library false Value Value * Arg
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:73
LegacyInlinerBase(char &ID)
Definition: Inliner.cpp:123
ProfileSummaryInfo * PSI
Definition: Inliner.h:76
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.
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.