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
123 //===----------------------------------------------------------------------===//
126 /// PMTopLevelManager manages LastUser info and collects common APIs used by
127 /// top level pass managers.
128 class VISIBILITY_HIDDEN PMTopLevelManager {
131 virtual unsigned getNumContainedManagers() {
132 return PassManagers.size();
135 /// Schedule pass P for execution. Make sure that passes required by
136 /// P are run before P is run. Update analysis info maintained by
137 /// the manager. Remove dead passes. This is a recursive function.
138 void schedulePass(Pass *P);
140 /// This is implemented by top level pass manager and used by
141 /// schedulePass() to add analysis info passes that are not available.
142 virtual void addTopLevelPass(Pass *P) = 0;
144 /// Set pass P as the last user of the given analysis passes.
145 void setLastUser(std::vector<Pass *> &AnalysisPasses, Pass *P);
147 /// Collect passes whose last user is P
148 void collectLastUses(std::vector<Pass *> &LastUses, Pass *P);
150 /// Find the pass that implements Analysis AID. Search immutable
151 /// passes and all pass managers. If desired pass is not found
152 /// then return NULL.
153 Pass *findAnalysisPass(AnalysisID AID);
155 virtual ~PMTopLevelManager() {
156 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
157 E = PassManagers.end(); I != E; ++I)
160 for (std::vector<ImmutablePass *>::iterator
161 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
164 PassManagers.clear();
167 /// Add immutable pass and initialize it.
168 inline void addImmutablePass(ImmutablePass *P) {
170 ImmutablePasses.push_back(P);
173 inline std::vector<ImmutablePass *>& getImmutablePasses() {
174 return ImmutablePasses;
177 void addPassManager(Pass *Manager) {
178 PassManagers.push_back(Manager);
181 // Add Manager into the list of managers that are not directly
182 // maintained by this top level pass manager
183 inline void addIndirectPassManager(PMDataManager *Manager) {
184 IndirectPassManagers.push_back(Manager);
187 // Print passes managed by this top level manager.
188 void dumpPasses() const;
189 void dumpArguments() const;
191 void initializeAllAnalysisInfo();
195 /// Collection of pass managers
196 std::vector<Pass *> PassManagers;
200 /// Collection of pass managers that are not directly maintained
201 /// by this pass manager
202 std::vector<PMDataManager *> IndirectPassManagers;
204 // Map to keep track of last user of the analysis pass.
205 // LastUser->second is the last user of Lastuser->first.
206 std::map<Pass *, Pass *> LastUser;
208 /// Immutable passes are managed by top level manager.
209 std::vector<ImmutablePass *> ImmutablePasses;
212 } // End of anon namespace
214 //===----------------------------------------------------------------------===//
218 /// PMDataManager provides the common place to manage the analysis data
219 /// used by pass managers.
220 class PMDataManager {
222 PMDataManager(int Depth) : TPM(NULL), Depth(Depth) {
223 initializeAnalysisInfo();
226 virtual ~PMDataManager() {
228 for (std::vector<Pass *>::iterator I = PassVector.begin(),
229 E = PassVector.end(); I != E; ++I)
235 /// Return true IFF pass P's required analysis set does not required new
237 bool manageablePass(Pass *P);
239 /// Augment AvailableAnalysis by adding analysis made available by pass P.
240 void recordAvailableAnalysis(Pass *P);
242 /// Remove Analysis that is not preserved by the pass
243 void removeNotPreservedAnalysis(Pass *P);
245 /// Remove dead passes
246 void removeDeadPasses(Pass *P, std::string &Msg);
248 /// Add pass P into the PassVector. Update
249 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
250 void addPassToManager(Pass *P, bool ProcessAnalysis = true);
252 /// Initialize available analysis information.
253 void initializeAnalysisInfo() {
254 TransferLastUses.clear();
255 AvailableAnalysis.clear();
258 /// Populate RequiredPasses with the analysis pass that are required by
260 void collectRequiredAnalysisPasses(std::vector<Pass *> &RequiredPasses,
263 /// All Required analyses should be available to the pass as it runs! Here
264 /// we fill in the AnalysisImpls member of the pass so that it can
265 /// successfully use the getAnalysis() method to retrieve the
266 /// implementations it needs.
267 void initializeAnalysisImpl(Pass *P);
269 /// Find the pass that implements Analysis AID. If desired pass is not found
270 /// then return NULL.
271 Pass *findAnalysisPass(AnalysisID AID, bool Direction);
273 // Access toplevel manager
274 PMTopLevelManager *getTopLevelManager() { return TPM; }
275 void setTopLevelManager(PMTopLevelManager *T) { TPM = T; }
277 unsigned getDepth() const { return Depth; }
279 // Print routines used by debug-pass
280 void dumpLastUses(Pass *P, unsigned Offset) const;
281 void dumpPassArguments() const;
282 void dumpPassInfo(Pass *P, std::string &Msg1, std::string &Msg2) const;
283 void dumpAnalysisSetInfo(const char *Msg, Pass *P,
284 const std::vector<AnalysisID> &Set) const;
286 std::vector<Pass *>& getTransferredLastUses() {
287 return TransferLastUses;
290 virtual unsigned getNumContainedPasses() {
291 return PassVector.size();
296 // If a FunctionPass F is the last user of ModulePass info M
297 // then the F's manager, not F, records itself as a last user of M.
298 // Current pass manage is requesting parent manager to record parent
299 // manager as the last user of these TrransferLastUses passes.
300 std::vector<Pass *> TransferLastUses;
302 // Top level manager.
303 PMTopLevelManager *TPM;
305 // Collection of pass that are managed by this manager
306 std::vector<Pass *> PassVector;
309 // Set of available Analysis. This information is used while scheduling
310 // pass. If a pass requires an analysis which is not not available then
311 // equired analysis pass is scheduled to run before the pass itself is
313 std::map<AnalysisID, Pass*> AvailableAnalysis;
318 //===----------------------------------------------------------------------===//
321 /// BBPassManager manages BasicBlockPass. It batches all the
322 /// pass together and sequence them to process one basic block before
323 /// processing next basic block.
324 class VISIBILITY_HIDDEN BBPassManager : public PMDataManager,
325 public FunctionPass {
328 BBPassManager(int Depth) : PMDataManager(Depth) { }
330 /// Add a pass into a passmanager queue.
331 bool addPass(Pass *p);
333 /// Execute all of the passes scheduled for execution. Keep track of
334 /// whether any of the passes modifies the function, and if so, return true.
335 bool runOnFunction(Function &F);
337 /// Pass Manager itself does not invalidate any analysis info.
338 void getAnalysisUsage(AnalysisUsage &Info) const {
339 Info.setPreservesAll();
342 bool doInitialization(Module &M);
343 bool doInitialization(Function &F);
344 bool doFinalization(Module &M);
345 bool doFinalization(Function &F);
347 // Print passes managed by this manager
348 void dumpPassStructure(unsigned Offset) {
349 llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
350 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
351 BasicBlockPass *BP = getContainedPass(Index);
352 BP->dumpPassStructure(Offset + 1);
353 dumpLastUses(BP, Offset+1);
357 BasicBlockPass *getContainedPass(unsigned N) {
358 assert ( N < PassVector.size() && "Pass number out of range!");
359 BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
364 //===----------------------------------------------------------------------===//
367 /// FPPassManager manages BBPassManagers and FunctionPasses.
368 /// It batches all function passes and basic block pass managers together and
369 /// sequence them to process one function at a time before processing next
372 class FPPassManager : public ModulePass, public PMDataManager {
375 FPPassManager(int Depth) : PMDataManager(Depth) {
376 activeBBPassManager = NULL;
379 /// Add a pass into a passmanager queue.
380 bool addPass(Pass *p);
382 /// run - Execute all of the passes scheduled for execution. Keep track of
383 /// whether any of the passes modifies the module, and if so, return true.
384 bool runOnFunction(Function &F);
385 bool runOnModule(Module &M);
387 /// doInitialization - Run all of the initializers for the function passes.
389 bool doInitialization(Module &M);
391 /// doFinalization - Run all of the initializers for the function passes.
393 bool doFinalization(Module &M);
395 /// Pass Manager itself does not invalidate any analysis info.
396 void getAnalysisUsage(AnalysisUsage &Info) const {
397 Info.setPreservesAll();
400 // Print passes managed by this manager
401 void dumpPassStructure(unsigned Offset) {
402 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
403 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
404 FunctionPass *FP = getContainedPass(Index);
405 FP->dumpPassStructure(Offset + 1);
406 dumpLastUses(FP, Offset+1);
410 FunctionPass *getContainedPass(unsigned N) {
411 assert ( N < PassVector.size() && "Pass number out of range!");
412 FunctionPass *FP = static_cast<FunctionPass *>(PassVector[N]);
417 // Active Pass Manager
418 BBPassManager *activeBBPassManager;
421 //===----------------------------------------------------------------------===//
422 // FunctionPassManagerImpl
424 /// FunctionPassManagerImpl manages FPPassManagers
425 class FunctionPassManagerImpl : public Pass,
426 public PMDataManager,
427 public PMTopLevelManager {
431 FunctionPassManagerImpl(int Depth) : PMDataManager(Depth) {
432 activeManager = NULL;
435 /// add - Add a pass to the queue of passes to run. This passes ownership of
436 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
437 /// will be destroyed as well, so there is no need to delete the pass. This
438 /// implies that all passes MUST be allocated with 'new'.
443 /// run - Execute all of the passes scheduled for execution. Keep track of
444 /// whether any of the passes modifies the module, and if so, return true.
445 bool run(Function &F);
447 /// doInitialization - Run all of the initializers for the function passes.
449 bool doInitialization(Module &M);
451 /// doFinalization - Run all of the initializers for the function passes.
453 bool doFinalization(Module &M);
455 /// Pass Manager itself does not invalidate any analysis info.
456 void getAnalysisUsage(AnalysisUsage &Info) const {
457 Info.setPreservesAll();
460 inline void addTopLevelPass(Pass *P) {
462 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
464 // P is a immutable pass and it will be managed by this
465 // top level manager. Set up analysis resolver to connect them.
466 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
468 initializeAnalysisImpl(P);
469 addImmutablePass(IP);
470 recordAvailableAnalysis(IP);
476 FPPassManager *getContainedManager(unsigned N) {
477 assert ( N < PassManagers.size() && "Pass number out of range!");
478 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
482 /// Add a pass into a passmanager queue.
483 bool addPass(Pass *p);
487 // Active Pass Manager
488 FPPassManager *activeManager;
491 //===----------------------------------------------------------------------===//
494 /// MPPassManager manages ModulePasses and function pass managers.
495 /// It batches all Module passes passes and function pass managers together and
496 /// sequence them to process one module.
497 class MPPassManager : public Pass, public PMDataManager {
500 MPPassManager(int Depth) : PMDataManager(Depth) {
501 activeFunctionPassManager = NULL;
504 /// Add a pass into a passmanager queue.
505 bool addPass(Pass *p);
507 /// run - Execute all of the passes scheduled for execution. Keep track of
508 /// whether any of the passes modifies the module, and if so, return true.
509 bool runOnModule(Module &M);
511 /// Pass Manager itself does not invalidate any analysis info.
512 void getAnalysisUsage(AnalysisUsage &Info) const {
513 Info.setPreservesAll();
516 // Print passes managed by this manager
517 void dumpPassStructure(unsigned Offset) {
518 llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n";
519 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
520 ModulePass *MP = getContainedPass(Index);
521 MP->dumpPassStructure(Offset + 1);
522 dumpLastUses(MP, Offset+1);
526 ModulePass *getContainedPass(unsigned N) {
527 assert ( N < PassVector.size() && "Pass number out of range!");
528 ModulePass *MP = static_cast<ModulePass *>(PassVector[N]);
533 // Active Pass Manager
534 FPPassManager *activeFunctionPassManager;
537 //===----------------------------------------------------------------------===//
540 /// PassManagerImpl manages MPPassManagers
541 class PassManagerImpl : public Pass,
542 public PMDataManager,
543 public PMTopLevelManager {
547 PassManagerImpl(int Depth) : PMDataManager(Depth) {
548 activeManager = NULL;
551 /// add - Add a pass to the queue of passes to run. This passes ownership of
552 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
553 /// will be destroyed as well, so there is no need to delete the pass. This
554 /// implies that all passes MUST be allocated with 'new'.
559 /// run - Execute all of the passes scheduled for execution. Keep track of
560 /// whether any of the passes modifies the module, and if so, return true.
563 /// Pass Manager itself does not invalidate any analysis info.
564 void getAnalysisUsage(AnalysisUsage &Info) const {
565 Info.setPreservesAll();
568 inline void addTopLevelPass(Pass *P) {
570 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
572 // P is a immutable pass and it will be managed by this
573 // top level manager. Set up analysis resolver to connect them.
574 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
576 initializeAnalysisImpl(P);
577 addImmutablePass(IP);
578 recordAvailableAnalysis(IP);
584 MPPassManager *getContainedManager(unsigned N) {
585 assert ( N < PassManagers.size() && "Pass number out of range!");
586 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
592 /// Add a pass into a passmanager queue.
593 bool addPass(Pass *p);
595 // Active Pass Manager
596 MPPassManager *activeManager;
599 } // End of llvm namespace
603 //===----------------------------------------------------------------------===//
604 // TimingInfo Class - This class is used to calculate information about the
605 // amount of time each pass takes to execute. This only happens when
606 // -time-passes is enabled on the command line.
609 class VISIBILITY_HIDDEN TimingInfo {
610 std::map<Pass*, Timer> TimingData;
614 // Use 'create' member to get this.
615 TimingInfo() : TG("... Pass execution timing report ...") {}
617 // TimingDtor - Print out information about timing information
619 // Delete all of the timers...
621 // TimerGroup is deleted next, printing the report.
624 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
625 // to a non null value (if the -time-passes option is enabled) or it leaves it
626 // null. It may be called multiple times.
627 static void createTheTimeInfo();
629 void passStarted(Pass *P) {
631 if (dynamic_cast<PMDataManager *>(P))
634 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
635 if (I == TimingData.end())
636 I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
637 I->second.startTimer();
639 void passEnded(Pass *P) {
641 if (dynamic_cast<PMDataManager *>(P))
644 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
645 assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
646 I->second.stopTimer();
650 static TimingInfo *TheTimeInfo;
652 } // End of anon namespace
654 //===----------------------------------------------------------------------===//
655 // PMTopLevelManager implementation
657 /// Set pass P as the last user of the given analysis passes.
658 void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses,
661 for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(),
662 E = AnalysisPasses.end(); I != E; ++I) {
665 // If AP is the last user of other passes then make P last user of
667 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
668 LUE = LastUser.end(); LUI != LUE; ++LUI) {
669 if (LUI->second == AP)
670 LastUser[LUI->first] = P;
675 /// Collect passes whose last user is P
676 void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
678 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
679 LUE = LastUser.end(); LUI != LUE; ++LUI)
680 if (LUI->second == P)
681 LastUses.push_back(LUI->first);
684 /// Schedule pass P for execution. Make sure that passes required by
685 /// P are run before P is run. Update analysis info maintained by
686 /// the manager. Remove dead passes. This is a recursive function.
687 void PMTopLevelManager::schedulePass(Pass *P) {
689 // TODO : Allocate function manager for this pass, other wise required set
690 // may be inserted into previous function manager
692 AnalysisUsage AnUsage;
693 P->getAnalysisUsage(AnUsage);
694 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
695 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
696 E = RequiredSet.end(); I != E; ++I) {
698 Pass *AnalysisPass = findAnalysisPass(*I);
700 // Schedule this analysis run first.
701 AnalysisPass = (*I)->createPass();
702 schedulePass(AnalysisPass);
706 // Now all required passes are available.
710 /// Find the pass that implements Analysis AID. Search immutable
711 /// passes and all pass managers. If desired pass is not found
712 /// then return NULL.
713 Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
716 // Check pass managers
717 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
718 E = PassManagers.end(); P == NULL && I != E; ++I) {
719 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
720 assert(PMD && "This is not a PassManager");
721 P = PMD->findAnalysisPass(AID, false);
724 // Check other pass managers
725 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
726 E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
727 P = (*I)->findAnalysisPass(AID, false);
729 for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
730 E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
731 const PassInfo *PI = (*I)->getPassInfo();
735 // If Pass not found then check the interfaces implemented by Immutable Pass
737 const std::vector<const PassInfo*> &ImmPI = PI->getInterfacesImplemented();
738 if (std::find(ImmPI.begin(), ImmPI.end(), AID) != ImmPI.end())
746 // Print passes managed by this top level manager.
747 void PMTopLevelManager::dumpPasses() const {
749 if (PassDebugging_New < Structure)
752 // Print out the immutable passes
753 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
754 ImmutablePasses[i]->dumpPassStructure(0);
757 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
758 E = PassManagers.end(); I != E; ++I)
759 (*I)->dumpPassStructure(1);
762 void PMTopLevelManager::dumpArguments() const {
764 if (PassDebugging_New < Arguments)
767 cerr << "Pass Arguments: ";
768 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
769 E = PassManagers.end(); I != E; ++I) {
770 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
771 assert(PMD && "This is not a PassManager");
772 PMD->dumpPassArguments();
777 void PMTopLevelManager::initializeAllAnalysisInfo() {
779 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
780 E = PassManagers.end(); I != E; ++I) {
781 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
782 assert(PMD && "This is not a PassManager");
783 PMD->initializeAnalysisInfo();
786 // Initailize other pass managers
787 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
788 E = IndirectPassManagers.end(); I != E; ++I)
789 (*I)->initializeAnalysisInfo();
792 //===----------------------------------------------------------------------===//
793 // PMDataManager implementation
795 /// Return true IFF pass P's required analysis set does not required new
797 bool PMDataManager::manageablePass(Pass *P) {
800 // If this pass is not preserving information that is required by a
801 // pass maintained by higher level pass manager then do not insert
802 // this pass into current manager. Use new manager. For example,
803 // For example, If FunctionPass F is not preserving ModulePass Info M1
804 // that is used by another ModulePass M2 then do not insert F in
805 // current function pass manager.
809 /// Augement AvailableAnalysis by adding analysis made available by pass P.
810 void PMDataManager::recordAvailableAnalysis(Pass *P) {
812 if (const PassInfo *PI = P->getPassInfo()) {
813 AvailableAnalysis[PI] = P;
815 //This pass is the current implementation of all of the interfaces it
816 //implements as well.
817 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
818 for (unsigned i = 0, e = II.size(); i != e; ++i)
819 AvailableAnalysis[II[i]] = P;
823 /// Remove Analyss not preserved by Pass P
824 void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
825 AnalysisUsage AnUsage;
826 P->getAnalysisUsage(AnUsage);
828 if (AnUsage.getPreservesAll())
831 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
832 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
833 E = AvailableAnalysis.end(); I != E; ) {
834 std::map<AnalysisID, Pass*>::iterator Info = I++;
835 if (std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
836 PreservedSet.end()) {
837 // Remove this analysis
838 if (!dynamic_cast<ImmutablePass*>(Info->second))
839 AvailableAnalysis.erase(Info);
844 /// Remove analysis passes that are not used any longer
845 void PMDataManager::removeDeadPasses(Pass *P, std::string &Msg) {
847 std::vector<Pass *> DeadPasses;
848 TPM->collectLastUses(DeadPasses, P);
850 for (std::vector<Pass *>::iterator I = DeadPasses.begin(),
851 E = DeadPasses.end(); I != E; ++I) {
853 std::string Msg1 = " Freeing Pass '";
854 dumpPassInfo(*I, Msg1, Msg);
856 if (TheTimeInfo) TheTimeInfo->passStarted(P);
857 (*I)->releaseMemory();
858 if (TheTimeInfo) TheTimeInfo->passEnded(P);
860 std::map<AnalysisID, Pass*>::iterator Pos =
861 AvailableAnalysis.find((*I)->getPassInfo());
863 // It is possible that pass is already removed from the AvailableAnalysis
864 if (Pos != AvailableAnalysis.end())
865 AvailableAnalysis.erase(Pos);
869 /// Add pass P into the PassVector. Update
870 /// AvailableAnalysis appropriately if ProcessAnalysis is true.
871 void PMDataManager::addPassToManager(Pass *P,
872 bool ProcessAnalysis) {
874 // This manager is going to manage pass P. Set up analysis resolver
876 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
879 if (ProcessAnalysis) {
881 // At the moment, this pass is the last user of all required passes.
882 std::vector<Pass *> LastUses;
883 std::vector<Pass *> RequiredPasses;
884 unsigned PDepth = this->getDepth();
886 collectRequiredAnalysisPasses(RequiredPasses, P);
887 for (std::vector<Pass *>::iterator I = RequiredPasses.begin(),
888 E = RequiredPasses.end(); I != E; ++I) {
889 Pass *PRequired = *I;
892 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
893 RDepth = DM.getDepth();
895 if (PDepth == RDepth)
896 LastUses.push_back(PRequired);
897 else if (PDepth > RDepth) {
898 // Let the parent claim responsibility of last use
899 TransferLastUses.push_back(PRequired);
901 // Note : This feature is not yet implemented
903 "Unable to handle Pass that requires lower level Analysis pass");
907 LastUses.push_back(P);
908 TPM->setLastUser(LastUses, P);
910 // Take a note of analysis required and made available by this pass.
911 // Remove the analysis not preserved by this pass
912 removeNotPreservedAnalysis(P);
913 recordAvailableAnalysis(P);
917 PassVector.push_back(P);
920 /// Populate RequiredPasses with the analysis pass that are required by
922 void PMDataManager::collectRequiredAnalysisPasses(std::vector<Pass *> &RP,
924 AnalysisUsage AnUsage;
925 P->getAnalysisUsage(AnUsage);
926 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
927 for (std::vector<AnalysisID>::const_iterator
928 I = RequiredSet.begin(), E = RequiredSet.end();
930 Pass *AnalysisPass = findAnalysisPass(*I, true);
931 assert (AnalysisPass && "Analysis pass is not available");
932 RP.push_back(AnalysisPass);
935 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
936 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
937 E = IDs.end(); I != E; ++I) {
938 Pass *AnalysisPass = findAnalysisPass(*I, true);
939 assert (AnalysisPass && "Analysis pass is not available");
940 RP.push_back(AnalysisPass);
944 // All Required analyses should be available to the pass as it runs! Here
945 // we fill in the AnalysisImpls member of the pass so that it can
946 // successfully use the getAnalysis() method to retrieve the
947 // implementations it needs.
949 void PMDataManager::initializeAnalysisImpl(Pass *P) {
950 AnalysisUsage AnUsage;
951 P->getAnalysisUsage(AnUsage);
953 for (std::vector<const PassInfo *>::const_iterator
954 I = AnUsage.getRequiredSet().begin(),
955 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
956 Pass *Impl = findAnalysisPass(*I, true);
958 assert(0 && "Analysis used but not available!");
959 AnalysisResolver_New *AR = P->getResolver();
960 AR->addAnalysisImplsPair(*I, Impl);
964 /// Find the pass that implements Analysis AID. If desired pass is not found
965 /// then return NULL.
966 Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
968 // Check if AvailableAnalysis map has one entry.
969 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
971 if (I != AvailableAnalysis.end())
974 // Search Parents through TopLevelManager
976 return TPM->findAnalysisPass(AID);
981 // Print list of passes that are last used by P.
982 void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
984 std::vector<Pass *> LUses;
986 assert (TPM && "Top Level Manager is missing");
987 TPM->collectLastUses(LUses, P);
989 for (std::vector<Pass *>::iterator I = LUses.begin(),
990 E = LUses.end(); I != E; ++I) {
991 llvm::cerr << "--" << std::string(Offset*2, ' ');
992 (*I)->dumpPassStructure(0);
996 void PMDataManager::dumpPassArguments() const {
997 for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
998 E = PassVector.end(); I != E; ++I) {
999 if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
1000 PMD->dumpPassArguments();
1002 if (const PassInfo *PI = (*I)->getPassInfo())
1003 if (!PI->isAnalysisGroup())
1004 cerr << " -" << PI->getPassArgument();
1008 void PMDataManager:: dumpPassInfo(Pass *P, std::string &Msg1,
1009 std::string &Msg2) const {
1010 if (PassDebugging_New < Executions)
1012 cerr << (void*)this << std::string(getDepth()*2+1, ' ');
1014 cerr << P->getPassName();
1018 void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
1019 const std::vector<AnalysisID> &Set)
1021 if (PassDebugging_New >= Details && !Set.empty()) {
1022 cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
1023 for (unsigned i = 0; i != Set.size(); ++i) {
1025 cerr << " " << Set[i]->getPassName();
1031 //===----------------------------------------------------------------------===//
1032 // NOTE: Is this the right place to define this method ?
1033 // getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
1034 Pass *AnalysisResolver_New::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
1035 return PM.findAnalysisPass(ID, dir);
1038 //===----------------------------------------------------------------------===//
1039 // BBPassManager implementation
1041 /// Add pass P into PassVector and return true. If this pass is not
1042 /// manageable by this manager then return false.
1044 BBPassManager::addPass(Pass *P) {
1046 BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
1050 // If this pass does not preserve analysis that is used by other passes
1051 // managed by this manager than it is not a suitable pass for this manager.
1052 if (!manageablePass(P))
1055 addPassToManager(BP);
1060 /// Execute all of the passes scheduled for execution by invoking
1061 /// runOnBasicBlock method. Keep track of whether any of the passes modifies
1062 /// the function, and if so, return true.
1064 BBPassManager::runOnFunction(Function &F) {
1069 bool Changed = doInitialization(F);
1071 std::string Msg1 = "Executing Pass '";
1072 std::string Msg3 = "' Made Modification '";
1074 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
1075 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1076 BasicBlockPass *BP = getContainedPass(Index);
1077 AnalysisUsage AnUsage;
1078 BP->getAnalysisUsage(AnUsage);
1080 std::string Msg2 = "' on BasicBlock '" + (*I).getName() + "'...\n";
1081 dumpPassInfo(BP, Msg1, Msg2);
1082 dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet());
1084 initializeAnalysisImpl(BP);
1086 if (TheTimeInfo) TheTimeInfo->passStarted(BP);
1087 Changed |= BP->runOnBasicBlock(*I);
1088 if (TheTimeInfo) TheTimeInfo->passEnded(BP);
1091 dumpPassInfo(BP, Msg3, Msg2);
1092 dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet());
1094 removeNotPreservedAnalysis(BP);
1095 recordAvailableAnalysis(BP);
1096 removeDeadPasses(BP, Msg2);
1098 return Changed |= doFinalization(F);
1101 // Implement doInitialization and doFinalization
1102 inline bool BBPassManager::doInitialization(Module &M) {
1103 bool Changed = false;
1105 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1106 BasicBlockPass *BP = getContainedPass(Index);
1107 Changed |= BP->doInitialization(M);
1113 inline bool BBPassManager::doFinalization(Module &M) {
1114 bool Changed = false;
1116 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1117 BasicBlockPass *BP = getContainedPass(Index);
1118 Changed |= BP->doFinalization(M);
1124 inline bool BBPassManager::doInitialization(Function &F) {
1125 bool Changed = false;
1127 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1128 BasicBlockPass *BP = getContainedPass(Index);
1129 Changed |= BP->doInitialization(F);
1135 inline bool BBPassManager::doFinalization(Function &F) {
1136 bool Changed = false;
1138 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1139 BasicBlockPass *BP = getContainedPass(Index);
1140 Changed |= BP->doFinalization(F);
1147 //===----------------------------------------------------------------------===//
1148 // FunctionPassManager implementation
1150 /// Create new Function pass manager
1151 FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
1152 FPM = new FunctionPassManagerImpl(0);
1153 // FPM is the top level manager.
1154 FPM->setTopLevelManager(FPM);
1156 PMDataManager *PMD = dynamic_cast<PMDataManager *>(FPM);
1157 AnalysisResolver_New *AR = new AnalysisResolver_New(*PMD);
1158 FPM->setResolver(AR);
1163 FunctionPassManager::~FunctionPassManager() {
1167 /// add - Add a pass to the queue of passes to run. This passes
1168 /// ownership of the Pass to the PassManager. When the
1169 /// PassManager_X is destroyed, the pass will be destroyed as well, so
1170 /// there is no need to delete the pass. (TODO delete passes.)
1171 /// This implies that all passes MUST be allocated with 'new'.
1172 void FunctionPassManager::add(Pass *P) {
1176 /// run - Execute all of the passes scheduled for execution. Keep
1177 /// track of whether any of the passes modifies the function, and if
1178 /// so, return true.
1180 bool FunctionPassManager::run(Function &F) {
1182 if (MP->materializeFunction(&F, &errstr)) {
1183 cerr << "Error reading bytecode file: " << errstr << "\n";
1190 /// doInitialization - Run all of the initializers for the function passes.
1192 bool FunctionPassManager::doInitialization() {
1193 return FPM->doInitialization(*MP->getModule());
1196 /// doFinalization - Run all of the initializers for the function passes.
1198 bool FunctionPassManager::doFinalization() {
1199 return FPM->doFinalization(*MP->getModule());
1202 //===----------------------------------------------------------------------===//
1203 // FunctionPassManagerImpl implementation
1205 /// Add P into active pass manager or use new module pass manager to
1207 bool FunctionPassManagerImpl::addPass(Pass *P) {
1209 if (!activeManager || !activeManager->addPass(P)) {
1210 activeManager = new FPPassManager(getDepth() + 1);
1211 // Inherit top level manager
1212 activeManager->setTopLevelManager(this->getTopLevelManager());
1214 // This top level manager is going to manage activeManager.
1215 // Set up analysis resolver to connect them.
1216 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
1217 activeManager->setResolver(AR);
1219 addPassManager(activeManager);
1220 return activeManager->addPass(P);
1225 inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
1226 bool Changed = false;
1228 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1229 FPPassManager *FP = getContainedManager(Index);
1230 Changed |= FP->doInitialization(M);
1236 inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
1237 bool Changed = false;
1239 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1240 FPPassManager *FP = getContainedManager(Index);
1241 Changed |= FP->doFinalization(M);
1247 // Execute all the passes managed by this top level manager.
1248 // Return true if any function is modified by a pass.
1249 bool FunctionPassManagerImpl::run(Function &F) {
1251 bool Changed = false;
1253 TimingInfo::createTheTimeInfo();
1258 initializeAllAnalysisInfo();
1259 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1260 FPPassManager *FP = getContainedManager(Index);
1261 Changed |= FP->runOnFunction(F);
1266 //===----------------------------------------------------------------------===//
1267 // FPPassManager implementation
1269 /// Add pass P into the pass manager queue. If P is a BasicBlockPass then
1270 /// either use it into active basic block pass manager or create new basic
1271 /// block pass manager to handle pass P.
1273 FPPassManager::addPass(Pass *P) {
1275 // If P is a BasicBlockPass then use BBPassManager.
1276 if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
1278 if (!activeBBPassManager || !activeBBPassManager->addPass(BP)) {
1280 // If active manager exists then clear its analysis info.
1281 if (activeBBPassManager)
1282 activeBBPassManager->initializeAnalysisInfo();
1284 // Create and add new manager
1285 activeBBPassManager = new BBPassManager(getDepth() + 1);
1286 // Inherit top level manager
1287 activeBBPassManager->setTopLevelManager(this->getTopLevelManager());
1289 // Add new manager into current manager's list.
1290 addPassToManager(activeBBPassManager, false);
1292 // Add new manager into top level manager's indirect passes list
1293 PMDataManager *PMD = dynamic_cast<PMDataManager *>(activeBBPassManager);
1294 assert (PMD && "Manager is not Pass Manager");
1295 TPM->addIndirectPassManager(PMD);
1297 // Add pass into new manager. This time it must succeed.
1298 if (!activeBBPassManager->addPass(BP))
1299 assert(0 && "Unable to add Pass");
1301 // If activeBBPassManager transfered any Last Uses then handle them here.
1302 std::vector<Pass *> &TLU = activeBBPassManager->getTransferredLastUses();
1304 TPM->setLastUser(TLU, this);
1311 FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
1315 // If this pass does not preserve analysis that is used by other passes
1316 // managed by this manager than it is not a suitable pass for this manager.
1317 if (!manageablePass(P))
1320 addPassToManager (FP);
1322 // If active manager exists then clear its analysis info.
1323 if (activeBBPassManager) {
1324 activeBBPassManager->initializeAnalysisInfo();
1325 activeBBPassManager = NULL;
1331 /// Execute all of the passes scheduled for execution by invoking
1332 /// runOnFunction method. Keep track of whether any of the passes modifies
1333 /// the function, and if so, return true.
1334 bool FPPassManager::runOnFunction(Function &F) {
1336 bool Changed = false;
1341 std::string Msg1 = "Executing Pass '";
1342 std::string Msg3 = "' Made Modification '";
1344 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1345 FunctionPass *FP = getContainedPass(Index);
1347 AnalysisUsage AnUsage;
1348 FP->getAnalysisUsage(AnUsage);
1350 std::string Msg2 = "' on Function '" + F.getName() + "'...\n";
1351 dumpPassInfo(FP, Msg1, Msg2);
1352 dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet());
1354 initializeAnalysisImpl(FP);
1356 if (TheTimeInfo) TheTimeInfo->passStarted(FP);
1357 Changed |= FP->runOnFunction(F);
1358 if (TheTimeInfo) TheTimeInfo->passEnded(FP);
1361 dumpPassInfo(FP, Msg3, Msg2);
1362 dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
1364 removeNotPreservedAnalysis(FP);
1365 recordAvailableAnalysis(FP);
1366 removeDeadPasses(FP, Msg2);
1371 bool FPPassManager::runOnModule(Module &M) {
1373 bool Changed = doInitialization(M);
1375 for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1376 this->runOnFunction(*I);
1378 return Changed |= doFinalization(M);
1381 inline bool FPPassManager::doInitialization(Module &M) {
1382 bool Changed = false;
1384 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1385 FunctionPass *FP = getContainedPass(Index);
1386 Changed |= FP->doInitialization(M);
1392 inline bool FPPassManager::doFinalization(Module &M) {
1393 bool Changed = false;
1395 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1396 FunctionPass *FP = getContainedPass(Index);
1397 Changed |= FP->doFinalization(M);
1403 //===----------------------------------------------------------------------===//
1404 // MPPassManager implementation
1406 /// Add P into pass vector if it is manageble. If P is a FunctionPass
1407 /// then use FPPassManager to manage it. Return false if P
1408 /// is not manageable by this manager.
1410 MPPassManager::addPass(Pass *P) {
1412 // If P is FunctionPass then use function pass maanager.
1413 if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
1415 if (!activeFunctionPassManager || !activeFunctionPassManager->addPass(P)) {
1417 // If active manager exists then clear its analysis info.
1418 if (activeFunctionPassManager)
1419 activeFunctionPassManager->initializeAnalysisInfo();
1421 // Create and add new manager
1422 activeFunctionPassManager =
1423 new FPPassManager(getDepth() + 1);
1425 // Add new manager into current manager's list
1426 addPassToManager(activeFunctionPassManager, false);
1428 // Inherit top level manager
1429 activeFunctionPassManager->setTopLevelManager(this->getTopLevelManager());
1431 // Add new manager into top level manager's indirect passes list
1432 PMDataManager *PMD =
1433 dynamic_cast<PMDataManager *>(activeFunctionPassManager);
1434 assert(PMD && "Manager is not Pass Manager");
1435 TPM->addIndirectPassManager(PMD);
1437 // Add pass into new manager. This time it must succeed.
1438 if (!activeFunctionPassManager->addPass(FP))
1439 assert(0 && "Unable to add pass");
1441 // If activeFunctionPassManager transfered any Last Uses then
1442 // handle them here.
1443 std::vector<Pass *> &TLU =
1444 activeFunctionPassManager->getTransferredLastUses();
1446 TPM->setLastUser(TLU, this);
1452 ModulePass *MP = dynamic_cast<ModulePass *>(P);
1456 // If this pass does not preserve analysis that is used by other passes
1457 // managed by this manager than it is not a suitable pass for this manager.
1458 if (!manageablePass(P))
1461 addPassToManager(MP);
1462 // If active manager exists then clear its analysis info.
1463 if (activeFunctionPassManager) {
1464 activeFunctionPassManager->initializeAnalysisInfo();
1465 activeFunctionPassManager = NULL;
1472 /// Execute all of the passes scheduled for execution by invoking
1473 /// runOnModule method. Keep track of whether any of the passes modifies
1474 /// the module, and if so, return true.
1476 MPPassManager::runOnModule(Module &M) {
1477 bool Changed = false;
1479 std::string Msg1 = "Executing Pass '";
1480 std::string Msg3 = "' Made Modification '";
1482 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1483 ModulePass *MP = getContainedPass(Index);
1485 AnalysisUsage AnUsage;
1486 MP->getAnalysisUsage(AnUsage);
1488 std::string Msg2 = "' on Module '" + M.getModuleIdentifier() + "'...\n";
1489 dumpPassInfo(MP, Msg1, Msg2);
1490 dumpAnalysisSetInfo("Required", MP, AnUsage.getRequiredSet());
1492 initializeAnalysisImpl(MP);
1494 if (TheTimeInfo) TheTimeInfo->passStarted(MP);
1495 Changed |= MP->runOnModule(M);
1496 if (TheTimeInfo) TheTimeInfo->passEnded(MP);
1499 dumpPassInfo(MP, Msg3, Msg2);
1500 dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
1502 removeNotPreservedAnalysis(MP);
1503 recordAvailableAnalysis(MP);
1504 removeDeadPasses(MP, Msg2);
1509 //===----------------------------------------------------------------------===//
1510 // PassManagerImpl implementation
1512 /// Add P into active pass manager or use new module pass manager to
1514 bool PassManagerImpl::addPass(Pass *P) {
1516 if (!activeManager || !activeManager->addPass(P)) {
1517 activeManager = new MPPassManager(getDepth() + 1);
1518 // Inherit top level manager
1519 activeManager->setTopLevelManager(this->getTopLevelManager());
1521 // This top level manager is going to manage activeManager.
1522 // Set up analysis resolver to connect them.
1523 AnalysisResolver_New *AR = new AnalysisResolver_New(*this);
1524 activeManager->setResolver(AR);
1526 addPassManager(activeManager);
1527 return activeManager->addPass(P);
1532 /// run - Execute all of the passes scheduled for execution. Keep track of
1533 /// whether any of the passes modifies the module, and if so, return true.
1534 bool PassManagerImpl::run(Module &M) {
1536 bool Changed = false;
1538 TimingInfo::createTheTimeInfo();
1543 initializeAllAnalysisInfo();
1544 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1545 MPPassManager *MP = getContainedManager(Index);
1546 Changed |= MP->runOnModule(M);
1551 //===----------------------------------------------------------------------===//
1552 // PassManager implementation
1554 /// Create new pass manager
1555 PassManager::PassManager() {
1556 PM = new PassManagerImpl(0);
1557 // PM is the top level manager
1558 PM->setTopLevelManager(PM);
1561 PassManager::~PassManager() {
1565 /// add - Add a pass to the queue of passes to run. This passes ownership of
1566 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
1567 /// will be destroyed as well, so there is no need to delete the pass. This
1568 /// implies that all passes MUST be allocated with 'new'.
1570 PassManager::add(Pass *P) {
1574 /// run - Execute all of the passes scheduled for execution. Keep track of
1575 /// whether any of the passes modifies the module, and if so, return true.
1577 PassManager::run(Module &M) {
1581 //===----------------------------------------------------------------------===//
1582 // TimingInfo Class - This class is used to calculate information about the
1583 // amount of time each pass takes to execute. This only happens with
1584 // -time-passes is enabled on the command line.
1586 bool llvm::TimePassesIsEnabled = false;
1587 static cl::opt<bool,true>
1588 EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1589 cl::desc("Time each pass, printing elapsed time for each on exit"));
1591 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1592 // a non null value (if the -time-passes option is enabled) or it leaves it
1593 // null. It may be called multiple times.
1594 void TimingInfo::createTheTimeInfo() {
1595 if (!TimePassesIsEnabled || TheTimeInfo) return;
1597 // Constructed the first time this is called, iff -time-passes is enabled.
1598 // This guarantees that the object will be constructed before static globals,
1599 // thus it will be destroyed before them.
1600 static ManagedStatic<TimingInfo> TTI;
1601 TheTimeInfo = &*TTI;