1 //===- llvm/PassManager.h - Container for Passes ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_PASSMANAGER_H
18 #define LLVM_PASSMANAGER_H
20 #include "llvm/Pass.h"
29 class ModulePassManager;
30 class FunctionPassManagerT;
31 class BasicBlockPassManager;
34 ModulePassManager *PM; // This is a straightforward Pimpl class
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'.
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.
56 class FunctionPassManager {
57 FunctionPassManagerT *PM; // This is a straightforward Pimpl class
60 FunctionPassManager(ModuleProvider *P);
61 ~FunctionPassManager();
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'.
69 void add(FunctionPass *P);
71 /// add - ImmutablePasses are not FunctionPasses, so we have a
72 /// special hack to get them into a FunctionPassManager.
74 void add(ImmutablePass *IP);
76 /// doInitialization - Run all of the initializers for the function passes.
78 bool doInitialization();
80 /// run - Execute all of the passes scheduled for execution. Keep
81 /// track of whether any of the passes modifies the function, and if
84 bool run(Function &F);
86 /// doFinalization - Run all of the initializers for the function passes.
88 bool doFinalization();
91 /// PassManagerAnalysisHelper helpes pass manager analysis required by
92 /// the managed passes.
93 class PassManagerAnalysisHelper {
97 /// Return TRUE IFF pass P's required analysis set does not required new
99 bool manageablePass(Pass *P);
101 /// Return TRUE iff AnalysisID AID is currently available.
102 bool analysisCurrentlyAvailable(AnalysisID AID);
104 /// Augment RequiredSet by adding analysis required by pass P.
105 void noteDownRequiredAnalysis(Pass *P);
107 /// Remove AnalysisID from the RequiredSet
108 void removeAnalysis(AnalysisID AID);
110 /// Remove Analysis that is not preserved by the pass
111 void removeNotPreservedAnalysis(Pass *P);
113 /// Remove dead passes
114 void removeDeadPasses() { /* TODO : Implement */ }
117 // Required set of analysis for the passes managed by this manager
118 std::vector<AnalysisID> RequiredSet;
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 {
127 BasicBlockPassManager_New() { }
129 /// Add a pass into a passmanager queue.
130 bool addPass(Pass *p);
132 /// Execute all of the passes scheduled for execution. Keep track of
133 /// whether any of the passes modifies the function, and if so, return true.
134 bool runOnFunction(Function &F);
137 // Collection of pass that are not yet scheduled
138 std::vector<Pass *> PassVector;
141 /// FunctionPassManager_New manages FunctionPasses and BasicBlockPassManagers.
142 /// It batches all function passes and basic block pass managers together and
143 /// sequence them to process one function at a time before processing next
145 class FunctionPassManager_New:public Pass {
147 FunctionPassManager_New(ModuleProvider *P) { /* TODO */ }
148 FunctionPassManager_New() {
149 activeBBPassManager = NULL;
151 ~FunctionPassManager_New() { /* TODO */ };
153 /// add - Add a pass to the queue of passes to run. This passes
154 /// ownership of the Pass to the PassManager. When the
155 /// PassManager_X is destroyed, the pass will be destroyed as well, so
156 /// there is no need to delete the pass. (TODO delete passes.)
157 /// This implies that all passes MUST be allocated with 'new'.
158 void add(Pass *P) { /* TODO*/ }
160 /// Add pass into the pass manager queue.
161 bool addPass(Pass *P);
163 /// Execute all of the passes scheduled for execution. Keep
164 /// track of whether any of the passes modifies the function, and if
166 bool runOnModule(Module &M);
169 // Collection of pass that are not yet scheduled
170 std::vector<Pass *> PassVector;
172 // Active Pass Managers
173 BasicBlockPassManager_New *activeBBPassManager;
176 /// ModulePassManager_New manages ModulePasses and function pass managers.
177 /// It batches all Module passes passes and function pass managers together and
178 /// sequence them to process one module.
179 class ModulePassManager_New: public Pass {
182 ModulePassManager_New() { activeFunctionPassManager = NULL; }
184 /// Add a pass into a passmanager queue.
185 bool addPass(Pass *p);
187 /// run - Execute all of the passes scheduled for execution. Keep track of
188 /// whether any of the passes modifies the module, and if so, return true.
189 bool runOnModule(Module &M);
192 // Collection of pass that are not yet scheduled
193 std::vector<Pass *> PassVector;
195 // Active Pass Manager
196 FunctionPassManager_New *activeFunctionPassManager;
199 /// PassManager_New manages ModulePassManagers
200 class PassManager_New: public Pass {
204 /// add - Add a pass to the queue of passes to run. This passes ownership of
205 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
206 /// will be destroyed as well, so there is no need to delete the pass. This
207 /// implies that all passes MUST be allocated with 'new'.
210 /// run - Execute all of the passes scheduled for execution. Keep track of
211 /// whether any of the passes modifies the module, and if so, return true.
216 /// Add a pass into a passmanager queue. This is used by schedulePasses
217 bool addPass(Pass *p);
219 /// Schedule all passes collected in pass queue using add(). Add all the
220 /// schedule passes into various manager's queue using addPass().
221 void schedulePasses();
223 // Collection of pass managers
224 std::vector<ModulePassManager_New *> PassManagers;
226 // Collection of pass that are not yet scheduled
227 std::vector<Pass *> PassVector;
229 // Active Pass Manager
230 ModulePassManager_New *activeManager;
233 } // End llvm namespace