LLVM  9.0.0svn
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 
17 #include <functional>
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 namespace llvm {
23 class ModuleSummaryIndex;
24 class Pass;
25 class TargetLibraryInfoImpl;
26 class TargetMachine;
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 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,
66  /// EP_EarlyAsPossible - This extension point allows adding passes before
67  /// any other transformations, allowing them to see the code as it is coming
68  /// out of the frontend.
70 
71  /// EP_ModuleOptimizerEarly - This extension point allows adding passes
72  /// just before the main module-level optimization passes.
74 
75  /// EP_LoopOptimizerEnd - This extension point allows adding loop passes to
76  /// the end of the loop optimizer.
78 
79  /// EP_ScalarOptimizerLate - This extension point allows adding optimization
80  /// passes after most of the main optimizations, but before the last
81  /// cleanup-ish optimizations.
83 
84  /// EP_OptimizerLast -- This extension point allows adding passes that
85  /// run after everything else.
87 
88  /// EP_VectorizerStart - This extension point allows adding optimization
89  /// passes before the vectorizer and other highly target specific
90  /// optimization passes are executed.
92 
93  /// EP_EnabledOnOptLevel0 - This extension point allows adding passes that
94  /// should not be disabled by O0 optimization level. The passes will be
95  /// inserted after the inlining pass.
97 
98  /// EP_Peephole - This extension point allows adding passes that perform
99  /// peephole optimizations similar to the instruction combiner. These passes
100  /// will be inserted after each instance of the instruction combiner pass.
102 
103  /// EP_LateLoopOptimizations - This extension point allows adding late loop
104  /// canonicalization and simplification passes. This is the last point in
105  /// the loop optimization pipeline before loop deletion. Each pass added
106  /// here must be an instance of LoopPass.
107  /// This is the place to add passes that can remove loops, such as target-
108  /// specific loop idiom recognition.
110 
111  /// EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC
112  /// passes at the end of the main CallGraphSCC passes and before any
113  /// function simplification passes run by CGPassManager.
115  };
116 
117  /// The Optimization Level - Specify the basic optimization level.
118  /// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
119  unsigned OptLevel;
120 
121  /// SizeLevel - How much we're optimizing for size.
122  /// 0 = none, 1 = -Os, 2 = -Oz
123  unsigned SizeLevel;
124 
125  /// LibraryInfo - Specifies information about the runtime library for the
126  /// optimizer. If this is non-null, it is added to both the function and
127  /// per-module pass pipeline.
129 
130  /// Inliner - Specifies the inliner to use. If this is non-null, it is
131  /// added to the per-module passes.
133 
134  /// The module summary index to use for exporting information from the
135  /// regular LTO phase, for example for the CFI and devirtualization type
136  /// tests.
137  ModuleSummaryIndex *ExportSummary = nullptr;
138 
139  /// The module summary index to use for importing information to the
140  /// thin LTO backends, for example for the CFI and devirtualization type
141  /// tests.
142  const ModuleSummaryIndex *ImportSummary = nullptr;
143 
150  bool NewGVN;
159 
160  /// Enable profile instrumentation pass.
162  /// Enable profile context sensitive instrumentation pass.
164  /// Enable profile context sensitive profile use pass.
166  /// Profile data file name that the instrumentation will be written to.
167  std::string PGOInstrGen;
168  /// Path of the profile data file.
169  std::string PGOInstrUse;
170  /// Path of the sample Profile data file.
171  std::string PGOSampleUse;
172 
173 private:
174  /// ExtensionList - This is list of all of the extensions that are registered.
175  std::vector<std::pair<ExtensionPointTy, ExtensionFn>> Extensions;
176 
177 public:
180  /// Adds an extension that will be used by all PassManagerBuilder instances.
181  /// This is intended to be used by plugins, to register a set of
182  /// optimisations to run automatically.
183  static void addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn);
184  void addExtension(ExtensionPointTy Ty, ExtensionFn Fn);
185 
186 private:
187  void addExtensionsToPM(ExtensionPointTy ETy,
188  legacy::PassManagerBase &PM) const;
189  void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
190  void addLTOOptimizationPasses(legacy::PassManagerBase &PM);
191  void addLateLTOOptimizationPasses(legacy::PassManagerBase &PM);
192  void addPGOInstrPasses(legacy::PassManagerBase &MPM, bool IsCS);
193  void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
194  void addInstructionCombiningPass(legacy::PassManagerBase &MPM) const;
195 
196 public:
197  /// populateFunctionPassManager - This fills in the function pass manager,
198  /// which is expected to be run on each function immediately as it is
199  /// generated. The idea is to reduce the size of the IR in memory.
200  void populateFunctionPassManager(legacy::FunctionPassManager &FPM);
201 
202  /// populateModulePassManager - This sets up the primary pass manager.
203  void populateModulePassManager(legacy::PassManagerBase &MPM);
204  void populateLTOPassManager(legacy::PassManagerBase &PM);
205  void populateThinLTOPassManager(legacy::PassManagerBase &PM);
206 };
207 
208 /// Registers a function for adding a standard set of passes. This should be
209 /// used by optimizer plugins to allow all front ends to transparently use
210 /// them. Create a static instance of this class in your plugin, providing a
211 /// private function that the PassManagerBuilder can use to add your passes.
215  PassManagerBuilder::addGlobalExtension(Ty, std::move(Fn));
216  }
217 };
218 
219 } // end namespace llvm
220 #endif
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
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:23
bool EnablePGOCSInstrUse
Enable profile context sensitive profile use pass.
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...
bool EnablePGOCSInstrGen
Enable profile context sensitive instrumentation pass.
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.
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:567
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...