Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 1 | //===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 5 | // This file was developed by Devang Patel and is distributed under |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the LLVM Pass Manager infrastructure. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | |
| 15 | #include "llvm/PassManager.h" |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 16 | #include "llvm/Module.h" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 20 | namespace llvm { |
| 21 | |
| 22 | /// BasicBlockPassManager_New manages BasicBlockPass. It batches all the |
| 23 | /// pass together and sequence them to process one basic block before |
| 24 | /// processing next basic block. |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 25 | class BasicBlockPassManager_New : public CommonPassManagerImpl { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 26 | |
| 27 | public: |
| 28 | BasicBlockPassManager_New() { } |
| 29 | |
| 30 | /// Add a pass into a passmanager queue. |
| 31 | bool addPass(Pass *p); |
| 32 | |
| 33 | /// Execute all of the passes scheduled for execution. Keep track of |
| 34 | /// whether any of the passes modifies the function, and if so, return true. |
| 35 | bool runOnFunction(Function &F); |
| 36 | |
| 37 | private: |
| 38 | // Collection of pass that are managed by this manager |
| 39 | std::vector<Pass *> PassVector; |
| 40 | }; |
| 41 | |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 42 | /// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers. |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 43 | /// It batches all function passes and basic block pass managers together and |
| 44 | /// sequence them to process one function at a time before processing next |
| 45 | /// function. |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 46 | class FunctionPassManagerImpl_New : public CommonPassManagerImpl { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 47 | public: |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 48 | FunctionPassManagerImpl_New(ModuleProvider *P) { /* TODO */ } |
| 49 | FunctionPassManagerImpl_New() { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 50 | activeBBPassManager = NULL; |
| 51 | } |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 52 | ~FunctionPassManagerImpl_New() { /* TODO */ }; |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 53 | |
| 54 | /// add - Add a pass to the queue of passes to run. This passes |
| 55 | /// ownership of the Pass to the PassManager. When the |
| 56 | /// PassManager_X is destroyed, the pass will be destroyed as well, so |
| 57 | /// there is no need to delete the pass. (TODO delete passes.) |
| 58 | /// This implies that all passes MUST be allocated with 'new'. |
| 59 | void add(Pass *P) { /* TODO*/ } |
| 60 | |
| 61 | /// Add pass into the pass manager queue. |
| 62 | bool addPass(Pass *P); |
| 63 | |
| 64 | /// Execute all of the passes scheduled for execution. Keep |
| 65 | /// track of whether any of the passes modifies the function, and if |
| 66 | /// so, return true. |
| 67 | bool runOnModule(Module &M); |
| 68 | |
| 69 | private: |
| 70 | // Collection of pass that are manged by this manager |
| 71 | std::vector<Pass *> PassVector; |
| 72 | |
| 73 | // Active Pass Managers |
| 74 | BasicBlockPassManager_New *activeBBPassManager; |
| 75 | }; |
| 76 | |
| 77 | /// ModulePassManager_New manages ModulePasses and function pass managers. |
| 78 | /// It batches all Module passes passes and function pass managers together and |
| 79 | /// sequence them to process one module. |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 80 | class ModulePassManager_New : public CommonPassManagerImpl { |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 81 | |
| 82 | public: |
| 83 | ModulePassManager_New() { activeFunctionPassManager = NULL; } |
| 84 | |
| 85 | /// Add a pass into a passmanager queue. |
| 86 | bool addPass(Pass *p); |
| 87 | |
| 88 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 89 | /// whether any of the passes modifies the module, and if so, return true. |
| 90 | bool runOnModule(Module &M); |
| 91 | |
| 92 | private: |
| 93 | // Collection of pass that are managed by this manager |
| 94 | std::vector<Pass *> PassVector; |
| 95 | |
| 96 | // Active Pass Manager |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 97 | FunctionPassManagerImpl_New *activeFunctionPassManager; |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 100 | /// PassManager_New manages ModulePassManagers |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 101 | class PassManagerImpl_New : public CommonPassManagerImpl { |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 102 | |
| 103 | public: |
| 104 | |
| 105 | /// add - Add a pass to the queue of passes to run. This passes ownership of |
| 106 | /// the Pass to the PassManager. When the PassManager is destroyed, the pass |
| 107 | /// will be destroyed as well, so there is no need to delete the pass. This |
| 108 | /// implies that all passes MUST be allocated with 'new'. |
| 109 | void add(Pass *P); |
| 110 | |
| 111 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 112 | /// whether any of the passes modifies the module, and if so, return true. |
| 113 | bool run(Module &M); |
| 114 | |
| 115 | private: |
| 116 | |
| 117 | /// Add a pass into a passmanager queue. This is used by schedulePasses |
| 118 | bool addPass(Pass *p); |
| 119 | |
| 120 | /// Schedule all passes collected in pass queue using add(). Add all the |
| 121 | /// schedule passes into various manager's queue using addPass(). |
| 122 | void schedulePasses(); |
| 123 | |
| 124 | // Collection of pass managers |
| 125 | std::vector<ModulePassManager_New *> PassManagers; |
| 126 | |
| 127 | // Collection of pass that are not yet scheduled |
| 128 | std::vector<Pass *> PassVector; |
| 129 | |
| 130 | // Active Pass Manager |
| 131 | ModulePassManager_New *activeManager; |
| 132 | }; |
| 133 | |
Devang Patel | ca58e35 | 2006-11-08 10:05:38 +0000 | [diff] [blame] | 134 | } // End of llvm namespace |
| 135 | |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 136 | // CommonPassManagerImpl implementation |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 137 | |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 138 | /// Return true IFF pass P's required analysis set does not required new |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 139 | /// manager. |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 140 | bool CommonPassManagerImpl::manageablePass(Pass *P) { |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 141 | |
| 142 | AnalysisUsage AnUsage; |
| 143 | P->getAnalysisUsage(AnUsage); |
| 144 | |
Devang Patel | 6c9f548 | 2006-11-11 00:42:16 +0000 | [diff] [blame^] | 145 | // If this pass is not preserving information that is required by the other |
| 146 | // passes managed by this manager then use new manager |
| 147 | if (!AnUsage.getPreservesAll()) { |
| 148 | const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet(); |
| 149 | for (std::vector<AnalysisID>::iterator I = RequiredAnalysis.begin(), |
| 150 | E = RequiredAnalysis.end(); I != E; ++I) { |
| 151 | if (std::find(PreservedSet.begin(), PreservedSet.end(), *I) == |
| 152 | PreservedSet.end()) |
| 153 | // This analysis is not preserved. Need new manager. |
| 154 | return false; |
| 155 | } |
| 156 | } |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 157 | return true; |
| 158 | } |
| 159 | |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 160 | /// Return true IFF AnalysisID AID is currently available. |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 161 | bool CommonPassManagerImpl::analysisCurrentlyAvailable(AnalysisID AID) { |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 162 | |
| 163 | // TODO |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | /// Augment RequiredSet by adding analysis required by pass P. |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 168 | void CommonPassManagerImpl::noteDownRequiredAnalysis(Pass *P) { |
Devang Patel | 6c9f548 | 2006-11-11 00:42:16 +0000 | [diff] [blame^] | 169 | AnalysisUsage AnUsage; |
| 170 | P->getAnalysisUsage(AnUsage); |
| 171 | const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet(); |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 172 | |
Devang Patel | 6c9f548 | 2006-11-11 00:42:16 +0000 | [diff] [blame^] | 173 | // FIXME: What about duplicates ? |
| 174 | RequiredAnalysis.insert(RequiredAnalysis.end(), RequiredSet.begin(), RequiredSet.end()); |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /// Remove AnalysisID from the RequiredSet |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 178 | void CommonPassManagerImpl::removeAnalysis(AnalysisID AID) { |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 179 | |
| 180 | // TODO |
| 181 | } |
| 182 | |
| 183 | /// Remove Analyss not preserved by Pass P |
Devang Patel | 0ed4779 | 2006-11-10 21:33:13 +0000 | [diff] [blame] | 184 | void CommonPassManagerImpl::removeNotPreservedAnalysis(Pass *P) { |
Devang Patel | f68a349 | 2006-11-07 22:35:17 +0000 | [diff] [blame] | 185 | |
| 186 | // TODO |
| 187 | } |
| 188 | |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 189 | /// BasicBlockPassManager implementation |
| 190 | |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 191 | /// Add pass P into PassVector and return true. If this pass is not |
| 192 | /// manageable by this manager then return false. |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 193 | bool |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 194 | BasicBlockPassManager_New::addPass(Pass *P) { |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 195 | |
| 196 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 197 | if (!BP) |
| 198 | return false; |
| 199 | |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 200 | // If this pass does not preserve anlysis that is used by other passes |
| 201 | // managed by this manager than it is not a suiable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 202 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 203 | return false; |
| 204 | |
| 205 | // Take a note of analysis required by this pass. |
| 206 | noteDownRequiredAnalysis(P); |
Devang Patel | 6e5a113 | 2006-11-07 21:31:57 +0000 | [diff] [blame] | 207 | |
| 208 | // Add pass |
| 209 | PassVector.push_back(BP); |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | /// Execute all of the passes scheduled for execution by invoking |
| 214 | /// runOnBasicBlock method. Keep track of whether any of the passes modifies |
| 215 | /// the function, and if so, return true. |
| 216 | bool |
| 217 | BasicBlockPassManager_New::runOnFunction(Function &F) { |
| 218 | |
| 219 | bool Changed = false; |
| 220 | for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) |
| 221 | for (std::vector<Pass *>::iterator itr = PassVector.begin(), |
| 222 | e = PassVector.end(); itr != e; ++itr) { |
| 223 | Pass *P = *itr; |
| 224 | BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P); |
| 225 | Changed |= BP->runOnBasicBlock(*I); |
| 226 | } |
| 227 | return Changed; |
| 228 | } |
| 229 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 230 | // FunctionPassManager_New implementation |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 231 | /// Create new Function pass manager |
| 232 | FunctionPassManager_New::FunctionPassManager_New() { |
| 233 | FPM = new FunctionPassManagerImpl_New(); |
| 234 | } |
| 235 | |
| 236 | /// add - Add a pass to the queue of passes to run. This passes |
| 237 | /// ownership of the Pass to the PassManager. When the |
| 238 | /// PassManager_X is destroyed, the pass will be destroyed as well, so |
| 239 | /// there is no need to delete the pass. (TODO delete passes.) |
| 240 | /// This implies that all passes MUST be allocated with 'new'. |
| 241 | void |
| 242 | FunctionPassManager_New::add(Pass *P) { |
| 243 | FPM->add(P); |
| 244 | } |
| 245 | |
| 246 | /// Execute all of the passes scheduled for execution. Keep |
| 247 | /// track of whether any of the passes modifies the function, and if |
| 248 | /// so, return true. |
| 249 | bool |
| 250 | FunctionPassManager_New::runOnModule(Module &M) { |
| 251 | return FPM->runOnModule(M); |
| 252 | } |
| 253 | |
| 254 | // FunctionPassManagerImpl_New implementation |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 255 | |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 256 | // FunctionPassManager |
| 257 | |
| 258 | /// Add pass P into the pass manager queue. If P is a BasicBlockPass then |
| 259 | /// either use it into active basic block pass manager or create new basic |
| 260 | /// block pass manager to handle pass P. |
| 261 | bool |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 262 | FunctionPassManagerImpl_New::addPass(Pass *P) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 263 | |
| 264 | // If P is a BasicBlockPass then use BasicBlockPassManager_New. |
| 265 | if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) { |
| 266 | |
| 267 | if (!activeBBPassManager |
| 268 | || !activeBBPassManager->addPass(BP)) { |
| 269 | |
| 270 | activeBBPassManager = new BasicBlockPassManager_New(); |
| 271 | |
| 272 | PassVector.push_back(activeBBPassManager); |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 273 | if (!activeBBPassManager->addPass(BP)) |
| 274 | assert(0 && "Unable to add Pass"); |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 275 | } |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | FunctionPass *FP = dynamic_cast<FunctionPass *>(P); |
| 280 | if (!FP) |
| 281 | return false; |
| 282 | |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 283 | // If this pass does not preserve anlysis that is used by other passes |
| 284 | // managed by this manager than it is not a suiable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 285 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 286 | return false; |
| 287 | |
| 288 | // Take a note of analysis required by this pass. |
| 289 | noteDownRequiredAnalysis(P); |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 290 | |
| 291 | PassVector.push_back(FP); |
| 292 | activeBBPassManager = NULL; |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | /// Execute all of the passes scheduled for execution by invoking |
| 297 | /// runOnFunction method. Keep track of whether any of the passes modifies |
| 298 | /// the function, and if so, return true. |
| 299 | bool |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 300 | FunctionPassManagerImpl_New::runOnModule(Module &M) { |
Devang Patel | 0c2012f | 2006-11-07 21:49:50 +0000 | [diff] [blame] | 301 | |
| 302 | bool Changed = false; |
| 303 | for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) |
| 304 | for (std::vector<Pass *>::iterator itr = PassVector.begin(), |
| 305 | e = PassVector.end(); itr != e; ++itr) { |
| 306 | Pass *P = *itr; |
| 307 | FunctionPass *FP = dynamic_cast<FunctionPass*>(P); |
| 308 | Changed |= FP->runOnFunction(*I); |
| 309 | } |
| 310 | return Changed; |
| 311 | } |
| 312 | |
| 313 | |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 314 | // ModulePassManager implementation |
| 315 | |
| 316 | /// Add P into pass vector if it is manageble. If P is a FunctionPass |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 317 | /// then use FunctionPassManagerImpl_New to manage it. Return false if P |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 318 | /// is not manageable by this manager. |
| 319 | bool |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 320 | ModulePassManager_New::addPass(Pass *P) { |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 321 | |
| 322 | // If P is FunctionPass then use function pass maanager. |
| 323 | if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) { |
| 324 | |
| 325 | activeFunctionPassManager = NULL; |
| 326 | |
| 327 | if (!activeFunctionPassManager |
| 328 | || !activeFunctionPassManager->addPass(P)) { |
| 329 | |
Devang Patel | 4e12f86 | 2006-11-08 10:44:40 +0000 | [diff] [blame] | 330 | activeFunctionPassManager = new FunctionPassManagerImpl_New(); |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 331 | |
| 332 | PassVector.push_back(activeFunctionPassManager); |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 333 | if (!activeFunctionPassManager->addPass(FP)) |
| 334 | assert(0 && "Unable to add pass"); |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 335 | } |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | ModulePass *MP = dynamic_cast<ModulePass *>(P); |
| 340 | if (!MP) |
| 341 | return false; |
| 342 | |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 343 | // If this pass does not preserve anlysis that is used by other passes |
| 344 | // managed by this manager than it is not a suiable pass for this manager. |
Devang Patel | d65e9e9 | 2006-11-08 01:31:28 +0000 | [diff] [blame] | 345 | if (!manageablePass(P)) |
Devang Patel | 3c8eb62 | 2006-11-07 22:56:50 +0000 | [diff] [blame] | 346 | return false; |
| 347 | |
| 348 | // Take a note of analysis required by this pass. |
| 349 | noteDownRequiredAnalysis(P); |
Devang Patel | 05e1a97 | 2006-11-07 22:03:15 +0000 | [diff] [blame] | 350 | |
| 351 | PassVector.push_back(MP); |
| 352 | activeFunctionPassManager = NULL; |
| 353 | return true; |
| 354 | } |
| 355 | |
| 356 | |
| 357 | /// Execute all of the passes scheduled for execution by invoking |
| 358 | /// runOnModule method. Keep track of whether any of the passes modifies |
| 359 | /// the module, and if so, return true. |
| 360 | bool |
| 361 | ModulePassManager_New::runOnModule(Module &M) { |
| 362 | bool Changed = false; |
| 363 | for (std::vector<Pass *>::iterator itr = PassVector.begin(), |
| 364 | e = PassVector.end(); itr != e; ++itr) { |
| 365 | Pass *P = *itr; |
| 366 | ModulePass *MP = dynamic_cast<ModulePass*>(P); |
| 367 | Changed |= MP->runOnModule(M); |
| 368 | } |
| 369 | return Changed; |
| 370 | } |
| 371 | |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 372 | /// Schedule all passes from the queue by adding them in their |
| 373 | /// respective manager's queue. |
| 374 | void |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 375 | PassManagerImpl_New::schedulePasses() { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 376 | /* TODO */ |
| 377 | } |
| 378 | |
| 379 | /// Add pass P to the queue of passes to run. |
| 380 | void |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 381 | PassManagerImpl_New::add(Pass *P) { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 382 | /* TODO */ |
| 383 | } |
| 384 | |
| 385 | // PassManager_New implementation |
| 386 | /// Add P into active pass manager or use new module pass manager to |
| 387 | /// manage it. |
| 388 | bool |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 389 | PassManagerImpl_New::addPass(Pass *P) { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 390 | |
Devang Patel | 6c9f548 | 2006-11-11 00:42:16 +0000 | [diff] [blame^] | 391 | if (!activeManager || !activeManager->addPass(P)) { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 392 | activeManager = new ModulePassManager_New(); |
| 393 | PassManagers.push_back(activeManager); |
| 394 | } |
| 395 | |
| 396 | return activeManager->addPass(P); |
| 397 | } |
| 398 | |
| 399 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 400 | /// whether any of the passes modifies the module, and if so, return true. |
| 401 | bool |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 402 | PassManagerImpl_New::run(Module &M) { |
Devang Patel | c290c8a | 2006-11-07 22:23:34 +0000 | [diff] [blame] | 403 | |
| 404 | schedulePasses(); |
| 405 | bool Changed = false; |
| 406 | for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(), |
| 407 | e = PassManagers.end(); itr != e; ++itr) { |
| 408 | ModulePassManager_New *pm = *itr; |
| 409 | Changed |= pm->runOnModule(M); |
| 410 | } |
| 411 | return Changed; |
| 412 | } |
Devang Patel | 376fefa | 2006-11-08 10:29:57 +0000 | [diff] [blame] | 413 | |
| 414 | /// Create new pass manager |
| 415 | PassManager_New::PassManager_New() { |
| 416 | PM = new PassManagerImpl_New(); |
| 417 | } |
| 418 | |
| 419 | /// add - Add a pass to the queue of passes to run. This passes ownership of |
| 420 | /// the Pass to the PassManager. When the PassManager is destroyed, the pass |
| 421 | /// will be destroyed as well, so there is no need to delete the pass. This |
| 422 | /// implies that all passes MUST be allocated with 'new'. |
| 423 | void |
| 424 | PassManager_New::add(Pass *P) { |
| 425 | PM->add(P); |
| 426 | } |
| 427 | |
| 428 | /// run - Execute all of the passes scheduled for execution. Keep track of |
| 429 | /// whether any of the passes modifies the module, and if so, return true. |
| 430 | bool |
| 431 | PassManager_New::run(Module &M) { |
| 432 | return PM->run(M); |
| 433 | } |
| 434 | |