Keep track of analysis required by the passes. Force use of new pass
[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 class ModulePassManager_New;
92 class PassManagerImpl_New;
93 class FunctionPassManagerImpl_New;
94
95 /// CommonPassManagerImpl helps pass manager analysis required by
96 /// the managed passes. It provides methods to add/remove analysis
97 /// available and query if certain analysis is available or not.
98 class CommonPassManagerImpl : public Pass{
99
100 public:
101
102   /// Return true IFF pass P's required analysis set does not required new
103   /// manager.
104   bool manageablePass(Pass *P);
105
106   /// Return true IFF AnalysisID AID is currently available.
107   bool analysisCurrentlyAvailable(AnalysisID AID);
108
109   /// Augment RequiredSet by adding analysis required by pass P.
110   void noteDownRequiredAnalysis(Pass *P);
111
112   /// Remove AnalysisID from the RequiredSet
113   void removeAnalysis(AnalysisID AID);
114
115   /// Remove Analysis that is not preserved by the pass
116   void removeNotPreservedAnalysis(Pass *P);
117   
118   /// Remove dead passes
119   void removeDeadPasses() { /* TODO : Implement */ }
120
121 private:
122    // Analysis required by the passes managed by this manager
123   std::vector<AnalysisID> RequiredAnalysis;
124 };
125
126 /// PassManager_New manages ModulePassManagers
127 class PassManager_New : public CommonPassManagerImpl {
128
129 public:
130
131   PassManager_New();
132
133   /// add - Add a pass to the queue of passes to run.  This passes ownership of
134   /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
135   /// will be destroyed as well, so there is no need to delete the pass.  This
136   /// implies that all passes MUST be allocated with 'new'.
137   void add(Pass *P);
138  
139   /// run - Execute all of the passes scheduled for execution.  Keep track of
140   /// whether any of the passes modifies the module, and if so, return true.
141   bool run(Module &M);
142
143 private:
144
145   /// PassManagerImpl_New is the actual class. PassManager_New is just the 
146   /// wraper to publish simple pass manager interface
147   PassManagerImpl_New *PM;
148
149 };
150
151 /// FunctionPassManager_New manages FunctionPasses and BasicBlockPassManagers.
152 class FunctionPassManager_New : public CommonPassManagerImpl {
153 public:
154   FunctionPassManager_New(ModuleProvider *P) { /* TODO */ }
155   FunctionPassManager_New();
156   ~FunctionPassManager_New() { /* TODO */ };
157  
158   /// add - Add a pass to the queue of passes to run.  This passes
159   /// ownership of the Pass to the PassManager.  When the
160   /// PassManager_X is destroyed, the pass will be destroyed as well, so
161   /// there is no need to delete the pass. (TODO delete passes.)
162   /// This implies that all passes MUST be allocated with 'new'.
163   void add(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   
172   FunctionPassManagerImpl_New *FPM;
173
174 };
175
176
177 } // End llvm namespace
178
179 #endif