]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h
MFV r316928: 7256 low probability race in zfs_get_data
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Transforms / IPO / PassManagerBuilder.h
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 Pass;
25 class TargetLibraryInfoImpl;
26 class TargetMachine;
27
28 // The old pass manager infrastructure is hidden in a legacy namespace now.
29 namespace legacy {
30 class FunctionPassManager;
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 ///   ...
58 class PassManagerBuilder {
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,
63                              legacy::PassManagerBase &PM)>
64       ExtensionFn;
65   enum ExtensionPointTy {
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.
69     EP_EarlyAsPossible,
70
71     /// EP_ModuleOptimizerEarly - This extension point allows adding passes
72     /// just before the main module-level optimization passes.
73     EP_ModuleOptimizerEarly,
74
75     /// EP_LoopOptimizerEnd - This extension point allows adding loop passes to
76     /// the end of the loop optimizer.
77     EP_LoopOptimizerEnd,
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.
82     EP_ScalarOptimizerLate,
83
84     /// EP_OptimizerLast -- This extension point allows adding passes that
85     /// run after everything else.
86     EP_OptimizerLast,
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.
91     EP_VectorizerStart,
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.
96     EP_EnabledOnOptLevel0,
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.
101     EP_Peephole,
102
103     /// EP_CGSCCOptimizerLate - This extension point allows adding CallGraphSCC
104     /// passes at the end of the main CallGraphSCC passes and before any
105     /// function simplification passes run by CGPassManager.
106     EP_CGSCCOptimizerLate,
107   };
108
109   /// The Optimization Level - Specify the basic optimization level.
110   ///    0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
111   unsigned OptLevel;
112
113   /// SizeLevel - How much we're optimizing for size.
114   ///    0 = none, 1 = -Os, 2 = -Oz
115   unsigned SizeLevel;
116
117   /// LibraryInfo - Specifies information about the runtime library for the
118   /// optimizer.  If this is non-null, it is added to both the function and
119   /// per-module pass pipeline.
120   TargetLibraryInfoImpl *LibraryInfo;
121
122   /// Inliner - Specifies the inliner to use.  If this is non-null, it is
123   /// added to the per-module passes.
124   Pass *Inliner;
125
126   bool DisableTailCalls;
127   bool DisableUnitAtATime;
128   bool DisableUnrollLoops;
129   bool BBVectorize;
130   bool SLPVectorize;
131   bool LoopVectorize;
132   bool RerollLoops;
133   bool LoadCombine;
134   bool NewGVN;
135   bool DisableGVNLoadPRE;
136   bool VerifyInput;
137   bool VerifyOutput;
138   bool MergeFunctions;
139   bool PrepareForLTO;
140   bool PrepareForThinLTO;
141   bool PerformThinLTO;
142
143   /// Enable profile instrumentation pass.
144   bool EnablePGOInstrGen;
145   /// Profile data file name that the instrumentation will be written to.
146   std::string PGOInstrGen;
147   /// Path of the profile data file.
148   std::string PGOInstrUse;
149   /// Path of the sample Profile data file.
150   std::string PGOSampleUse;
151
152 private:
153   /// ExtensionList - This is list of all of the extensions that are registered.
154   std::vector<std::pair<ExtensionPointTy, ExtensionFn>> Extensions;
155
156 public:
157   PassManagerBuilder();
158   ~PassManagerBuilder();
159   /// Adds an extension that will be used by all PassManagerBuilder instances.
160   /// This is intended to be used by plugins, to register a set of
161   /// optimisations to run automatically.
162   static void addGlobalExtension(ExtensionPointTy Ty, ExtensionFn Fn);
163   void addExtension(ExtensionPointTy Ty, ExtensionFn Fn);
164
165 private:
166   void addExtensionsToPM(ExtensionPointTy ETy,
167                          legacy::PassManagerBase &PM) const;
168   void addInitialAliasAnalysisPasses(legacy::PassManagerBase &PM) const;
169   void addLTOOptimizationPasses(legacy::PassManagerBase &PM);
170   void addLateLTOOptimizationPasses(legacy::PassManagerBase &PM);
171   void addPGOInstrPasses(legacy::PassManagerBase &MPM);
172   void addFunctionSimplificationPasses(legacy::PassManagerBase &MPM);
173   void addInstructionCombiningPass(legacy::PassManagerBase &MPM) const;
174
175 public:
176   /// populateFunctionPassManager - This fills in the function pass manager,
177   /// which is expected to be run on each function immediately as it is
178   /// generated.  The idea is to reduce the size of the IR in memory.
179   void populateFunctionPassManager(legacy::FunctionPassManager &FPM);
180
181   /// populateModulePassManager - This sets up the primary pass manager.
182   void populateModulePassManager(legacy::PassManagerBase &MPM);
183   void populateLTOPassManager(legacy::PassManagerBase &PM);
184   void populateThinLTOPassManager(legacy::PassManagerBase &PM);
185 };
186
187 /// Registers a function for adding a standard set of passes.  This should be
188 /// used by optimizer plugins to allow all front ends to transparently use
189 /// them.  Create a static instance of this class in your plugin, providing a
190 /// private function that the PassManagerBuilder can use to add your passes.
191 struct RegisterStandardPasses {
192   RegisterStandardPasses(PassManagerBuilder::ExtensionPointTy Ty,
193                          PassManagerBuilder::ExtensionFn Fn) {
194     PassManagerBuilder::addGlobalExtension(Ty, std::move(Fn));
195   }
196 };
197
198 } // end namespace llvm
199 #endif