LLVM  14.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 <memory>
20 #include <string>
21 #include <vector>
22 
23 namespace llvm {
24 class ModuleSummaryIndex;
25 class Pass;
26 class TargetLibraryInfoImpl;
27 class TargetMachine;
28 
29 // The old pass manager infrastructure is hidden in a legacy namespace now.
30 namespace legacy {
32 class PassManagerBase;
33 }
34 
35 /// PassManagerBuilder - This class is used to set up a standard optimization
36 /// sequence for languages like C and C++, allowing some APIs to customize the
37 /// pass sequence in various ways. A simple example of using it would be:
38 ///
39 /// PassManagerBuilder Builder;
40 /// Builder.OptLevel = 2;
41 /// Builder.populateFunctionPassManager(FPM);
42 /// Builder.populateModulePassManager(MPM);
43 ///
44 /// In addition to setting up the basic passes, PassManagerBuilder allows
45 /// frontends to vend a plugin API, where plugins are allowed to add extensions
46 /// to the default pass manager. They do this by specifying where in the pass
47 /// pipeline they want to be added, along with a callback function that adds
48 /// the pass(es). For example, a plugin that wanted to add a loop optimization
49 /// could do something like this:
50 ///
51 /// static void addMyLoopPass(const PMBuilder &Builder, PassManagerBase &PM) {
52 /// if (Builder.getOptLevel() > 2 && Builder.getOptSizeLevel() == 0)
53 /// PM.add(createMyAwesomePass());
54 /// }
55 /// ...
56 /// Builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd,
57 /// addMyLoopPass);
58 /// ...
60 public:
61  /// Extensions are passed to the builder itself (so they can see how it is
62  /// configured) as well as the pass manager to add stuff to.
63  typedef std::function<void(const PassManagerBuilder &Builder,
66  typedef int GlobalExtensionID;
67 
69  /// EP_EarlyAsPossible - This extension point allows adding passes before
70  /// any other transformations, allowing them to see the code as it is coming
71  /// out of the frontend.
73 
74  /// EP_ModuleOptimizerEarly - This extension point allows adding passes
75  /// just before the main module-level optimization passes.
77 
78  /// EP_LoopOptimizerEnd - This extension point allows adding loop passes to
79  /// the end of the loop optimizer.
81 
82  /// EP_ScalarOptimizerLate - This extension point allows adding optimization
83  /// passes after most of the main optimizations, but before the last
84  /// cleanup-ish optimizations.
86 
87  /// EP_OptimizerLast -- This extension point allows adding passes that
88  /// run after everything else.
90 
91  /// EP_VectorizerStart - This extension point allows adding optimization
92  /// passes before the vectorizer and other highly target specific
93  /// optimization passes are executed.
95 
96  /// EP_EnabledOnOptLevel0 - This extension point allows adding passes that
97  /// should not be disabled by O0 optimization level. The passes will be
98  /// inserted after the inlining pass.
100 
101  /// EP_Peephole - This extension point allows adding passes that perform
102  /// peephole optimizations similar to the instruction combiner. These passes
103  /// will be inserted after each instance of the instruction combiner pass.
105 
106  /// EP_LateLoopOptimizations - This extension point allows adding late loop
107  /// canonicalization and simplification passes. This is the last point in
108  /// the loop optimization pipeline before loop deletion. Each pass added
109  /// here must be an instance of LoopPass.
110  /// This is the place to add passes that can remove loops, such as target-
111  /// specific loop idiom recognition.
113 
114  /// EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC
115  /// passes at the end of the main CallGraphSCC passes and before any
116  /// function simplification passes run by CGPassManager.
118 
119  /// EP_FullLinkTimeOptimizationEarly - This extensions point allow adding
120  /// passes that
121  /// run at Link Time, before Full Link Time Optimization.
123 
124  /// EP_FullLinkTimeOptimizationLast - This extensions point allow adding
125  /// passes that
126  /// run at Link Time, after Full Link Time Optimization.
128  };
129 
130  /// The Optimization Level - Specify the basic optimization level.
131  /// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
132  unsigned OptLevel;
133 
134  /// SizeLevel - How much we're optimizing for size.
135  /// 0 = none, 1 = -Os, 2 = -Oz
136  unsigned SizeLevel;
137 
138  /// LibraryInfo - Specifies information about the runtime library for the
139  /// optimizer. If this is non-null, it is added to both the function and
140  /// per-module pass pipeline.
142 
143  /// Inliner - Specifies the inliner to use. If this is non-null, it is
144  /// added to the per-module passes.
146 
147  /// The module summary index to use for exporting information from the
148  /// regular LTO phase, for example for the CFI and devirtualization type
149  /// tests.
151 
152  /// The module summary index to use for importing information to the
153  /// thin LTO backends, for example for the CFI and devirtualization type
154  /// tests.
156 
163  bool NewGVN;
173  unsigned LicmMssaOptCap;
175 
176  /// Enable profile instrumentation pass.
178  /// Enable profile context sensitive instrumentation pass.
180  /// Enable profile context sensitive profile use pass.
182  /// Profile data file name that the instrumentation will be written to.
183  std::string PGOInstrGen;
184  /// Path of the profile data file.
185  std::string PGOInstrUse;
186  /// Path of the sample Profile data file.
187  std::string PGOSampleUse;
188 
189 private:
190  /// ExtensionList - This is list of all of the extensions that are registered.
191  std::vector<std::pair<ExtensionPointTy, ExtensionFn>> Extensions;
192 
193 public:
196  /// Adds an extension that will be used by all PassManagerBuilder instances.
197  /// This is intended to be used by plugins, to register a set of
198  /// optimisations to run automatically.
199  ///
200  /// \returns A global extension identifier that can be used to remove the
201  /// extension.
203  ExtensionFn Fn);
204  /// Removes an extension that was previously added using addGlobalExtension.
205  /// This is also intended to be used by plugins, to remove any extension that
206  /// was previously registered before being unloaded.
207  ///
208  /// \param ExtensionID Identifier of the extension to be removed.
209  static void removeGlobalExtension(GlobalExtensionID ExtensionID);
211 
212 private:
213  void addExtensionsToPM(ExtensionPointTy ETy,
214  legacy::PassManagerBase &PM) const;
215  void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
216  void addLTOOptimizationPasses(legacy::PassManagerBase &PM);
217  void addLateLTOOptimizationPasses(legacy::PassManagerBase &PM);
218  void addPGOInstrPasses(legacy::PassManagerBase &MPM, bool IsCS);
219  void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
220  void addVectorPasses(legacy::PassManagerBase &PM, bool IsFullLTO);
221 
222 public:
223  /// populateFunctionPassManager - This fills in the function pass manager,
224  /// which is expected to be run on each function immediately as it is
225  /// generated. The idea is to reduce the size of the IR in memory.
227 
228  /// populateModulePassManager - This sets up the primary pass manager.
232 };
233 
234 /// Registers a function for adding a standard set of passes. This should be
235 /// used by optimizer plugins to allow all front ends to transparently use
236 /// them. Create a static instance of this class in your plugin, providing a
237 /// private function that the PassManagerBuilder can use to add your passes.
240 
241 public:
244  ExtensionID = PassManagerBuilder::addGlobalExtension(Ty, std::move(Fn));
245  }
246 
248  // If the collection holding the global extensions is destroyed after the
249  // plugin is unloaded, the extension has to be removed here. Indeed, the
250  // destructor of the ExtensionFn may reference code in the plugin.
252  }
253 };
254 
256  return reinterpret_cast<PassManagerBuilder*>(P);
257 }
258 
260  return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
261 }
262 
263 } // end namespace llvm
264 #endif
llvm::PassManagerBuilder::LicmMssaOptCap
unsigned LicmMssaOptCap
Definition: PassManagerBuilder.h:173
llvm::PassManagerBuilder::EP_OptimizerLast
@ EP_OptimizerLast
EP_OptimizerLast – This extension point allows adding passes that run after everything else.
Definition: PassManagerBuilder.h:89
llvm::PassManagerBuilder::PGOSampleUse
std::string PGOSampleUse
Path of the sample Profile data file.
Definition: PassManagerBuilder.h:187
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Pass
print lazy value Lazy Value Info Printer Pass
Definition: LazyValueInfo.cpp:1966
llvm::PassManagerBuilder::PassManagerBuilder
PassManagerBuilder()
Definition: PassManagerBuilder.cpp:194
llvm::PassManagerBuilder::VerifyOutput
bool VerifyOutput
Definition: PassManagerBuilder.h:167
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::populateLTOPassManager
void populateLTOPassManager(legacy::PassManagerBase &PM)
Definition: PassManagerBuilder.cpp:1211
llvm::PassManagerBuilder::LoopVectorize
bool LoopVectorize
Definition: PassManagerBuilder.h:160
llvm::PassManagerBuilder::DisableGVNLoadPRE
bool DisableGVNLoadPRE
Definition: PassManagerBuilder.h:164
llvm::PassManagerBuilder::ImportSummary
const ModuleSummaryIndex * ImportSummary
The module summary index to use for importing information to the thin LTO backends,...
Definition: PassManagerBuilder.h:155
llvm::PassManagerBuilder::PerformThinLTO
bool PerformThinLTO
Definition: PassManagerBuilder.h:171
llvm::PassManagerBuilder::ExtensionPointTy
ExtensionPointTy
Definition: PassManagerBuilder.h:68
llvm::PassManagerBuilder::ForgetAllSCEVInLoopUnroll
bool ForgetAllSCEVInLoopUnroll
Definition: PassManagerBuilder.h:165
llvm::TargetLibraryInfoImpl
Implementation of the target library information.
Definition: TargetLibraryInfo.h:48
llvm::PassManagerBuilder::ExportSummary
ModuleSummaryIndex * ExportSummary
The module summary index to use for exporting information from the regular LTO phase,...
Definition: PassManagerBuilder.h:150
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:80
llvm::PassManagerBuilder::PGOInstrGen
std::string PGOInstrGen
Profile data file name that the instrumentation will be written to.
Definition: PassManagerBuilder.h:183
llvm::PassManagerBuilder::NewGVN
bool NewGVN
Definition: PassManagerBuilder.h:163
llvm::PassManagerBuilder::addGlobalExtension
static GlobalExtensionID addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn)
Adds an extension that will be used by all PassManagerBuilder instances.
Definition: PassManagerBuilder.cpp:247
llvm::PassManagerBuilder::LibraryInfo
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
Definition: PassManagerBuilder.h:141
llvm::FunctionPassManager
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
Definition: PassManager.h:592
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:256
llvm::PassManagerBuilder::PrepareForThinLTO
bool PrepareForThinLTO
Definition: PassManagerBuilder.h:170
llvm::PassManagerBuilder::Inliner
Pass * Inliner
Inliner - Specifies the inliner to use.
Definition: PassManagerBuilder.h:145
llvm::PassManagerBuilder::MergeFunctions
bool MergeFunctions
Definition: PassManagerBuilder.h:168
llvm::PassManagerBuilder::LicmMssaNoAccForPromotionCap
unsigned LicmMssaNoAccForPromotionCap
Definition: PassManagerBuilder.h:174
llvm::PassManagerBuilder::LoopsInterleaved
bool LoopsInterleaved
Definition: PassManagerBuilder.h:161
llvm::PassManagerBuilder
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
Definition: PassManagerBuilder.h:59
llvm::PassManagerBuilder::~PassManagerBuilder
~PassManagerBuilder()
Definition: PassManagerBuilder.cpp:225
llvm::PassManagerBuilder::EP_ScalarOptimizerLate
@ EP_ScalarOptimizerLate
EP_ScalarOptimizerLate - This extension point allows adding optimization passes after most of the mai...
Definition: PassManagerBuilder.h:85
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:65
llvm::RegisterStandardPasses::~RegisterStandardPasses
~RegisterStandardPasses()
Definition: PassManagerBuilder.h:247
LLVMPassManagerBuilderRef
struct LLVMOpaquePassManagerBuilder * LLVMPassManagerBuilderRef
Definition: PassManagerBuilder.h:20
llvm::PassManagerBuilder::RerollLoops
bool RerollLoops
Definition: PassManagerBuilder.h:162
llvm::PassManagerBuilder::OptLevel
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
Definition: PassManagerBuilder.h:132
llvm::PassManagerBuilder::PGOInstrUse
std::string PGOInstrUse
Path of the profile data file.
Definition: PassManagerBuilder.h:185
llvm::PassManagerBuilder::GlobalExtensionID
int GlobalExtensionID
Definition: PassManagerBuilder.h:66
llvm::PassManagerBuilder::VerifyInput
bool VerifyInput
Definition: PassManagerBuilder.h:166
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:251
llvm::PassManagerBuilder::CallGraphProfile
bool CallGraphProfile
Definition: PassManagerBuilder.h:158
llvm::PassManagerBuilder::SLPVectorize
bool SLPVectorize
Definition: PassManagerBuilder.h:159
llvm::RegisterStandardPasses
Registers a function for adding a standard set of passes.
Definition: PassManagerBuilder.h:238
llvm::PassManagerBuilder::EP_Peephole
@ EP_Peephole
EP_Peephole - This extension point allows adding passes that perform peephole optimizations similar t...
Definition: PassManagerBuilder.h:104
llvm::PassManagerBuilder::PrepareForLTO
bool PrepareForLTO
Definition: PassManagerBuilder.h:169
llvm::PassManagerBuilder::removeGlobalExtension
static void removeGlobalExtension(GlobalExtensionID ExtensionID)
Removes an extension that was previously added using addGlobalExtension.
Definition: PassManagerBuilder.cpp:254
llvm::PassManagerBuilder::EP_VectorizerStart
@ EP_VectorizerStart
EP_VectorizerStart - This extension point allows adding optimization passes before the vectorizer and...
Definition: PassManagerBuilder.h:94
llvm::PassManagerBuilder::EnablePGOInstrGen
bool EnablePGOInstrGen
Enable profile instrumentation pass.
Definition: PassManagerBuilder.h:177
llvm::PassManagerBuilder::populateModulePassManager
void populateModulePassManager(legacy::PassManagerBase &MPM)
populateModulePassManager - This sets up the primary pass manager.
Definition: PassManagerBuilder.cpp:658
llvm::PassManagerBuilder::EP_FullLinkTimeOptimizationLast
@ EP_FullLinkTimeOptimizationLast
EP_FullLinkTimeOptimizationLast - This extensions point allow adding passes that run at Link Time,...
Definition: PassManagerBuilder.h:127
llvm::PassManagerBuilder::EP_ModuleOptimizerEarly
@ EP_ModuleOptimizerEarly
EP_ModuleOptimizerEarly - This extension point allows adding passes just before the main module-level...
Definition: PassManagerBuilder.h:76
PassManagerBuilder.h
llvm::PassManagerBuilder::SizeLevel
unsigned SizeLevel
SizeLevel - How much we're optimizing for size.
Definition: PassManagerBuilder.h:136
llvm::PassManagerBuilder::EP_LateLoopOptimizations
@ EP_LateLoopOptimizations
EP_LateLoopOptimizations - This extension point allows adding late loop canonicalization and simplifi...
Definition: PassManagerBuilder.h:112
llvm::PassManagerBuilder::EnablePGOCSInstrGen
bool EnablePGOCSInstrGen
Enable profile context sensitive instrumentation pass.
Definition: PassManagerBuilder.h:179
llvm::PassManagerBuilder::EnablePGOCSInstrUse
bool EnablePGOCSInstrUse
Enable profile context sensitive profile use pass.
Definition: PassManagerBuilder.h:181
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:312
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::PassManagerBuilder::DisableUnrollLoops
bool DisableUnrollLoops
Definition: PassManagerBuilder.h:157
llvm::PassManagerBuilder::EP_EarlyAsPossible
@ EP_EarlyAsPossible
EP_EarlyAsPossible - This extension point allows adding passes before any other transformations,...
Definition: PassManagerBuilder.h:72
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1030
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:99
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:271
llvm::PassManagerBuilder::populateThinLTOPassManager
void populateThinLTOPassManager(legacy::PassManagerBase &PM)
Definition: PassManagerBuilder.cpp:1178
llvm::PassManagerBuilder::EP_FullLinkTimeOptimizationEarly
@ EP_FullLinkTimeOptimizationEarly
EP_FullLinkTimeOptimizationEarly - This extensions point allow adding passes that run at Link Time,...
Definition: PassManagerBuilder.h:122
llvm::PassManagerBuilder::DivergentTarget
bool DivergentTarget
Definition: PassManagerBuilder.h:172
llvm::PassManagerBuilder::EP_CGSCCOptimizerLate
@ EP_CGSCCOptimizerLate
EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC passes at the end of the main...
Definition: PassManagerBuilder.h:117
MPM
ModulePassManager MPM
Definition: PassBuilderBindings.cpp:70
llvm::RegisterStandardPasses::RegisterStandardPasses
RegisterStandardPasses(PassManagerBuilder::ExtensionPointTy Ty, PassManagerBuilder::ExtensionFn Fn)
Definition: PassManagerBuilder.h:242