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