1 //===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Devang Patel and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the LLVM Pass Manager infrastructure.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/PassManager.h"
16 #include "llvm/Module.h"
17 #include "llvm/ModuleProvider.h"
18 #include "llvm/Support/Streams.h"
23 //===----------------------------------------------------------------------===//
25 // The Pass Manager Infrastructure manages passes. It's responsibilities are:
27 // o Manage optimization pass execution order
28 // o Make required Analysis information available before pass P is run
29 // o Release memory occupied by dead passes
30 // o If Analysis information is dirtied by a pass then regenerate Analysis
31 // information before it is consumed by another pass.
33 // Pass Manager Infrastructure uses multipe pass managers. They are PassManager,
34 // FunctionPassManager, ModulePassManager, BasicBlockPassManager. This class
35 // hierarcy uses multiple inheritance but pass managers do not derive from
36 // another pass manager.
38 // PassManager and FunctionPassManager are two top level pass manager that
39 // represents the external interface of this entire pass manager infrastucture.
41 // Important classes :
43 // [o] class PMTopLevelManager;
45 // Two top level managers, PassManager and FunctionPassManager, derive from
46 // PMTopLevelManager. PMTopLevelManager manages information used by top level
47 // managers such as last user info.
49 // [o] class PMDataManager;
51 // PMDataManager manages information, e.g. list of available analysis info,
52 // used by a pass manager to manage execution order of passes. It also provides
53 // a place to implement common pass manager APIs. All pass managers derive from
56 // [o] class BasicBlockPassManager : public FunctionPass, public PMDataManager;
58 // BasicBlockPassManager manages BasicBlockPasses.
60 // [o] class FunctionPassManager;
62 // This is a external interface used by JIT to manage FunctionPasses. This
63 // interface relies on FunctionPassManagerImpl to do all the tasks.
65 // [o] class FunctionPassManagerImpl : public ModulePass, PMDataManager,
66 // public PMTopLevelManager;
68 // FunctionPassManagerImpl is a top level manager. It manages FunctionPasses
69 // and BasicBlockPassManagers.
71 // [o] class ModulePassManager : public Pass, public PMDataManager;
73 // ModulePassManager manages ModulePasses and FunctionPassManagerImpls.
75 // [o] class PassManager;
77 // This is a external interface used by various tools to manages passes. It
78 // relies on PassManagerImpl to do all the tasks.
80 // [o] class PassManagerImpl : public Pass, public PMDataManager,
81 // public PMDTopLevelManager
83 // PassManagerImpl is a top level pass manager responsible for managing
84 // ModulePassManagers.
85 //===----------------------------------------------------------------------===//
89 /// PMDataManager provides the common place to manage the analysis data
90 /// used by pass managers.
95 /// Return true IFF pass P's required analysis set does not required new
97 bool manageablePass(Pass *P);
99 Pass *getAnalysisPass(AnalysisID AID) const {
101 std::map<AnalysisID, Pass*>::const_iterator I =
102 AvailableAnalysis.find(AID);
104 if (I != AvailableAnalysis.end())
110 /// Augment RequiredAnalysis by adding analysis required by pass P.
111 void noteDownRequiredAnalysis(Pass *P);
113 /// Augment AvailableAnalysis by adding analysis made available by pass P.
114 void noteDownAvailableAnalysis(Pass *P);
116 /// Remove Analysis that is not preserved by the pass
117 void removeNotPreservedAnalysis(Pass *P);
119 /// Remove dead passes
120 void removeDeadPasses(Pass *P);
122 /// Add pass P into the PassVector. Update RequiredAnalysis and
123 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
124 void addPassToManager (Pass *P, bool ProcessAnalysis = true);
126 // Initialize available analysis information.
127 void initializeAnalysisInfo() {
128 RequiredAnalysis.clear();
129 AvailableAnalysis.clear();
133 // All Required analyses should be available to the pass as it runs! Here
134 // we fill in the AnalysisImpls member of the pass so that it can
135 // successfully use the getAnalysis() method to retrieve the
136 // implementations it needs.
138 void initializeAnalysisImpl(Pass *P);
140 inline std::vector<Pass *>::iterator passVectorBegin() {
141 return PassVector.begin();
144 inline std::vector<Pass *>::iterator passVectorEnd() {
145 return PassVector.end();
148 inline void setLastUser(Pass *P, Pass *LU) {
150 // TODO : Check if pass P is available.
154 // Analysis required by the passes managed by this manager. This information
155 // used while selecting pass manager during addPass. If a pass does not
156 // preserve any analysis required by other passes managed by current
157 // pass manager then new pass manager is used.
158 std::vector<AnalysisID> RequiredAnalysis;
160 // Set of available Analysis. This information is used while scheduling
161 // pass. If a pass requires an analysis which is not not available then
162 // equired analysis pass is scheduled to run before the pass itself is
164 std::map<AnalysisID, Pass*> AvailableAnalysis;
166 // Map to keep track of last user of the analysis pass.
167 // LastUser->second is the last user of Lastuser->first.
168 std::map<Pass *, Pass *> LastUser;
170 // Collection of pass that are managed by this manager
171 std::vector<Pass *> PassVector;
174 /// BasicBlockPassManager_New manages BasicBlockPass. It batches all the
175 /// pass together and sequence them to process one basic block before
176 /// processing next basic block.
177 class BasicBlockPassManager_New : public PMDataManager,
178 public FunctionPass {
181 BasicBlockPassManager_New() { }
183 /// Add a pass into a passmanager queue.
184 bool addPass(Pass *p);
186 /// Execute all of the passes scheduled for execution. Keep track of
187 /// whether any of the passes modifies the function, and if so, return true.
188 bool runOnFunction(Function &F);
190 /// Return true IFF AnalysisID AID is currently available.
191 Pass *getAnalysisPassFromManager(AnalysisID AID);
196 /// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers.
197 /// It batches all function passes and basic block pass managers together and
198 /// sequence them to process one function at a time before processing next
200 class FunctionPassManagerImpl_New : public PMDataManager,
203 FunctionPassManagerImpl_New(ModuleProvider *P) { /* TODO */ }
204 FunctionPassManagerImpl_New() {
205 activeBBPassManager = NULL;
207 ~FunctionPassManagerImpl_New() { /* TODO */ };
209 /// add - Add a pass to the queue of passes to run. This passes
210 /// ownership of the Pass to the PassManager. When the
211 /// PassManager_X is destroyed, the pass will be destroyed as well, so
212 /// there is no need to delete the pass. (TODO delete passes.)
213 /// This implies that all passes MUST be allocated with 'new'.
214 void add(Pass *P) { /* TODO*/ }
216 /// Add pass into the pass manager queue.
217 bool addPass(Pass *P);
219 /// Execute all of the passes scheduled for execution. Keep
220 /// track of whether any of the passes modifies the function, and if
222 bool runOnModule(Module &M);
223 bool runOnFunction(Function &F);
225 /// Return true IFF AnalysisID AID is currently available.
226 Pass *getAnalysisPassFromManager(AnalysisID AID);
228 /// doInitialization - Run all of the initializers for the function passes.
230 bool doInitialization(Module &M);
232 /// doFinalization - Run all of the initializers for the function passes.
234 bool doFinalization(Module &M);
236 // Active Pass Managers
237 BasicBlockPassManager_New *activeBBPassManager;
240 /// ModulePassManager_New manages ModulePasses and function pass managers.
241 /// It batches all Module passes passes and function pass managers together and
242 /// sequence them to process one module.
243 class ModulePassManager_New : public PMDataManager {
246 ModulePassManager_New() { activeFunctionPassManager = NULL; }
248 /// Add a pass into a passmanager queue.
249 bool addPass(Pass *p);
251 /// run - Execute all of the passes scheduled for execution. Keep track of
252 /// whether any of the passes modifies the module, and if so, return true.
253 bool runOnModule(Module &M);
255 /// Return true IFF AnalysisID AID is currently available.
256 Pass *getAnalysisPassFromManager(AnalysisID AID);
259 // Active Pass Manager
260 FunctionPassManagerImpl_New *activeFunctionPassManager;
263 /// PassManager_New manages ModulePassManagers
264 class PassManagerImpl_New : public PMDataManager {
268 /// add - Add a pass to the queue of passes to run. This passes ownership of
269 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
270 /// will be destroyed as well, so there is no need to delete the pass. This
271 /// implies that all passes MUST be allocated with 'new'.
274 /// run - Execute all of the passes scheduled for execution. Keep track of
275 /// whether any of the passes modifies the module, and if so, return true.
278 /// Return true IFF AnalysisID AID is currently available.
279 Pass *getAnalysisPassFromManager(AnalysisID AID);
283 /// Add a pass into a passmanager queue. This is used by schedulePasses
284 bool addPass(Pass *p);
286 /// Schedule pass P for execution. Make sure that passes required by
287 /// P are run before P is run. Update analysis info maintained by
288 /// the manager. Remove dead passes. This is a recursive function.
289 void schedulePass(Pass *P);
291 /// Schedule all passes collected in pass queue using add(). Add all the
292 /// schedule passes into various manager's queue using addPass().
293 void schedulePasses();
295 // Collection of pass managers
296 std::vector<ModulePassManager_New *> PassManagers;
298 // Active Pass Manager
299 ModulePassManager_New *activeManager;
302 } // End of llvm namespace
304 // PMDataManager implementation
306 /// Return true IFF pass P's required analysis set does not required new
308 bool PMDataManager::manageablePass(Pass *P) {
310 AnalysisUsage AnUsage;
311 P->getAnalysisUsage(AnUsage);
313 // If this pass is not preserving information that is required by the other
314 // passes managed by this manager then use new manager
315 if (!AnUsage.getPreservesAll()) {
316 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
317 for (std::vector<AnalysisID>::iterator I = RequiredAnalysis.begin(),
318 E = RequiredAnalysis.end(); I != E; ++I) {
319 if (std::find(PreservedSet.begin(), PreservedSet.end(), *I) ==
321 // This analysis is not preserved. Need new manager.
328 /// Augment RequiredAnalysis by adding analysis required by pass P.
329 void PMDataManager::noteDownRequiredAnalysis(Pass *P) {
330 AnalysisUsage AnUsage;
331 P->getAnalysisUsage(AnUsage);
332 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
334 // FIXME: What about duplicates ?
335 RequiredAnalysis.insert(RequiredAnalysis.end(), RequiredSet.begin(),
338 initializeAnalysisImpl(P);
341 /// Augement AvailableAnalysis by adding analysis made available by pass P.
342 void PMDataManager::noteDownAvailableAnalysis(Pass *P) {
344 if (const PassInfo *PI = P->getPassInfo()) {
345 AvailableAnalysis[PI] = P;
347 //TODO This pass is the current implementation of all of the interfaces it
348 //TODO implements as well.
350 //TODO const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
351 //TODO for (unsigned i = 0, e = II.size(); i != e; ++i)
352 //TODO CurrentAnalyses[II[i]] = P;
356 /// Remove Analyss not preserved by Pass P
357 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
358 AnalysisUsage AnUsage;
359 P->getAnalysisUsage(AnUsage);
360 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
362 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
363 E = AvailableAnalysis.end(); I != E; ++I ) {
364 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) ==
365 PreservedSet.end()) {
366 // Remove this analysis
367 std::map<AnalysisID, Pass*>::iterator J = I++;
368 AvailableAnalysis.erase(J);
373 /// Remove analysis passes that are not used any longer
374 void PMDataManager::removeDeadPasses(Pass *P) {
376 for (std::map<Pass *, Pass *>::iterator I = LastUser.begin(),
377 E = LastUser.end(); I !=E; ++I) {
378 if (I->second == P) {
379 Pass *deadPass = I->first;
380 deadPass->releaseMemory();
382 std::map<AnalysisID, Pass*>::iterator Pos =
383 AvailableAnalysis.find(deadPass->getPassInfo());
385 assert (Pos != AvailableAnalysis.end() &&
386 "Pass is not available");
387 AvailableAnalysis.erase(Pos);
392 /// Add pass P into the PassVector. Update RequiredAnalysis and
393 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
394 void PMDataManager::addPassToManager (Pass *P,
395 bool ProcessAnalysis) {
397 if (ProcessAnalysis) {
398 // Take a note of analysis required and made available by this pass
399 noteDownRequiredAnalysis(P);
400 noteDownAvailableAnalysis(P);
402 // Remove the analysis not preserved by this pass
403 removeNotPreservedAnalysis(P);
407 PassVector.push_back(P);
410 // All Required analyses should be available to the pass as it runs! Here
411 // we fill in the AnalysisImpls member of the pass so that it can
412 // successfully use the getAnalysis() method to retrieve the
413 // implementations it needs.
415 void PMDataManager::initializeAnalysisImpl(Pass *P) {
416 AnalysisUsage AnUsage;
417 P->getAnalysisUsage(AnUsage);
419 for (std::vector<const PassInfo *>::const_iterator
420 I = AnUsage.getRequiredSet().begin(),
421 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
422 Pass *Impl = getAnalysisPass(*I);
424 assert(0 && "Analysis used but not available!");
425 // TODO: P->AnalysisImpls.push_back(std::make_pair(*I, Impl));
429 /// BasicBlockPassManager implementation
431 /// Add pass P into PassVector and return true. If this pass is not
432 /// manageable by this manager then return false.
434 BasicBlockPassManager_New::addPass(Pass *P) {
436 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
440 // If this pass does not preserve anlysis that is used by other passes
441 // managed by this manager than it is not a suiable pass for this manager.
442 if (!manageablePass(P))
445 addPassToManager (BP);
450 /// Execute all of the passes scheduled for execution by invoking
451 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
452 /// the function, and if so, return true.
454 BasicBlockPassManager_New::runOnFunction(Function &F) {
456 bool Changed = false;
457 initializeAnalysisInfo();
459 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
460 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
461 e = passVectorEnd(); itr != e; ++itr) {
464 noteDownAvailableAnalysis(P);
465 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
466 Changed |= BP->runOnBasicBlock(*I);
467 removeNotPreservedAnalysis(P);
473 /// Return true IFF AnalysisID AID is currently available.
474 Pass * BasicBlockPassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
475 return getAnalysisPass(AID);
478 // FunctionPassManager_New implementation
479 /// Create new Function pass manager
480 FunctionPassManager_New::FunctionPassManager_New() {
481 FPM = new FunctionPassManagerImpl_New();
484 /// add - Add a pass to the queue of passes to run. This passes
485 /// ownership of the Pass to the PassManager. When the
486 /// PassManager_X is destroyed, the pass will be destroyed as well, so
487 /// there is no need to delete the pass. (TODO delete passes.)
488 /// This implies that all passes MUST be allocated with 'new'.
489 void FunctionPassManager_New::add(Pass *P) {
493 /// Execute all of the passes scheduled for execution. Keep
494 /// track of whether any of the passes modifies the function, and if
496 bool FunctionPassManager_New::runOnModule(Module &M) {
497 return FPM->runOnModule(M);
500 /// run - Execute all of the passes scheduled for execution. Keep
501 /// track of whether any of the passes modifies the function, and if
504 bool FunctionPassManager_New::run(Function &F) {
506 if (MP->materializeFunction(&F, &errstr)) {
507 cerr << "Error reading bytecode file: " << errstr << "\n";
510 return FPM->runOnFunction(F);
514 /// doInitialization - Run all of the initializers for the function passes.
516 bool FunctionPassManager_New::doInitialization() {
517 return FPM->doInitialization(*MP->getModule());
520 /// doFinalization - Run all of the initializers for the function passes.
522 bool FunctionPassManager_New::doFinalization() {
523 return FPM->doFinalization(*MP->getModule());
526 // FunctionPassManagerImpl_New implementation
528 // FunctionPassManager
530 /// Add pass P into the pass manager queue. If P is a BasicBlockPass then
531 /// either use it into active basic block pass manager or create new basic
532 /// block pass manager to handle pass P.
534 FunctionPassManagerImpl_New::addPass(Pass *P) {
536 // If P is a BasicBlockPass then use BasicBlockPassManager_New.
537 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
539 if (!activeBBPassManager
540 || !activeBBPassManager->addPass(BP)) {
542 activeBBPassManager = new BasicBlockPassManager_New();
543 addPassToManager(activeBBPassManager, false);
544 if (!activeBBPassManager->addPass(BP))
545 assert(0 && "Unable to add Pass");
550 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
554 // If this pass does not preserve anlysis that is used by other passes
555 // managed by this manager than it is not a suiable pass for this manager.
556 if (!manageablePass(P))
559 addPassToManager (FP);
560 activeBBPassManager = NULL;
564 /// Execute all of the passes scheduled for execution by invoking
565 /// runOnFunction method. Keep track of whether any of the passes modifies
566 /// the function, and if so, return true.
567 bool FunctionPassManagerImpl_New::runOnModule(Module &M) {
569 bool Changed = false;
570 initializeAnalysisInfo();
572 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
573 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
574 e = passVectorEnd(); itr != e; ++itr) {
577 noteDownAvailableAnalysis(P);
578 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
579 Changed |= FP->runOnFunction(*I);
580 removeNotPreservedAnalysis(P);
586 /// Execute all of the passes scheduled for execution by invoking
587 /// runOnFunction method. Keep track of whether any of the passes modifies
588 /// the function, and if so, return true.
589 bool FunctionPassManagerImpl_New::runOnFunction(Function &F) {
591 bool Changed = false;
592 initializeAnalysisInfo();
594 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
595 e = passVectorEnd(); itr != e; ++itr) {
598 noteDownAvailableAnalysis(P);
599 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
600 Changed |= FP->runOnFunction(F);
601 removeNotPreservedAnalysis(P);
608 /// Return true IFF AnalysisID AID is currently available.
609 Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
611 Pass *P = getAnalysisPass(AID);
615 if (activeBBPassManager &&
616 activeBBPassManager->getAnalysisPass(AID) != 0)
617 return activeBBPassManager->getAnalysisPass(AID);
619 // TODO : Check inactive managers
623 inline bool FunctionPassManagerImpl_New::doInitialization(Module &M) {
624 bool Changed = false;
626 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
627 e = passVectorEnd(); itr != e; ++itr) {
630 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
631 Changed |= FP->doInitialization(M);
637 inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) {
638 bool Changed = false;
640 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
641 e = passVectorEnd(); itr != e; ++itr) {
644 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
645 Changed |= FP->doFinalization(M);
653 // ModulePassManager implementation
655 /// Add P into pass vector if it is manageble. If P is a FunctionPass
656 /// then use FunctionPassManagerImpl_New to manage it. Return false if P
657 /// is not manageable by this manager.
659 ModulePassManager_New::addPass(Pass *P) {
661 // If P is FunctionPass then use function pass maanager.
662 if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
664 activeFunctionPassManager = NULL;
666 if (!activeFunctionPassManager
667 || !activeFunctionPassManager->addPass(P)) {
669 activeFunctionPassManager = new FunctionPassManagerImpl_New();
670 addPassToManager(activeFunctionPassManager, false);
671 if (!activeFunctionPassManager->addPass(FP))
672 assert(0 && "Unable to add pass");
677 ModulePass *MP = dynamic_cast<ModulePass *>(P);
681 // If this pass does not preserve anlysis that is used by other passes
682 // managed by this manager than it is not a suiable pass for this manager.
683 if (!manageablePass(P))
686 addPassToManager(MP);
687 activeFunctionPassManager = NULL;
692 /// Execute all of the passes scheduled for execution by invoking
693 /// runOnModule method. Keep track of whether any of the passes modifies
694 /// the module, and if so, return true.
696 ModulePassManager_New::runOnModule(Module &M) {
697 bool Changed = false;
698 initializeAnalysisInfo();
700 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
701 e = passVectorEnd(); itr != e; ++itr) {
704 noteDownAvailableAnalysis(P);
705 ModulePass *MP = dynamic_cast<ModulePass*>(P);
706 Changed |= MP->runOnModule(M);
707 removeNotPreservedAnalysis(P);
713 /// Return true IFF AnalysisID AID is currently available.
714 Pass *ModulePassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
717 Pass *P = getAnalysisPass(AID);
721 if (activeFunctionPassManager &&
722 activeFunctionPassManager->getAnalysisPass(AID) != 0)
723 return activeFunctionPassManager->getAnalysisPass(AID);
725 // TODO : Check inactive managers
729 /// Return true IFF AnalysisID AID is currently available.
730 Pass *PassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
733 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
734 e = PassManagers.end(); !P && itr != e; ++itr)
735 P = (*itr)->getAnalysisPassFromManager(AID);
739 /// Schedule pass P for execution. Make sure that passes required by
740 /// P are run before P is run. Update analysis info maintained by
741 /// the manager. Remove dead passes. This is a recursive function.
742 void PassManagerImpl_New::schedulePass(Pass *P) {
744 AnalysisUsage AnUsage;
745 P->getAnalysisUsage(AnUsage);
746 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
747 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
748 E = RequiredSet.end(); I != E; ++I) {
750 Pass *AnalysisPass = getAnalysisPassFromManager(*I);
752 // Schedule this analysis run first.
753 AnalysisPass = (*I)->createPass();
754 schedulePass(AnalysisPass);
756 setLastUser (AnalysisPass, P);
758 // Prolong live range of analyses that are needed after an analysis pass
759 // is destroyed, for querying by subsequent passes
760 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
761 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
762 E = IDs.end(); I != E; ++I) {
763 Pass *AP = getAnalysisPassFromManager(*I);
764 assert (AP && "Analysis pass is not available");
771 /// Schedule all passes from the queue by adding them in their
772 /// respective manager's queue.
773 void PassManagerImpl_New::schedulePasses() {
774 for (std::vector<Pass *>::iterator I = passVectorBegin(),
775 E = passVectorEnd(); I != E; ++I)
779 /// Add pass P to the queue of passes to run.
780 void PassManagerImpl_New::add(Pass *P) {
781 // Do not process Analysis now. Analysis is process while scheduling
783 addPassToManager(P, false);
786 // PassManager_New implementation
787 /// Add P into active pass manager or use new module pass manager to
789 bool PassManagerImpl_New::addPass(Pass *P) {
791 if (!activeManager || !activeManager->addPass(P)) {
792 activeManager = new ModulePassManager_New();
793 PassManagers.push_back(activeManager);
796 return activeManager->addPass(P);
799 /// run - Execute all of the passes scheduled for execution. Keep track of
800 /// whether any of the passes modifies the module, and if so, return true.
801 bool PassManagerImpl_New::run(Module &M) {
804 bool Changed = false;
805 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
806 e = PassManagers.end(); itr != e; ++itr) {
807 ModulePassManager_New *pm = *itr;
808 Changed |= pm->runOnModule(M);
813 /// Create new pass manager
814 PassManager_New::PassManager_New() {
815 PM = new PassManagerImpl_New();
818 /// add - Add a pass to the queue of passes to run. This passes ownership of
819 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
820 /// will be destroyed as well, so there is no need to delete the pass. This
821 /// implies that all passes MUST be allocated with 'new'.
823 PassManager_New::add(Pass *P) {
827 /// run - Execute all of the passes scheduled for execution. Keep track of
828 /// whether any of the passes modifies the module, and if so, return true.
830 PassManager_New::run(Module &M) {