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