Derive new pass managers from PassManagerAnalysisHelper.
[oota-llvm.git] / include / llvm / PassManager.h
1 //===- llvm/PassManager.h - Container for Passes ----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the PassManager class.  This class is used to hold,
11 // maintain, and optimize execution of Passes.  The PassManager class ensures
12 // that analysis results are available before a pass runs, and that Pass's are
13 // destroyed when the PassManager is destroyed.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_PASSMANAGER_H
18 #define LLVM_PASSMANAGER_H
19
20 #include "llvm/Pass.h"
21 #include <vector>
22
23 namespace llvm {
24
25 class Pass;
26 class ModulePass;
27 class Module;
28 class ModuleProvider;
29 class ModulePassManager;
30 class FunctionPassManagerT;
31 class BasicBlockPassManager;
32
33 class PassManager {
34   ModulePassManager *PM;    // This is a straightforward Pimpl class
35 public:
36   PassManager();
37   ~PassManager();
38
39   /// add - Add a pass to the queue of passes to run.  This passes ownership of
40   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
41   /// will be destroyed as well, so there is no need to delete the pass.  This
42   /// implies that all passes MUST be allocated with 'new'.
43   ///
44   void add(Pass *P);
45
46   /// run - Execute all of the passes scheduled for execution.  Keep track of
47   /// whether any of the passes modifies the module, and if so, return true.
48   ///
49   bool run(Module &M);
50 };
51
52 class FunctionPass;
53 class ImmutablePass;
54 class Function;
55
56 class FunctionPassManager {
57   FunctionPassManagerT *PM;    // This is a straightforward Pimpl class
58   ModuleProvider *MP;
59 public:
60   FunctionPassManager(ModuleProvider *P);
61   ~FunctionPassManager();
62
63   /// add - Add a pass to the queue of passes to run.  This passes
64   /// ownership of the FunctionPass to the PassManager.  When the
65   /// PassManager is destroyed, the pass will be destroyed as well, so
66   /// there is no need to delete the pass.  This implies that all
67   /// passes MUST be allocated with 'new'.
68   ///
69   void add(FunctionPass *P);
70
71   /// add - ImmutablePasses are not FunctionPasses, so we have a
72   /// special hack to get them into a FunctionPassManager.
73   ///
74   void add(ImmutablePass *IP);
75
76   /// doInitialization - Run all of the initializers for the function passes.
77   ///
78   bool doInitialization();
79   
80   /// run - Execute all of the passes scheduled for execution.  Keep
81   /// track of whether any of the passes modifies the function, and if
82   /// so, return true.
83   ///
84   bool run(Function &F);
85   
86   /// doFinalization - Run all of the initializers for the function passes.
87   ///
88   bool doFinalization();
89 };
90
91 /// PassManagerAnalysisHelper helpes pass manager analysis required by
92 /// the managed passes.
93 class PassManagerAnalysisHelper {
94
95 public:
96
97   /// Return TRUE IFF pass P's required analysis set does not required new
98   /// manager.
99   bool manageablePass(Pass *P);
100
101   /// Return TRUE iff AnalysisID AID is currently available.
102   bool analysisCurrentlyAvailable(AnalysisID AID);
103
104   /// Augment RequiredSet by adding analysis required by pass P.
105   void noteDownRequiredAnalysis(Pass *P);
106
107   /// Remove AnalysisID from the RequiredSet
108   void removeAnalysis(AnalysisID AID);
109
110   /// Remove Analysis that is not preserved by the pass
111   void removeNotPreservedAnalysis(Pass *P);
112   
113   /// Remove dead passes
114   void removeDeadPasses() { /* TODO : Implement */ }
115
116 private:
117    // Required set of analysis for the passes managed by this manager
118   std::vector<AnalysisID> RequiredSet;
119 };
120
121 /// BasicBlockpassManager_New manages BasicBlockPass. It batches all the
122 /// pass together and sequence them to process one basic block before
123 /// processing next basic block.
124 class BasicBlockPassManager_New: public Pass,
125                                  public PassManagerAnalysisHelper {
126
127 public:
128   BasicBlockPassManager_New() { }
129
130   /// Add a pass into a passmanager queue. 
131   bool addPass(Pass *p);
132   
133   /// Execute all of the passes scheduled for execution.  Keep track of
134   /// whether any of the passes modifies the function, and if so, return true.
135   bool runOnFunction(Function &F);
136
137 private:
138   // Collection of pass that are not yet scheduled
139   std::vector<Pass *> PassVector;
140 };
141
142 /// FunctionPassManager_New manages FunctionPasses and BasicBlockPassManagers.
143 /// It batches all function passes and basic block pass managers together and
144 /// sequence them to process one function at a time before processing next
145 /// function.
146 class FunctionPassManager_New: public Pass,
147                                public PassManagerAnalysisHelper {
148 public:
149   FunctionPassManager_New(ModuleProvider *P) { /* TODO */ }
150   FunctionPassManager_New() { 
151     activeBBPassManager = NULL;
152   }
153   ~FunctionPassManager_New() { /* TODO */ };
154  
155   /// add - Add a pass to the queue of passes to run.  This passes
156   /// ownership of the Pass to the PassManager.  When the
157   /// PassManager_X is destroyed, the pass will be destroyed as well, so
158   /// there is no need to delete the pass. (TODO delete passes.)
159   /// This implies that all passes MUST be allocated with 'new'.
160   void add(Pass *P) { /* TODO*/  }
161
162   /// Add pass into the pass manager queue.
163   bool addPass(Pass *P);
164
165   /// Execute all of the passes scheduled for execution.  Keep
166   /// track of whether any of the passes modifies the function, and if
167   /// so, return true.
168   bool runOnModule(Module &M);
169
170 private:
171   // Collection of pass that are not yet scheduled
172   std::vector<Pass *> PassVector;
173  
174   // Active Pass Managers
175   BasicBlockPassManager_New *activeBBPassManager;
176 };
177
178 /// ModulePassManager_New manages ModulePasses and function pass managers.
179 /// It batches all Module passes  passes and function pass managers together and
180 /// sequence them to process one module.
181 class ModulePassManager_New: public Pass,
182                              public PassManagerAnalysisHelper {
183  
184 public:
185   ModulePassManager_New() { activeFunctionPassManager = NULL; }
186   
187   /// Add a pass into a passmanager queue. 
188   bool addPass(Pass *p);
189   
190   /// run - Execute all of the passes scheduled for execution.  Keep track of
191   /// whether any of the passes modifies the module, and if so, return true.
192   bool runOnModule(Module &M);
193   
194 private:
195   // Collection of pass that are not yet scheduled
196   std::vector<Pass *> PassVector;
197   
198   // Active Pass Manager
199   FunctionPassManager_New *activeFunctionPassManager;
200 };
201
202 /// PassManager_New manages ModulePassManagers
203 class PassManager_New: public Pass,
204                        public PassManagerAnalysisHelper {
205
206 public:
207
208   /// add - Add a pass to the queue of passes to run.  This passes ownership of
209   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
210   /// will be destroyed as well, so there is no need to delete the pass.  This
211   /// implies that all passes MUST be allocated with 'new'.
212   void add(Pass *P);
213  
214   /// run - Execute all of the passes scheduled for execution.  Keep track of
215   /// whether any of the passes modifies the module, and if so, return true.
216   bool run(Module &M);
217
218 private:
219  
220   /// Add a pass into a passmanager queue. This is used by schedulePasses
221   bool addPass(Pass *p);
222
223   /// Schedule all passes collected in pass queue using add(). Add all the
224   /// schedule passes into various manager's queue using addPass().
225   void schedulePasses();
226
227   // Collection of pass managers
228   std::vector<ModulePassManager_New *> PassManagers;
229
230   // Collection of pass that are not yet scheduled
231   std::vector<Pass *> PassVector;
232   
233   // Active Pass Manager
234   ModulePassManager_New *activeManager;
235 };
236
237 } // End llvm namespace
238
239 #endif