blob: d4dfda02d66d9af91b9f44b2e833848093e2bcee [file] [log] [blame]
Chris Lattner67d25652002-01-30 23:20:39 +00001//===- llvm/PassManager.h - Container for Passes -----------------*- C++ -*--=//
2//
3// This file defines the PassManager 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.
7//
8// The PassManagerT template is instantiated three times to do its job.
9//
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_PASSMANAGER_H
13#define LLVM_PASSMANAGER_H
14
15#include "llvm/Pass.h"
16#include <string>
Chris Lattnerc8e66542002-04-27 06:56:12 +000017#include <algorithm>
Chris Lattnera454b5b2002-04-28 05:14:06 +000018class Annotable;
Chris Lattner67d25652002-01-30 23:20:39 +000019
Chris Lattner67d25652002-01-30 23:20:39 +000020//===----------------------------------------------------------------------===//
Chris Lattner57d2ba32002-04-04 19:35:24 +000021// PMDebug class - a set of debugging functions, that are not to be
22// instantiated by the template.
Chris Lattner67d25652002-01-30 23:20:39 +000023//
24struct PMDebug {
Chris Lattner67d25652002-01-30 23:20:39 +000025 // If compiled in debug mode, these functions can be enabled by setting
26 // -debug-pass on the command line of the tool being used.
27 //
28 static void PrintPassStructure(Pass *P);
Chris Lattnera454b5b2002-04-28 05:14:06 +000029 static void PrintPassInformation(unsigned,const char*,Pass *, Annotable *);
Chris Lattnerac3e0602002-01-31 18:32:27 +000030 static void PrintAnalysisSetInfo(unsigned,const char*,Pass *P,
Chris Lattnerc8e66542002-04-27 06:56:12 +000031 const std::vector<AnalysisID> &);
Chris Lattner67d25652002-01-30 23:20:39 +000032};
33
34
35
36//===----------------------------------------------------------------------===//
37// Declare the PassManagerTraits which will be specialized...
38//
39template<class UnitType> class PassManagerTraits; // Do not define.
40
41
42//===----------------------------------------------------------------------===//
43// PassManagerT - Container object for passes. The PassManagerT destructor
44// deletes all passes contained inside of the PassManagerT, so you shouldn't
45// delete passes manually, and all passes should be dynamically allocated.
46//
47template<typename UnitType>
48class PassManagerT : public PassManagerTraits<UnitType>,public AnalysisResolver{
49 typedef typename PassManagerTraits<UnitType>::PassClass PassClass;
50 typedef typename PassManagerTraits<UnitType>::SubPassClass SubPassClass;
51 typedef typename PassManagerTraits<UnitType>::BatcherClass BatcherClass;
52 typedef typename PassManagerTraits<UnitType>::ParentClass ParentClass;
53 typedef PassManagerTraits<UnitType> Traits;
54
55 friend typename PassManagerTraits<UnitType>::PassClass;
56 friend typename PassManagerTraits<UnitType>::SubPassClass;
57 friend class PassManagerTraits<UnitType>;
58
59 std::vector<PassClass*> Passes; // List of pass's to run
60
61 // The parent of this pass manager...
Chris Lattnerac3e0602002-01-31 18:32:27 +000062 ParentClass * const Parent;
Chris Lattner67d25652002-01-30 23:20:39 +000063
64 // The current batcher if one is in use, or null
65 BatcherClass *Batcher;
66
67 // CurrentAnalyses - As the passes are being run, this map contains the
68 // analyses that are available to the current pass for use. This is accessed
69 // through the getAnalysis() function in this class and in Pass.
70 //
71 std::map<AnalysisID, Pass*> CurrentAnalyses;
72
Chris Lattnerac3e0602002-01-31 18:32:27 +000073 // LastUseOf - This map keeps track of the last usage in our pipeline of a
74 // particular pass. When executing passes, the memory for .first is free'd
75 // after .second is run.
76 //
77 std::map<Pass*, Pass*> LastUseOf;
78
Chris Lattner67d25652002-01-30 23:20:39 +000079public:
80 PassManagerT(ParentClass *Par = 0) : Parent(Par), Batcher(0) {}
81 ~PassManagerT() {
82 // Delete all of the contained passes...
83 for (std::vector<PassClass*>::iterator I = Passes.begin(), E = Passes.end();
84 I != E; ++I)
85 delete *I;
86 }
87
88 // run - Run all of the queued passes on the specified module in an optimal
89 // way.
90 virtual bool runOnUnit(UnitType *M) {
91 bool MadeChanges = false;
92 closeBatcher();
93 CurrentAnalyses.clear();
94
Chris Lattnerac3e0602002-01-31 18:32:27 +000095 // LastUserOf - This contains the inverted LastUseOfMap...
96 std::map<Pass *, std::vector<Pass*> > LastUserOf;
97 for (std::map<Pass*, Pass*>::iterator I = LastUseOf.begin(),
98 E = LastUseOf.end(); I != E; ++I)
99 LastUserOf[I->second].push_back(I->first);
100
101
Chris Lattner67d25652002-01-30 23:20:39 +0000102 // Output debug information...
103 if (Parent == 0) PMDebug::PrintPassStructure(this);
104
105 // Run all of the passes
106 for (unsigned i = 0, e = Passes.size(); i < e; ++i) {
107 PassClass *P = Passes[i];
108
Chris Lattnera454b5b2002-04-28 05:14:06 +0000109 PMDebug::PrintPassInformation(getDepth(), "Executing Pass", P,
110 (Annotable*)M);
Chris Lattner67d25652002-01-30 23:20:39 +0000111
112 // Get information about what analyses the pass uses...
Chris Lattnerc8e66542002-04-27 06:56:12 +0000113 AnalysisUsage AnUsage;
114 P->getAnalysisUsage(AnUsage);
115 PMDebug::PrintAnalysisSetInfo(getDepth(), "Required", P,
116 AnUsage.getRequiredSet());
Chris Lattner67d25652002-01-30 23:20:39 +0000117
118#ifndef NDEBUG
119 // All Required analyses should be available to the pass as it runs!
Chris Lattnerc8e66542002-04-27 06:56:12 +0000120 for (vector<AnalysisID>::const_iterator
121 I = AnUsage.getRequiredSet().begin(),
122 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
Chris Lattner67d25652002-01-30 23:20:39 +0000123 assert(getAnalysisOrNullUp(*I) && "Analysis used but not available!");
124 }
125#endif
126
127 // Run the sub pass!
Chris Lattnerf2f31bd2002-02-01 04:53:36 +0000128 bool Changed = Traits::runPass(P, M);
129 MadeChanges |= Changed;
Chris Lattner67d25652002-01-30 23:20:39 +0000130
Chris Lattnerf2f31bd2002-02-01 04:53:36 +0000131 if (Changed)
132 PMDebug::PrintPassInformation(getDepth()+1, "Made Modification", P,
Chris Lattnera454b5b2002-04-28 05:14:06 +0000133 (Annotable*)M);
Chris Lattnerc8e66542002-04-27 06:56:12 +0000134 PMDebug::PrintAnalysisSetInfo(getDepth(), "Preserved", P,
135 AnUsage.getPreservedSet());
136 PMDebug::PrintAnalysisSetInfo(getDepth(), "Provided", P,
137 AnUsage.getProvidedSet());
Chris Lattner67d25652002-01-30 23:20:39 +0000138
Chris Lattnerc8e66542002-04-27 06:56:12 +0000139
140 // Erase all analyses not in the preserved set...
141 if (!AnUsage.preservesAll()) {
142 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
143 for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
144 E = CurrentAnalyses.end(); I != E; )
145 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) !=
146 PreservedSet.end())
147 ++I; // This analysis is preserved, leave it in the available set...
148 else {
149#if MAP_DOESNT_HAVE_BROKEN_ERASE_MEMBER
150 I = CurrentAnalyses.erase(I); // Analysis not preserved!
151#else
152 // GCC 2.95.3 STL doesn't have correct erase member!
153 CurrentAnalyses.erase(I);
154 I = CurrentAnalyses.begin();
155#endif
156 }
157 }
158
Chris Lattner67d25652002-01-30 23:20:39 +0000159 // Add all analyses in the provided set...
Chris Lattnerc8e66542002-04-27 06:56:12 +0000160 for (std::vector<AnalysisID>::const_iterator
161 I = AnUsage.getProvidedSet().begin(),
162 E = AnUsage.getProvidedSet().end(); I != E; ++I)
Chris Lattner67d25652002-01-30 23:20:39 +0000163 CurrentAnalyses[*I] = P;
Chris Lattnerac3e0602002-01-31 18:32:27 +0000164
165 // Free memory for any passes that we are the last use of...
166 std::vector<Pass*> &DeadPass = LastUserOf[P];
167 for (std::vector<Pass*>::iterator I = DeadPass.begin(),E = DeadPass.end();
168 I != E; ++I) {
169 PMDebug::PrintPassInformation(getDepth()+1, "Freeing Pass", *I,
Chris Lattnera454b5b2002-04-28 05:14:06 +0000170 (Annotable*)M);
Chris Lattnerac3e0602002-01-31 18:32:27 +0000171 (*I)->releaseMemory();
172 }
Chris Lattner67d25652002-01-30 23:20:39 +0000173 }
174 return MadeChanges;
175 }
176
Chris Lattnerac3e0602002-01-31 18:32:27 +0000177 // dumpPassStructure - Implement the -debug-passes=PassStructure option
178 virtual void dumpPassStructure(unsigned Offset = 0) {
179 std::cerr << std::string(Offset*2, ' ') << Traits::getPMName()
180 << " Pass Manager\n";
181 for (std::vector<PassClass*>::iterator I = Passes.begin(), E = Passes.end();
182 I != E; ++I) {
183 PassClass *P = *I;
184 P->dumpPassStructure(Offset+1);
185
186 // Loop through and see which classes are destroyed after this one...
187 for (std::map<Pass*, Pass*>::iterator I = LastUseOf.begin(),
188 E = LastUseOf.end(); I != E; ++I) {
189 if (P == I->second) {
190 std::cerr << "Fr" << std::string(Offset*2, ' ');
191 I->first->dumpPassStructure(0);
192 }
193 }
194 }
195 }
Chris Lattnerac3e0602002-01-31 18:32:27 +0000196
197 Pass *getAnalysisOrNullDown(AnalysisID ID) const {
198 std::map<AnalysisID, Pass*>::const_iterator I = CurrentAnalyses.find(ID);
199 if (I == CurrentAnalyses.end()) {
200 if (Batcher)
201 return ((AnalysisResolver*)Batcher)->getAnalysisOrNullDown(ID);
202 return 0;
203 }
204 return I->second;
205 }
206
207 Pass *getAnalysisOrNullUp(AnalysisID ID) const {
208 std::map<AnalysisID, Pass*>::const_iterator I = CurrentAnalyses.find(ID);
209 if (I == CurrentAnalyses.end()) {
210 if (Parent)
211 return Parent->getAnalysisOrNullUp(ID);
212 return 0;
213 }
214 return I->second;
215 }
216
217 // markPassUsed - Inform higher level pass managers (and ourselves)
218 // that these analyses are being used by this pass. This is used to
219 // make sure that analyses are not free'd before we have to use
220 // them...
221 //
222 void markPassUsed(AnalysisID P, Pass *User) {
223 std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.find(P);
224 if (I != CurrentAnalyses.end()) {
225 LastUseOf[I->second] = User; // Local pass, extend the lifetime
226 } else {
227 // Pass not in current available set, must be a higher level pass
228 // available to us, propogate to parent pass manager... We tell the
229 // parent that we (the passmanager) are using the analysis so that it
230 // frees the analysis AFTER this pass manager runs.
231 //
Chris Lattnerde421a72002-03-17 21:16:01 +0000232 assert(Parent != 0 && "Pass available but not found! "
233 "Did your analysis pass 'Provide' itself?");
Chris Lattnerac3e0602002-01-31 18:32:27 +0000234 Parent->markPassUsed(P, this);
235 }
236 }
237
238 // Return the number of parent PassManagers that exist
239 virtual unsigned getDepth() const {
240 if (Parent == 0) return 0;
241 return 1 + Parent->getDepth();
242 }
243
Chris Lattner67d25652002-01-30 23:20:39 +0000244 // add - Add a pass to the queue of passes to run. This passes ownership of
245 // the Pass to the PassManager. When the PassManager is destroyed, the pass
Chris Lattnerac3e0602002-01-31 18:32:27 +0000246 // will be destroyed as well, so there is no need to delete the pass. This
247 // implies that all passes MUST be new'd.
Chris Lattner67d25652002-01-30 23:20:39 +0000248 //
249 void add(PassClass *P) {
250 // Get information about what analyses the pass uses...
Chris Lattnerc8e66542002-04-27 06:56:12 +0000251 AnalysisUsage AnUsage;
252 P->getAnalysisUsage(AnUsage);
253 const std::vector<AnalysisID> &Required = AnUsage.getRequiredSet();
Chris Lattner67d25652002-01-30 23:20:39 +0000254
255 // Loop over all of the analyses used by this pass,
Chris Lattnerc8e66542002-04-27 06:56:12 +0000256 for (std::vector<AnalysisID>::const_iterator I = Required.begin(),
257 E = Required.end(); I != E; ++I) {
Chris Lattner67d25652002-01-30 23:20:39 +0000258 if (getAnalysisOrNullDown(*I) == 0)
Chris Lattner2eaac392002-01-31 00:40:44 +0000259 add((PassClass*)I->createPass());
Chris Lattner67d25652002-01-30 23:20:39 +0000260 }
261
262 // Tell the pass to add itself to this PassManager... the way it does so
263 // depends on the class of the pass, and is critical to laying out passes in
264 // an optimal order..
265 //
Chris Lattnerc8e66542002-04-27 06:56:12 +0000266 P->addToPassManager(this, AnUsage);
Chris Lattner67d25652002-01-30 23:20:39 +0000267 }
268
269private:
270
271 // addPass - These functions are used to implement the subclass specific
272 // behaviors present in PassManager. Basically the add(Pass*) method ends up
273 // reflecting its behavior into a Pass::addToPassManager call. Subclasses of
274 // Pass override it specifically so that they can reflect the type
275 // information inherent in "this" back to the PassManager.
276 //
277 // For generic Pass subclasses (which are interprocedural passes), we simply
278 // add the pass to the end of the pass list and terminate any accumulation of
Chris Lattnerc8e66542002-04-27 06:56:12 +0000279 // FunctionPass's that are present.
Chris Lattner67d25652002-01-30 23:20:39 +0000280 //
Chris Lattnerc8e66542002-04-27 06:56:12 +0000281 void addPass(PassClass *P, AnalysisUsage &AnUsage) {
282 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
283 const std::vector<AnalysisID> &ProvidedSet = AnUsage.getProvidedSet();
284
Chris Lattner67d25652002-01-30 23:20:39 +0000285 // Providers are analysis classes which are forbidden to modify the module
286 // they are operating on, so they are allowed to be reordered to before the
287 // batcher...
288 //
Chris Lattnerc8e66542002-04-27 06:56:12 +0000289 if (Batcher && ProvidedSet.empty())
Chris Lattner67d25652002-01-30 23:20:39 +0000290 closeBatcher(); // This pass cannot be batched!
291
292 // Set the Resolver instance variable in the Pass so that it knows where to
293 // find this object...
294 //
295 setAnalysisResolver(P, this);
296 Passes.push_back(P);
297
Chris Lattnerac3e0602002-01-31 18:32:27 +0000298 // Inform higher level pass managers (and ourselves) that these analyses are
299 // being used by this pass. This is used to make sure that analyses are not
300 // free'd before we have to use them...
301 //
Chris Lattnerc8e66542002-04-27 06:56:12 +0000302 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
303 E = RequiredSet.end(); I != E; ++I)
Chris Lattnerac3e0602002-01-31 18:32:27 +0000304 markPassUsed(*I, P); // Mark *I as used by P
305
Chris Lattnerc8e66542002-04-27 06:56:12 +0000306 // Erase all analyses not in the preserved set...
307 if (!AnUsage.preservesAll()) {
308 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
309 for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
310 E = CurrentAnalyses.end(); I != E; )
311 if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) !=
312 PreservedSet.end())
313 ++I; // This analysis is preserved, leave it in the available set...
314 else {
315#if MAP_DOESNT_HAVE_BROKEN_ERASE_MEMBER
316 I = CurrentAnalyses.erase(I); // Analysis not preserved!
317#else
318 CurrentAnalyses.erase(I);// GCC 2.95.3 STL doesn't have correct erase!
319 I = CurrentAnalyses.begin();
320#endif
321 }
322 }
Chris Lattner67d25652002-01-30 23:20:39 +0000323
324 // Add all analyses in the provided set...
Chris Lattnerc8e66542002-04-27 06:56:12 +0000325 for (std::vector<AnalysisID>::const_iterator I = ProvidedSet.begin(),
326 E = ProvidedSet.end(); I != E; ++I)
Chris Lattner67d25652002-01-30 23:20:39 +0000327 CurrentAnalyses[*I] = P;
Chris Lattnerac3e0602002-01-31 18:32:27 +0000328
329 // For now assume that our results are never used...
330 LastUseOf[P] = P;
Chris Lattner67d25652002-01-30 23:20:39 +0000331 }
332
Chris Lattnerc8e66542002-04-27 06:56:12 +0000333 // For FunctionPass subclasses, we must be sure to batch the FunctionPass's
334 // together in a BatcherClass object so that all of the analyses are run
335 // together a function at a time.
Chris Lattner67d25652002-01-30 23:20:39 +0000336 //
Chris Lattnerc8e66542002-04-27 06:56:12 +0000337 void addPass(SubPassClass *MP, AnalysisUsage &AnUsage) {
Chris Lattner67d25652002-01-30 23:20:39 +0000338 if (Batcher == 0) // If we don't have a batcher yet, make one now.
339 Batcher = new BatcherClass(this);
340 // The Batcher will queue them passes up
Chris Lattnerc8e66542002-04-27 06:56:12 +0000341 MP->addToPassManager(Batcher, AnUsage);
Chris Lattner67d25652002-01-30 23:20:39 +0000342 }
343
344 // closeBatcher - Terminate the batcher that is being worked on.
345 void closeBatcher() {
346 if (Batcher) {
347 Passes.push_back(Batcher);
348 Batcher = 0;
349 }
350 }
351};
352
353
354
355//===----------------------------------------------------------------------===//
356// PassManagerTraits<BasicBlock> Specialization
357//
358// This pass manager is used to group together all of the BasicBlockPass's
359// into a single unit.
360//
361template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass {
362 // PassClass - The type of passes tracked by this PassManager
363 typedef BasicBlockPass PassClass;
364
365 // SubPassClass - The types of classes that should be collated together
366 // This is impossible to match, so BasicBlock instantiations of PassManagerT
367 // do not collate.
368 //
369 typedef PassManagerT<Module> SubPassClass;
370
371 // BatcherClass - The type to use for collation of subtypes... This class is
372 // never instantiated for the PassManager<BasicBlock>, but it must be an
373 // instance of PassClass to typecheck.
374 //
375 typedef PassClass BatcherClass;
376
377 // ParentClass - The type of the parent PassManager...
Chris Lattner4e8c4872002-03-23 22:51:58 +0000378 typedef PassManagerT<Function> ParentClass;
Chris Lattner67d25652002-01-30 23:20:39 +0000379
Chris Lattner2eaac392002-01-31 00:40:44 +0000380 // PMType - The type of the passmanager that subclasses this class
381 typedef PassManagerT<BasicBlock> PMType;
382
Chris Lattner67d25652002-01-30 23:20:39 +0000383 // runPass - Specify how the pass should be run on the UnitType
384 static bool runPass(PassClass *P, BasicBlock *M) {
385 // todo, init and finalize
386 return P->runOnBasicBlock(M);
387 }
388
Chris Lattnerac3e0602002-01-31 18:32:27 +0000389 // getPMName() - Return the name of the unit the PassManager operates on for
390 // debugging.
391 const char *getPMName() const { return "BasicBlock"; }
392
Chris Lattner2eaac392002-01-31 00:40:44 +0000393 // Implement the BasicBlockPass interface...
394 virtual bool doInitialization(Module *M);
Chris Lattner67d25652002-01-30 23:20:39 +0000395 virtual bool runOnBasicBlock(BasicBlock *BB);
Chris Lattner2eaac392002-01-31 00:40:44 +0000396 virtual bool doFinalization(Module *M);
Chris Lattner67d25652002-01-30 23:20:39 +0000397};
398
399
400
401//===----------------------------------------------------------------------===//
Chris Lattner4e8c4872002-03-23 22:51:58 +0000402// PassManagerTraits<Function> Specialization
Chris Lattner67d25652002-01-30 23:20:39 +0000403//
Chris Lattnerc8e66542002-04-27 06:56:12 +0000404// This pass manager is used to group together all of the FunctionPass's
Chris Lattner67d25652002-01-30 23:20:39 +0000405// into a single unit.
406//
Chris Lattnerc8e66542002-04-27 06:56:12 +0000407template<> struct PassManagerTraits<Function> : public FunctionPass {
Chris Lattner67d25652002-01-30 23:20:39 +0000408 // PassClass - The type of passes tracked by this PassManager
Chris Lattnerc8e66542002-04-27 06:56:12 +0000409 typedef FunctionPass PassClass;
Chris Lattner67d25652002-01-30 23:20:39 +0000410
411 // SubPassClass - The types of classes that should be collated together
412 typedef BasicBlockPass SubPassClass;
413
414 // BatcherClass - The type to use for collation of subtypes...
415 typedef PassManagerT<BasicBlock> BatcherClass;
416
417 // ParentClass - The type of the parent PassManager...
418 typedef PassManagerT<Module> ParentClass;
419
420 // PMType - The type of the passmanager that subclasses this class
Chris Lattner4e8c4872002-03-23 22:51:58 +0000421 typedef PassManagerT<Function> PMType;
Chris Lattner67d25652002-01-30 23:20:39 +0000422
423 // runPass - Specify how the pass should be run on the UnitType
Chris Lattnerc8e66542002-04-27 06:56:12 +0000424 static bool runPass(PassClass *P, Function *F) {
425 return P->runOnFunction(F);
Chris Lattner67d25652002-01-30 23:20:39 +0000426 }
427
Chris Lattnerac3e0602002-01-31 18:32:27 +0000428 // getPMName() - Return the name of the unit the PassManager operates on for
429 // debugging.
Chris Lattner4e8c4872002-03-23 22:51:58 +0000430 const char *getPMName() const { return "Function"; }
Chris Lattnerac3e0602002-01-31 18:32:27 +0000431
Chris Lattnerc8e66542002-04-27 06:56:12 +0000432 // Implement the FunctionPass interface...
Chris Lattner67d25652002-01-30 23:20:39 +0000433 virtual bool doInitialization(Module *M);
Chris Lattnerc8e66542002-04-27 06:56:12 +0000434 virtual bool runOnFunction(Function *F);
Chris Lattner67d25652002-01-30 23:20:39 +0000435 virtual bool doFinalization(Module *M);
436};
437
438
439
440//===----------------------------------------------------------------------===//
441// PassManagerTraits<Module> Specialization
442//
443// This is the top level PassManager implementation that holds generic passes.
444//
445template<> struct PassManagerTraits<Module> : public Pass {
446 // PassClass - The type of passes tracked by this PassManager
447 typedef Pass PassClass;
448
449 // SubPassClass - The types of classes that should be collated together
Chris Lattnerc8e66542002-04-27 06:56:12 +0000450 typedef FunctionPass SubPassClass;
Chris Lattner67d25652002-01-30 23:20:39 +0000451
452 // BatcherClass - The type to use for collation of subtypes...
Chris Lattner4e8c4872002-03-23 22:51:58 +0000453 typedef PassManagerT<Function> BatcherClass;
Chris Lattner67d25652002-01-30 23:20:39 +0000454
455 // ParentClass - The type of the parent PassManager...
Chris Lattnerac3e0602002-01-31 18:32:27 +0000456 typedef AnalysisResolver ParentClass;
Chris Lattner67d25652002-01-30 23:20:39 +0000457
458 // runPass - Specify how the pass should be run on the UnitType
459 static bool runPass(PassClass *P, Module *M) { return P->run(M); }
460
Chris Lattnerac3e0602002-01-31 18:32:27 +0000461 // getPMName() - Return the name of the unit the PassManager operates on for
462 // debugging.
463 const char *getPMName() const { return "Module"; }
464
Chris Lattner67d25652002-01-30 23:20:39 +0000465 // run - Implement the Pass interface...
466 virtual bool run(Module *M) {
467 return ((PassManagerT<Module>*)this)->runOnUnit(M);
468 }
469};
470
471
472
473//===----------------------------------------------------------------------===//
474// PassManagerTraits Method Implementations
475//
476
477// PassManagerTraits<BasicBlock> Implementations
478//
Chris Lattner2eaac392002-01-31 00:40:44 +0000479inline bool PassManagerTraits<BasicBlock>::doInitialization(Module *M) {
480 bool Changed = false;
481 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
482 ((PMType*)this)->Passes[i]->doInitialization(M);
483 return Changed;
484}
485
Chris Lattner67d25652002-01-30 23:20:39 +0000486inline bool PassManagerTraits<BasicBlock>::runOnBasicBlock(BasicBlock *BB) {
Chris Lattner2eaac392002-01-31 00:40:44 +0000487 return ((PMType*)this)->runOnUnit(BB);
488}
489
490inline bool PassManagerTraits<BasicBlock>::doFinalization(Module *M) {
491 bool Changed = false;
492 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
493 ((PMType*)this)->Passes[i]->doFinalization(M);
494 return Changed;
Chris Lattner67d25652002-01-30 23:20:39 +0000495}
496
497
Chris Lattner4e8c4872002-03-23 22:51:58 +0000498// PassManagerTraits<Function> Implementations
Chris Lattner67d25652002-01-30 23:20:39 +0000499//
Chris Lattner4e8c4872002-03-23 22:51:58 +0000500inline bool PassManagerTraits<Function>::doInitialization(Module *M) {
Chris Lattner67d25652002-01-30 23:20:39 +0000501 bool Changed = false;
502 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
503 ((PMType*)this)->Passes[i]->doInitialization(M);
504 return Changed;
505}
506
Chris Lattnerc8e66542002-04-27 06:56:12 +0000507inline bool PassManagerTraits<Function>::runOnFunction(Function *F) {
508 return ((PMType*)this)->runOnUnit(F);
Chris Lattner67d25652002-01-30 23:20:39 +0000509}
510
Chris Lattner4e8c4872002-03-23 22:51:58 +0000511inline bool PassManagerTraits<Function>::doFinalization(Module *M) {
Chris Lattner67d25652002-01-30 23:20:39 +0000512 bool Changed = false;
513 for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
514 ((PMType*)this)->Passes[i]->doFinalization(M);
515 return Changed;
516}
517
518#endif