LLVM  8.0.1
PassManagerBuilder.h
Go to the documentation of this file.
1 // llvm/Transforms/IPO/PassManagerBuilder.h - Build Standard Pass -*- C++ -*-=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the PassManagerBuilder class, which is used to set up a
11 // "standard" optimization sequence suitable for languages like C and C++.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
16 #define LLVM_TRANSFORMS_IPO_PASSMANAGERBUILDER_H
17 
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 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,
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 
118  /// The Optimization Level - Specify the basic optimization level.
119  /// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
120  unsigned OptLevel;
121 
122  /// SizeLevel - How much we're optimizing for size.
123  /// 0 = none, 1 = -Os, 2 = -Oz
124  unsigned SizeLevel;
125 
126  /// LibraryInfo - Specifies information about the runtime library for the
127  /// optimizer. If this is non-null, it is added to both the function and
128  /// per-module pass pipeline.
130 
131  /// Inliner - Specifies the inliner to use. If this is non-null, it is
132  /// added to the per-module passes.
134 
135  /// The module summary index to use for exporting information from the
136  /// regular LTO phase, for example for the CFI and devirtualization type
137  /// tests.
138  ModuleSummaryIndex *ExportSummary = nullptr;
139 
140  /// The module summary index to use for importing information to the
141  /// thin LTO backends, for example for the CFI and devirtualization type
142  /// tests.
143  const ModuleSummaryIndex *ImportSummary = nullptr;
144 
151  bool NewGVN;
160 
161  /// Enable profile instrumentation pass.
163  /// Profile data file name that the instrumentation will be written to.
164  std::string PGOInstrGen;
165  /// Path of the profile data file.
166  std::string PGOInstrUse;
167  /// Path of the sample Profile data file.
168  std::string PGOSampleUse;
169 
170 private:
171  /// ExtensionList - This is list of all of the extensions that are registered.
172  std::vector<std::pair<ExtensionPointTy, ExtensionFn>> Extensions;
173 
174 public:
177  /// Adds an extension that will be used by all PassManagerBuilder instances.
178  /// This is intended to be used by plugins, to register a set of
179  /// optimisations to run automatically.
180  static void addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn);
181  void addExtension(ExtensionPointTy Ty, ExtensionFn Fn);
182 
183 private:
184  void addExtensionsToPM(ExtensionPointTy ETy,
185  legacy::PassManagerBase &PM) const;
186  void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
187  void addLTOOptimizationPasses(legacy::PassManagerBase &PM);
188  void addLateLTOOptimizationPasses(legacy::PassManagerBase &PM);
189  void addPGOInstrPasses(legacy::PassManagerBase &MPM);
190  void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
191  void addInstructionCombiningPass(legacy::PassManagerBase &MPM) const;
192 
193 public:
194  /// populateFunctionPassManager - This fills in the function pass manager,
195  /// which is expected to be run on each function immediately as it is
196  /// generated. The idea is to reduce the size of the IR in memory.
197  void populateFunctionPassManager(legacy::FunctionPassManager &FPM);
198 
199  /// populateModulePassManager - This sets up the primary pass manager.
200  void populateModulePassManager(legacy::PassManagerBase &MPM);
201  void populateLTOPassManager(legacy::PassManagerBase &PM);
202  void populateThinLTOPassManager(legacy::PassManagerBase &PM);
203 };
204 
205 /// Registers a function for adding a standard set of passes. This should be
206 /// used by optimizer plugins to allow all front ends to transparently use
207 /// them. Create a static instance of this class in your plugin, providing a
208 /// private function that the PassManagerBuilder can use to add your passes.
212  PassManagerBuilder::addGlobalExtension(Ty, std::move(Fn));
213  }
214 };
215 
216 } // end namespace llvm
217 #endif
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
Registers a function for adding a standard set of passes.
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
bool EnablePGOInstrGen
Enable profile instrumentation pass.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
EP_ScalarOptimizerLate - This extension point allows adding optimization passes after most of the mai...
Implementation of the target library information.
std::string PGOSampleUse
Path of the sample Profile data file.
Pass * Inliner
Inliner - Specifies the inliner to use.
static void addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn)
Adds an extension that will be used by all PassManagerBuilder instances.
EP_ModuleOptimizerEarly - This extension point allows adding passes just before the main module-level...
EP_EnabledOnOptLevel0 - This extension point allows adding passes that should not be disabled by O0 o...
std::function< void(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)> ExtensionFn
Extensions are passed the builder itself (so they can see how it is configured) as well as the pass m...
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
std::string PGOInstrUse
Path of the profile data file.
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
static const struct @395 Extensions[]
FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
EP_OptimizerLast – This extension point allows adding passes that run after everything else...
EP_EarlyAsPossible - This extension point allows adding passes before any other transformations, allowing them to see the code as it is coming out of the frontend.
EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC passes at the end of the main...
EP_VectorizerStart - This extension point allows adding optimization passes before the vectorizer and...
print lazy value Lazy Value Info Printer Pass
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
EP_Peephole - This extension point allows adding passes that perform peephole optimizations similar t...
std::string PGOInstrGen
Profile data file name that the instrumentation will be written to.
unsigned SizeLevel
SizeLevel - How much we&#39;re optimizing for size.
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
Definition: PassManager.h:568
RegisterStandardPasses(PassManagerBuilder::ExtensionPointTy Ty, PassManagerBuilder::ExtensionFn Fn)
print Print MemDeps of function
EP_LateLoopOptimizations - This extension point allows adding late loop canonicalization and simplifi...
EP_LoopOptimizerEnd - This extension point allows adding loop passes to the end of the loop optimizer...