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/Support/CommandLine.h"
17 #include "llvm/Support/Timer.h"
18 #include "llvm/Module.h"
19 #include "llvm/ModuleProvider.h"
20 #include "llvm/Support/Streams.h"
21 #include "llvm/Support/ManagedStatic.h"
26 class llvm::PMDataManager;
28 //===----------------------------------------------------------------------===//
30 // The Pass Manager Infrastructure manages passes. It's responsibilities are:
32 // o Manage optimization pass execution order
33 // o Make required Analysis information available before pass P is run
34 // o Release memory occupied by dead passes
35 // o If Analysis information is dirtied by a pass then regenerate Analysis
36 // information before it is consumed by another pass.
38 // Pass Manager Infrastructure uses multiple pass managers. They are
39 // PassManager, FunctionPassManager, MPPassManager, FPPassManager, BBPassManager.
40 // This class hierarcy uses multiple inheritance but pass managers do not derive
41 // from another pass manager.
43 // PassManager and FunctionPassManager are two top-level pass manager that
44 // represents the external interface of this entire pass manager infrastucture.
46 // Important classes :
48 // [o] class PMTopLevelManager;
50 // Two top level managers, PassManager and FunctionPassManager, derive from
51 // PMTopLevelManager. PMTopLevelManager manages information used by top level
52 // managers such as last user info.
54 // [o] class PMDataManager;
56 // PMDataManager manages information, e.g. list of available analysis info,
57 // used by a pass manager to manage execution order of passes. It also provides
58 // a place to implement common pass manager APIs. All pass managers derive from
61 // [o] class BBPassManager : public FunctionPass, public PMDataManager;
63 // BBPassManager manages BasicBlockPasses.
65 // [o] class FunctionPassManager;
67 // This is a external interface used by JIT to manage FunctionPasses. This
68 // interface relies on FunctionPassManagerImpl to do all the tasks.
70 // [o] class FunctionPassManagerImpl : public ModulePass, PMDataManager,
71 // public PMTopLevelManager;
73 // FunctionPassManagerImpl is a top level manager. It manages FPPassManagers
75 // [o] class FPPassManager : public ModulePass, public PMDataManager;
77 // FPPassManager manages FunctionPasses and BBPassManagers
79 // [o] class MPPassManager : public Pass, public PMDataManager;
81 // MPPassManager manages ModulePasses and FPPassManagers
83 // [o] class PassManager;
85 // This is a external interface used by various tools to manages passes. It
86 // relies on PassManagerImpl to do all the tasks.
88 // [o] class PassManagerImpl : public Pass, public PMDataManager,
89 // public PMDTopLevelManager
91 // PassManagerImpl is a top level pass manager responsible for managing
93 //===----------------------------------------------------------------------===//
97 //===----------------------------------------------------------------------===//
98 // Pass debugging information. Often it is useful to find out what pass is
99 // running when a crash occurs in a utility. When this library is compiled with
100 // debugging on, a command line option (--debug-pass) is enabled that causes the
101 // pass name to be printed before it executes.
104 // Different debug levels that can be enabled...
105 enum PassDebugLevel {
106 None, Arguments, Structure, Executions, Details
109 static cl::opt<enum PassDebugLevel>
110 PassDebugging_New("debug-pass", cl::Hidden,
111 cl::desc("Print PassManager debugging information"),
113 clEnumVal(None , "disable debug output"),
114 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
115 clEnumVal(Structure , "print pass structure before run()"),
116 clEnumVal(Executions, "print pass name before it is executed"),
117 clEnumVal(Details , "print pass details when it is executed"),
119 } // End of llvm namespace
121 #ifndef USE_OLD_PASSMANAGER
124 //===----------------------------------------------------------------------===//
127 /// PMTopLevelManager manages LastUser info and collects common APIs used by
128 /// top level pass managers.
129 class VISIBILITY_HIDDEN PMTopLevelManager {
132 virtual unsigned getNumContainedManagers() {
133 return PassManagers.size();
136 /// Schedule pass P for execution. Make sure that passes required by
137 /// P are run before P is run. Update analysis info maintained by
138 /// the manager. Remove dead passes. This is a recursive function.
139 void schedulePass(Pass *P);
141 /// This is implemented by top level pass manager and used by
142 /// schedulePass() to add analysis info passes that are not available.
143 virtual void addTopLevelPass(Pass *P) = 0;
145 /// Set pass P as the last user of the given analysis passes.
146 void setLastUser(std::vector<Pass *> &AnalysisPasses, Pass *P);
148 /// Collect passes whose last user is P
149 void collectLastUses(std::vector<Pass *> &LastUses, Pass *P);
151 /// Find the pass that implements Analysis AID. Search immutable
152 /// passes and all pass managers. If desired pass is not found
153 /// then return NULL.
154 Pass *findAnalysisPass(AnalysisID AID);
156 virtual ~PMTopLevelManager() {
157 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
158 E = PassManagers.end(); I != E; ++I)
161 for (std::vector<ImmutablePass *>::iterator
162 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
165 PassManagers.clear();
168 /// Add immutable pass and initialize it.
169 inline void addImmutablePass(ImmutablePass *P) {
171 ImmutablePasses.push_back(P);
174 inline std::vector<ImmutablePass *>& getImmutablePasses() {
175 return ImmutablePasses;
178 void addPassManager(Pass *Manager) {
179 PassManagers.push_back(Manager);
182 // Add Manager into the list of managers that are not directly
183 // maintained by this top level pass manager
184 inline void addIndirectPassManager(PMDataManager *Manager) {
185 IndirectPassManagers.push_back(Manager);
188 // Print passes managed by this top level manager.
189 void dumpPasses() const;
190 void dumpArguments() const;
192 void initializeAllAnalysisInfo();
196 /// Collection of pass managers
197 std::vector<Pass *> PassManagers;
201 /// Collection of pass managers that are not directly maintained
202 /// by this pass manager
203 std::vector<PMDataManager *> IndirectPassManagers;
205 // Map to keep track of last user of the analysis pass.
206 // LastUser->second is the last user of Lastuser->first.
207 std::map<Pass *, Pass *> LastUser;
209 /// Immutable passes are managed by top level manager.
210 std::vector<ImmutablePass *> ImmutablePasses;
213 } // End of anon namespace
215 //===----------------------------------------------------------------------===//
219 /// PMDataManager provides the common place to manage the analysis data
220 /// used by pass managers.
221 class PMDataManager {
223 PMDataManager(int Depth) : TPM(NULL), Depth(Depth) {
224 initializeAnalysisInfo();
227 virtual ~PMDataManager() {
229 for (std::vector<Pass *>::iterator I = PassVector.begin(),
230 E = PassVector.end(); I != E; ++I)
236 /// Return true IFF pass P's required analysis set does not required new
238 bool manageablePass(Pass *P);
240 /// Augment AvailableAnalysis by adding analysis made available by pass P.
241 void recordAvailableAnalysis(Pass *P);
243 /// Remove Analysis that is not preserved by the pass
244 void removeNotPreservedAnalysis(Pass *P);
246 /// Remove dead passes
247 void removeDeadPasses(Pass *P, std::string &Msg);
249 /// Add pass P into the PassVector. Update
250 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
251 void addPassToManager(Pass *P, bool ProcessAnalysis = true);
253 /// Initialize available analysis information.
254 void initializeAnalysisInfo() {
255 TransferLastUses.clear();
256 AvailableAnalysis.clear();
259 /// Populate RequiredPasses with the analysis pass that are required by
261 void collectRequiredAnalysisPasses(std::vector<Pass *> &RequiredPasses,
264 /// All Required analyses should be available to the pass as it runs! Here
265 /// we fill in the AnalysisImpls member of the pass so that it can
266 /// successfully use the getAnalysis() method to retrieve the
267 /// implementations it needs.
268 void initializeAnalysisImpl(Pass *P);
270 /// Find the pass that implements Analysis AID. If desired pass is not found
271 /// then return NULL.
272 Pass *findAnalysisPass(AnalysisID AID, bool Direction);
274 // Access toplevel manager
275 PMTopLevelManager *getTopLevelManager() { return TPM; }
276 void setTopLevelManager(PMTopLevelManager *T) { TPM = T; }
278 unsigned getDepth() const { return Depth; }
280 // Print routines used by debug-pass
281 void dumpLastUses(Pass *P, unsigned Offset) const;
282 void dumpPassArguments() const;
283 void dumpPassInfo(Pass *P, std::string &Msg1, std::string &Msg2) const;
284 void dumpAnalysisSetInfo(const char *Msg, Pass *P,
285 const std::vector<AnalysisID> &Set) const;
287 std::vector<Pass *>& getTransferredLastUses() {
288 return TransferLastUses;
291 virtual unsigned getNumContainedPasses() {
292 return PassVector.size();
297 // If a FunctionPass F is the last user of ModulePass info M
298 // then the F's manager, not F, records itself as a last user of M.
299 // Current pass manage is requesting parent manager to record parent
300 // manager as the last user of these TrransferLastUses passes.
301 std::vector<Pass *> TransferLastUses;
303 // Top level manager.
304 PMTopLevelManager *TPM;
306 // Collection of pass that are managed by this manager
307 std::vector<Pass *> PassVector;
310 // Set of available Analysis. This information is used while scheduling
311 // pass. If a pass requires an analysis which is not not available then
312 // equired analysis pass is scheduled to run before the pass itself is
314 std::map<AnalysisID, Pass*> AvailableAnalysis;
319 //===----------------------------------------------------------------------===//
322 /// BBPassManager manages BasicBlockPass. It batches all the
323 /// pass together and sequence them to process one basic block before
324 /// processing next basic block.
325 class VISIBILITY_HIDDEN BBPassManager : public PMDataManager,
326 public FunctionPass {
329 BBPassManager(int Depth) : PMDataManager(Depth) { }
331 /// Add a pass into a passmanager queue.
332 bool addPass(Pass *p);
334 /// Execute all of the passes scheduled for execution. Keep track of
335 /// whether any of the passes modifies the function, and if so, return true.
336 bool runOnFunction(Function &F);
338 /// Pass Manager itself does not invalidate any analysis info.
339 void getAnalysisUsage(AnalysisUsage &Info) const {
340 Info.setPreservesAll();
343 bool doInitialization(Module &M);
344 bool doInitialization(Function &F);
345 bool doFinalization(Module &M);
346 bool doFinalization(Function &F);
348 // Print passes managed by this manager
349 void dumpPassStructure(unsigned Offset) {
350 llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
351 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
352 BasicBlockPass *BP = getContainedPass(Index);
353 BP->dumpPassStructure(Offset + 1);
354 dumpLastUses(BP, Offset+1);
358 BasicBlockPass *getContainedPass(unsigned N) {
359 assert ( N < PassVector.size() && "Pass number out of range!");
360 BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
365 //===----------------------------------------------------------------------===//
368 /// FPPassManager manages BBPassManagers and FunctionPasses.
369 /// It batches all function passes and basic block pass managers together and
370 /// sequence them to process one function at a time before processing next
373 class FPPassManager : public ModulePass, public PMDataManager {
376 FPPassManager(int Depth) : PMDataManager(Depth) {
377 activeBBPassManager = NULL;
380 /// Add a pass into a passmanager queue.
381 bool addPass(Pass *p);
383 /// run - Execute all of the passes scheduled for execution. Keep track of
384 /// whether any of the passes modifies the module, and if so, return true.
385 bool runOnFunction(Function &F);
386 bool runOnModule(Module &M);
388 /// doInitialization - Run all of the initializers for the function passes.
390 bool doInitialization(Module &M);
392 /// doFinalization - Run all of the initializers for the function passes.
394 bool doFinalization(Module &M);
396 /// Pass Manager itself does not invalidate any analysis info.
397 void getAnalysisUsage(AnalysisUsage &Info) const {
398 Info.setPreservesAll();
401 // Print passes managed by this manager
402 void dumpPassStructure(unsigned Offset) {
403 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
404 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
405 FunctionPass *FP = getContainedPass(Index);
406 FP->dumpPassStructure(Offset + 1);
407 dumpLastUses(FP, Offset+1);
411 FunctionPass *getContainedPass(unsigned N) {
412 assert ( N < PassVector.size() && "Pass number out of range!");
413 FunctionPass *FP = static_cast<FunctionPass *>(PassVector[N]);
418 // Active Pass Manager
419 BBPassManager *activeBBPassManager;
422 //===----------------------------------------------------------------------===//
423 // FunctionPassManagerImpl
425 /// FunctionPassManagerImpl manages FPPassManagers
426 class FunctionPassManagerImpl : public Pass,
427 public PMDataManager,
428 public PMTopLevelManager {
432 FunctionPassManagerImpl(int Depth) : PMDataManager(Depth) {
433 activeManager = NULL;
436 /// add - Add a pass to the queue of passes to run. This passes ownership of
437 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
438 /// will be destroyed as well, so there is no need to delete the pass. This
439 /// implies that all passes MUST be allocated with 'new'.
444 /// run - Execute all of the passes scheduled for execution. Keep track of
445 /// whether any of the passes modifies the module, and if so, return true.
446 bool run(Function &F);
448 /// doInitialization - Run all of the initializers for the function passes.
450 bool doInitialization(Module &M);
452 /// doFinalization - Run all of the initializers for the function passes.
454 bool doFinalization(Module &M);
456 /// Pass Manager itself does not invalidate any analysis info.
457 void getAnalysisUsage(AnalysisUsage &Info) const {
458 Info.setPreservesAll();
461 inline void addTopLevelPass(Pass *P) {
463 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
465 // P is a immutable pass and it will be managed by this
466 // top level manager. Set up analysis resolver to connect them.
467 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
469 initializeAnalysisImpl(P);
470 addImmutablePass(IP);
471 recordAvailableAnalysis(IP);
477 FPPassManager *getContainedManager(unsigned N) {
478 assert ( N < PassManagers.size() && "Pass number out of range!");
479 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
483 /// Add a pass into a passmanager queue.
484 bool addPass(Pass *p);
488 // Active Pass Manager
489 FPPassManager *activeManager;
492 //===----------------------------------------------------------------------===//
495 /// MPPassManager manages ModulePasses and function pass managers.
496 /// It batches all Module passes passes and function pass managers together and
497 /// sequence them to process one module.
498 class MPPassManager : public Pass, public PMDataManager {
501 MPPassManager(int Depth) : PMDataManager(Depth) {
502 activeFunctionPassManager = NULL;
505 /// Add a pass into a passmanager queue.
506 bool addPass(Pass *p);
508 /// run - Execute all of the passes scheduled for execution. Keep track of
509 /// whether any of the passes modifies the module, and if so, return true.
510 bool runOnModule(Module &M);
512 /// Pass Manager itself does not invalidate any analysis info.
513 void getAnalysisUsage(AnalysisUsage &Info) const {
514 Info.setPreservesAll();
517 // Print passes managed by this manager
518 void dumpPassStructure(unsigned Offset) {
519 llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n";
520 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
521 ModulePass *MP = getContainedPass(Index);
522 MP->dumpPassStructure(Offset + 1);
523 dumpLastUses(MP, Offset+1);
527 ModulePass *getContainedPass(unsigned N) {
528 assert ( N < PassVector.size() && "Pass number out of range!");
529 ModulePass *MP = static_cast<ModulePass *>(PassVector[N]);
534 // Active Pass Manager
535 FPPassManager *activeFunctionPassManager;
538 //===----------------------------------------------------------------------===//
541 /// PassManagerImpl manages MPPassManagers
542 class PassManagerImpl : public Pass,
543 public PMDataManager,
544 public PMTopLevelManager {
548 PassManagerImpl(int Depth) : PMDataManager(Depth) {
549 activeManager = NULL;
552 /// add - Add a pass to the queue of passes to run. This passes ownership of
553 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
554 /// will be destroyed as well, so there is no need to delete the pass. This
555 /// implies that all passes MUST be allocated with 'new'.
560 /// run - Execute all of the passes scheduled for execution. Keep track of
561 /// whether any of the passes modifies the module, and if so, return true.
564 /// Pass Manager itself does not invalidate any analysis info.
565 void getAnalysisUsage(AnalysisUsage &Info) const {
566 Info.setPreservesAll();
569 inline void addTopLevelPass(Pass *P) {
571 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
573 // P is a immutable pass and it will be managed by this
574 // top level manager. Set up analysis resolver to connect them.
575 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
577 initializeAnalysisImpl(P);
578 addImmutablePass(IP);
579 recordAvailableAnalysis(IP);
585 MPPassManager *getContainedManager(unsigned N) {
586 assert ( N < PassManagers.size() && "Pass number out of range!");
587 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
593 /// Add a pass into a passmanager queue.
594 bool addPass(Pass *p);
596 // Active Pass Manager
597 MPPassManager *activeManager;
600 } // End of llvm namespace
604 //===----------------------------------------------------------------------===//
605 // TimingInfo Class - This class is used to calculate information about the
606 // amount of time each pass takes to execute. This only happens when
607 // -time-passes is enabled on the command line.
610 class VISIBILITY_HIDDEN TimingInfo {
611 std::map<Pass*, Timer> TimingData;
615 // Use 'create' member to get this.
616 TimingInfo() : TG("... Pass execution timing report ...") {}
618 // TimingDtor - Print out information about timing information
620 // Delete all of the timers...
622 // TimerGroup is deleted next, printing the report.
625 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
626 // to a non null value (if the -time-passes option is enabled) or it leaves it
627 // null. It may be called multiple times.
628 static void createTheTimeInfo();
630 void passStarted(Pass *P) {
632 if (dynamic_cast<PMDataManager *>(P))
635 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
636 if (I == TimingData.end())
637 I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
638 I->second.startTimer();
640 void passEnded(Pass *P) {
642 if (dynamic_cast<PMDataManager *>(P))
645 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
646 assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
647 I->second.stopTimer();
651 static TimingInfo *TheTimeInfo;
653 } // End of anon namespace
655 //===----------------------------------------------------------------------===//
656 // PMTopLevelManager implementation
658 /// Set pass P as the last user of the given analysis passes.
659 void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses,
662 for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(),
663 E = AnalysisPasses.end(); I != E; ++I) {
666 // If AP is the last user of other passes then make P last user of
668 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
669 LUE = LastUser.end(); LUI != LUE; ++LUI) {
670 if (LUI->second == AP)
671 LastUser[LUI->first] = P;
676 /// Collect passes whose last user is P
677 void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
679 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
680 LUE = LastUser.end(); LUI != LUE; ++LUI)
681 if (LUI->second == P)
682 LastUses.push_back(LUI->first);
685 /// Schedule pass P for execution. Make sure that passes required by
686 /// P are run before P is run. Update analysis info maintained by
687 /// the manager. Remove dead passes. This is a recursive function.
688 void PMTopLevelManager::schedulePass(Pass *P) {
690 // TODO : Allocate function manager for this pass, other wise required set
691 // may be inserted into previous function manager
693 AnalysisUsage AnUsage;
694 P->getAnalysisUsage(AnUsage);
695 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
696 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
697 E = RequiredSet.end(); I != E; ++I) {
699 Pass *AnalysisPass = findAnalysisPass(*I);
701 // Schedule this analysis run first.
702 AnalysisPass = (*I)->createPass();
703 schedulePass(AnalysisPass);
707 // Now all required passes are available.
711 /// Find the pass that implements Analysis AID. Search immutable
712 /// passes and all pass managers. If desired pass is not found
713 /// then return NULL.
714 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
717 // Check pass managers
718 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
719 E = PassManagers.end(); P == NULL && I != E; ++I) {
720 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
721 assert(PMD && "This is not a PassManager");
722 P = PMD->findAnalysisPass(AID, false);
725 // Check other pass managers
726 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
727 E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
728 P = (*I)->findAnalysisPass(AID, false);
730 for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
731 E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
732 const PassInfo *PI = (*I)->getPassInfo();
736 // If Pass not found then check the interfaces implemented by Immutable Pass
738 const std::vector<const PassInfo*> &ImmPI = PI->getInterfacesImplemented();
739 if (std::find(ImmPI.begin(), ImmPI.end(), AID) != ImmPI.end())
747 // Print passes managed by this top level manager.
748 void PMTopLevelManager::dumpPasses() const {
750 if (PassDebugging_New < Structure)
753 // Print out the immutable passes
754 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
755 ImmutablePasses[i]->dumpPassStructure(0);
758 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
759 E = PassManagers.end(); I != E; ++I)
760 (*I)->dumpPassStructure(1);
763 void PMTopLevelManager::dumpArguments() const {
765 if (PassDebugging_New < Arguments)
768 cerr << "Pass Arguments: ";
769 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
770 E = PassManagers.end(); I != E; ++I) {
771 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
772 assert(PMD && "This is not a PassManager");
773 PMD->dumpPassArguments();
778 void PMTopLevelManager::initializeAllAnalysisInfo() {
780 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
781 E = PassManagers.end(); I != E; ++I) {
782 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
783 assert(PMD && "This is not a PassManager");
784 PMD->initializeAnalysisInfo();
787 // Initailize other pass managers
788 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
789 E = IndirectPassManagers.end(); I != E; ++I)
790 (*I)->initializeAnalysisInfo();
793 //===----------------------------------------------------------------------===//
794 // PMDataManager implementation
796 /// Return true IFF pass P's required analysis set does not required new
798 bool PMDataManager::manageablePass(Pass *P) {
801 // If this pass is not preserving information that is required by a
802 // pass maintained by higher level pass manager then do not insert
803 // this pass into current manager. Use new manager. For example,
804 // For example, If FunctionPass F is not preserving ModulePass Info M1
805 // that is used by another ModulePass M2 then do not insert F in
806 // current function pass manager.
810 /// Augement AvailableAnalysis by adding analysis made available by pass P.
811 void PMDataManager::recordAvailableAnalysis(Pass *P) {
813 if (const PassInfo *PI = P->getPassInfo()) {
814 AvailableAnalysis[PI] = P;
816 //This pass is the current implementation of all of the interfaces it
817 //implements as well.
818 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
819 for (unsigned i = 0, e = II.size(); i != e; ++i)
820 AvailableAnalysis[II[i]] = P;
824 /// Remove Analyss not preserved by Pass P
825 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
826 AnalysisUsage AnUsage;
827 P->getAnalysisUsage(AnUsage);
829 if (AnUsage.getPreservesAll())
832 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
833 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
834 E = AvailableAnalysis.end(); I != E; ) {
835 std::map<AnalysisID, Pass*>::iterator Info = I++;
836 if (std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
837 PreservedSet.end()) {
838 // Remove this analysis
839 if (!dynamic_cast<ImmutablePass*>(Info->second))
840 AvailableAnalysis.erase(Info);
845 /// Remove analysis passes that are not used any longer
846 void PMDataManager::removeDeadPasses(Pass *P, std::string &Msg) {
848 std::vector<Pass *> DeadPasses;
849 TPM->collectLastUses(DeadPasses, P);
851 for (std::vector<Pass *>::iterator I = DeadPasses.begin(),
852 E = DeadPasses.end(); I != E; ++I) {
854 std::string Msg1 = " Freeing Pass '";
855 dumpPassInfo(*I, Msg1, Msg);
857 if (TheTimeInfo) TheTimeInfo->passStarted(P);
858 (*I)->releaseMemory();
859 if (TheTimeInfo) TheTimeInfo->passEnded(P);
861 std::map<AnalysisID, Pass*>::iterator Pos =
862 AvailableAnalysis.find((*I)->getPassInfo());
864 // It is possible that pass is already removed from the AvailableAnalysis
865 if (Pos != AvailableAnalysis.end())
866 AvailableAnalysis.erase(Pos);
870 /// Add pass P into the PassVector. Update
871 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
872 void PMDataManager::addPassToManager(Pass *P,
873 bool ProcessAnalysis) {
875 // This manager is going to manage pass P. Set up analysis resolver
877 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
880 if (ProcessAnalysis) {
882 // At the moment, this pass is the last user of all required passes.
883 std::vector<Pass *> LastUses;
884 std::vector<Pass *> RequiredPasses;
885 unsigned PDepth = this->getDepth();
887 collectRequiredAnalysisPasses(RequiredPasses, P);
888 for (std::vector<Pass *>::iterator I = RequiredPasses.begin(),
889 E = RequiredPasses.end(); I != E; ++I) {
890 Pass *PRequired = *I;
893 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
894 RDepth = DM.getDepth();
896 if (PDepth == RDepth)
897 LastUses.push_back(PRequired);
898 else if (PDepth > RDepth) {
899 // Let the parent claim responsibility of last use
900 TransferLastUses.push_back(PRequired);
902 // Note : This feature is not yet implemented
904 "Unable to handle Pass that requires lower level Analysis pass");
908 LastUses.push_back(P);
909 TPM->setLastUser(LastUses, P);
911 // Take a note of analysis required and made available by this pass.
912 // Remove the analysis not preserved by this pass
913 removeNotPreservedAnalysis(P);
914 recordAvailableAnalysis(P);
918 PassVector.push_back(P);
921 /// Populate RequiredPasses with the analysis pass that are required by
923 void PMDataManager::collectRequiredAnalysisPasses(std::vector<Pass *> &RP,
925 AnalysisUsage AnUsage;
926 P->getAnalysisUsage(AnUsage);
927 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
928 for (std::vector<AnalysisID>::const_iterator
929 I = RequiredSet.begin(), E = RequiredSet.end();
931 Pass *AnalysisPass = findAnalysisPass(*I, true);
932 assert (AnalysisPass && "Analysis pass is not available");
933 RP.push_back(AnalysisPass);
936 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
937 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
938 E = IDs.end(); I != E; ++I) {
939 Pass *AnalysisPass = findAnalysisPass(*I, true);
940 assert (AnalysisPass && "Analysis pass is not available");
941 RP.push_back(AnalysisPass);
945 // All Required analyses should be available to the pass as it runs! Here
946 // we fill in the AnalysisImpls member of the pass so that it can
947 // successfully use the getAnalysis() method to retrieve the
948 // implementations it needs.
950 void PMDataManager::initializeAnalysisImpl(Pass *P) {
951 AnalysisUsage AnUsage;
952 P->getAnalysisUsage(AnUsage);
954 for (std::vector<const PassInfo *>::const_iterator
955 I = AnUsage.getRequiredSet().begin(),
956 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
957 Pass *Impl = findAnalysisPass(*I, true);
959 assert(0 && "Analysis used but not available!");
960 AnalysisResolver_New *AR = P->getResolver();
961 AR->addAnalysisImplsPair(*I, Impl);
965 /// Find the pass that implements Analysis AID. If desired pass is not found
966 /// then return NULL.
967 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
969 // Check if AvailableAnalysis map has one entry.
970 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
972 if (I != AvailableAnalysis.end())
975 // Search Parents through TopLevelManager
977 return TPM->findAnalysisPass(AID);
982 // Print list of passes that are last used by P.
983 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
985 std::vector<Pass *> LUses;
987 assert (TPM && "Top Level Manager is missing");
988 TPM->collectLastUses(LUses, P);
990 for (std::vector<Pass *>::iterator I = LUses.begin(),
991 E = LUses.end(); I != E; ++I) {
992 llvm::cerr << "--" << std::string(Offset*2, ' ');
993 (*I)->dumpPassStructure(0);
997 void PMDataManager::dumpPassArguments() const {
998 for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
999 E = PassVector.end(); I != E; ++I) {
1000 if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
1001 PMD->dumpPassArguments();
1003 if (const PassInfo *PI = (*I)->getPassInfo())
1004 if (!PI->isAnalysisGroup())
1005 cerr << " -" << PI->getPassArgument();
1009 void PMDataManager:: dumpPassInfo(Pass *P, std::string &Msg1,
1010 std::string &Msg2) const {
1011 if (PassDebugging_New < Executions)
1013 cerr << (void*)this << std::string(getDepth()*2+1, ' ');
1015 cerr << P->getPassName();
1019 void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
1020 const std::vector<AnalysisID> &Set)
1022 if (PassDebugging_New >= Details && !Set.empty()) {
1023 cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
1024 for (unsigned i = 0; i != Set.size(); ++i) {
1026 cerr << " " << Set[i]->getPassName();
1032 //===----------------------------------------------------------------------===//
1033 // NOTE: Is this the right place to define this method ?
1034 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
1035 Pass *AnalysisResolver_New::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
1036 return PM.findAnalysisPass(ID, dir);
1039 //===----------------------------------------------------------------------===//
1040 // BBPassManager implementation
1042 /// Add pass P into PassVector and return true. If this pass is not
1043 /// manageable by this manager then return false.
1045 BBPassManager::addPass(Pass *P) {
1047 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
1051 // If this pass does not preserve analysis that is used by other passes
1052 // managed by this manager than it is not a suitable pass for this manager.
1053 if (!manageablePass(P))
1056 addPassToManager(BP);
1061 /// Execute all of the passes scheduled for execution by invoking
1062 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
1063 /// the function, and if so, return true.
1065 BBPassManager::runOnFunction(Function &F) {
1070 bool Changed = doInitialization(F);
1072 std::string Msg1 = "Executing Pass '";
1073 std::string Msg3 = "' Made Modification '";
1075 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
1076 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1077 BasicBlockPass *BP = getContainedPass(Index);
1078 AnalysisUsage AnUsage;
1079 BP->getAnalysisUsage(AnUsage);
1081 std::string Msg2 = "' on BasicBlock '" + (*I).getName() + "'...\n";
1082 dumpPassInfo(BP, Msg1, Msg2);
1083 dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet());
1085 initializeAnalysisImpl(BP);
1087 if (TheTimeInfo) TheTimeInfo->passStarted(BP);
1088 Changed |= BP->runOnBasicBlock(*I);
1089 if (TheTimeInfo) TheTimeInfo->passEnded(BP);
1092 dumpPassInfo(BP, Msg3, Msg2);
1093 dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet());
1095 removeNotPreservedAnalysis(BP);
1096 recordAvailableAnalysis(BP);
1097 removeDeadPasses(BP, Msg2);
1099 return Changed |= doFinalization(F);
1102 // Implement doInitialization and doFinalization
1103 inline bool BBPassManager::doInitialization(Module &M) {
1104 bool Changed = false;
1106 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1107 BasicBlockPass *BP = getContainedPass(Index);
1108 Changed |= BP->doInitialization(M);
1114 inline bool BBPassManager::doFinalization(Module &M) {
1115 bool Changed = false;
1117 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1118 BasicBlockPass *BP = getContainedPass(Index);
1119 Changed |= BP->doFinalization(M);
1125 inline bool BBPassManager::doInitialization(Function &F) {
1126 bool Changed = false;
1128 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1129 BasicBlockPass *BP = getContainedPass(Index);
1130 Changed |= BP->doInitialization(F);
1136 inline bool BBPassManager::doFinalization(Function &F) {
1137 bool Changed = false;
1139 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1140 BasicBlockPass *BP = getContainedPass(Index);
1141 Changed |= BP->doFinalization(F);
1148 //===----------------------------------------------------------------------===//
1149 // FunctionPassManager implementation
1151 /// Create new Function pass manager
1152 FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
1153 FPM = new FunctionPassManagerImpl(0);
1154 // FPM is the top level manager.
1155 FPM->setTopLevelManager(FPM);
1157 PMDataManager *PMD = dynamic_cast<PMDataManager *>(FPM);
1158 AnalysisResolver_New *AR = new AnalysisResolver_New(*PMD);
1159 FPM->setResolver(AR);
1164 FunctionPassManager::~FunctionPassManager() {
1168 /// add - Add a pass to the queue of passes to run. This passes
1169 /// ownership of the Pass to the PassManager. When the
1170 /// PassManager_X is destroyed, the pass will be destroyed as well, so
1171 /// there is no need to delete the pass. (TODO delete passes.)
1172 /// This implies that all passes MUST be allocated with 'new'.
1173 void FunctionPassManager::add(Pass *P) {
1177 /// run - Execute all of the passes scheduled for execution. Keep
1178 /// track of whether any of the passes modifies the function, and if
1179 /// so, return true.
1181 bool FunctionPassManager::run(Function &F) {
1183 if (MP->materializeFunction(&F, &errstr)) {
1184 cerr << "Error reading bytecode file: " << errstr << "\n";
1191 /// doInitialization - Run all of the initializers for the function passes.
1193 bool FunctionPassManager::doInitialization() {
1194 return FPM->doInitialization(*MP->getModule());
1197 /// doFinalization - Run all of the initializers for the function passes.
1199 bool FunctionPassManager::doFinalization() {
1200 return FPM->doFinalization(*MP->getModule());
1203 //===----------------------------------------------------------------------===//
1204 // FunctionPassManagerImpl implementation
1206 /// Add P into active pass manager or use new module pass manager to
1208 bool FunctionPassManagerImpl::addPass(Pass *P) {
1210 if (!activeManager || !activeManager->addPass(P)) {
1211 activeManager = new FPPassManager(getDepth() + 1);
1212 // Inherit top level manager
1213 activeManager->setTopLevelManager(this->getTopLevelManager());
1215 // This top level manager is going to manage activeManager.
1216 // Set up analysis resolver to connect them.
1217 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
1218 activeManager->setResolver(AR);
1220 addPassManager(activeManager);
1221 return activeManager->addPass(P);
1226 inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
1227 bool Changed = false;
1229 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1230 FPPassManager *FP = getContainedManager(Index);
1231 Changed |= FP->doInitialization(M);
1237 inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
1238 bool Changed = false;
1240 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1241 FPPassManager *FP = getContainedManager(Index);
1242 Changed |= FP->doFinalization(M);
1248 // Execute all the passes managed by this top level manager.
1249 // Return true if any function is modified by a pass.
1250 bool FunctionPassManagerImpl::run(Function &F) {
1252 bool Changed = false;
1254 TimingInfo::createTheTimeInfo();
1259 initializeAllAnalysisInfo();
1260 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1261 FPPassManager *FP = getContainedManager(Index);
1262 Changed |= FP->runOnFunction(F);
1267 //===----------------------------------------------------------------------===//
1268 // FPPassManager implementation
1270 /// Add pass P into the pass manager queue. If P is a BasicBlockPass then
1271 /// either use it into active basic block pass manager or create new basic
1272 /// block pass manager to handle pass P.
1274 FPPassManager::addPass(Pass *P) {
1276 // If P is a BasicBlockPass then use BBPassManager.
1277 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
1279 if (!activeBBPassManager || !activeBBPassManager->addPass(BP)) {
1281 // If active manager exists then clear its analysis info.
1282 if (activeBBPassManager)
1283 activeBBPassManager->initializeAnalysisInfo();
1285 // Create and add new manager
1286 activeBBPassManager = new BBPassManager(getDepth() + 1);
1287 // Inherit top level manager
1288 activeBBPassManager->setTopLevelManager(this->getTopLevelManager());
1290 // Add new manager into current manager's list.
1291 addPassToManager(activeBBPassManager, false);
1293 // Add new manager into top level manager's indirect passes list
1294 PMDataManager *PMD = dynamic_cast<PMDataManager *>(activeBBPassManager);
1295 assert (PMD && "Manager is not Pass Manager");
1296 TPM->addIndirectPassManager(PMD);
1298 // Add pass into new manager. This time it must succeed.
1299 if (!activeBBPassManager->addPass(BP))
1300 assert(0 && "Unable to add Pass");
1302 // If activeBBPassManager transfered any Last Uses then handle them here.
1303 std::vector<Pass *> &TLU = activeBBPassManager->getTransferredLastUses();
1305 TPM->setLastUser(TLU, this);
1312 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
1316 // If this pass does not preserve analysis that is used by other passes
1317 // managed by this manager than it is not a suitable pass for this manager.
1318 if (!manageablePass(P))
1321 addPassToManager (FP);
1323 // If active manager exists then clear its analysis info.
1324 if (activeBBPassManager) {
1325 activeBBPassManager->initializeAnalysisInfo();
1326 activeBBPassManager = NULL;
1332 /// Execute all of the passes scheduled for execution by invoking
1333 /// runOnFunction method. Keep track of whether any of the passes modifies
1334 /// the function, and if so, return true.
1335 bool FPPassManager::runOnFunction(Function &F) {
1337 bool Changed = false;
1342 std::string Msg1 = "Executing Pass '";
1343 std::string Msg3 = "' Made Modification '";
1345 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1346 FunctionPass *FP = getContainedPass(Index);
1348 AnalysisUsage AnUsage;
1349 FP->getAnalysisUsage(AnUsage);
1351 std::string Msg2 = "' on Function '" + F.getName() + "'...\n";
1352 dumpPassInfo(FP, Msg1, Msg2);
1353 dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet());
1355 initializeAnalysisImpl(FP);
1357 if (TheTimeInfo) TheTimeInfo->passStarted(FP);
1358 Changed |= FP->runOnFunction(F);
1359 if (TheTimeInfo) TheTimeInfo->passEnded(FP);
1362 dumpPassInfo(FP, Msg3, Msg2);
1363 dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
1365 removeNotPreservedAnalysis(FP);
1366 recordAvailableAnalysis(FP);
1367 removeDeadPasses(FP, Msg2);
1372 bool FPPassManager::runOnModule(Module &M) {
1374 bool Changed = doInitialization(M);
1376 for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1377 this->runOnFunction(*I);
1379 return Changed |= doFinalization(M);
1382 inline bool FPPassManager::doInitialization(Module &M) {
1383 bool Changed = false;
1385 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1386 FunctionPass *FP = getContainedPass(Index);
1387 Changed |= FP->doInitialization(M);
1393 inline bool FPPassManager::doFinalization(Module &M) {
1394 bool Changed = false;
1396 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1397 FunctionPass *FP = getContainedPass(Index);
1398 Changed |= FP->doFinalization(M);
1404 //===----------------------------------------------------------------------===//
1405 // MPPassManager implementation
1407 /// Add P into pass vector if it is manageble. If P is a FunctionPass
1408 /// then use FPPassManager to manage it. Return false if P
1409 /// is not manageable by this manager.
1411 MPPassManager::addPass(Pass *P) {
1413 // If P is FunctionPass then use function pass maanager.
1414 if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
1416 if (!activeFunctionPassManager || !activeFunctionPassManager->addPass(P)) {
1418 // If active manager exists then clear its analysis info.
1419 if (activeFunctionPassManager)
1420 activeFunctionPassManager->initializeAnalysisInfo();
1422 // Create and add new manager
1423 activeFunctionPassManager =
1424 new FPPassManager(getDepth() + 1);
1426 // Add new manager into current manager's list
1427 addPassToManager(activeFunctionPassManager, false);
1429 // Inherit top level manager
1430 activeFunctionPassManager->setTopLevelManager(this->getTopLevelManager());
1432 // Add new manager into top level manager's indirect passes list
1433 PMDataManager *PMD =
1434 dynamic_cast<PMDataManager *>(activeFunctionPassManager);
1435 assert(PMD && "Manager is not Pass Manager");
1436 TPM->addIndirectPassManager(PMD);
1438 // Add pass into new manager. This time it must succeed.
1439 if (!activeFunctionPassManager->addPass(FP))
1440 assert(0 && "Unable to add pass");
1442 // If activeFunctionPassManager transfered any Last Uses then
1443 // handle them here.
1444 std::vector<Pass *> &TLU =
1445 activeFunctionPassManager->getTransferredLastUses();
1447 TPM->setLastUser(TLU, this);
1453 ModulePass *MP = dynamic_cast<ModulePass *>(P);
1457 // If this pass does not preserve analysis that is used by other passes
1458 // managed by this manager than it is not a suitable pass for this manager.
1459 if (!manageablePass(P))
1462 addPassToManager(MP);
1463 // If active manager exists then clear its analysis info.
1464 if (activeFunctionPassManager) {
1465 activeFunctionPassManager->initializeAnalysisInfo();
1466 activeFunctionPassManager = NULL;
1473 /// Execute all of the passes scheduled for execution by invoking
1474 /// runOnModule method. Keep track of whether any of the passes modifies
1475 /// the module, and if so, return true.
1477 MPPassManager::runOnModule(Module &M) {
1478 bool Changed = false;
1480 std::string Msg1 = "Executing Pass '";
1481 std::string Msg3 = "' Made Modification '";
1483 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1484 ModulePass *MP = getContainedPass(Index);
1486 AnalysisUsage AnUsage;
1487 MP->getAnalysisUsage(AnUsage);
1489 std::string Msg2 = "' on Module '" + M.getModuleIdentifier() + "'...\n";
1490 dumpPassInfo(MP, Msg1, Msg2);
1491 dumpAnalysisSetInfo("Required", MP, AnUsage.getRequiredSet());
1493 initializeAnalysisImpl(MP);
1495 if (TheTimeInfo) TheTimeInfo->passStarted(MP);
1496 Changed |= MP->runOnModule(M);
1497 if (TheTimeInfo) TheTimeInfo->passEnded(MP);
1500 dumpPassInfo(MP, Msg3, Msg2);
1501 dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
1503 removeNotPreservedAnalysis(MP);
1504 recordAvailableAnalysis(MP);
1505 removeDeadPasses(MP, Msg2);
1510 //===----------------------------------------------------------------------===//
1511 // PassManagerImpl implementation
1513 /// Add P into active pass manager or use new module pass manager to
1515 bool PassManagerImpl::addPass(Pass *P) {
1517 if (!activeManager || !activeManager->addPass(P)) {
1518 activeManager = new MPPassManager(getDepth() + 1);
1519 // Inherit top level manager
1520 activeManager->setTopLevelManager(this->getTopLevelManager());
1522 // This top level manager is going to manage activeManager.
1523 // Set up analysis resolver to connect them.
1524 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
1525 activeManager->setResolver(AR);
1527 addPassManager(activeManager);
1528 return activeManager->addPass(P);
1533 /// run - Execute all of the passes scheduled for execution. Keep track of
1534 /// whether any of the passes modifies the module, and if so, return true.
1535 bool PassManagerImpl::run(Module &M) {
1537 bool Changed = false;
1539 TimingInfo::createTheTimeInfo();
1544 initializeAllAnalysisInfo();
1545 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1546 MPPassManager *MP = getContainedManager(Index);
1547 Changed |= MP->runOnModule(M);
1552 //===----------------------------------------------------------------------===//
1553 // PassManager implementation
1555 /// Create new pass manager
1556 PassManager::PassManager() {
1557 PM = new PassManagerImpl(0);
1558 // PM is the top level manager
1559 PM->setTopLevelManager(PM);
1562 PassManager::~PassManager() {
1566 /// add - Add a pass to the queue of passes to run. This passes ownership of
1567 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
1568 /// will be destroyed as well, so there is no need to delete the pass. This
1569 /// implies that all passes MUST be allocated with 'new'.
1571 PassManager::add(Pass *P) {
1575 /// run - Execute all of the passes scheduled for execution. Keep track of
1576 /// whether any of the passes modifies the module, and if so, return true.
1578 PassManager::run(Module &M) {
1582 //===----------------------------------------------------------------------===//
1583 // TimingInfo Class - This class is used to calculate information about the
1584 // amount of time each pass takes to execute. This only happens with
1585 // -time-passes is enabled on the command line.
1587 bool llvm::TimePassesIsEnabled = false;
1588 static cl::opt<bool,true>
1589 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1590 cl::desc("Time each pass, printing elapsed time for each on exit"));
1592 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1593 // a non null value (if the -time-passes option is enabled) or it leaves it
1594 // null. It may be called multiple times.
1595 void TimingInfo::createTheTimeInfo() {
1596 if (!TimePassesIsEnabled || TheTimeInfo) return;
1598 // Constructed the first time this is called, iff -time-passes is enabled.
1599 // This guarantees that the object will be constructed before static globals,
1600 // thus it will be destroyed before them.
1601 static ManagedStatic<TimingInfo> TTI;
1602 TheTimeInfo = &*TTI;