LLVM 22.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
17#include "llvm/IR/PassManager.h"
19
20namespace llvm {
21
22/// The inliner pass for the new pass manager.
23///
24/// This pass wires together the inlining utilities and the inline cost
25/// analysis into a CGSCC pass. It considers every call in every function in
26/// the SCC and tries to inline if profitable. It can be tuned with a number of
27/// parameters to control what cost model is used and what tradeoffs are made
28/// when making the decision.
29///
30/// It should be noted that the legacy inliners do considerably more than this
31/// inliner pass does. They provide logic for manually merging allocas, and
32/// doing considerable DCE including the DCE of dead functions. This pass makes
33/// every attempt to be simpler. DCE of functions requires complex reasoning
34/// about comdat groups, etc. Instead, it is expected that other more focused
35/// passes be composed to achieve the same end result.
36class InlinerPass : public PassInfoMixin<InlinerPass> {
37public:
38 InlinerPass(bool OnlyMandatory = false,
40 : OnlyMandatory(OnlyMandatory), LTOPhase(LTOPhase) {}
41 InlinerPass(InlinerPass &&Arg) = default;
42
46
47 LLVM_ABI void
49 function_ref<StringRef(StringRef)> MapClassName2PassName);
50
51private:
54 std::unique_ptr<InlineAdvisor> OwnedAdvisor;
55 const bool OnlyMandatory;
56 const ThinOrFullLTOPhase LTOPhase;
57};
58
59/// Module pass, wrapping the inliner pass. This works in conjunction with the
60/// InlineAdvisorAnalysis to facilitate inlining decisions taking into account
61/// module-wide state, that need to keep track of inter-inliner pass runs, for
62/// a given module. An InlineAdvisor is configured and kept alive for the
63/// duration of the ModuleInlinerWrapperPass::run.
65 : public PassInfoMixin<ModuleInlinerWrapperPass> {
66public:
68 InlineParams Params = getInlineParams(), bool MandatoryFirst = true,
69 InlineContext IC = {},
71 unsigned MaxDevirtIterations = 0);
73
75
76 /// Allow adding more CGSCC passes, besides inlining. This should be called
77 /// before run is called, as part of pass pipeline building.
78 CGSCCPassManager &getPM() { return PM; }
79
80 /// Add a module pass that runs before the CGSCC passes.
81 template <class T> void addModulePass(T Pass) {
82 MPM.addPass(std::move(Pass));
83 }
84
85 /// Add a module pass that runs after the CGSCC passes.
86 template <class T> void addLateModulePass(T Pass) {
87 AfterCGMPM.addPass(std::move(Pass));
88 }
89
90 LLVM_ABI void
92 function_ref<StringRef(StringRef)> MapClassName2PassName);
93
94private:
95 const InlineParams Params;
96 const InlineContext IC;
97 const InliningAdvisorMode Mode;
98 const unsigned MaxDevirtIterations;
99 // TODO: Clean this up so we only have one ModulePassManager.
102 ModulePassManager AfterCGMPM;
103};
104} // end namespace llvm
105
106#endif // LLVM_TRANSFORMS_IPO_INLINER_H
This header provides classes for managing passes over SCCs of the call graph.
#define LLVM_ABI
Definition: Compiler.h:213
This header defines various interfaces for pass management in LLVM.
Implements a lazy call graph analysis and related passes for the new pass manager.
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
Interface for deciding whether to inline a call site or not.
The inliner pass for the new pass manager.
Definition: Inliner.h:36
InlinerPass(bool OnlyMandatory=false, ThinOrFullLTOPhase LTOPhase=ThinOrFullLTOPhase::None)
Definition: Inliner.h:38
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: Inliner.cpp:644
LLVM_ABI PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Definition: Inliner.cpp:206
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:65
void addModulePass(T Pass)
Add a module pass that runs before the CGSCC passes.
Definition: Inliner.h:81
LLVM_ABI PreservedAnalyses run(Module &, ModuleAnalysisManager &)
Definition: Inliner.cpp:605
CGSCCPassManager & getPM()
Allow adding more CGSCC passes, besides inlining.
Definition: Inliner.h:78
void addLateModulePass(T Pass)
Add a module pass that runs after the CGSCC passes.
Definition: Inliner.h:86
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
Definition: Inliner.cpp:652
ModuleInlinerWrapperPass(ModuleInlinerWrapperPass &&Arg)=default
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
Result proxy object for OuterAnalysisManagerProxy.
Definition: PassManager.h:719
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
Definition: PassManager.h:196
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
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:53
@ 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:43
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
Definition: Pass.h:77
@ None
No LTO/ThinLTO behavior needed.
LLVM_ABI 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:59
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:207
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:70