1 //===- PassManagerT.h - Container for Passes ---------------------*- C++ -*--=//
3 // This file defines the PassManagerT class. This class is used to hold,
4 // maintain, and optimize execution of Pass's. The PassManager class ensures
5 // that analysis results are available before a pass runs, and that Pass's are
6 // destroyed when the PassManager is destroyed.
8 // The PassManagerT template is instantiated three times to do its job. The
9 // public PassManager class is a Pimpl around the PassManagerT<Module> interface
10 // to avoid having all of the PassManager clients being exposed to the
11 // implementation details herein.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_PASSMANAGER_T_H
16 #define LLVM_PASSMANAGER_T_H
18 #include "llvm/Pass.h"
19 #include "Support/CommandLine.h"
20 #include "Support/LeakDetector.h"
21 #include "Support/Timer.h"
26 //===----------------------------------------------------------------------===//
27 // Pass debugging information. Often it is useful to find out what pass is
28 // running when a crash occurs in a utility. When this library is compiled with
29 // debugging on, a command line option (--debug-pass) is enabled that causes the
30 // pass name to be printed before it executes.
33 // Different debug levels that can be enabled...
35 None, Arguments, Structure, Executions, Details
38 static cl::opt<enum PassDebugLevel>
39 PassDebugging("debug-pass", cl::Hidden,
40 cl::desc("Print PassManager debugging information"),
42 clEnumVal(None , "disable debug output"),
43 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
44 clEnumVal(Structure , "print pass structure before run()"),
45 clEnumVal(Executions, "print pass name before it is executed"),
46 clEnumVal(Details , "print pass details when it is executed"),
49 //===----------------------------------------------------------------------===//
50 // PMDebug class - a set of debugging functions, that are not to be
51 // instantiated by the template.
54 static void PerformPassStartupStuff(Pass *P) {
55 // If debugging is enabled, print out argument information...
56 if (PassDebugging >= Arguments) {
57 std::cerr << "Pass Arguments: ";
58 PrintArgumentInformation(P);
61 // Print the pass execution structure
62 if (PassDebugging >= Structure)
63 P->dumpPassStructure();
67 static void PrintArgumentInformation(const Pass *P);
68 static void PrintPassInformation(unsigned,const char*,Pass *, Annotable *);
69 static void PrintAnalysisSetInfo(unsigned,const char*,Pass *P,
70 const std::vector<AnalysisID> &);
74 //===----------------------------------------------------------------------===//
75 // TimingInfo Class - This class is used to calculate information about the
76 // amount of time each pass takes to execute. This only happens when
77 // -time-passes is enabled on the command line.
81 std::map<Pass*, Timer> TimingData;
84 // Private ctor, must use 'create' member
85 TimingInfo() : TG("... Pass execution timing report ...") {}
87 // Create method. If Timing is enabled, this creates and returns a new timing
88 // object, otherwise it returns null.
90 static TimingInfo *create();
92 // TimingDtor - Print out information about timing information
94 // Delete all of the timers...
96 // TimerGroup is deleted next, printing the report.
99 void passStarted(Pass *P) {
100 if (dynamic_cast<AnalysisResolver*>(P)) return;
101 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
102 if (I == TimingData.end())
103 I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
104 I->second.startTimer();
106 void passEnded(Pass *P) {
107 if (dynamic_cast<AnalysisResolver*>(P)) return;
108 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
109 assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
110 I->second.stopTimer();
114 //===----------------------------------------------------------------------===//
115 // Declare the PassManagerTraits which will be specialized...
117 template<class UnitType> class PassManagerTraits; // Do not define.
120 //===----------------------------------------------------------------------===//
121 // PassManagerT - Container object for passes. The PassManagerT destructor
122 // deletes all passes contained inside of the PassManagerT, so you shouldn't
123 // delete passes manually, and all passes should be dynamically allocated.
125 template<typename UnitType>
126 class PassManagerT : public PassManagerTraits<UnitType>,public AnalysisResolver{
127 typedef PassManagerTraits<UnitType> Traits;
128 typedef typename Traits::PassClass PassClass;
129 typedef typename Traits::SubPassClass SubPassClass;
130 typedef typename Traits::BatcherClass BatcherClass;
131 typedef typename Traits::ParentClass ParentClass;
133 friend class PassManagerTraits<UnitType>::PassClass;
134 friend class PassManagerTraits<UnitType>::SubPassClass;
136 friend class ImmutablePass;
138 std::vector<PassClass*> Passes; // List of passes to run
139 std::vector<ImmutablePass*> ImmutablePasses; // List of immutable passes
141 // The parent of this pass manager...
142 ParentClass * const Parent;
144 // The current batcher if one is in use, or null
145 BatcherClass *Batcher;
147 // CurrentAnalyses - As the passes are being run, this map contains the
148 // analyses that are available to the current pass for use. This is accessed
149 // through the getAnalysis() function in this class and in Pass.
151 std::map<AnalysisID, Pass*> CurrentAnalyses;
153 // LastUseOf - This map keeps track of the last usage in our pipeline of a
154 // particular pass. When executing passes, the memory for .first is free'd
155 // after .second is run.
157 std::map<Pass*, Pass*> LastUseOf;
160 PassManagerT(ParentClass *Par = 0) : Parent(Par), Batcher(0) {}
162 // Delete all of the contained passes...
163 for (typename std::vector<PassClass*>::iterator
164 I = Passes.begin(), E = Passes.end(); I != E; ++I)
167 for (std::vector<ImmutablePass*>::iterator
168 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
172 // run - Run all of the queued passes on the specified module in an optimal
174 virtual bool runOnUnit(UnitType *M) {
175 bool MadeChanges = false;
177 CurrentAnalyses.clear();
179 // Add any immutable passes to the CurrentAnalyses set...
180 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
181 ImmutablePass *IPass = ImmutablePasses[i];
182 if (const PassInfo *PI = IPass->getPassInfo()) {
183 CurrentAnalyses[PI] = IPass;
185 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
186 for (unsigned i = 0, e = II.size(); i != e; ++i)
187 CurrentAnalyses[II[i]] = IPass;
191 // LastUserOf - This contains the inverted LastUseOfMap...
192 std::map<Pass *, std::vector<Pass*> > LastUserOf;
193 for (std::map<Pass*, Pass*>::iterator I = LastUseOf.begin(),
194 E = LastUseOf.end(); I != E; ++I)
195 LastUserOf[I->second].push_back(I->first);
198 // Output debug information...
199 if (Parent == 0) PMDebug::PerformPassStartupStuff(this);
201 // Run all of the passes
202 for (unsigned i = 0, e = Passes.size(); i < e; ++i) {
203 PassClass *P = Passes[i];
205 PMDebug::PrintPassInformation(getDepth(), "Executing Pass", P,
208 // Get information about what analyses the pass uses...
209 AnalysisUsage AnUsage;
210 P->getAnalysisUsage(AnUsage);
211 PMDebug::PrintAnalysisSetInfo(getDepth(), "Required", P,
212 AnUsage.getRequiredSet());
214 // All Required analyses should be available to the pass as it runs! Here
215 // we fill in the AnalysisImpls member of the pass so that it can
216 // successfully use the getAnalysis() method to retrieve the
217 // implementations it needs.
219 P->AnalysisImpls.clear();
220 P->AnalysisImpls.reserve(AnUsage.getRequiredSet().size());
221 for (std::vector<const PassInfo *>::const_iterator
222 I = AnUsage.getRequiredSet().begin(),
223 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
224 Pass *Impl = getAnalysisOrNullUp(*I);
226 std::cerr << "Analysis '" << (*I)->getPassName()
227 << "' used but not available!";
228 assert(0 && "Analysis used but not available!");
229 } else if (PassDebugging == Details) {
230 if ((*I)->getPassName() != std::string(Impl->getPassName()))
231 std::cerr << " Interface '" << (*I)->getPassName()
232 << "' implemented by '" << Impl->getPassName() << "'\n";
234 P->AnalysisImpls.push_back(std::make_pair(*I, Impl));
239 bool Changed = runPass(P, M);
241 MadeChanges |= Changed;
243 // Check for memory leaks by the pass...
244 LeakDetector::checkForGarbage(std::string("after running pass '") +
245 P->getPassName() + "'");
248 PMDebug::PrintPassInformation(getDepth()+1, "Made Modification", P,
250 PMDebug::PrintAnalysisSetInfo(getDepth(), "Preserved", P,
251 AnUsage.getPreservedSet());
254 // Erase all analyses not in the preserved set...
255 if (!AnUsage.getPreservesAll()) {
256 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
257 for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
258 E = CurrentAnalyses.end(); I != E; )
259 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) !=
261 ++I; // This analysis is preserved, leave it in the available set...
263 if (!dynamic_cast<ImmutablePass*>(I->second)) {
264 std::map<AnalysisID, Pass*>::iterator J = I++;
265 CurrentAnalyses.erase(J); // Analysis not preserved!
272 // Add the current pass to the set of passes that have been run, and are
273 // thus available to users.
275 if (const PassInfo *PI = P->getPassInfo()) {
276 CurrentAnalyses[PI] = P;
278 // This pass is the current implementation of all of the interfaces it
279 // implements as well.
281 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
282 for (unsigned i = 0, e = II.size(); i != e; ++i)
283 CurrentAnalyses[II[i]] = P;
286 // Free memory for any passes that we are the last use of...
287 std::vector<Pass*> &DeadPass = LastUserOf[P];
288 for (std::vector<Pass*>::iterator I = DeadPass.begin(),E = DeadPass.end();
290 PMDebug::PrintPassInformation(getDepth()+1, "Freeing Pass", *I,
292 (*I)->releaseMemory();
295 // Make sure to remove dead passes from the CurrentAnalyses list...
296 for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin();
297 I != CurrentAnalyses.end(); ) {
298 std::vector<Pass*>::iterator DPI = std::find(DeadPass.begin(),
299 DeadPass.end(), I->second);
300 if (DPI != DeadPass.end()) { // This pass is dead now... remove it
301 std::map<AnalysisID, Pass*>::iterator IDead = I++;
302 CurrentAnalyses.erase(IDead);
304 ++I; // Move on to the next element...
311 // dumpPassStructure - Implement the -debug-passes=PassStructure option
312 virtual void dumpPassStructure(unsigned Offset = 0) {
313 // Print out the immutable passes...
314 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i)
315 ImmutablePasses[i]->dumpPassStructure(0);
317 std::cerr << std::string(Offset*2, ' ') << Traits::getPMName()
318 << " Pass Manager\n";
319 for (typename std::vector<PassClass*>::iterator
320 I = Passes.begin(), E = Passes.end(); I != E; ++I) {
322 P->dumpPassStructure(Offset+1);
324 // Loop through and see which classes are destroyed after this one...
325 for (std::map<Pass*, Pass*>::iterator I = LastUseOf.begin(),
326 E = LastUseOf.end(); I != E; ++I) {
327 if (P == I->second) {
328 std::cerr << "--" << std::string(Offset*2, ' ');
329 I->first->dumpPassStructure(0);
335 Pass *getImmutablePassOrNull(const PassInfo *ID) const {
336 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
337 const PassInfo *IPID = ImmutablePasses[i]->getPassInfo();
339 return ImmutablePasses[i];
341 // This pass is the current implementation of all of the interfaces it
342 // implements as well.
344 const std::vector<const PassInfo*> &II =
345 IPID->getInterfacesImplemented();
346 for (unsigned j = 0, e = II.size(); j != e; ++j)
347 if (II[j] == ID) return ImmutablePasses[i];
352 Pass *getAnalysisOrNullDown(const PassInfo *ID) const {
353 std::map<AnalysisID, Pass*>::const_iterator I = CurrentAnalyses.find(ID);
355 if (I != CurrentAnalyses.end())
356 return I->second; // Found it.
358 if (Pass *P = getImmutablePassOrNull(ID))
362 return ((AnalysisResolver*)Batcher)->getAnalysisOrNullDown(ID);
366 Pass *getAnalysisOrNullUp(const PassInfo *ID) const {
367 std::map<AnalysisID, Pass*>::const_iterator I = CurrentAnalyses.find(ID);
368 if (I != CurrentAnalyses.end())
369 return I->second; // Found it.
371 if (Parent) // Try scanning...
372 return Parent->getAnalysisOrNullUp(ID);
373 else if (!ImmutablePasses.empty())
374 return getImmutablePassOrNull(ID);
378 // {start/end}Pass - Called when a pass is started, it just propagates
379 // information up to the top level PassManagerT object to tell it that a pass
380 // has started or ended. This is used to gather timing information about
383 void startPass(Pass *P) {
384 if (Parent) Parent->startPass(P);
387 void endPass(Pass *P) {
388 if (Parent) Parent->endPass(P);
392 // markPassUsed - Inform higher level pass managers (and ourselves)
393 // that these analyses are being used by this pass. This is used to
394 // make sure that analyses are not free'd before we have to use
397 void markPassUsed(const PassInfo *P, Pass *User) {
398 std::map<AnalysisID, Pass*>::const_iterator I = CurrentAnalyses.find(P);
400 if (I != CurrentAnalyses.end()) {
401 LastUseOf[I->second] = User; // Local pass, extend the lifetime
403 // Pass not in current available set, must be a higher level pass
404 // available to us, propagate to parent pass manager... We tell the
405 // parent that we (the passmanager) are using the analysis so that it
406 // frees the analysis AFTER this pass manager runs.
409 Parent->markPassUsed(P, this);
411 assert(getAnalysisOrNullUp(P) &&
412 dynamic_cast<ImmutablePass*>(getAnalysisOrNullUp(P)) &&
413 "Pass available but not found! "
414 "Perhaps this is a module pass requiring a function pass?");
419 // Return the number of parent PassManagers that exist
420 virtual unsigned getDepth() const {
421 if (Parent == 0) return 0;
422 return 1 + Parent->getDepth();
425 virtual unsigned getNumContainedPasses() const { return Passes.size(); }
426 virtual const Pass *getContainedPass(unsigned N) const {
427 assert(N < Passes.size() && "Pass number out of range!");
431 // add - Add a pass to the queue of passes to run. This gives ownership of
432 // the Pass to the PassManager. When the PassManager is destroyed, the pass
433 // will be destroyed as well, so there is no need to delete the pass. This
434 // implies that all passes MUST be new'd.
436 void add(PassClass *P) {
437 // Get information about what analyses the pass uses...
438 AnalysisUsage AnUsage;
439 P->getAnalysisUsage(AnUsage);
440 const std::vector<AnalysisID> &Required = AnUsage.getRequiredSet();
442 // Loop over all of the analyses used by this pass,
443 for (std::vector<AnalysisID>::const_iterator I = Required.begin(),
444 E = Required.end(); I != E; ++I) {
445 if (getAnalysisOrNullDown(*I) == 0)
446 add((PassClass*)(*I)->createPass());
449 // Tell the pass to add itself to this PassManager... the way it does so
450 // depends on the class of the pass, and is critical to laying out passes in
451 // an optimal order..
453 P->addToPassManager(this, AnUsage);
458 // addPass - These functions are used to implement the subclass specific
459 // behaviors present in PassManager. Basically the add(Pass*) method ends up
460 // reflecting its behavior into a Pass::addToPassManager call. Subclasses of
461 // Pass override it specifically so that they can reflect the type
462 // information inherent in "this" back to the PassManager.
464 // For generic Pass subclasses (which are interprocedural passes), we simply
465 // add the pass to the end of the pass list and terminate any accumulation of
466 // FunctionPass's that are present.
468 void addPass(PassClass *P, AnalysisUsage &AnUsage) {
469 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
471 // FIXME: If this pass being added isn't killed by any of the passes in the
472 // batcher class then we can reorder to pass to execute before the batcher
473 // does, which will potentially allow us to batch more passes!
475 //const std::vector<AnalysisID> &ProvidedSet = AnUsage.getProvidedSet();
476 if (Batcher /*&& ProvidedSet.empty()*/)
477 closeBatcher(); // This pass cannot be batched!
479 // Set the Resolver instance variable in the Pass so that it knows where to
480 // find this object...
482 setAnalysisResolver(P, this);
485 // Inform higher level pass managers (and ourselves) that these analyses are
486 // being used by this pass. This is used to make sure that analyses are not
487 // free'd before we have to use them...
489 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
490 E = RequiredSet.end(); I != E; ++I)
491 markPassUsed(*I, P); // Mark *I as used by P
493 // Erase all analyses not in the preserved set...
494 if (!AnUsage.getPreservesAll()) {
495 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
496 for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
497 E = CurrentAnalyses.end(); I != E; ) {
498 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) ==
499 PreservedSet.end()) { // Analysis not preserved!
500 CurrentAnalyses.erase(I); // Remove from available analyses
501 I = CurrentAnalyses.begin();
508 // Add this pass to the currently available set...
509 if (const PassInfo *PI = P->getPassInfo()) {
510 CurrentAnalyses[PI] = P;
512 // This pass is the current implementation of all of the interfaces it
513 // implements as well.
515 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
516 for (unsigned i = 0, e = II.size(); i != e; ++i)
517 CurrentAnalyses[II[i]] = P;
520 // For now assume that our results are never used...
524 // For FunctionPass subclasses, we must be sure to batch the FunctionPass's
525 // together in a BatcherClass object so that all of the analyses are run
526 // together a function at a time.
528 void addPass(SubPassClass *MP, AnalysisUsage &AnUsage) {
529 if (Batcher == 0) // If we don't have a batcher yet, make one now.
530 Batcher = new BatcherClass(this);
531 // The Batcher will queue the passes up
532 MP->addToPassManager(Batcher, AnUsage);
535 // closeBatcher - Terminate the batcher that is being worked on.
536 void closeBatcher() {
538 Passes.push_back(Batcher);
544 // When an ImmutablePass is added, it gets added to the top level pass
546 void addPass(ImmutablePass *IP, AnalysisUsage &AU) {
547 if (Parent) { // Make sure this request goes to the top level passmanager...
548 Parent->addPass(IP, AU);
552 // Set the Resolver instance variable in the Pass so that it knows where to
553 // find this object...
555 setAnalysisResolver(IP, this);
556 ImmutablePasses.push_back(IP);
558 // All Required analyses should be available to the pass as it initializes!
559 // Here we fill in the AnalysisImpls member of the pass so that it can
560 // successfully use the getAnalysis() method to retrieve the implementations
563 IP->AnalysisImpls.clear();
564 IP->AnalysisImpls.reserve(AU.getRequiredSet().size());
565 for (std::vector<const PassInfo *>::const_iterator
566 I = AU.getRequiredSet().begin(),
567 E = AU.getRequiredSet().end(); I != E; ++I) {
568 Pass *Impl = getAnalysisOrNullUp(*I);
570 std::cerr << "Analysis '" << (*I)->getPassName()
571 << "' used but not available!";
572 assert(0 && "Analysis used but not available!");
573 } else if (PassDebugging == Details) {
574 if ((*I)->getPassName() != std::string(Impl->getPassName()))
575 std::cerr << " Interface '" << (*I)->getPassName()
576 << "' implemented by '" << Impl->getPassName() << "'\n";
578 IP->AnalysisImpls.push_back(std::make_pair(*I, Impl));
581 // Initialize the immutable pass...
582 IP->initializePass();
588 //===----------------------------------------------------------------------===//
589 // PassManagerTraits<BasicBlock> Specialization
591 // This pass manager is used to group together all of the BasicBlockPass's
592 // into a single unit.
594 template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass {
595 // PassClass - The type of passes tracked by this PassManager
596 typedef BasicBlockPass PassClass;
598 // SubPassClass - The types of classes that should be collated together
599 // This is impossible to match, so BasicBlock instantiations of PassManagerT
602 typedef PassManagerT<Module> SubPassClass;
604 // BatcherClass - The type to use for collation of subtypes... This class is
605 // never instantiated for the PassManager<BasicBlock>, but it must be an
606 // instance of PassClass to typecheck.
608 typedef PassClass BatcherClass;
610 // ParentClass - The type of the parent PassManager...
611 typedef PassManagerT<Function> ParentClass;
613 // PMType - The type of the passmanager that subclasses this class
614 typedef PassManagerT<BasicBlock> PMType;
616 // runPass - Specify how the pass should be run on the UnitType
617 static bool runPass(PassClass *P, BasicBlock *M) {
618 // todo, init and finalize
619 return P->runOnBasicBlock(*M);
622 // Dummy implementation of PassStarted/PassEnded
623 static void PassStarted(Pass *P) {}
624 static void PassEnded(Pass *P) {}
626 // getPMName() - Return the name of the unit the PassManager operates on for
628 const char *getPMName() const { return "BasicBlock"; }
629 virtual const char *getPassName() const { return "BasicBlock Pass Manager"; }
631 // Implement the BasicBlockPass interface...
632 virtual bool doInitialization(Module &M);
633 virtual bool doInitialization(Function &F);
634 virtual bool runOnBasicBlock(BasicBlock &BB);
635 virtual bool doFinalization(Function &F);
636 virtual bool doFinalization(Module &M);
638 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
639 AU.setPreservesAll();
645 //===----------------------------------------------------------------------===//
646 // PassManagerTraits<Function> Specialization
648 // This pass manager is used to group together all of the FunctionPass's
649 // into a single unit.
651 template<> struct PassManagerTraits<Function> : public FunctionPass {
652 // PassClass - The type of passes tracked by this PassManager
653 typedef FunctionPass PassClass;
655 // SubPassClass - The types of classes that should be collated together
656 typedef BasicBlockPass SubPassClass;
658 // BatcherClass - The type to use for collation of subtypes...
659 typedef PassManagerT<BasicBlock> BatcherClass;
661 // ParentClass - The type of the parent PassManager...
662 typedef PassManagerT<Module> ParentClass;
664 // PMType - The type of the passmanager that subclasses this class
665 typedef PassManagerT<Function> PMType;
667 // runPass - Specify how the pass should be run on the UnitType
668 static bool runPass(PassClass *P, Function *F) {
669 return P->runOnFunction(*F);
672 // Dummy implementation of PassStarted/PassEnded
673 static void PassStarted(Pass *P) {}
674 static void PassEnded(Pass *P) {}
676 // getPMName() - Return the name of the unit the PassManager operates on for
678 const char *getPMName() const { return "Function"; }
679 virtual const char *getPassName() const { return "Function Pass Manager"; }
681 // Implement the FunctionPass interface...
682 virtual bool doInitialization(Module &M);
683 virtual bool runOnFunction(Function &F);
684 virtual bool doFinalization(Module &M);
686 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
687 AU.setPreservesAll();
693 //===----------------------------------------------------------------------===//
694 // PassManagerTraits<Module> Specialization
696 // This is the top level PassManager implementation that holds generic passes.
698 template<> struct PassManagerTraits<Module> : public Pass {
699 // PassClass - The type of passes tracked by this PassManager
700 typedef Pass PassClass;
702 // SubPassClass - The types of classes that should be collated together
703 typedef FunctionPass SubPassClass;
705 // BatcherClass - The type to use for collation of subtypes...
706 typedef PassManagerT<Function> BatcherClass;
708 // ParentClass - The type of the parent PassManager...
709 typedef AnalysisResolver ParentClass;
711 // runPass - Specify how the pass should be run on the UnitType
712 static bool runPass(PassClass *P, Module *M) { return P->run(*M); }
714 // getPMName() - Return the name of the unit the PassManager operates on for
716 const char *getPMName() const { return "Module"; }
717 virtual const char *getPassName() const { return "Module Pass Manager"; }
719 // TimingInformation - This data member maintains timing information for each
720 // of the passes that is executed.
722 TimingInfo *TimeInfo;
724 // PassStarted/Ended - This callback is notified any time a pass is started
725 // or stops. This is used to collect timing information about the different
726 // passes being executed.
728 void PassStarted(Pass *P) {
729 if (TimeInfo) TimeInfo->passStarted(P);
731 void PassEnded(Pass *P) {
732 if (TimeInfo) TimeInfo->passEnded(P);
735 // run - Implement the PassManager interface...
736 bool run(Module &M) {
737 TimeInfo = TimingInfo::create();
738 bool Result = ((PassManagerT<Module>*)this)->runOnUnit(&M);
746 // PassManagerTraits constructor - Create a timing info object if the user
747 // specified timing info should be collected on the command line.
749 PassManagerTraits() : TimeInfo(0) {}
754 //===----------------------------------------------------------------------===//
755 // PassManagerTraits Method Implementations
758 // PassManagerTraits<BasicBlock> Implementations
760 inline bool PassManagerTraits<BasicBlock>::doInitialization(Module &M) {
761 bool Changed = false;
762 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
763 ((PMType*)this)->Passes[i]->doInitialization(M);
767 inline bool PassManagerTraits<BasicBlock>::doInitialization(Function &F) {
768 bool Changed = false;
769 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
770 ((PMType*)this)->Passes[i]->doInitialization(F);
774 inline bool PassManagerTraits<BasicBlock>::runOnBasicBlock(BasicBlock &BB) {
775 return ((PMType*)this)->runOnUnit(&BB);
778 inline bool PassManagerTraits<BasicBlock>::doFinalization(Function &F) {
779 bool Changed = false;
780 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
781 ((PMType*)this)->Passes[i]->doFinalization(F);
785 inline bool PassManagerTraits<BasicBlock>::doFinalization(Module &M) {
786 bool Changed = false;
787 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
788 ((PMType*)this)->Passes[i]->doFinalization(M);
793 // PassManagerTraits<Function> Implementations
795 inline bool PassManagerTraits<Function>::doInitialization(Module &M) {
796 bool Changed = false;
797 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
798 ((PMType*)this)->Passes[i]->doInitialization(M);
802 inline bool PassManagerTraits<Function>::runOnFunction(Function &F) {
803 return ((PMType*)this)->runOnUnit(&F);
806 inline bool PassManagerTraits<Function>::doFinalization(Module &M) {
807 bool Changed = false;
808 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
809 ((PMType*)this)->Passes[i]->doFinalization(M);