PassManager.cpp revision 861967815396df9f8b01327197fd2715d2c7555c
1//===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
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.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the LLVM Pass Manager infrastructure.
11//
12//===----------------------------------------------------------------------===//
13
14
15#include "llvm/PassManager.h"
16#include "llvm/Module.h"
17#include "llvm/ModuleProvider.h"
18#include <vector>
19#include <map>
20
21using namespace llvm;
22
23namespace llvm {
24
25/// CommonPassManagerImpl helps pass manager analysis required by
26/// the managed passes. It provides methods to add/remove analysis
27/// available and query if certain analysis is available or not.
28class CommonPassManagerImpl {
29
30public:
31
32  /// Return true IFF pass P's required analysis set does not required new
33  /// manager.
34  bool manageablePass(Pass *P);
35
36  Pass *getAnalysisPass(AnalysisID AID) const {
37
38    std::map<AnalysisID, Pass*>::const_iterator I =
39      AvailableAnalysis.find(AID);
40
41    if (I != AvailableAnalysis.end())
42      return NULL;
43    else
44      return I->second;
45  }
46
47  /// Augment RequiredAnalysis by adding analysis required by pass P.
48  void noteDownRequiredAnalysis(Pass *P);
49
50  /// Augment AvailableAnalysis by adding analysis made available by pass P.
51  void noteDownAvailableAnalysis(Pass *P);
52
53  /// Remove Analysis that is not preserved by the pass
54  void removeNotPreservedAnalysis(Pass *P);
55
56  /// Remove dead passes
57  void removeDeadPasses(Pass *P);
58
59  /// Add pass P into the PassVector. Update RequiredAnalysis and
60  /// AvailableAnalysis appropriately if ProcessAnalysis is true.
61  void addPassToManager (Pass *P, bool ProcessAnalysis = true);
62
63  /// Clear analysis vectors RequiredAnalysis and AvailableAnalysis.
64  /// This is used before running passes managed by the manager.
65  void clearAnalysis() {
66    RequiredAnalysis.clear();
67    AvailableAnalysis.clear();
68    LastUser.clear();
69  }
70
71  // All Required analyses should be available to the pass as it runs!  Here
72  // we fill in the AnalysisImpls member of the pass so that it can
73  // successfully use the getAnalysis() method to retrieve the
74  // implementations it needs.
75  //
76 void initializeAnalysisImpl(Pass *P);
77
78  inline std::vector<Pass *>::iterator passVectorBegin() {
79    return PassVector.begin();
80  }
81
82  inline std::vector<Pass *>::iterator passVectorEnd() {
83    return PassVector.end();
84  }
85
86  inline void setLastUser(Pass *P, Pass *LU) {
87    LastUser[P] = LU;
88    // TODO : Check if pass P is available.
89  }
90
91private:
92  // Analysis required by the passes managed by this manager. This information
93  // used while selecting pass manager during addPass. If a pass does not
94  // preserve any analysis required by other passes managed by current
95  // pass manager then new pass manager is used.
96  std::vector<AnalysisID> RequiredAnalysis;
97
98  // Set of available Analysis. This information is used while scheduling
99  // pass. If a pass requires an analysis which is not not available then
100  // equired analysis pass is scheduled to run before the pass itself is
101  // scheduled to run.
102  std::map<AnalysisID, Pass*> AvailableAnalysis;
103
104  // Map to keep track of last user of the analysis pass.
105  // LastUser->second is the last user of Lastuser->first.
106  std::map<Pass *, Pass *> LastUser;
107
108  // Collection of pass that are managed by this manager
109  std::vector<Pass *> PassVector;
110};
111
112/// BasicBlockPassManager_New manages BasicBlockPass. It batches all the
113/// pass together and sequence them to process one basic block before
114/// processing next basic block.
115class BasicBlockPassManager_New : public CommonPassManagerImpl,
116                                  public FunctionPass {
117
118public:
119  BasicBlockPassManager_New() { }
120
121  /// Add a pass into a passmanager queue.
122  bool addPass(Pass *p);
123
124  /// Execute all of the passes scheduled for execution.  Keep track of
125  /// whether any of the passes modifies the function, and if so, return true.
126  bool runOnFunction(Function &F);
127
128  /// Return true IFF AnalysisID AID is currently available.
129  Pass *getAnalysisPassFromManager(AnalysisID AID);
130
131private:
132};
133
134/// FunctionPassManagerImpl_New manages FunctionPasses and BasicBlockPassManagers.
135/// It batches all function passes and basic block pass managers together and
136/// sequence them to process one function at a time before processing next
137/// function.
138class FunctionPassManagerImpl_New : public CommonPassManagerImpl,
139                                    public ModulePass {
140public:
141  FunctionPassManagerImpl_New(ModuleProvider *P) { /* TODO */ }
142  FunctionPassManagerImpl_New() {
143    activeBBPassManager = NULL;
144  }
145  ~FunctionPassManagerImpl_New() { /* TODO */ };
146
147  /// add - Add a pass to the queue of passes to run.  This passes
148  /// ownership of the Pass to the PassManager.  When the
149  /// PassManager_X is destroyed, the pass will be destroyed as well, so
150  /// there is no need to delete the pass. (TODO delete passes.)
151  /// This implies that all passes MUST be allocated with 'new'.
152  void add(Pass *P) { /* TODO*/  }
153
154  /// Add pass into the pass manager queue.
155  bool addPass(Pass *P);
156
157  /// Execute all of the passes scheduled for execution.  Keep
158  /// track of whether any of the passes modifies the function, and if
159  /// so, return true.
160  bool runOnModule(Module &M);
161
162  /// Return true IFF AnalysisID AID is currently available.
163  Pass *getAnalysisPassFromManager(AnalysisID AID);
164
165  /// doInitialization - Run all of the initializers for the function passes.
166  ///
167  bool doInitialization(Module &M);
168
169  /// doFinalization - Run all of the initializers for the function passes.
170  ///
171  bool doFinalization(Module &M);
172private:
173  // Active Pass Managers
174  BasicBlockPassManager_New *activeBBPassManager;
175};
176
177/// ModulePassManager_New manages ModulePasses and function pass managers.
178/// It batches all Module passes  passes and function pass managers together and
179/// sequence them to process one module.
180class ModulePassManager_New : public CommonPassManagerImpl {
181
182public:
183  ModulePassManager_New() { activeFunctionPassManager = NULL; }
184
185  /// Add a pass into a passmanager queue.
186  bool addPass(Pass *p);
187
188  /// run - Execute all of the passes scheduled for execution.  Keep track of
189  /// whether any of the passes modifies the module, and if so, return true.
190  bool runOnModule(Module &M);
191
192  /// Return true IFF AnalysisID AID is currently available.
193  Pass *getAnalysisPassFromManager(AnalysisID AID);
194
195private:
196  // Active Pass Manager
197  FunctionPassManagerImpl_New *activeFunctionPassManager;
198};
199
200/// PassManager_New manages ModulePassManagers
201class PassManagerImpl_New : public CommonPassManagerImpl {
202
203public:
204
205  /// add - Add a pass to the queue of passes to run.  This passes ownership of
206  /// the Pass to the PassManager.  When the PassManager is destroyed, the pass
207  /// will be destroyed as well, so there is no need to delete the pass.  This
208  /// implies that all passes MUST be allocated with 'new'.
209  void add(Pass *P);
210
211  /// run - Execute all of the passes scheduled for execution.  Keep track of
212  /// whether any of the passes modifies the module, and if so, return true.
213  bool run(Module &M);
214
215  /// Return true IFF AnalysisID AID is currently available.
216  Pass *getAnalysisPassFromManager(AnalysisID AID);
217
218private:
219
220  /// Add a pass into a passmanager queue. This is used by schedulePasses
221  bool addPass(Pass *p);
222
223  /// Schedule pass P for execution. Make sure that passes required by
224  /// P are run before P is run. Update analysis info maintained by
225  /// the manager. Remove dead passes. This is a recursive function.
226  void schedulePass(Pass *P);
227
228  /// Schedule all passes collected in pass queue using add(). Add all the
229  /// schedule passes into various manager's queue using addPass().
230  void schedulePasses();
231
232  // Collection of pass managers
233  std::vector<ModulePassManager_New *> PassManagers;
234
235  // Active Pass Manager
236  ModulePassManager_New *activeManager;
237};
238
239} // End of llvm namespace
240
241// CommonPassManagerImpl implementation
242
243/// Return true IFF pass P's required analysis set does not required new
244/// manager.
245bool CommonPassManagerImpl::manageablePass(Pass *P) {
246
247  AnalysisUsage AnUsage;
248  P->getAnalysisUsage(AnUsage);
249
250  // If this pass is not preserving information that is required by the other
251  // passes managed by this manager then use new manager
252  if (!AnUsage.getPreservesAll()) {
253    const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
254    for (std::vector<AnalysisID>::iterator I = RequiredAnalysis.begin(),
255           E = RequiredAnalysis.end(); I != E; ++I) {
256      if (std::find(PreservedSet.begin(), PreservedSet.end(), *I) ==
257          PreservedSet.end())
258        // This analysis is not preserved. Need new manager.
259        return false;
260    }
261  }
262  return true;
263}
264
265/// Augment RequiredAnalysis by adding analysis required by pass P.
266void CommonPassManagerImpl::noteDownRequiredAnalysis(Pass *P) {
267  AnalysisUsage AnUsage;
268  P->getAnalysisUsage(AnUsage);
269  const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
270
271  // FIXME: What about duplicates ?
272  RequiredAnalysis.insert(RequiredAnalysis.end(), RequiredSet.begin(),
273                          RequiredSet.end());
274
275  initializeAnalysisImpl(P);
276}
277
278/// Augement AvailableAnalysis by adding analysis made available by pass P.
279void CommonPassManagerImpl::noteDownAvailableAnalysis(Pass *P) {
280
281  if (const PassInfo *PI = P->getPassInfo()) {
282    AvailableAnalysis[PI] = P;
283
284    //TODO This pass is the current implementation of all of the interfaces it
285    //TODO implements as well.
286    //TODO
287    //TODO const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
288    //TODO for (unsigned i = 0, e = II.size(); i != e; ++i)
289    //TODO CurrentAnalyses[II[i]] = P;
290  }
291}
292
293/// Remove Analyss not preserved by Pass P
294void CommonPassManagerImpl::removeNotPreservedAnalysis(Pass *P) {
295  AnalysisUsage AnUsage;
296  P->getAnalysisUsage(AnUsage);
297  const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
298
299  for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
300         E = AvailableAnalysis.end(); I != E; ++I ) {
301    if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) ==
302        PreservedSet.end()) {
303      // Remove this analysis
304      std::map<AnalysisID, Pass*>::iterator J = I++;
305      AvailableAnalysis.erase(J);
306    }
307  }
308}
309
310/// Remove analysis passes that are not used any longer
311void CommonPassManagerImpl::removeDeadPasses(Pass *P) {
312
313  for (std::map<Pass *, Pass *>::iterator I = LastUser.begin(),
314         E = LastUser.end(); I !=E; ++I) {
315    if (I->second == P) {
316      Pass *deadPass = I->first;
317      deadPass->releaseMemory();
318
319      std::map<AnalysisID, Pass*>::iterator Pos =
320        AvailableAnalysis.find(deadPass->getPassInfo());
321
322      assert (Pos != AvailableAnalysis.end() &&
323              "Pass is not available");
324      AvailableAnalysis.erase(Pos);
325    }
326  }
327}
328
329/// Add pass P into the PassVector. Update RequiredAnalysis and
330/// AvailableAnalysis appropriately if ProcessAnalysis is true.
331void CommonPassManagerImpl::addPassToManager (Pass *P,
332                                              bool ProcessAnalysis) {
333
334  if (ProcessAnalysis) {
335    // Take a note of analysis required and made available by this pass
336    noteDownRequiredAnalysis(P);
337    noteDownAvailableAnalysis(P);
338
339    // Remove the analysis not preserved by this pass
340    removeNotPreservedAnalysis(P);
341  }
342
343  // Add pass
344  PassVector.push_back(P);
345}
346
347// All Required analyses should be available to the pass as it runs!  Here
348// we fill in the AnalysisImpls member of the pass so that it can
349// successfully use the getAnalysis() method to retrieve the
350// implementations it needs.
351//
352void CommonPassManagerImpl::initializeAnalysisImpl(Pass *P) {
353  AnalysisUsage AnUsage;
354  P->getAnalysisUsage(AnUsage);
355
356  for (std::vector<const PassInfo *>::const_iterator
357         I = AnUsage.getRequiredSet().begin(),
358         E = AnUsage.getRequiredSet().end(); I != E; ++I) {
359    Pass *Impl = getAnalysisPass(*I);
360    if (Impl == 0)
361      assert(0 && "Analysis used but not available!");
362    // TODO:  P->AnalysisImpls.push_back(std::make_pair(*I, Impl));
363  }
364}
365
366/// BasicBlockPassManager implementation
367
368/// Add pass P into PassVector and return true. If this pass is not
369/// manageable by this manager then return false.
370bool
371BasicBlockPassManager_New::addPass(Pass *P) {
372
373  BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
374  if (!BP)
375    return false;
376
377  // If this pass does not preserve anlysis that is used by other passes
378  // managed by this manager than it is not a suiable pass for this manager.
379  if (!manageablePass(P))
380    return false;
381
382  addPassToManager (BP);
383
384  return true;
385}
386
387/// Execute all of the passes scheduled for execution by invoking
388/// runOnBasicBlock method.  Keep track of whether any of the passes modifies
389/// the function, and if so, return true.
390bool
391BasicBlockPassManager_New::runOnFunction(Function &F) {
392
393  bool Changed = false;
394  clearAnalysis();
395
396  for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
397    for (std::vector<Pass *>::iterator itr = passVectorBegin(),
398           e = passVectorEnd(); itr != e; ++itr) {
399      Pass *P = *itr;
400
401      noteDownAvailableAnalysis(P);
402      BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P);
403      Changed |= BP->runOnBasicBlock(*I);
404      removeNotPreservedAnalysis(P);
405      removeDeadPasses(P);
406    }
407  return Changed;
408}
409
410/// Return true IFF AnalysisID AID is currently available.
411Pass * BasicBlockPassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
412  return getAnalysisPass(AID);
413}
414
415// FunctionPassManager_New implementation
416/// Create new Function pass manager
417FunctionPassManager_New::FunctionPassManager_New() {
418  FPM = new FunctionPassManagerImpl_New();
419}
420
421/// add - Add a pass to the queue of passes to run.  This passes
422/// ownership of the Pass to the PassManager.  When the
423/// PassManager_X is destroyed, the pass will be destroyed as well, so
424/// there is no need to delete the pass. (TODO delete passes.)
425/// This implies that all passes MUST be allocated with 'new'.
426void
427FunctionPassManager_New::add(Pass *P) {
428  FPM->add(P);
429}
430
431/// Execute all of the passes scheduled for execution.  Keep
432/// track of whether any of the passes modifies the function, and if
433/// so, return true.
434bool
435FunctionPassManager_New::runOnModule(Module &M) {
436  return FPM->runOnModule(M);
437}
438
439/// doInitialization - Run all of the initializers for the function passes.
440///
441bool FunctionPassManager_New::doInitialization() {
442  return FPM->doInitialization(*MP->getModule());
443}
444
445/// doFinalization - Run all of the initializers for the function passes.
446///
447bool FunctionPassManager_New::doFinalization() {
448  return FPM->doFinalization(*MP->getModule());
449}
450
451// FunctionPassManagerImpl_New implementation
452
453// FunctionPassManager
454
455/// Add pass P into the pass manager queue. If P is a BasicBlockPass then
456/// either use it into active basic block pass manager or create new basic
457/// block pass manager to handle pass P.
458bool
459FunctionPassManagerImpl_New::addPass(Pass *P) {
460
461  // If P is a BasicBlockPass then use BasicBlockPassManager_New.
462  if (BasicBlockPass *BP = dynamic_cast<BasicBlockPass*>(P)) {
463
464    if (!activeBBPassManager
465        || !activeBBPassManager->addPass(BP)) {
466
467      activeBBPassManager = new BasicBlockPassManager_New();
468      addPassToManager(activeBBPassManager, false);
469      if (!activeBBPassManager->addPass(BP))
470        assert(0 && "Unable to add Pass");
471    }
472    return true;
473  }
474
475  FunctionPass *FP = dynamic_cast<FunctionPass *>(P);
476  if (!FP)
477    return false;
478
479  // If this pass does not preserve anlysis that is used by other passes
480  // managed by this manager than it is not a suiable pass for this manager.
481  if (!manageablePass(P))
482    return false;
483
484  addPassToManager (FP);
485  activeBBPassManager = NULL;
486  return true;
487}
488
489/// Execute all of the passes scheduled for execution by invoking
490/// runOnFunction method.  Keep track of whether any of the passes modifies
491/// the function, and if so, return true.
492bool
493FunctionPassManagerImpl_New::runOnModule(Module &M) {
494
495  bool Changed = false;
496  clearAnalysis();
497
498  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
499    for (std::vector<Pass *>::iterator itr = passVectorBegin(),
500           e = passVectorEnd(); itr != e; ++itr) {
501      Pass *P = *itr;
502
503      noteDownAvailableAnalysis(P);
504      FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
505      Changed |= FP->runOnFunction(*I);
506      removeNotPreservedAnalysis(P);
507      removeDeadPasses(P);
508    }
509  return Changed;
510}
511
512/// Return true IFF AnalysisID AID is currently available.
513Pass *FunctionPassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
514
515  Pass *P = getAnalysisPass(AID);
516  if (P)
517    return P;
518
519  if (activeBBPassManager &&
520      activeBBPassManager->getAnalysisPass(AID) != 0)
521    return activeBBPassManager->getAnalysisPass(AID);
522
523  // TODO : Check inactive managers
524  return NULL;
525}
526
527inline bool FunctionPassManagerImpl_New::doInitialization(Module &M) {
528  bool Changed = false;
529
530  for (std::vector<Pass *>::iterator itr = passVectorBegin(),
531         e = passVectorEnd(); itr != e; ++itr) {
532    Pass *P = *itr;
533
534    FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
535    Changed |= FP->doInitialization(M);
536  }
537
538  return Changed;
539}
540
541inline bool FunctionPassManagerImpl_New::doFinalization(Module &M) {
542  bool Changed = false;
543
544  for (std::vector<Pass *>::iterator itr = passVectorBegin(),
545         e = passVectorEnd(); itr != e; ++itr) {
546    Pass *P = *itr;
547
548    FunctionPass *FP = dynamic_cast<FunctionPass*>(P);
549    Changed |= FP->doFinalization(M);
550  }
551
552
553  return Changed;
554}
555
556
557// ModulePassManager implementation
558
559/// Add P into pass vector if it is manageble. If P is a FunctionPass
560/// then use FunctionPassManagerImpl_New to manage it. Return false if P
561/// is not manageable by this manager.
562bool
563ModulePassManager_New::addPass(Pass *P) {
564
565  // If P is FunctionPass then use function pass maanager.
566  if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P)) {
567
568    activeFunctionPassManager = NULL;
569
570    if (!activeFunctionPassManager
571        || !activeFunctionPassManager->addPass(P)) {
572
573      activeFunctionPassManager = new FunctionPassManagerImpl_New();
574      addPassToManager(activeFunctionPassManager, false);
575      if (!activeFunctionPassManager->addPass(FP))
576        assert(0 && "Unable to add pass");
577    }
578    return true;
579  }
580
581  ModulePass *MP = dynamic_cast<ModulePass *>(P);
582  if (!MP)
583    return false;
584
585  // If this pass does not preserve anlysis that is used by other passes
586  // managed by this manager than it is not a suiable pass for this manager.
587  if (!manageablePass(P))
588    return false;
589
590  addPassToManager(MP);
591  activeFunctionPassManager = NULL;
592  return true;
593}
594
595
596/// Execute all of the passes scheduled for execution by invoking
597/// runOnModule method.  Keep track of whether any of the passes modifies
598/// the module, and if so, return true.
599bool
600ModulePassManager_New::runOnModule(Module &M) {
601  bool Changed = false;
602  clearAnalysis();
603
604  for (std::vector<Pass *>::iterator itr = passVectorBegin(),
605         e = passVectorEnd(); itr != e; ++itr) {
606    Pass *P = *itr;
607
608    noteDownAvailableAnalysis(P);
609    ModulePass *MP = dynamic_cast<ModulePass*>(P);
610    Changed |= MP->runOnModule(M);
611    removeNotPreservedAnalysis(P);
612    removeDeadPasses(P);
613  }
614  return Changed;
615}
616
617/// Return true IFF AnalysisID AID is currently available.
618Pass *ModulePassManager_New::getAnalysisPassFromManager(AnalysisID AID) {
619
620
621  Pass *P = getAnalysisPass(AID);
622  if (P)
623    return P;
624
625  if (activeFunctionPassManager &&
626      activeFunctionPassManager->getAnalysisPass(AID) != 0)
627    return activeFunctionPassManager->getAnalysisPass(AID);
628
629  // TODO : Check inactive managers
630  return NULL;
631}
632
633/// Return true IFF AnalysisID AID is currently available.
634Pass *PassManagerImpl_New::getAnalysisPassFromManager(AnalysisID AID) {
635
636  Pass *P = NULL;
637  for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
638         e = PassManagers.end(); !P && itr != e; ++itr)
639    P  = (*itr)->getAnalysisPassFromManager(AID);
640  return P;
641}
642
643/// Schedule pass P for execution. Make sure that passes required by
644/// P are run before P is run. Update analysis info maintained by
645/// the manager. Remove dead passes. This is a recursive function.
646void PassManagerImpl_New::schedulePass(Pass *P) {
647
648  AnalysisUsage AnUsage;
649  P->getAnalysisUsage(AnUsage);
650  const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
651  for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
652         E = RequiredSet.end(); I != E; ++I) {
653
654    Pass *AnalysisPass = getAnalysisPassFromManager(*I);
655    if (!AnalysisPass) {
656      // Schedule this analysis run first.
657      AnalysisPass = (*I)->createPass();
658      schedulePass(AnalysisPass);
659    }
660    setLastUser (AnalysisPass, P);
661
662    // Prolong live range of analyses that are needed after an analysis pass
663    // is destroyed, for querying by subsequent passes
664    const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
665    for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
666           E = IDs.end(); I != E; ++I) {
667      Pass *AP = getAnalysisPassFromManager(*I);
668      assert (AP && "Analysis pass is not available");
669      setLastUser(AP, P);
670    }
671  }
672  addPass(P);
673}
674
675/// Schedule all passes from the queue by adding them in their
676/// respective manager's queue.
677void PassManagerImpl_New::schedulePasses() {
678  for (std::vector<Pass *>::iterator I = passVectorBegin(),
679         E = passVectorEnd(); I != E; ++I)
680    schedulePass (*I);
681}
682
683/// Add pass P to the queue of passes to run.
684void PassManagerImpl_New::add(Pass *P) {
685  // Do not process Analysis now. Analysis is process while scheduling
686  // the pass vector.
687  addPassToManager(P, false);
688}
689
690// PassManager_New implementation
691/// Add P into active pass manager or use new module pass manager to
692/// manage it.
693bool PassManagerImpl_New::addPass(Pass *P) {
694
695  if (!activeManager || !activeManager->addPass(P)) {
696    activeManager = new ModulePassManager_New();
697    PassManagers.push_back(activeManager);
698  }
699
700  return activeManager->addPass(P);
701}
702
703/// run - Execute all of the passes scheduled for execution.  Keep track of
704/// whether any of the passes modifies the module, and if so, return true.
705bool PassManagerImpl_New::run(Module &M) {
706
707  schedulePasses();
708  bool Changed = false;
709  for (std::vector<ModulePassManager_New *>::iterator itr = PassManagers.begin(),
710         e = PassManagers.end(); itr != e; ++itr) {
711    ModulePassManager_New *pm = *itr;
712    Changed |= pm->runOnModule(M);
713  }
714  return Changed;
715}
716
717/// Create new pass manager
718PassManager_New::PassManager_New() {
719  PM = new PassManagerImpl_New();
720}
721
722/// add - Add a pass to the queue of passes to run.  This passes ownership of
723/// the Pass to the PassManager.  When the PassManager is destroyed, the pass
724/// will be destroyed as well, so there is no need to delete the pass.  This
725/// implies that all passes MUST be allocated with 'new'.
726void
727PassManager_New::add(Pass *P) {
728  PM->add(P);
729}
730
731/// run - Execute all of the passes scheduled for execution.  Keep track of
732/// whether any of the passes modifies the module, and if so, return true.
733bool
734PassManager_New::run(Module &M) {
735  return PM->run(M);
736}
737
738