LLVM  16.0.0git
PassManagerBuilder.h
Go to the documentation of this file.
1 // llvm/Transforms/IPO/PassManagerBuilder.h - Build Standard Pass -*- 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 // This file defines the PassManagerBuilder class, which is used to set up a
10 // "standard" optimization sequence suitable for languages like C and C++.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
15 #define LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
16 
18 #include <functional>
19 #include <string>
20 #include <vector>
21 
22 namespace llvm {
23 class ModuleSummaryIndex;
24 class Pass;
25 class TargetLibraryInfoImpl;
26 
27 // The old pass manager infrastructure is hidden in a legacy namespace now.
28 namespace legacy {
30 class PassManagerBase;
31 }
32 
33 /// PassManagerBuilder - This class is used to set up a standard optimization
34 /// sequence for languages like C and C++, allowing some APIs to customize the
35 /// pass sequence in various ways. A simple example of using it would be:
36 ///
37 /// PassManagerBuilder Builder;
38 /// Builder.OptLevel = 2;
39 /// Builder.populateFunctionPassManager(FPM);
40 /// Builder.populateModulePassManager(MPM);
41 ///
42 /// In addition to setting up the basic passes, PassManagerBuilder allows
43 /// frontends to vend a plugin API, where plugins are allowed to add extensions
44 /// to the default pass manager. They do this by specifying where in the pass
45 /// pipeline they want to be added, along with a callback function that adds
46 /// the pass(es). For example, a plugin that wanted to add a loop optimization
47 /// could do something like this:
48 ///
49 /// static void addMyLoopPass(const PMBuilder &Builder, PassManagerBase &PM) {
50 /// if (Builder.getOptLevel() > 2 && Builder.getOptSizeLevel() == 0)
51 /// PM.add(createMyAwesomePass());
52 /// }
53 /// ...
54 /// Builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd,
55 /// addMyLoopPass);
56 /// ...
58 public:
59  /// Extensions are passed to the builder itself (so they can see how it is
60  /// configured) as well as the pass manager to add stuff to.
61  typedef std::function<void(const PassManagerBuilder &Builder,
64  typedef int GlobalExtensionID;
65 
67  /// EP_EarlyAsPossible - This extension point allows adding passes before
68  /// any other transformations, allowing them to see the code as it is coming
69  /// out of the frontend.
71 
72  /// EP_ModuleOptimizerEarly - This extension point allows adding passes
73  /// just before the main module-level optimization passes.
75 
76  /// EP_LoopOptimizerEnd - This extension point allows adding loop passes to
77  /// the end of the loop optimizer.
79 
80  /// EP_ScalarOptimizerLate - This extension point allows adding optimization
81  /// passes after most of the main optimizations, but before the last
82  /// cleanup-ish optimizations.
84 
85  /// EP_OptimizerLast -- This extension point allows adding passes that
86  /// run after everything else.
88 
89  /// EP_VectorizerStart - This extension point allows adding optimization
90  /// passes before the vectorizer and other highly target specific
91  /// optimization passes are executed.
93 
94  /// EP_EnabledOnOptLevel0 - This extension point allows adding passes that
95  /// should not be disabled by O0 optimization level. The passes will be
96  /// inserted after the inlining pass.
98 
99  /// EP_Peephole - This extension point allows adding passes that perform
100  /// peephole optimizations similar to the instruction combiner. These passes
101  /// will be inserted after each instance of the instruction combiner pass.
103 
104  /// EP_LateLoopOptimizations - This extension point allows adding late loop
105  /// canonicalization and simplification passes. This is the last point in
106  /// the loop optimization pipeline before loop deletion. Each pass added
107  /// here must be an instance of LoopPass.
108  /// This is the place to add passes that can remove loops, such as target-
109  /// specific loop idiom recognition.
111 
112  /// EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC
113  /// passes at the end of the main CallGraphSCC passes and before any
114  /// function simplification passes run by CGPassManager.
116 
117  /// EP_FullLinkTimeOptimizationEarly - This extensions point allow adding
118  /// passes that
119  /// run at Link Time, before Full Link Time Optimization.
121 
122  /// EP_FullLinkTimeOptimizationLast - This extensions point allow adding
123  /// passes that
124  /// run at Link Time, after Full Link Time Optimization.
126  };
127 
128  /// The Optimization Level - Specify the basic optimization level.
129  /// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
130  unsigned OptLevel;
131 
132  /// SizeLevel - How much we're optimizing for size.
133  /// 0 = none, 1 = -Os, 2 = -Oz
134  unsigned SizeLevel;
135 
136  /// LibraryInfo - Specifies information about the runtime library for the
137  /// optimizer. If this is non-null, it is added to both the function and
138  /// per-module pass pipeline.
140 
141  /// Inliner - Specifies the inliner to use. If this is non-null, it is
142  /// added to the per-module passes.
144 
145  /// The module summary index to use for exporting information from the
146  /// regular LTO phase, for example for the CFI and devirtualization type
147  /// tests.
149 
150  /// The module summary index to use for importing information to the
151  /// thin LTO backends, for example for the CFI and devirtualization type
152  /// tests.
154 
161  bool NewGVN;
168  unsigned LicmMssaOptCap;
170 
171 private:
172  /// ExtensionList - This is list of all of the extensions that are registered.
173  std::vector<std::pair<ExtensionPointTy, ExtensionFn>> Extensions;
174 
175 public:
178  /// Adds an extension that will be used by all PassManagerBuilder instances.
179  /// This is intended to be used by plugins, to register a set of
180  /// optimisations to run automatically.
181  ///
182  /// \returns A global extension identifier that can be used to remove the
183  /// extension.
185  ExtensionFn Fn);
186  /// Removes an extension that was previously added using addGlobalExtension.
187  /// This is also intended to be used by plugins, to remove any extension that
188  /// was previously registered before being unloaded.
189  ///
190  /// \param ExtensionID Identifier of the extension to be removed.
191  static void removeGlobalExtension(GlobalExtensionID ExtensionID);
193 
194 private:
195  void addExtensionsToPM(ExtensionPointTy ETy,
196  legacy::PassManagerBase &PM) const;
197  void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
198  void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
199  void addVectorPasses(legacy::PassManagerBase &PM, bool IsFullLTO);
200 
201 public:
202  /// populateFunctionPassManager - This fills in the function pass manager,
203  /// which is expected to be run on each function immediately as it is
204  /// generated. The idea is to reduce the size of the IR in memory.
206 
207  /// populateModulePassManager - This sets up the primary pass manager.
209 };
210 
211 /// Registers a function for adding a standard set of passes. This should be
212 /// used by optimizer plugins to allow all front ends to transparently use
213 /// them. Create a static instance of this class in your plugin, providing a
214 /// private function that the PassManagerBuilder can use to add your passes.
217 
218 public:
221  ExtensionID = PassManagerBuilder::addGlobalExtension(Ty, std::move(Fn));
222  }
223 
225  // If the collection holding the global extensions is destroyed after the
226  // plugin is unloaded, the extension has to be removed here. Indeed, the
227  // destructor of the ExtensionFn may reference code in the plugin.
229  }
230 };
231 
233  return reinterpret_cast<PassManagerBuilder*>(P);
234 }
235 
237  return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
238 }
239 
240 } // end namespace llvm
241 #endif
llvm::PassManagerBuilder::LicmMssaOptCap
unsigned LicmMssaOptCap
Definition: PassManagerBuilder.h:168
llvm::PassManagerBuilder::EP_OptimizerLast
@ EP_OptimizerLast
EP_OptimizerLast – This extension point allows adding passes that run after everything else.
Definition: PassManagerBuilder.h:87
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Pass
print lazy value Lazy Value Info Printer Pass
Definition: LazyValueInfo.cpp:1979
llvm::PassManagerBuilder::PassManagerBuilder
PassManagerBuilder()
Definition: PassManagerBuilder.cpp:169
llvm::PassManagerBuilder::VerifyOutput
bool VerifyOutput
Definition: PassManagerBuilder.h:165
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::PassManagerBuilder::LoopVectorize
bool LoopVectorize
Definition: PassManagerBuilder.h:158
llvm::PassManagerBuilder::DisableGVNLoadPRE
bool DisableGVNLoadPRE
Definition: PassManagerBuilder.h:162
llvm::PassManagerBuilder::ImportSummary
const ModuleSummaryIndex * ImportSummary
The module summary index to use for importing information to the thin LTO backends,...
Definition: PassManagerBuilder.h:153
llvm::PassManagerBuilder::ExtensionPointTy
ExtensionPointTy
Definition: PassManagerBuilder.h:66
llvm::PassManagerBuilder::ForgetAllSCEVInLoopUnroll
bool ForgetAllSCEVInLoopUnroll
Definition: PassManagerBuilder.h:163
llvm::TargetLibraryInfoImpl
Implementation of the target library information.
Definition: TargetLibraryInfo.h:49
llvm::PassManagerBuilder::ExportSummary
ModuleSummaryIndex * ExportSummary
The module summary index to use for exporting information from the regular LTO phase,...
Definition: PassManagerBuilder.h:148
llvm::PassManagerBuilder::EP_LoopOptimizerEnd
@ EP_LoopOptimizerEnd
EP_LoopOptimizerEnd - This extension point allows adding loop passes to the end of the loop optimizer...
Definition: PassManagerBuilder.h:78
llvm::PassManagerBuilder::NewGVN
bool NewGVN
Definition: PassManagerBuilder.h:161
llvm::PassManagerBuilder::addGlobalExtension
static GlobalExtensionID addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn)
Adds an extension that will be used by all PassManagerBuilder instances.
Definition: PassManagerBuilder.cpp:213
llvm::PassManagerBuilder::LibraryInfo
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
Definition: PassManagerBuilder.h:139
llvm::FunctionPassManager
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
Definition: PassManager.h:587
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:280
llvm::PassManagerBuilder::Inliner
Pass * Inliner
Inliner - Specifies the inliner to use.
Definition: PassManagerBuilder.h:143
llvm::PassManagerBuilder::MergeFunctions
bool MergeFunctions
Definition: PassManagerBuilder.h:166
llvm::PassManagerBuilder::LicmMssaNoAccForPromotionCap
unsigned LicmMssaNoAccForPromotionCap
Definition: PassManagerBuilder.h:169
llvm::PassManagerBuilder::LoopsInterleaved
bool LoopsInterleaved
Definition: PassManagerBuilder.h:159
llvm::PassManagerBuilder
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
Definition: PassManagerBuilder.h:57
llvm::PassManagerBuilder::~PassManagerBuilder
~PassManagerBuilder()
Definition: PassManagerBuilder.cpp:191
llvm::PassManagerBuilder::EP_ScalarOptimizerLate
@ EP_ScalarOptimizerLate
EP_ScalarOptimizerLate - This extension point allows adding optimization passes after most of the mai...
Definition: PassManagerBuilder.h:83
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::PassManagerBuilder::ExtensionFn
std::function< void(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)> ExtensionFn
Extensions are passed to the builder itself (so they can see how it is configured) as well as the pas...
Definition: PassManagerBuilder.h:63
llvm::RegisterStandardPasses::~RegisterStandardPasses
~RegisterStandardPasses()
Definition: PassManagerBuilder.h:224
LLVMPassManagerBuilderRef
struct LLVMOpaquePassManagerBuilder * LLVMPassManagerBuilderRef
Definition: PassManagerBuilder.h:20
llvm::PassManagerBuilder::RerollLoops
bool RerollLoops
Definition: PassManagerBuilder.h:160
llvm::PassManagerBuilder::OptLevel
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
Definition: PassManagerBuilder.h:130
llvm::PassManagerBuilder::GlobalExtensionID
int GlobalExtensionID
Definition: PassManagerBuilder.h:64
llvm::PassManagerBuilder::VerifyInput
bool VerifyInput
Definition: PassManagerBuilder.h:164
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:275
llvm::PassManagerBuilder::CallGraphProfile
bool CallGraphProfile
Definition: PassManagerBuilder.h:156
llvm::PassManagerBuilder::SLPVectorize
bool SLPVectorize
Definition: PassManagerBuilder.h:157
llvm::RegisterStandardPasses
Registers a function for adding a standard set of passes.
Definition: PassManagerBuilder.h:215
llvm::PassManagerBuilder::EP_Peephole
@ EP_Peephole
EP_Peephole - This extension point allows adding passes that perform peephole optimizations similar t...
Definition: PassManagerBuilder.h:102
llvm::PassManagerBuilder::removeGlobalExtension
static void removeGlobalExtension(GlobalExtensionID ExtensionID)
Removes an extension that was previously added using addGlobalExtension.
Definition: PassManagerBuilder.cpp:220
llvm::PassManagerBuilder::EP_VectorizerStart
@ EP_VectorizerStart
EP_VectorizerStart - This extension point allows adding optimization passes before the vectorizer and...
Definition: PassManagerBuilder.h:92
llvm::PassManagerBuilder::populateModulePassManager
void populateModulePassManager(legacy::PassManagerBase &MPM)
populateModulePassManager - This sets up the primary pass manager.
Definition: PassManagerBuilder.cpp:576
llvm::PassManagerBuilder::EP_FullLinkTimeOptimizationLast
@ EP_FullLinkTimeOptimizationLast
EP_FullLinkTimeOptimizationLast - This extensions point allow adding passes that run at Link Time,...
Definition: PassManagerBuilder.h:125
llvm::PassManagerBuilder::EP_ModuleOptimizerEarly
@ EP_ModuleOptimizerEarly
EP_ModuleOptimizerEarly - This extension point allows adding passes just before the main module-level...
Definition: PassManagerBuilder.h:74
PassManagerBuilder.h
llvm::PassManagerBuilder::SizeLevel
unsigned SizeLevel
SizeLevel - How much we're optimizing for size.
Definition: PassManagerBuilder.h:134
llvm::PassManagerBuilder::EP_LateLoopOptimizations
@ EP_LateLoopOptimizations
EP_LateLoopOptimizations - This extension point allows adding late loop canonicalization and simplifi...
Definition: PassManagerBuilder.h:110
llvm::PassManagerBuilder::populateFunctionPassManager
void populateFunctionPassManager(legacy::FunctionPassManager &FPM)
populateFunctionPassManager - This fills in the function pass manager, which is expected to be run on...
Definition: PassManagerBuilder.cpp:278
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::PassManagerBuilder::DisableUnrollLoops
bool DisableUnrollLoops
Definition: PassManagerBuilder.h:155
llvm::PassManagerBuilder::EP_EarlyAsPossible
@ EP_EarlyAsPossible
EP_EarlyAsPossible - This extension point allows adding passes before any other transformations,...
Definition: PassManagerBuilder.h:70
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1087
llvm::legacy::FunctionPassManager
FunctionPassManager manages FunctionPasses.
Definition: LegacyPassManager.h:71
llvm::PassManagerBuilder::EP_EnabledOnOptLevel0
@ EP_EnabledOnOptLevel0
EP_EnabledOnOptLevel0 - This extension point allows adding passes that should not be disabled by O0 o...
Definition: PassManagerBuilder.h:97
llvm::legacy::PassManagerBase
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Definition: LegacyPassManager.h:39
llvm::PassManagerBuilder::addExtension
void addExtension(ExtensionPointTy Ty, ExtensionFn Fn)
Definition: PassManagerBuilder.cpp:237
llvm::PassManagerBuilder::EP_FullLinkTimeOptimizationEarly
@ EP_FullLinkTimeOptimizationEarly
EP_FullLinkTimeOptimizationEarly - This extensions point allow adding passes that run at Link Time,...
Definition: PassManagerBuilder.h:120
llvm::PassManagerBuilder::DivergentTarget
bool DivergentTarget
Definition: PassManagerBuilder.h:167
llvm::PassManagerBuilder::EP_CGSCCOptimizerLate
@ EP_CGSCCOptimizerLate
EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC passes at the end of the main...
Definition: PassManagerBuilder.h:115
MPM
ModulePassManager MPM
Definition: PassBuilderBindings.cpp:70
llvm::RegisterStandardPasses::RegisterStandardPasses
RegisterStandardPasses(PassManagerBuilder::ExtensionPointTy Ty, PassManagerBuilder::ExtensionFn Fn)
Definition: PassManagerBuilder.h:219