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 //===----------------------------------------------------------------------===//
92 /// PMTopLevelManager manages LastUser info and collects common APIs used by
93 /// top level pass managers.
94 class PMTopLevelManager {
98 inline std::vector<Pass *>::iterator passManagersBegin() {
99 return PassManagers.begin();
102 inline std::vector<Pass *>::iterator passManagersEnd() {
103 return PassManagers.end();
106 /// Schedule pass P for execution. Make sure that passes required by
107 /// P are run before P is run. Update analysis info maintained by
108 /// the manager. Remove dead passes. This is a recursive function.
109 void schedulePass(Pass *P, Pass *PM);
111 /// This is implemented by top level pass manager and used by
112 /// schedulePass() to add analysis info passes that are not available.
113 virtual void addTopLevelPass(Pass *P) = 0;
115 /// Set pass P as the last user of the given analysis passes.
116 void setLastUser(std::vector<Pass *> &AnalysisPasses, Pass *P);
118 /// Collect passes whose last user is P
119 void collectLastUses(std::vector<Pass *> &LastUses, Pass *P);
121 virtual ~PMTopLevelManager() {
122 PassManagers.clear();
127 /// Collection of pass managers
128 std::vector<Pass *> PassManagers;
130 // Map to keep track of last user of the analysis pass.
131 // LastUser->second is the last user of Lastuser->first.
132 std::map<Pass *, Pass *> LastUser;
135 /// Set pass P as the last user of the given analysis passes.
136 void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses,
139 for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(),
140 E = AnalysisPasses.end(); I != E; ++I) {
143 // If AP is the last user of other passes then make P last user of
145 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
146 LUE = LastUser.end(); LUI != LUE; ++LUI) {
147 if (LUI->second == AP)
148 LastUser[LUI->first] = P;
154 /// Collect passes whose last user is P
155 void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
157 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
158 LUE = LastUser.end(); LUI != LUE; ++LUI)
159 if (LUI->second == P)
160 LastUses.push_back(LUI->first);
165 /// PMDataManager provides the common place to manage the analysis data
166 /// used by pass managers.
167 class PMDataManager {
171 /// Return true IFF pass P's required analysis set does not required new
173 bool manageablePass(Pass *P);
175 Pass *getAnalysisPass(AnalysisID AID) const {
177 std::map<AnalysisID, Pass*>::const_iterator I =
178 AvailableAnalysis.find(AID);
180 if (I != AvailableAnalysis.end())
186 /// Augment AvailableAnalysis by adding analysis made available by pass P.
187 void noteDownAvailableAnalysis(Pass *P);
189 /// Remove Analysis that is not preserved by the pass
190 void removeNotPreservedAnalysis(Pass *P);
192 /// Remove dead passes
193 void removeDeadPasses(Pass *P);
195 /// Add pass P into the PassVector. Update
196 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
197 void addPassToManager (Pass *P, bool ProcessAnalysis = true);
199 // Initialize available analysis information.
200 void initializeAnalysisInfo() {
201 AvailableAnalysis.clear();
205 // All Required analyses should be available to the pass as it runs! Here
206 // we fill in the AnalysisImpls member of the pass so that it can
207 // successfully use the getAnalysis() method to retrieve the
208 // implementations it needs.
210 void initializeAnalysisImpl(Pass *P);
212 inline std::vector<Pass *>::iterator passVectorBegin() {
213 return PassVector.begin();
216 inline std::vector<Pass *>::iterator passVectorEnd() {
217 return PassVector.end();
220 inline void setLastUser(Pass *P, Pass *LU) {
222 // TODO : Check if pass P is available.
226 // Set of available Analysis. This information is used while scheduling
227 // pass. If a pass requires an analysis which is not not available then
228 // equired analysis pass is scheduled to run before the pass itself is
230 std::map<AnalysisID, Pass*> AvailableAnalysis;
232 // Map to keep track of last user of the analysis pass.
233 // LastUser->second is the last user of Lastuser->first.
234 std::map<Pass *, Pass *> LastUser;
236 // Collection of pass that are managed by this manager
237 std::vector<Pass *> PassVector;
240 /// BasicBlockPassManager_New manages BasicBlockPass. It batches all the
241 /// pass together and sequence them to process one basic block before
242 /// processing next basic block.
243 class BasicBlockPassManager_New : public PMDataManager,
244 public FunctionPass {
247 BasicBlockPassManager_New() { }
249 /// Add a pass into a passmanager queue.
250 bool addPass(Pass *p);
252 /// Execute all of the passes scheduled for execution. Keep track of
253 /// whether any of the passes modifies the function, and if so, return true.
254 bool runOnFunction(Function &F);
256 /// Return true IFF AnalysisID AID is currently available.
257 Pass *getAnalysisPassFromManager(AnalysisID AID);
262 /// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers.
263 /// It batches all function passes and basic block pass managers together and
264 /// sequence them to process one function at a time before processing next
266 class FunctionPassManagerImpl_New : public PMDataManager,
269 FunctionPassManagerImpl_New(ModuleProvider *P) { /* TODO */ }
270 FunctionPassManagerImpl_New() {
271 activeBBPassManager = NULL;
273 ~FunctionPassManagerImpl_New() { /* TODO */ };
275 /// add - Add a pass to the queue of passes to run. This passes
276 /// ownership of the Pass to the PassManager. When the
277 /// PassManager_X is destroyed, the pass will be destroyed as well, so
278 /// there is no need to delete the pass. (TODO delete passes.)
279 /// This implies that all passes MUST be allocated with 'new'.
280 void add(Pass *P) { /* TODO*/ }
282 /// Add pass into the pass manager queue.
283 bool addPass(Pass *P);
285 /// Execute all of the passes scheduled for execution. Keep
286 /// track of whether any of the passes modifies the function, and if
288 bool runOnModule(Module &M);
289 bool runOnFunction(Function &F);
291 /// Return true IFF AnalysisID AID is currently available.
292 Pass *getAnalysisPassFromManager(AnalysisID AID);
294 /// doInitialization - Run all of the initializers for the function passes.
296 bool doInitialization(Module &M);
298 /// doFinalization - Run all of the initializers for the function passes.
300 bool doFinalization(Module &M);
302 // Active Pass Managers
303 BasicBlockPassManager_New *activeBBPassManager;
306 /// ModulePassManager_New manages ModulePasses and function pass managers.
307 /// It batches all Module passes passes and function pass managers together and
308 /// sequence them to process one module.
309 class ModulePassManager_New : public PMDataManager {
312 ModulePassManager_New() { activeFunctionPassManager = NULL; }
314 /// Add a pass into a passmanager queue.
315 bool addPass(Pass *p);
317 /// run - Execute all of the passes scheduled for execution. Keep track of
318 /// whether any of the passes modifies the module, and if so, return true.
319 bool runOnModule(Module &M);
321 /// Return true IFF AnalysisID AID is currently available.
322 Pass *getAnalysisPassFromManager(AnalysisID AID);
325 // Active Pass Manager
326 FunctionPassManagerImpl_New *activeFunctionPassManager;
329 /// PassManager_New manages ModulePassManagers
330 class PassManagerImpl_New : public PMDataManager {
334 /// add - Add a pass to the queue of passes to run. This passes ownership of
335 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
336 /// will be destroyed as well, so there is no need to delete the pass. This
337 /// implies that all passes MUST be allocated with 'new'.
340 /// run - Execute all of the passes scheduled for execution. Keep track of
341 /// whether any of the passes modifies the module, and if so, return true.
344 /// Return true IFF AnalysisID AID is currently available.
345 Pass *getAnalysisPassFromManager(AnalysisID AID);
349 /// Add a pass into a passmanager queue. This is used by schedulePasses
350 bool addPass(Pass *p);
352 /// Schedule pass P for execution. Make sure that passes required by
353 /// P are run before P is run. Update analysis info maintained by
354 /// the manager. Remove dead passes. This is a recursive function.
355 void schedulePass(Pass *P);
357 /// Schedule all passes collected in pass queue using add(). Add all the
358 /// schedule passes into various manager's queue using addPass().
359 void schedulePasses();
361 // Collection of pass managers
362 std::vector<ModulePassManager_New *> PassManagers;
364 // Active Pass Manager
365 ModulePassManager_New *activeManager;
368 } // End of llvm namespace
370 // PMDataManager implementation
372 /// Return true IFF pass P's required analysis set does not required new
374 bool PMDataManager::manageablePass(Pass *P) {
377 // If this pass is not preserving information that is required by a
378 // pass maintained by higher level pass manager then do not insert
379 // this pass into current manager. Use new manager. For example,
380 // For example, If FunctionPass F is not preserving ModulePass Info M1
381 // that is used by another ModulePass M2 then do not insert F in
382 // current function pass manager.
386 /// Augement AvailableAnalysis by adding analysis made available by pass P.
387 void PMDataManager::noteDownAvailableAnalysis(Pass *P) {
389 if (const PassInfo *PI = P->getPassInfo()) {
390 AvailableAnalysis[PI] = P;
392 //TODO This pass is the current implementation of all of the interfaces it
393 //TODO implements as well.
395 //TODO const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
396 //TODO for (unsigned i = 0, e = II.size(); i != e; ++i)
397 //TODO CurrentAnalyses[II[i]] = P;
401 /// Remove Analyss not preserved by Pass P
402 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
403 AnalysisUsage AnUsage;
404 P->getAnalysisUsage(AnUsage);
405 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
407 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
408 E = AvailableAnalysis.end(); I != E; ++I ) {
409 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) ==
410 PreservedSet.end()) {
411 // Remove this analysis
412 std::map<AnalysisID, Pass*>::iterator J = I++;
413 AvailableAnalysis.erase(J);
418 /// Remove analysis passes that are not used any longer
419 void PMDataManager::removeDeadPasses(Pass *P) {
421 for (std::map<Pass *, Pass *>::iterator I = LastUser.begin(),
422 E = LastUser.end(); I !=E; ++I) {
423 if (I->second == P) {
424 Pass *deadPass = I->first;
425 deadPass->releaseMemory();
427 std::map<AnalysisID, Pass*>::iterator Pos =
428 AvailableAnalysis.find(deadPass->getPassInfo());
430 assert (Pos != AvailableAnalysis.end() &&
431 "Pass is not available");
432 AvailableAnalysis.erase(Pos);
437 /// Add pass P into the PassVector. Update
438 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
439 void PMDataManager::addPassToManager (Pass *P,
440 bool ProcessAnalysis) {
442 if (ProcessAnalysis) {
443 // Take a note of analysis required and made available by this pass
444 initializeAnalysisImpl(P);
445 noteDownAvailableAnalysis(P);
447 // Remove the analysis not preserved by this pass
448 removeNotPreservedAnalysis(P);
452 PassVector.push_back(P);
455 // All Required analyses should be available to the pass as it runs! Here
456 // we fill in the AnalysisImpls member of the pass so that it can
457 // successfully use the getAnalysis() method to retrieve the
458 // implementations it needs.
460 void PMDataManager::initializeAnalysisImpl(Pass *P) {
461 AnalysisUsage AnUsage;
462 P->getAnalysisUsage(AnUsage);
464 for (std::vector<const PassInfo *>::const_iterator
465 I = AnUsage.getRequiredSet().begin(),
466 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
467 Pass *Impl = getAnalysisPass(*I);
469 assert(0 && "Analysis used but not available!");
470 // TODO: P->AnalysisImpls.push_back(std::make_pair(*I, Impl));
474 /// BasicBlockPassManager implementation
476 /// Add pass P into PassVector and return true. If this pass is not
477 /// manageable by this manager then return false.
479 BasicBlockPassManager_New::addPass(Pass *P) {
481 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
485 // If this pass does not preserve anlysis that is used by other passes
486 // managed by this manager than it is not a suiable pass for this manager.
487 if (!manageablePass(P))
490 addPassToManager (BP);
495 /// Execute all of the passes scheduled for execution by invoking
496 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
497 /// the function, and if so, return true.
499 BasicBlockPassManager_New::runOnFunction(Function &F) {
501 bool Changed = false;
502 initializeAnalysisInfo();
504 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
505 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
506 e = passVectorEnd(); itr != e; ++itr) {
509 noteDownAvailableAnalysis(P);
510 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
511 Changed |= BP->runOnBasicBlock(*I);
512 removeNotPreservedAnalysis(P);
518 /// Return true IFF AnalysisID AID is currently available.
519 Pass * BasicBlockPassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
520 return getAnalysisPass(AID);
523 // FunctionPassManager_New implementation
524 /// Create new Function pass manager
525 FunctionPassManager_New::FunctionPassManager_New() {
526 FPM = new FunctionPassManagerImpl_New();
529 /// add - Add a pass to the queue of passes to run. This passes
530 /// ownership of the Pass to the PassManager. When the
531 /// PassManager_X is destroyed, the pass will be destroyed as well, so
532 /// there is no need to delete the pass. (TODO delete passes.)
533 /// This implies that all passes MUST be allocated with 'new'.
534 void FunctionPassManager_New::add(Pass *P) {
538 /// Execute all of the passes scheduled for execution. Keep
539 /// track of whether any of the passes modifies the function, and if
541 bool FunctionPassManager_New::runOnModule(Module &M) {
542 return FPM->runOnModule(M);
545 /// run - Execute all of the passes scheduled for execution. Keep
546 /// track of whether any of the passes modifies the function, and if
549 bool FunctionPassManager_New::run(Function &F) {
551 if (MP->materializeFunction(&F, &errstr)) {
552 cerr << "Error reading bytecode file: " << errstr << "\n";
555 return FPM->runOnFunction(F);
559 /// doInitialization - Run all of the initializers for the function passes.
561 bool FunctionPassManager_New::doInitialization() {
562 return FPM->doInitialization(*MP->getModule());
565 /// doFinalization - Run all of the initializers for the function passes.
567 bool FunctionPassManager_New::doFinalization() {
568 return FPM->doFinalization(*MP->getModule());
571 // FunctionPassManagerImpl_New implementation
573 // FunctionPassManager
575 /// Add pass P into the pass manager queue. If P is a BasicBlockPass then
576 /// either use it into active basic block pass manager or create new basic
577 /// block pass manager to handle pass P.
579 FunctionPassManagerImpl_New::addPass(Pass *P) {
581 // If P is a BasicBlockPass then use BasicBlockPassManager_New.
582 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
584 if (!activeBBPassManager
585 || !activeBBPassManager->addPass(BP)) {
587 activeBBPassManager = new BasicBlockPassManager_New();
588 addPassToManager(activeBBPassManager, false);
589 if (!activeBBPassManager->addPass(BP))
590 assert(0 && "Unable to add Pass");
595 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
599 // If this pass does not preserve anlysis that is used by other passes
600 // managed by this manager than it is not a suiable pass for this manager.
601 if (!manageablePass(P))
604 addPassToManager (FP);
605 activeBBPassManager = NULL;
609 /// Execute all of the passes scheduled for execution by invoking
610 /// runOnFunction method. Keep track of whether any of the passes modifies
611 /// the function, and if so, return true.
612 bool FunctionPassManagerImpl_New::runOnModule(Module &M) {
614 bool Changed = false;
615 initializeAnalysisInfo();
617 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
618 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
619 e = passVectorEnd(); itr != e; ++itr) {
622 noteDownAvailableAnalysis(P);
623 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
624 Changed |= FP->runOnFunction(*I);
625 removeNotPreservedAnalysis(P);
631 /// Execute all of the passes scheduled for execution by invoking
632 /// runOnFunction method. Keep track of whether any of the passes modifies
633 /// the function, and if so, return true.
634 bool FunctionPassManagerImpl_New::runOnFunction(Function &F) {
636 bool Changed = false;
637 initializeAnalysisInfo();
639 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
640 e = passVectorEnd(); itr != e; ++itr) {
643 noteDownAvailableAnalysis(P);
644 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
645 Changed |= FP->runOnFunction(F);
646 removeNotPreservedAnalysis(P);
653 /// Return true IFF AnalysisID AID is currently available.
654 Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
656 Pass *P = getAnalysisPass(AID);
660 if (activeBBPassManager &&
661 activeBBPassManager->getAnalysisPass(AID) != 0)
662 return activeBBPassManager->getAnalysisPass(AID);
664 // TODO : Check inactive managers
668 inline bool FunctionPassManagerImpl_New::doInitialization(Module &M) {
669 bool Changed = false;
671 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
672 e = passVectorEnd(); itr != e; ++itr) {
675 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
676 Changed |= FP->doInitialization(M);
682 inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) {
683 bool Changed = false;
685 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
686 e = passVectorEnd(); itr != e; ++itr) {
689 FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
690 Changed |= FP->doFinalization(M);
698 // ModulePassManager implementation
700 /// Add P into pass vector if it is manageble. If P is a FunctionPass
701 /// then use FunctionPassManagerImpl_New to manage it. Return false if P
702 /// is not manageable by this manager.
704 ModulePassManager_New::addPass(Pass *P) {
706 // If P is FunctionPass then use function pass maanager.
707 if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
709 activeFunctionPassManager = NULL;
711 if (!activeFunctionPassManager
712 || !activeFunctionPassManager->addPass(P)) {
714 activeFunctionPassManager = new FunctionPassManagerImpl_New();
715 addPassToManager(activeFunctionPassManager, false);
716 if (!activeFunctionPassManager->addPass(FP))
717 assert(0 && "Unable to add pass");
722 ModulePass *MP = dynamic_cast<ModulePass *>(P);
726 // If this pass does not preserve anlysis that is used by other passes
727 // managed by this manager than it is not a suiable pass for this manager.
728 if (!manageablePass(P))
731 addPassToManager(MP);
732 activeFunctionPassManager = NULL;
737 /// Execute all of the passes scheduled for execution by invoking
738 /// runOnModule method. Keep track of whether any of the passes modifies
739 /// the module, and if so, return true.
741 ModulePassManager_New::runOnModule(Module &M) {
742 bool Changed = false;
743 initializeAnalysisInfo();
745 for (std::vector<Pass *>::iterator itr = passVectorBegin(),
746 e = passVectorEnd(); itr != e; ++itr) {
749 noteDownAvailableAnalysis(P);
750 ModulePass *MP = dynamic_cast<ModulePass*>(P);
751 Changed |= MP->runOnModule(M);
752 removeNotPreservedAnalysis(P);
758 /// Return true IFF AnalysisID AID is currently available.
759 Pass *ModulePassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
762 Pass *P = getAnalysisPass(AID);
766 if (activeFunctionPassManager &&
767 activeFunctionPassManager->getAnalysisPass(AID) != 0)
768 return activeFunctionPassManager->getAnalysisPass(AID);
770 // TODO : Check inactive managers
774 /// Return true IFF AnalysisID AID is currently available.
775 Pass *PassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
778 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
779 e = PassManagers.end(); !P && itr != e; ++itr)
780 P = (*itr)->getAnalysisPassFromManager(AID);
784 /// Schedule pass P for execution. Make sure that passes required by
785 /// P are run before P is run. Update analysis info maintained by
786 /// the manager. Remove dead passes. This is a recursive function.
787 void PassManagerImpl_New::schedulePass(Pass *P) {
789 AnalysisUsage AnUsage;
790 P->getAnalysisUsage(AnUsage);
791 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
792 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
793 E = RequiredSet.end(); I != E; ++I) {
795 Pass *AnalysisPass = getAnalysisPassFromManager(*I);
797 // Schedule this analysis run first.
798 AnalysisPass = (*I)->createPass();
799 schedulePass(AnalysisPass);
801 setLastUser (AnalysisPass, P);
803 // Prolong live range of analyses that are needed after an analysis pass
804 // is destroyed, for querying by subsequent passes
805 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
806 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
807 E = IDs.end(); I != E; ++I) {
808 Pass *AP = getAnalysisPassFromManager(*I);
809 assert (AP && "Analysis pass is not available");
816 /// Schedule all passes from the queue by adding them in their
817 /// respective manager's queue.
818 void PassManagerImpl_New::schedulePasses() {
819 for (std::vector<Pass *>::iterator I = passVectorBegin(),
820 E = passVectorEnd(); I != E; ++I)
824 /// Add pass P to the queue of passes to run.
825 void PassManagerImpl_New::add(Pass *P) {
826 // Do not process Analysis now. Analysis is process while scheduling
828 addPassToManager(P, false);
831 // PassManager_New implementation
832 /// Add P into active pass manager or use new module pass manager to
834 bool PassManagerImpl_New::addPass(Pass *P) {
836 if (!activeManager || !activeManager->addPass(P)) {
837 activeManager = new ModulePassManager_New();
838 PassManagers.push_back(activeManager);
841 return activeManager->addPass(P);
844 /// run - Execute all of the passes scheduled for execution. Keep track of
845 /// whether any of the passes modifies the module, and if so, return true.
846 bool PassManagerImpl_New::run(Module &M) {
849 bool Changed = false;
850 for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
851 e = PassManagers.end(); itr != e; ++itr) {
852 ModulePassManager_New *pm = *itr;
853 Changed |= pm->runOnModule(M);
858 /// Create new pass manager
859 PassManager_New::PassManager_New() {
860 PM = new PassManagerImpl_New();
863 /// add - Add a pass to the queue of passes to run. This passes ownership of
864 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
865 /// will be destroyed as well, so there is no need to delete the pass. This
866 /// implies that all passes MUST be allocated with 'new'.
868 PassManager_New::add(Pass *P) {
872 /// run - Execute all of the passes scheduled for execution. Keep track of
873 /// whether any of the passes modifies the module, and if so, return true.
875 PassManager_New::run(Module &M) {