blob: d48c198bbffe82b020df7336520038495e17dc9b [file] [log] [blame]
Devang Patel6e5a1132006-11-07 21:31:57 +00001//===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Devang Patelca58e352006-11-08 10:05:38 +00005// This file was developed by Devang Patel and is distributed under
Devang Patel6e5a1132006-11-07 21:31:57 +00006// 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
Devang Patele7599552007-01-12 18:52:44 +000015#include "llvm/PassManagers.h"
Devang Patelf1567a52006-12-13 20:03:48 +000016#include "llvm/Support/CommandLine.h"
Devang Patelb8817b92006-12-14 00:59:42 +000017#include "llvm/Support/Timer.h"
Devang Patel6e5a1132006-11-07 21:31:57 +000018#include "llvm/Module.h"
Devang Patelff631ae2006-11-15 01:27:05 +000019#include "llvm/ModuleProvider.h"
Bill Wendlingdfc91892006-11-28 02:09:03 +000020#include "llvm/Support/Streams.h"
Devang Patelb8817b92006-12-14 00:59:42 +000021#include "llvm/Support/ManagedStatic.h"
Devang Patela9844592006-11-11 01:31:05 +000022#include <vector>
Devang Patelf60b5d92006-11-14 01:59:59 +000023#include <map>
Devang Patelffca9102006-12-15 19:39:30 +000024
Devang Patele7599552007-01-12 18:52:44 +000025// See PassManagers.h for Pass Manager infrastructure overview.
Devang Patel6fea2852006-12-07 18:23:30 +000026
Devang Patelf1567a52006-12-13 20:03:48 +000027namespace llvm {
28
29//===----------------------------------------------------------------------===//
30// Pass debugging information. Often it is useful to find out what pass is
31// running when a crash occurs in a utility. When this library is compiled with
32// debugging on, a command line option (--debug-pass) is enabled that causes the
33// pass name to be printed before it executes.
34//
35
Devang Patel03fb5872006-12-13 21:13:31 +000036// Different debug levels that can be enabled...
37enum PassDebugLevel {
38 None, Arguments, Structure, Executions, Details
39};
40
Devang Patelf1567a52006-12-13 20:03:48 +000041static cl::opt<enum PassDebugLevel>
42PassDebugging_New("debug-pass", cl::Hidden,
43 cl::desc("Print PassManager debugging information"),
44 cl::values(
Devang Patel03fb5872006-12-13 21:13:31 +000045 clEnumVal(None , "disable debug output"),
46 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
47 clEnumVal(Structure , "print pass structure before run()"),
48 clEnumVal(Executions, "print pass name before it is executed"),
49 clEnumVal(Details , "print pass details when it is executed"),
Devang Patelf1567a52006-12-13 20:03:48 +000050 clEnumValEnd));
51} // End of llvm namespace
52
Devang Patelffca9102006-12-15 19:39:30 +000053namespace {
Devang Patelafb1f3622006-12-12 22:35:25 +000054
Devang Patelf33f3eb2006-12-07 19:21:29 +000055//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +000056// BBPassManager
Devang Patel10c2ca62006-12-12 22:47:13 +000057//
Devang Patel67d6a5e2006-12-19 19:46:59 +000058/// BBPassManager manages BasicBlockPass. It batches all the
Devang Patelca58e352006-11-08 10:05:38 +000059/// pass together and sequence them to process one basic block before
60/// processing next basic block.
Devang Patel67d6a5e2006-12-19 19:46:59 +000061class VISIBILITY_HIDDEN BBPassManager : public PMDataManager,
62 public FunctionPass {
Devang Patelca58e352006-11-08 10:05:38 +000063
64public:
Devang Patel67d6a5e2006-12-19 19:46:59 +000065 BBPassManager(int Depth) : PMDataManager(Depth) { }
Devang Patelca58e352006-11-08 10:05:38 +000066
Devang Patelca58e352006-11-08 10:05:38 +000067 /// Execute all of the passes scheduled for execution. Keep track of
68 /// whether any of the passes modifies the function, and if so, return true.
69 bool runOnFunction(Function &F);
70
Devang Patelf9d96b92006-12-07 19:57:52 +000071 /// Pass Manager itself does not invalidate any analysis info.
72 void getAnalysisUsage(AnalysisUsage &Info) const {
73 Info.setPreservesAll();
74 }
75
Devang Patel475c4532006-12-08 00:59:05 +000076 bool doInitialization(Module &M);
77 bool doInitialization(Function &F);
78 bool doFinalization(Module &M);
79 bool doFinalization(Function &F);
80
Devang Pateleda56172006-12-12 23:34:33 +000081 // Print passes managed by this manager
82 void dumpPassStructure(unsigned Offset) {
Devang Patelffca9102006-12-15 19:39:30 +000083 llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +000084 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
85 BasicBlockPass *BP = getContainedPass(Index);
86 BP->dumpPassStructure(Offset + 1);
87 dumpLastUses(BP, Offset+1);
Devang Pateleda56172006-12-12 23:34:33 +000088 }
89 }
Devang Patelabfbe3b2006-12-16 00:56:26 +000090
91 BasicBlockPass *getContainedPass(unsigned N) {
92 assert ( N < PassVector.size() && "Pass number out of range!");
93 BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
94 return BP;
95 }
Devang Patel3b3f8992007-01-11 01:10:25 +000096
97 virtual PassManagerType getPassManagerType() {
98 return PMT_BasicBlockPassManager;
99 }
Devang Patelca58e352006-11-08 10:05:38 +0000100};
101
Devang Patele7599552007-01-12 18:52:44 +0000102}
Devang Patel67d6a5e2006-12-19 19:46:59 +0000103
Devang Patele7599552007-01-12 18:52:44 +0000104namespace llvm {
Devang Patelca58e352006-11-08 10:05:38 +0000105
Devang Patel10c2ca62006-12-12 22:47:13 +0000106//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000107// FunctionPassManagerImpl
Devang Patel10c2ca62006-12-12 22:47:13 +0000108//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000109/// FunctionPassManagerImpl manages FPPassManagers
110class FunctionPassManagerImpl : public Pass,
Devang Patelad98d232007-01-11 22:15:30 +0000111 public PMDataManager,
112 public PMTopLevelManager {
Devang Patel67d6a5e2006-12-19 19:46:59 +0000113public:
114
Devang Patel0f080042007-01-12 17:23:48 +0000115 FunctionPassManagerImpl(int Depth) : PMDataManager(Depth) { }
Devang Patel67d6a5e2006-12-19 19:46:59 +0000116
117 /// add - Add a pass to the queue of passes to run. This passes ownership of
118 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
119 /// will be destroyed as well, so there is no need to delete the pass. This
120 /// implies that all passes MUST be allocated with 'new'.
121 void add(Pass *P) {
122 schedulePass(P);
123 }
124
125 /// run - Execute all of the passes scheduled for execution. Keep track of
126 /// whether any of the passes modifies the module, and if so, return true.
127 bool run(Function &F);
128
129 /// doInitialization - Run all of the initializers for the function passes.
130 ///
131 bool doInitialization(Module &M);
132
133 /// doFinalization - Run all of the initializers for the function passes.
134 ///
135 bool doFinalization(Module &M);
136
137 /// Pass Manager itself does not invalidate any analysis info.
138 void getAnalysisUsage(AnalysisUsage &Info) const {
139 Info.setPreservesAll();
140 }
141
142 inline void addTopLevelPass(Pass *P) {
143
144 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
145
146 // P is a immutable pass and it will be managed by this
147 // top level manager. Set up analysis resolver to connect them.
Devang Patelb66334b2007-01-05 22:47:07 +0000148 AnalysisResolver *AR = new AnalysisResolver(*this);
Devang Patel67d6a5e2006-12-19 19:46:59 +0000149 P->setResolver(AR);
150 initializeAnalysisImpl(P);
151 addImmutablePass(IP);
152 recordAvailableAnalysis(IP);
Devang Patel0f080042007-01-12 17:23:48 +0000153 } else {
154 // Assign manager
155 if (activeStack.empty()) {
156 FPPassManager *FPP = new FPPassManager(getDepth() + 1);
157 FPP->setTopLevelManager(this->getTopLevelManager());
158 addPassManager(FPP);
159 activeStack.push(FPP);
160 }
161 P->assignPassManager(activeStack);
Devang Patel67d6a5e2006-12-19 19:46:59 +0000162 }
Devang Patel0f080042007-01-12 17:23:48 +0000163
Devang Patel67d6a5e2006-12-19 19:46:59 +0000164 }
165
166 FPPassManager *getContainedManager(unsigned N) {
167 assert ( N < PassManagers.size() && "Pass number out of range!");
168 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
169 return FP;
170 }
171
Devang Patel67d6a5e2006-12-19 19:46:59 +0000172};
173
174//===----------------------------------------------------------------------===//
175// MPPassManager
176//
177/// MPPassManager manages ModulePasses and function pass managers.
Devang Patelca58e352006-11-08 10:05:38 +0000178/// It batches all Module passes passes and function pass managers together and
179/// sequence them to process one module.
Devang Patel67d6a5e2006-12-19 19:46:59 +0000180class MPPassManager : public Pass, public PMDataManager {
Devang Patelca58e352006-11-08 10:05:38 +0000181
182public:
Devang Patel0f080042007-01-12 17:23:48 +0000183 MPPassManager(int Depth) : PMDataManager(Depth) { }
Devang Patelca58e352006-11-08 10:05:38 +0000184
185 /// run - Execute all of the passes scheduled for execution. Keep track of
186 /// whether any of the passes modifies the module, and if so, return true.
187 bool runOnModule(Module &M);
Devang Patelebba9702006-11-13 22:40:09 +0000188
Devang Patelf9d96b92006-12-07 19:57:52 +0000189 /// Pass Manager itself does not invalidate any analysis info.
190 void getAnalysisUsage(AnalysisUsage &Info) const {
191 Info.setPreservesAll();
192 }
193
Devang Pateleda56172006-12-12 23:34:33 +0000194 // Print passes managed by this manager
195 void dumpPassStructure(unsigned Offset) {
196 llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +0000197 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
198 ModulePass *MP = getContainedPass(Index);
199 MP->dumpPassStructure(Offset + 1);
200 dumpLastUses(MP, Offset+1);
Devang Pateleda56172006-12-12 23:34:33 +0000201 }
202 }
203
Devang Patelabfbe3b2006-12-16 00:56:26 +0000204 ModulePass *getContainedPass(unsigned N) {
205 assert ( N < PassVector.size() && "Pass number out of range!");
206 ModulePass *MP = static_cast<ModulePass *>(PassVector[N]);
207 return MP;
208 }
209
Devang Patel3b3f8992007-01-11 01:10:25 +0000210 virtual PassManagerType getPassManagerType() { return PMT_ModulePassManager; }
Devang Patelca58e352006-11-08 10:05:38 +0000211};
212
Devang Patel10c2ca62006-12-12 22:47:13 +0000213//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000214// PassManagerImpl
Devang Patel10c2ca62006-12-12 22:47:13 +0000215//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000216/// PassManagerImpl manages MPPassManagers
217class PassManagerImpl : public Pass,
Devang Patelad98d232007-01-11 22:15:30 +0000218 public PMDataManager,
219 public PMTopLevelManager {
Devang Patel376fefa2006-11-08 10:29:57 +0000220
221public:
222
Devang Patel0f080042007-01-12 17:23:48 +0000223 PassManagerImpl(int Depth) : PMDataManager(Depth) { }
Devang Patel4c36e6b2006-12-07 23:24:58 +0000224
Devang Patel376fefa2006-11-08 10:29:57 +0000225 /// add - Add a pass to the queue of passes to run. This passes ownership of
226 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
227 /// will be destroyed as well, so there is no need to delete the pass. This
228 /// implies that all passes MUST be allocated with 'new'.
Devang Patel31217af2006-12-07 21:32:57 +0000229 void add(Pass *P) {
Devang Pateldf6c9ae2006-12-08 22:34:02 +0000230 schedulePass(P);
Devang Patel31217af2006-12-07 21:32:57 +0000231 }
Devang Patel376fefa2006-11-08 10:29:57 +0000232
233 /// run - Execute all of the passes scheduled for execution. Keep track of
234 /// whether any of the passes modifies the module, and if so, return true.
235 bool run(Module &M);
236
Devang Patelf9d96b92006-12-07 19:57:52 +0000237 /// Pass Manager itself does not invalidate any analysis info.
238 void getAnalysisUsage(AnalysisUsage &Info) const {
239 Info.setPreservesAll();
240 }
241
Devang Patelabcd1d32006-12-07 21:27:23 +0000242 inline void addTopLevelPass(Pass *P) {
Devang Pateld440cd92006-12-08 23:53:00 +0000243
Devang Patelfa971cd2006-12-08 23:57:43 +0000244 if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
Devang Pateld440cd92006-12-08 23:53:00 +0000245
246 // P is a immutable pass and it will be managed by this
247 // top level manager. Set up analysis resolver to connect them.
Devang Patelb66334b2007-01-05 22:47:07 +0000248 AnalysisResolver *AR = new AnalysisResolver(*this);
Devang Pateld440cd92006-12-08 23:53:00 +0000249 P->setResolver(AR);
Devang Patel95257542006-12-12 22:21:37 +0000250 initializeAnalysisImpl(P);
Devang Patelfa971cd2006-12-08 23:57:43 +0000251 addImmutablePass(IP);
Devang Patel95257542006-12-12 22:21:37 +0000252 recordAvailableAnalysis(IP);
Devang Patel0f080042007-01-12 17:23:48 +0000253 } else {
254
255 // Assign manager
256 if (activeStack.empty()) {
257 MPPassManager *MPP = new MPPassManager(getDepth() + 1);
258 MPP->setTopLevelManager(this->getTopLevelManager());
259 addPassManager(MPP);
260 activeStack.push(MPP);
261 }
262
263 P->assignPassManager(activeStack);
Devang Pateld440cd92006-12-08 23:53:00 +0000264 }
Devang Patel0f080042007-01-12 17:23:48 +0000265
Devang Patelabcd1d32006-12-07 21:27:23 +0000266 }
267
Devang Patel67d6a5e2006-12-19 19:46:59 +0000268 MPPassManager *getContainedManager(unsigned N) {
269 assert ( N < PassManagers.size() && "Pass number out of range!");
270 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
271 return MP;
272 }
273
Devang Patel376fefa2006-11-08 10:29:57 +0000274};
275
Devang Patelffca9102006-12-15 19:39:30 +0000276} // End of llvm namespace
277
278namespace {
279
Devang Patelb8817b92006-12-14 00:59:42 +0000280//===----------------------------------------------------------------------===//
281// TimingInfo Class - This class is used to calculate information about the
282// amount of time each pass takes to execute. This only happens when
283// -time-passes is enabled on the command line.
284//
285
Devang Patelffca9102006-12-15 19:39:30 +0000286class VISIBILITY_HIDDEN TimingInfo {
Devang Patelb8817b92006-12-14 00:59:42 +0000287 std::map<Pass*, Timer> TimingData;
288 TimerGroup TG;
289
290public:
291 // Use 'create' member to get this.
292 TimingInfo() : TG("... Pass execution timing report ...") {}
293
294 // TimingDtor - Print out information about timing information
295 ~TimingInfo() {
296 // Delete all of the timers...
297 TimingData.clear();
298 // TimerGroup is deleted next, printing the report.
299 }
300
301 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
302 // to a non null value (if the -time-passes option is enabled) or it leaves it
303 // null. It may be called multiple times.
304 static void createTheTimeInfo();
305
306 void passStarted(Pass *P) {
307
308 if (dynamic_cast<PMDataManager *>(P))
309 return;
310
311 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
312 if (I == TimingData.end())
313 I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
314 I->second.startTimer();
315 }
316 void passEnded(Pass *P) {
317
318 if (dynamic_cast<PMDataManager *>(P))
319 return;
320
321 std::map<Pass*, Timer>::iterator I = TimingData.find(P);
322 assert (I != TimingData.end() && "passStarted/passEnded not nested right!");
323 I->second.stopTimer();
324 }
325};
326
327static TimingInfo *TheTimeInfo;
328
Devang Patelffca9102006-12-15 19:39:30 +0000329} // End of anon namespace
Devang Patelca58e352006-11-08 10:05:38 +0000330
Devang Patela1514cb2006-12-07 19:39:39 +0000331//===----------------------------------------------------------------------===//
Devang Patelafb1f3622006-12-12 22:35:25 +0000332// PMTopLevelManager implementation
333
334/// Set pass P as the last user of the given analysis passes.
335void PMTopLevelManager::setLastUser(std::vector<Pass *> &AnalysisPasses,
336 Pass *P) {
337
338 for (std::vector<Pass *>::iterator I = AnalysisPasses.begin(),
339 E = AnalysisPasses.end(); I != E; ++I) {
340 Pass *AP = *I;
341 LastUser[AP] = P;
342 // If AP is the last user of other passes then make P last user of
343 // such passes.
344 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
345 LUE = LastUser.end(); LUI != LUE; ++LUI) {
346 if (LUI->second == AP)
347 LastUser[LUI->first] = P;
348 }
349 }
Devang Patelafb1f3622006-12-12 22:35:25 +0000350}
351
352/// Collect passes whose last user is P
353void PMTopLevelManager::collectLastUses(std::vector<Pass *> &LastUses,
354 Pass *P) {
355 for (std::map<Pass *, Pass *>::iterator LUI = LastUser.begin(),
356 LUE = LastUser.end(); LUI != LUE; ++LUI)
357 if (LUI->second == P)
358 LastUses.push_back(LUI->first);
359}
360
361/// Schedule pass P for execution. Make sure that passes required by
362/// P are run before P is run. Update analysis info maintained by
363/// the manager. Remove dead passes. This is a recursive function.
364void PMTopLevelManager::schedulePass(Pass *P) {
365
366 // TODO : Allocate function manager for this pass, other wise required set
367 // may be inserted into previous function manager
368
369 AnalysisUsage AnUsage;
370 P->getAnalysisUsage(AnUsage);
371 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
372 for (std::vector<AnalysisID>::const_iterator I = RequiredSet.begin(),
373 E = RequiredSet.end(); I != E; ++I) {
374
375 Pass *AnalysisPass = findAnalysisPass(*I);
376 if (!AnalysisPass) {
377 // Schedule this analysis run first.
378 AnalysisPass = (*I)->createPass();
379 schedulePass(AnalysisPass);
380 }
381 }
382
383 // Now all required passes are available.
384 addTopLevelPass(P);
385}
386
387/// Find the pass that implements Analysis AID. Search immutable
388/// passes and all pass managers. If desired pass is not found
389/// then return NULL.
390Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
391
392 Pass *P = NULL;
Devang Patelcd6ba152006-12-12 22:50:05 +0000393 // Check pass managers
394 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
395 E = PassManagers.end(); P == NULL && I != E; ++I) {
396 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
397 assert(PMD && "This is not a PassManager");
398 P = PMD->findAnalysisPass(AID, false);
399 }
400
401 // Check other pass managers
402 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
403 E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
404 P = (*I)->findAnalysisPass(AID, false);
405
Devang Patelafb1f3622006-12-12 22:35:25 +0000406 for (std::vector<ImmutablePass *>::iterator I = ImmutablePasses.begin(),
407 E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
408 const PassInfo *PI = (*I)->getPassInfo();
409 if (PI == AID)
410 P = *I;
411
412 // If Pass not found then check the interfaces implemented by Immutable Pass
413 if (!P) {
Devang Patel56d48ec2006-12-15 22:57:49 +0000414 const std::vector<const PassInfo*> &ImmPI = PI->getInterfacesImplemented();
415 if (std::find(ImmPI.begin(), ImmPI.end(), AID) != ImmPI.end())
416 P = *I;
Devang Patelafb1f3622006-12-12 22:35:25 +0000417 }
418 }
419
Devang Patelafb1f3622006-12-12 22:35:25 +0000420 return P;
421}
422
Devang Pateleda56172006-12-12 23:34:33 +0000423// Print passes managed by this top level manager.
Devang Patel991aeba2006-12-15 20:13:01 +0000424void PMTopLevelManager::dumpPasses() const {
Devang Pateleda56172006-12-12 23:34:33 +0000425
Devang Patel67d6a5e2006-12-19 19:46:59 +0000426 if (PassDebugging_New < Structure)
427 return;
428
Devang Pateleda56172006-12-12 23:34:33 +0000429 // Print out the immutable passes
430 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
431 ImmutablePasses[i]->dumpPassStructure(0);
432 }
433
Devang Patel991aeba2006-12-15 20:13:01 +0000434 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
Devang Pateleda56172006-12-12 23:34:33 +0000435 E = PassManagers.end(); I != E; ++I)
436 (*I)->dumpPassStructure(1);
Devang Pateleda56172006-12-12 23:34:33 +0000437}
438
Devang Patel991aeba2006-12-15 20:13:01 +0000439void PMTopLevelManager::dumpArguments() const {
Devang Patelcfd70c42006-12-13 22:10:00 +0000440
441 if (PassDebugging_New < Arguments)
442 return;
443
444 cerr << "Pass Arguments: ";
Devang Patel991aeba2006-12-15 20:13:01 +0000445 for (std::vector<Pass *>::const_iterator I = PassManagers.begin(),
Devang Patelcfd70c42006-12-13 22:10:00 +0000446 E = PassManagers.end(); I != E; ++I) {
447 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
448 assert(PMD && "This is not a PassManager");
449 PMD->dumpPassArguments();
450 }
451 cerr << "\n";
452}
453
Devang Patele3068402006-12-21 00:16:50 +0000454void PMTopLevelManager::initializeAllAnalysisInfo() {
455
456 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
457 E = PassManagers.end(); I != E; ++I) {
458 PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I);
459 assert(PMD && "This is not a PassManager");
460 PMD->initializeAnalysisInfo();
461 }
462
463 // Initailize other pass managers
464 for (std::vector<PMDataManager *>::iterator I = IndirectPassManagers.begin(),
465 E = IndirectPassManagers.end(); I != E; ++I)
466 (*I)->initializeAnalysisInfo();
467}
468
Devang Patele7599552007-01-12 18:52:44 +0000469/// Destructor
470PMTopLevelManager::~PMTopLevelManager() {
471 for (std::vector<Pass *>::iterator I = PassManagers.begin(),
472 E = PassManagers.end(); I != E; ++I)
473 delete *I;
474
475 for (std::vector<ImmutablePass *>::iterator
476 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
477 delete *I;
478
479 PassManagers.clear();
480}
481
Devang Patelafb1f3622006-12-12 22:35:25 +0000482//===----------------------------------------------------------------------===//
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000483// PMDataManager implementation
Devang Patelf68a3492006-11-07 22:35:17 +0000484
Devang Pateld65e9e92006-11-08 01:31:28 +0000485/// Return true IFF pass P's required analysis set does not required new
Devang Patelf68a3492006-11-07 22:35:17 +0000486/// manager.
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000487bool PMDataManager::manageablePass(Pass *P) {
Devang Patelf68a3492006-11-07 22:35:17 +0000488
Devang Patel8f677ce2006-12-07 18:47:25 +0000489 // TODO
490 // If this pass is not preserving information that is required by a
491 // pass maintained by higher level pass manager then do not insert
492 // this pass into current manager. Use new manager. For example,
493 // For example, If FunctionPass F is not preserving ModulePass Info M1
494 // that is used by another ModulePass M2 then do not insert F in
495 // current function pass manager.
Devang Patelf68a3492006-11-07 22:35:17 +0000496 return true;
497}
498
Devang Patel643676c2006-11-11 01:10:19 +0000499/// Augement AvailableAnalysis by adding analysis made available by pass P.
Devang Patele9976aa2006-12-07 19:33:53 +0000500void PMDataManager::recordAvailableAnalysis(Pass *P) {
Devang Patelf60b5d92006-11-14 01:59:59 +0000501
Devang Patel643676c2006-11-11 01:10:19 +0000502 if (const PassInfo *PI = P->getPassInfo()) {
Devang Patelf60b5d92006-11-14 01:59:59 +0000503 AvailableAnalysis[PI] = P;
Devang Patel643676c2006-11-11 01:10:19 +0000504
Devang Patele9976aa2006-12-07 19:33:53 +0000505 //This pass is the current implementation of all of the interfaces it
506 //implements as well.
507 const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
508 for (unsigned i = 0, e = II.size(); i != e; ++i)
509 AvailableAnalysis[II[i]] = P;
Devang Patel643676c2006-11-11 01:10:19 +0000510 }
511}
512
Devang Patelf68a3492006-11-07 22:35:17 +0000513/// Remove Analyss not preserved by Pass P
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000514void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
Devang Patel349170f2006-11-11 01:24:55 +0000515 AnalysisUsage AnUsage;
516 P->getAnalysisUsage(AnUsage);
Devang Patelf68a3492006-11-07 22:35:17 +0000517
Devang Patel2e169c32006-12-07 20:03:49 +0000518 if (AnUsage.getPreservesAll())
519 return;
520
521 const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
Devang Patelf60b5d92006-11-14 01:59:59 +0000522 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
Devang Patelbe6bd55e2006-12-12 23:07:44 +0000523 E = AvailableAnalysis.end(); I != E; ) {
Devang Patel56d48ec2006-12-15 22:57:49 +0000524 std::map<AnalysisID, Pass*>::iterator Info = I++;
525 if (std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
Devang Patel349170f2006-11-11 01:24:55 +0000526 PreservedSet.end()) {
527 // Remove this analysis
Devang Patel56d48ec2006-12-15 22:57:49 +0000528 if (!dynamic_cast<ImmutablePass*>(Info->second))
529 AvailableAnalysis.erase(Info);
530 }
Devang Patel349170f2006-11-11 01:24:55 +0000531 }
Devang Patelf68a3492006-11-07 22:35:17 +0000532}
533
Devang Patelca189262006-11-14 03:05:08 +0000534/// Remove analysis passes that are not used any longer
Devang Patel200d3052006-12-13 23:50:44 +0000535void PMDataManager::removeDeadPasses(Pass *P, std::string &Msg) {
Devang Patel17ad0962006-12-08 00:37:52 +0000536
537 std::vector<Pass *> DeadPasses;
538 TPM->collectLastUses(DeadPasses, P);
539
540 for (std::vector<Pass *>::iterator I = DeadPasses.begin(),
541 E = DeadPasses.end(); I != E; ++I) {
Devang Patel200d3052006-12-13 23:50:44 +0000542
543 std::string Msg1 = " Freeing Pass '";
544 dumpPassInfo(*I, Msg1, Msg);
545
Devang Patelb8817b92006-12-14 00:59:42 +0000546 if (TheTimeInfo) TheTimeInfo->passStarted(P);
Devang Patel17ad0962006-12-08 00:37:52 +0000547 (*I)->releaseMemory();
Devang Patelb8817b92006-12-14 00:59:42 +0000548 if (TheTimeInfo) TheTimeInfo->passEnded(P);
549
Devang Patel17ad0962006-12-08 00:37:52 +0000550 std::map<AnalysisID, Pass*>::iterator Pos =
551 AvailableAnalysis.find((*I)->getPassInfo());
552
Devang Patel475c4532006-12-08 00:59:05 +0000553 // It is possible that pass is already removed from the AvailableAnalysis
Devang Patel17ad0962006-12-08 00:37:52 +0000554 if (Pos != AvailableAnalysis.end())
555 AvailableAnalysis.erase(Pos);
556 }
Devang Patelca189262006-11-14 03:05:08 +0000557}
558
Devang Patel8f677ce2006-12-07 18:47:25 +0000559/// Add pass P into the PassVector. Update
Devang Patel90b05e02006-11-11 02:04:19 +0000560/// AvailableAnalysis appropriately if ProcessAnalysis is true.
Devang Patelf85793d2007-01-12 20:07:16 +0000561void PMDataManager::add(Pass *P,
Devang Patel2e169c32006-12-07 20:03:49 +0000562 bool ProcessAnalysis) {
Devang Patel8cad70d2006-11-11 01:51:02 +0000563
Devang Pateld440cd92006-12-08 23:53:00 +0000564 // This manager is going to manage pass P. Set up analysis resolver
565 // to connect them.
Devang Patelb66334b2007-01-05 22:47:07 +0000566 AnalysisResolver *AR = new AnalysisResolver(*this);
Devang Pateld440cd92006-12-08 23:53:00 +0000567 P->setResolver(AR);
568
Devang Patel90b05e02006-11-11 02:04:19 +0000569 if (ProcessAnalysis) {
Devang Patelbc03f132006-12-07 23:55:10 +0000570
571 // At the moment, this pass is the last user of all required passes.
572 std::vector<Pass *> LastUses;
573 std::vector<Pass *> RequiredPasses;
574 unsigned PDepth = this->getDepth();
575
576 collectRequiredAnalysisPasses(RequiredPasses, P);
577 for (std::vector<Pass *>::iterator I = RequiredPasses.begin(),
578 E = RequiredPasses.end(); I != E; ++I) {
579 Pass *PRequired = *I;
580 unsigned RDepth = 0;
Devang Patel64619be2006-12-09 00:07:38 +0000581
582 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
583 RDepth = DM.getDepth();
584
Devang Patelbc03f132006-12-07 23:55:10 +0000585 if (PDepth == RDepth)
586 LastUses.push_back(PRequired);
587 else if (PDepth > RDepth) {
588 // Let the parent claim responsibility of last use
Devang Patel832bc072006-12-15 00:08:26 +0000589 TransferLastUses.push_back(PRequired);
Devang Patelbc03f132006-12-07 23:55:10 +0000590 } else {
591 // Note : This feature is not yet implemented
592 assert (0 &&
593 "Unable to handle Pass that requires lower level Analysis pass");
594 }
595 }
596
Devang Patel39786a92007-01-15 20:31:54 +0000597 // Set P as P's last user until someone starts using P.
598 // However, if P is a Pass Manager then it does not need
599 // to record its last user.
600 if (!dynamic_cast<PMDataManager *>(P)) {
601 LastUses.push_back(P);
602 TPM->setLastUser(LastUses, P);
603 }
Devang Patelbc03f132006-12-07 23:55:10 +0000604
Devang Patel17bff0d2006-12-07 22:09:36 +0000605 // Take a note of analysis required and made available by this pass.
Devang Patel90b05e02006-11-11 02:04:19 +0000606 // Remove the analysis not preserved by this pass
607 removeNotPreservedAnalysis(P);
Devang Patel17bff0d2006-12-07 22:09:36 +0000608 recordAvailableAnalysis(P);
Devang Patel90b05e02006-11-11 02:04:19 +0000609 }
Devang Patel8cad70d2006-11-11 01:51:02 +0000610
611 // Add pass
612 PassVector.push_back(P);
Devang Patel8cad70d2006-11-11 01:51:02 +0000613}
614
Devang Patel1d6267c2006-12-07 23:05:44 +0000615/// Populate RequiredPasses with the analysis pass that are required by
616/// pass P.
617void PMDataManager::collectRequiredAnalysisPasses(std::vector<Pass *> &RP,
618 Pass *P) {
619 AnalysisUsage AnUsage;
620 P->getAnalysisUsage(AnUsage);
621 const std::vector<AnalysisID> &RequiredSet = AnUsage.getRequiredSet();
622 for (std::vector<AnalysisID>::const_iterator
623 I = RequiredSet.begin(), E = RequiredSet.end();
624 I != E; ++I) {
Devang Patel640c5bb2006-12-08 22:30:11 +0000625 Pass *AnalysisPass = findAnalysisPass(*I, true);
Devang Patel1d6267c2006-12-07 23:05:44 +0000626 assert (AnalysisPass && "Analysis pass is not available");
627 RP.push_back(AnalysisPass);
628 }
Devang Patelf58183d2006-12-12 23:09:32 +0000629
630 const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
631 for (std::vector<AnalysisID>::const_iterator I = IDs.begin(),
632 E = IDs.end(); I != E; ++I) {
633 Pass *AnalysisPass = findAnalysisPass(*I, true);
634 assert (AnalysisPass && "Analysis pass is not available");
635 RP.push_back(AnalysisPass);
636 }
Devang Patel1d6267c2006-12-07 23:05:44 +0000637}
638
Devang Patel07f4f582006-11-14 21:49:36 +0000639// All Required analyses should be available to the pass as it runs! Here
640// we fill in the AnalysisImpls member of the pass so that it can
641// successfully use the getAnalysis() method to retrieve the
642// implementations it needs.
643//
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000644void PMDataManager::initializeAnalysisImpl(Pass *P) {
Devang Patelff631ae2006-11-15 01:27:05 +0000645 AnalysisUsage AnUsage;
646 P->getAnalysisUsage(AnUsage);
Devang Patel07f4f582006-11-14 21:49:36 +0000647
648 for (std::vector<const PassInfo *>::const_iterator
649 I = AnUsage.getRequiredSet().begin(),
650 E = AnUsage.getRequiredSet().end(); I != E; ++I) {
Devang Patel640c5bb2006-12-08 22:30:11 +0000651 Pass *Impl = findAnalysisPass(*I, true);
Devang Patel07f4f582006-11-14 21:49:36 +0000652 if (Impl == 0)
653 assert(0 && "Analysis used but not available!");
Devang Patelb66334b2007-01-05 22:47:07 +0000654 AnalysisResolver *AR = P->getResolver();
Devang Patel984698a2006-12-09 01:11:34 +0000655 AR->addAnalysisImplsPair(*I, Impl);
Devang Patel07f4f582006-11-14 21:49:36 +0000656 }
657}
658
Devang Patel640c5bb2006-12-08 22:30:11 +0000659/// Find the pass that implements Analysis AID. If desired pass is not found
660/// then return NULL.
661Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
662
663 // Check if AvailableAnalysis map has one entry.
664 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
665
666 if (I != AvailableAnalysis.end())
667 return I->second;
668
669 // Search Parents through TopLevelManager
670 if (SearchParent)
671 return TPM->findAnalysisPass(AID);
672
Devang Patel9d759b82006-12-09 00:09:12 +0000673 return NULL;
Devang Patel640c5bb2006-12-08 22:30:11 +0000674}
675
Devang Patel991aeba2006-12-15 20:13:01 +0000676// Print list of passes that are last used by P.
677void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
678
679 std::vector<Pass *> LUses;
680
681 assert (TPM && "Top Level Manager is missing");
682 TPM->collectLastUses(LUses, P);
683
684 for (std::vector<Pass *>::iterator I = LUses.begin(),
685 E = LUses.end(); I != E; ++I) {
686 llvm::cerr << "--" << std::string(Offset*2, ' ');
687 (*I)->dumpPassStructure(0);
688 }
689}
690
691void PMDataManager::dumpPassArguments() const {
692 for(std::vector<Pass *>::const_iterator I = PassVector.begin(),
693 E = PassVector.end(); I != E; ++I) {
694 if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
695 PMD->dumpPassArguments();
696 else
697 if (const PassInfo *PI = (*I)->getPassInfo())
698 if (!PI->isAnalysisGroup())
699 cerr << " -" << PI->getPassArgument();
700 }
701}
702
703void PMDataManager:: dumpPassInfo(Pass *P, std::string &Msg1,
704 std::string &Msg2) const {
705 if (PassDebugging_New < Executions)
706 return;
707 cerr << (void*)this << std::string(getDepth()*2+1, ' ');
708 cerr << Msg1;
709 cerr << P->getPassName();
710 cerr << Msg2;
711}
712
713void PMDataManager::dumpAnalysisSetInfo(const char *Msg, Pass *P,
714 const std::vector<AnalysisID> &Set)
715 const {
716 if (PassDebugging_New >= Details && !Set.empty()) {
717 cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
718 for (unsigned i = 0; i != Set.size(); ++i) {
719 if (i) cerr << ",";
720 cerr << " " << Set[i]->getPassName();
721 }
722 cerr << "\n";
723 }
724}
Devang Patel9bdf7d42006-12-08 23:28:54 +0000725
Devang Patele7599552007-01-12 18:52:44 +0000726// Destructor
727PMDataManager::~PMDataManager() {
728
729 for (std::vector<Pass *>::iterator I = PassVector.begin(),
730 E = PassVector.end(); I != E; ++I)
731 delete *I;
732
733 PassVector.clear();
734}
735
Devang Patel9bdf7d42006-12-08 23:28:54 +0000736//===----------------------------------------------------------------------===//
737// NOTE: Is this the right place to define this method ?
738// getAnalysisToUpdate - Return an analysis result or null if it doesn't exist
Devang Patelb66334b2007-01-05 22:47:07 +0000739Pass *AnalysisResolver::getAnalysisToUpdate(AnalysisID ID, bool dir) const {
Devang Patel9bdf7d42006-12-08 23:28:54 +0000740 return PM.findAnalysisPass(ID, dir);
741}
742
Devang Patela1514cb2006-12-07 19:39:39 +0000743//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000744// BBPassManager implementation
Devang Patel6e5a1132006-11-07 21:31:57 +0000745
Devang Patel6e5a1132006-11-07 21:31:57 +0000746/// Execute all of the passes scheduled for execution by invoking
747/// runOnBasicBlock method. Keep track of whether any of the passes modifies
748/// the function, and if so, return true.
749bool
Devang Patel67d6a5e2006-12-19 19:46:59 +0000750BBPassManager::runOnFunction(Function &F) {
Devang Patel6e5a1132006-11-07 21:31:57 +0000751
Devang Patel745a6962006-12-12 23:15:28 +0000752 if (F.isExternal())
753 return false;
754
Devang Patele9585592006-12-08 01:38:28 +0000755 bool Changed = doInitialization(F);
Devang Patel050ec722006-11-14 01:23:29 +0000756
Devang Patel93a197c2006-12-14 00:08:04 +0000757 std::string Msg1 = "Executing Pass '";
758 std::string Msg3 = "' Made Modification '";
759
Devang Patel6e5a1132006-11-07 21:31:57 +0000760 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
Devang Patelabfbe3b2006-12-16 00:56:26 +0000761 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
762 BasicBlockPass *BP = getContainedPass(Index);
Devang Patelf6d1d212006-12-14 00:25:06 +0000763 AnalysisUsage AnUsage;
Devang Patelabfbe3b2006-12-16 00:56:26 +0000764 BP->getAnalysisUsage(AnUsage);
Devang Patelf6d1d212006-12-14 00:25:06 +0000765
Devang Patel200d3052006-12-13 23:50:44 +0000766 std::string Msg2 = "' on BasicBlock '" + (*I).getName() + "'...\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +0000767 dumpPassInfo(BP, Msg1, Msg2);
768 dumpAnalysisSetInfo("Required", BP, AnUsage.getRequiredSet());
Devang Patelf6d1d212006-12-14 00:25:06 +0000769
Devang Patelabfbe3b2006-12-16 00:56:26 +0000770 initializeAnalysisImpl(BP);
Devang Patel93a197c2006-12-14 00:08:04 +0000771
Devang Patelabfbe3b2006-12-16 00:56:26 +0000772 if (TheTimeInfo) TheTimeInfo->passStarted(BP);
Devang Patel6e5a1132006-11-07 21:31:57 +0000773 Changed |= BP->runOnBasicBlock(*I);
Devang Patelabfbe3b2006-12-16 00:56:26 +0000774 if (TheTimeInfo) TheTimeInfo->passEnded(BP);
Devang Patel93a197c2006-12-14 00:08:04 +0000775
776 if (Changed)
Devang Patelabfbe3b2006-12-16 00:56:26 +0000777 dumpPassInfo(BP, Msg3, Msg2);
778 dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet());
Devang Patel93a197c2006-12-14 00:08:04 +0000779
Devang Patelabfbe3b2006-12-16 00:56:26 +0000780 removeNotPreservedAnalysis(BP);
781 recordAvailableAnalysis(BP);
782 removeDeadPasses(BP, Msg2);
Devang Patel6e5a1132006-11-07 21:31:57 +0000783 }
Devang Patel56d48ec2006-12-15 22:57:49 +0000784 return Changed |= doFinalization(F);
Devang Patel6e5a1132006-11-07 21:31:57 +0000785}
786
Devang Patel475c4532006-12-08 00:59:05 +0000787// Implement doInitialization and doFinalization
Devang Patel67d6a5e2006-12-19 19:46:59 +0000788inline bool BBPassManager::doInitialization(Module &M) {
Devang Patel475c4532006-12-08 00:59:05 +0000789 bool Changed = false;
790
Devang Patelabfbe3b2006-12-16 00:56:26 +0000791 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
792 BasicBlockPass *BP = getContainedPass(Index);
Devang Patel475c4532006-12-08 00:59:05 +0000793 Changed |= BP->doInitialization(M);
794 }
795
796 return Changed;
797}
798
Devang Patel67d6a5e2006-12-19 19:46:59 +0000799inline bool BBPassManager::doFinalization(Module &M) {
Devang Patel475c4532006-12-08 00:59:05 +0000800 bool Changed = false;
801
Devang Patelabfbe3b2006-12-16 00:56:26 +0000802 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
803 BasicBlockPass *BP = getContainedPass(Index);
Devang Patel475c4532006-12-08 00:59:05 +0000804 Changed |= BP->doFinalization(M);
805 }
806
807 return Changed;
808}
809
Devang Patel67d6a5e2006-12-19 19:46:59 +0000810inline bool BBPassManager::doInitialization(Function &F) {
Devang Patel475c4532006-12-08 00:59:05 +0000811 bool Changed = false;
812
Devang Patelabfbe3b2006-12-16 00:56:26 +0000813 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
814 BasicBlockPass *BP = getContainedPass(Index);
Devang Patel475c4532006-12-08 00:59:05 +0000815 Changed |= BP->doInitialization(F);
816 }
817
818 return Changed;
819}
820
Devang Patel67d6a5e2006-12-19 19:46:59 +0000821inline bool BBPassManager::doFinalization(Function &F) {
Devang Patel475c4532006-12-08 00:59:05 +0000822 bool Changed = false;
823
Devang Patelabfbe3b2006-12-16 00:56:26 +0000824 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
825 BasicBlockPass *BP = getContainedPass(Index);
Devang Patel475c4532006-12-08 00:59:05 +0000826 Changed |= BP->doFinalization(F);
827 }
828
829 return Changed;
830}
831
832
Devang Patela1514cb2006-12-07 19:39:39 +0000833//===----------------------------------------------------------------------===//
Devang Patelb67904d2006-12-13 02:36:01 +0000834// FunctionPassManager implementation
Devang Patela1514cb2006-12-07 19:39:39 +0000835
Devang Patel4e12f862006-11-08 10:44:40 +0000836/// Create new Function pass manager
Devang Patelb67904d2006-12-13 02:36:01 +0000837FunctionPassManager::FunctionPassManager(ModuleProvider *P) {
Devang Patel67d6a5e2006-12-19 19:46:59 +0000838 FPM = new FunctionPassManagerImpl(0);
Devang Patel9c6290c2006-12-12 22:02:16 +0000839 // FPM is the top level manager.
840 FPM->setTopLevelManager(FPM);
Devang Patel1036b652006-12-12 23:27:37 +0000841
842 PMDataManager *PMD = dynamic_cast<PMDataManager *>(FPM);
Devang Patelb66334b2007-01-05 22:47:07 +0000843 AnalysisResolver *AR = new AnalysisResolver(*PMD);
Devang Patel1036b652006-12-12 23:27:37 +0000844 FPM->setResolver(AR);
845
Devang Patel1f653682006-12-08 18:57:16 +0000846 MP = P;
847}
848
Devang Patelb67904d2006-12-13 02:36:01 +0000849FunctionPassManager::~FunctionPassManager() {
Devang Patelab97cf42006-12-13 00:09:23 +0000850 delete FPM;
851}
852
Devang Patel4e12f862006-11-08 10:44:40 +0000853/// add - Add a pass to the queue of passes to run. This passes
854/// ownership of the Pass to the PassManager. When the
855/// PassManager_X is destroyed, the pass will be destroyed as well, so
856/// there is no need to delete the pass. (TODO delete passes.)
857/// This implies that all passes MUST be allocated with 'new'.
Devang Patelb67904d2006-12-13 02:36:01 +0000858void FunctionPassManager::add(Pass *P) {
Devang Patel4e12f862006-11-08 10:44:40 +0000859 FPM->add(P);
860}
861
Devang Patel9f3083e2006-11-15 19:39:54 +0000862/// run - Execute all of the passes scheduled for execution. Keep
863/// track of whether any of the passes modifies the function, and if
864/// so, return true.
865///
Devang Patelb67904d2006-12-13 02:36:01 +0000866bool FunctionPassManager::run(Function &F) {
Devang Patel9f3083e2006-11-15 19:39:54 +0000867 std::string errstr;
868 if (MP->materializeFunction(&F, &errstr)) {
Bill Wendlingf3baad32006-12-07 01:30:32 +0000869 cerr << "Error reading bytecode file: " << errstr << "\n";
Devang Patel9f3083e2006-11-15 19:39:54 +0000870 abort();
871 }
Devang Patel272908d2006-12-08 22:57:48 +0000872 return FPM->run(F);
Devang Patel9f3083e2006-11-15 19:39:54 +0000873}
874
875
Devang Patelff631ae2006-11-15 01:27:05 +0000876/// doInitialization - Run all of the initializers for the function passes.
877///
Devang Patelb67904d2006-12-13 02:36:01 +0000878bool FunctionPassManager::doInitialization() {
Devang Patelff631ae2006-11-15 01:27:05 +0000879 return FPM->doInitialization(*MP->getModule());
880}
881
882/// doFinalization - Run all of the initializers for the function passes.
883///
Devang Patelb67904d2006-12-13 02:36:01 +0000884bool FunctionPassManager::doFinalization() {
Devang Patelff631ae2006-11-15 01:27:05 +0000885 return FPM->doFinalization(*MP->getModule());
886}
887
Devang Patela1514cb2006-12-07 19:39:39 +0000888//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000889// FunctionPassManagerImpl implementation
890//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000891inline bool FunctionPassManagerImpl::doInitialization(Module &M) {
892 bool Changed = false;
893
894 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
895 FPPassManager *FP = getContainedManager(Index);
896 Changed |= FP->doInitialization(M);
897 }
898
899 return Changed;
900}
901
902inline bool FunctionPassManagerImpl::doFinalization(Module &M) {
903 bool Changed = false;
904
905 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
906 FPPassManager *FP = getContainedManager(Index);
907 Changed |= FP->doFinalization(M);
908 }
909
910 return Changed;
911}
912
913// Execute all the passes managed by this top level manager.
914// Return true if any function is modified by a pass.
915bool FunctionPassManagerImpl::run(Function &F) {
916
917 bool Changed = false;
918
919 TimingInfo::createTheTimeInfo();
920
921 dumpArguments();
922 dumpPasses();
923
Devang Patele3068402006-12-21 00:16:50 +0000924 initializeAllAnalysisInfo();
Devang Patel67d6a5e2006-12-19 19:46:59 +0000925 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
926 FPPassManager *FP = getContainedManager(Index);
927 Changed |= FP->runOnFunction(F);
928 }
929 return Changed;
930}
931
932//===----------------------------------------------------------------------===//
933// FPPassManager implementation
Devang Patel0c2012f2006-11-07 21:49:50 +0000934
Devang Patele7599552007-01-12 18:52:44 +0000935/// Print passes managed by this manager
936void FPPassManager::dumpPassStructure(unsigned Offset) {
937 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
938 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
939 FunctionPass *FP = getContainedPass(Index);
940 FP->dumpPassStructure(Offset + 1);
941 dumpLastUses(FP, Offset+1);
942 }
943}
944
945
Devang Patel0c2012f2006-11-07 21:49:50 +0000946/// Execute all of the passes scheduled for execution by invoking
947/// runOnFunction method. Keep track of whether any of the passes modifies
948/// the function, and if so, return true.
Devang Patel67d6a5e2006-12-19 19:46:59 +0000949bool FPPassManager::runOnFunction(Function &F) {
Devang Patel9f3083e2006-11-15 19:39:54 +0000950
951 bool Changed = false;
Devang Patel745a6962006-12-12 23:15:28 +0000952
953 if (F.isExternal())
954 return false;
955
Devang Patel93a197c2006-12-14 00:08:04 +0000956 std::string Msg1 = "Executing Pass '";
957 std::string Msg3 = "' Made Modification '";
958
Devang Patelabfbe3b2006-12-16 00:56:26 +0000959 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
960 FunctionPass *FP = getContainedPass(Index);
961
Devang Patelf6d1d212006-12-14 00:25:06 +0000962 AnalysisUsage AnUsage;
Devang Patelabfbe3b2006-12-16 00:56:26 +0000963 FP->getAnalysisUsage(AnUsage);
Devang Patel93a197c2006-12-14 00:08:04 +0000964
Devang Patel200d3052006-12-13 23:50:44 +0000965 std::string Msg2 = "' on Function '" + F.getName() + "'...\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +0000966 dumpPassInfo(FP, Msg1, Msg2);
967 dumpAnalysisSetInfo("Required", FP, AnUsage.getRequiredSet());
Devang Patel93a197c2006-12-14 00:08:04 +0000968
Devang Patelabfbe3b2006-12-16 00:56:26 +0000969 initializeAnalysisImpl(FP);
Devang Patelb8817b92006-12-14 00:59:42 +0000970
Devang Patelabfbe3b2006-12-16 00:56:26 +0000971 if (TheTimeInfo) TheTimeInfo->passStarted(FP);
Devang Patel9f3083e2006-11-15 19:39:54 +0000972 Changed |= FP->runOnFunction(F);
Devang Patelabfbe3b2006-12-16 00:56:26 +0000973 if (TheTimeInfo) TheTimeInfo->passEnded(FP);
Devang Patel93a197c2006-12-14 00:08:04 +0000974
975 if (Changed)
Devang Patelabfbe3b2006-12-16 00:56:26 +0000976 dumpPassInfo(FP, Msg3, Msg2);
977 dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
Devang Patel93a197c2006-12-14 00:08:04 +0000978
Devang Patelabfbe3b2006-12-16 00:56:26 +0000979 removeNotPreservedAnalysis(FP);
980 recordAvailableAnalysis(FP);
981 removeDeadPasses(FP, Msg2);
Devang Patel9f3083e2006-11-15 19:39:54 +0000982 }
983 return Changed;
984}
985
Devang Patel67d6a5e2006-12-19 19:46:59 +0000986bool FPPassManager::runOnModule(Module &M) {
Devang Patel9f3083e2006-11-15 19:39:54 +0000987
Devang Patel67d6a5e2006-12-19 19:46:59 +0000988 bool Changed = doInitialization(M);
Devang Patel67d6a5e2006-12-19 19:46:59 +0000989
990 for(Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
991 this->runOnFunction(*I);
992
993 return Changed |= doFinalization(M);
994}
995
996inline bool FPPassManager::doInitialization(Module &M) {
Devang Patelff631ae2006-11-15 01:27:05 +0000997 bool Changed = false;
998
Devang Patelabfbe3b2006-12-16 00:56:26 +0000999 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1000 FunctionPass *FP = getContainedPass(Index);
Devang Patelff631ae2006-11-15 01:27:05 +00001001 Changed |= FP->doInitialization(M);
1002 }
1003
1004 return Changed;
1005}
1006
Devang Patel67d6a5e2006-12-19 19:46:59 +00001007inline bool FPPassManager::doFinalization(Module &M) {
Devang Patelff631ae2006-11-15 01:27:05 +00001008 bool Changed = false;
1009
Devang Patelabfbe3b2006-12-16 00:56:26 +00001010 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1011 FunctionPass *FP = getContainedPass(Index);
Devang Patelff631ae2006-11-15 01:27:05 +00001012 Changed |= FP->doFinalization(M);
1013 }
1014
Devang Patelff631ae2006-11-15 01:27:05 +00001015 return Changed;
1016}
1017
Devang Patela1514cb2006-12-07 19:39:39 +00001018//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +00001019// MPPassManager implementation
Devang Patel05e1a972006-11-07 22:03:15 +00001020
Devang Patel05e1a972006-11-07 22:03:15 +00001021/// Execute all of the passes scheduled for execution by invoking
1022/// runOnModule method. Keep track of whether any of the passes modifies
1023/// the module, and if so, return true.
1024bool
Devang Patel67d6a5e2006-12-19 19:46:59 +00001025MPPassManager::runOnModule(Module &M) {
Devang Patel05e1a972006-11-07 22:03:15 +00001026 bool Changed = false;
Devang Patel050ec722006-11-14 01:23:29 +00001027
Devang Patel93a197c2006-12-14 00:08:04 +00001028 std::string Msg1 = "Executing Pass '";
1029 std::string Msg3 = "' Made Modification '";
1030
Devang Patelabfbe3b2006-12-16 00:56:26 +00001031 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1032 ModulePass *MP = getContainedPass(Index);
1033
Devang Patelf6d1d212006-12-14 00:25:06 +00001034 AnalysisUsage AnUsage;
Devang Patelabfbe3b2006-12-16 00:56:26 +00001035 MP->getAnalysisUsage(AnUsage);
Devang Patel93a197c2006-12-14 00:08:04 +00001036
Devang Patel200d3052006-12-13 23:50:44 +00001037 std::string Msg2 = "' on Module '" + M.getModuleIdentifier() + "'...\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +00001038 dumpPassInfo(MP, Msg1, Msg2);
1039 dumpAnalysisSetInfo("Required", MP, AnUsage.getRequiredSet());
Devang Patel93a197c2006-12-14 00:08:04 +00001040
Devang Patelabfbe3b2006-12-16 00:56:26 +00001041 initializeAnalysisImpl(MP);
Devang Patelb8817b92006-12-14 00:59:42 +00001042
Devang Patelabfbe3b2006-12-16 00:56:26 +00001043 if (TheTimeInfo) TheTimeInfo->passStarted(MP);
Devang Patel05e1a972006-11-07 22:03:15 +00001044 Changed |= MP->runOnModule(M);
Devang Patelabfbe3b2006-12-16 00:56:26 +00001045 if (TheTimeInfo) TheTimeInfo->passEnded(MP);
Devang Patel93a197c2006-12-14 00:08:04 +00001046
1047 if (Changed)
Devang Patelabfbe3b2006-12-16 00:56:26 +00001048 dumpPassInfo(MP, Msg3, Msg2);
1049 dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
Devang Patelf6d1d212006-12-14 00:25:06 +00001050
Devang Patelabfbe3b2006-12-16 00:56:26 +00001051 removeNotPreservedAnalysis(MP);
1052 recordAvailableAnalysis(MP);
1053 removeDeadPasses(MP, Msg2);
Devang Patel05e1a972006-11-07 22:03:15 +00001054 }
1055 return Changed;
1056}
1057
Devang Patela1514cb2006-12-07 19:39:39 +00001058//===----------------------------------------------------------------------===//
1059// PassManagerImpl implementation
Devang Patelab97cf42006-12-13 00:09:23 +00001060//
Devang Patelc290c8a2006-11-07 22:23:34 +00001061/// run - Execute all of the passes scheduled for execution. Keep track of
1062/// whether any of the passes modifies the module, and if so, return true.
Devang Patel67d6a5e2006-12-19 19:46:59 +00001063bool PassManagerImpl::run(Module &M) {
Devang Patelc290c8a2006-11-07 22:23:34 +00001064
Devang Patelc290c8a2006-11-07 22:23:34 +00001065 bool Changed = false;
Devang Patelf1567a52006-12-13 20:03:48 +00001066
Devang Patelb8817b92006-12-14 00:59:42 +00001067 TimingInfo::createTheTimeInfo();
1068
Devang Patelcfd70c42006-12-13 22:10:00 +00001069 dumpArguments();
Devang Patel67d6a5e2006-12-19 19:46:59 +00001070 dumpPasses();
Devang Patelf1567a52006-12-13 20:03:48 +00001071
Devang Patele3068402006-12-21 00:16:50 +00001072 initializeAllAnalysisInfo();
Devang Patel67d6a5e2006-12-19 19:46:59 +00001073 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1074 MPPassManager *MP = getContainedManager(Index);
Devang Patel5bbeb492006-12-08 22:47:25 +00001075 Changed |= MP->runOnModule(M);
Devang Patelc290c8a2006-11-07 22:23:34 +00001076 }
1077 return Changed;
1078}
Devang Patel376fefa2006-11-08 10:29:57 +00001079
Devang Patela1514cb2006-12-07 19:39:39 +00001080//===----------------------------------------------------------------------===//
1081// PassManager implementation
1082
Devang Patel376fefa2006-11-08 10:29:57 +00001083/// Create new pass manager
Devang Patelb67904d2006-12-13 02:36:01 +00001084PassManager::PassManager() {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001085 PM = new PassManagerImpl(0);
Devang Patel9c6290c2006-12-12 22:02:16 +00001086 // PM is the top level manager
1087 PM->setTopLevelManager(PM);
Devang Patel376fefa2006-11-08 10:29:57 +00001088}
1089
Devang Patelb67904d2006-12-13 02:36:01 +00001090PassManager::~PassManager() {
Devang Patelab97cf42006-12-13 00:09:23 +00001091 delete PM;
1092}
1093
Devang Patel376fefa2006-11-08 10:29:57 +00001094/// add - Add a pass to the queue of passes to run. This passes ownership of
1095/// the Pass to the PassManager. When the PassManager is destroyed, the pass
1096/// will be destroyed as well, so there is no need to delete the pass. This
1097/// implies that all passes MUST be allocated with 'new'.
1098void
Devang Patelb67904d2006-12-13 02:36:01 +00001099PassManager::add(Pass *P) {
Devang Patel376fefa2006-11-08 10:29:57 +00001100 PM->add(P);
1101}
1102
1103/// run - Execute all of the passes scheduled for execution. Keep track of
1104/// whether any of the passes modifies the module, and if so, return true.
1105bool
Devang Patelb67904d2006-12-13 02:36:01 +00001106PassManager::run(Module &M) {
Devang Patel376fefa2006-11-08 10:29:57 +00001107 return PM->run(M);
1108}
1109
Devang Patelb8817b92006-12-14 00:59:42 +00001110//===----------------------------------------------------------------------===//
1111// TimingInfo Class - This class is used to calculate information about the
1112// amount of time each pass takes to execute. This only happens with
1113// -time-passes is enabled on the command line.
1114//
1115bool llvm::TimePassesIsEnabled = false;
1116static cl::opt<bool,true>
1117EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1118 cl::desc("Time each pass, printing elapsed time for each on exit"));
1119
1120// createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1121// a non null value (if the -time-passes option is enabled) or it leaves it
1122// null. It may be called multiple times.
1123void TimingInfo::createTheTimeInfo() {
1124 if (!TimePassesIsEnabled || TheTimeInfo) return;
1125
1126 // Constructed the first time this is called, iff -time-passes is enabled.
1127 // This guarantees that the object will be constructed before static globals,
1128 // thus it will be destroyed before them.
1129 static ManagedStatic<TimingInfo> TTI;
1130 TheTimeInfo = &*TTI;
1131}
1132
Devang Patel1c56a632007-01-08 19:29:38 +00001133//===----------------------------------------------------------------------===//
1134// PMStack implementation
1135//
Devang Patelad98d232007-01-11 22:15:30 +00001136
Devang Patel1c56a632007-01-08 19:29:38 +00001137// Pop Pass Manager from the stack and clear its analysis info.
1138void PMStack::pop() {
1139
1140 PMDataManager *Top = this->top();
1141 Top->initializeAnalysisInfo();
1142
1143 S.pop_back();
1144}
1145
1146// Push PM on the stack and set its top level manager.
Devang Patel15701b52007-01-11 00:19:00 +00001147void PMStack::push(Pass *P) {
Devang Patel1c56a632007-01-08 19:29:38 +00001148
Devang Patel15701b52007-01-11 00:19:00 +00001149 PMDataManager *Top = NULL;
1150 PMDataManager *PM = dynamic_cast<PMDataManager *>(P);
1151 assert (PM && "Unable to push. Pass Manager expected");
Devang Patel1c56a632007-01-08 19:29:38 +00001152
Devang Patel15701b52007-01-11 00:19:00 +00001153 if (this->empty()) {
1154 Top = PM;
1155 }
1156 else {
1157 Top = this->top();
1158 PMTopLevelManager *TPM = Top->getTopLevelManager();
1159
1160 assert (TPM && "Unable to find top level manager");
1161 TPM->addIndirectPassManager(PM);
1162 PM->setTopLevelManager(TPM);
1163 }
1164
1165 AnalysisResolver *AR = new AnalysisResolver(*Top);
1166 P->setResolver(AR);
1167
1168 S.push_back(PM);
1169}
1170
1171// Dump content of the pass manager stack.
1172void PMStack::dump() {
1173 for(std::deque<PMDataManager *>::iterator I = S.begin(),
1174 E = S.end(); I != E; ++I) {
1175 Pass *P = dynamic_cast<Pass *>(*I);
1176 printf ("%s ", P->getPassName());
1177 }
1178 if (!S.empty())
1179 printf ("\n");
Devang Patel1c56a632007-01-08 19:29:38 +00001180}
1181
1182// Walk Pass Manager stack and set LastUse markers if any
1183// manager is transfering this priviledge to its parent manager
1184void PMStack::handleLastUserOverflow() {
1185
1186 for(PMStack::iterator I = this->begin(), E = this->end(); I != E;) {
1187
1188 PMDataManager *Child = *I++;
1189 if (I != E) {
1190 PMDataManager *Parent = *I++;
1191 PMTopLevelManager *TPM = Parent->getTopLevelManager();
1192 std::vector<Pass *> &TLU = Child->getTransferredLastUses();
1193 if (!TLU.empty()) {
1194 Pass *P = dynamic_cast<Pass *>(Parent);
1195 TPM->setLastUser(TLU, P);
1196 }
1197 }
1198 }
1199}
1200
1201/// Find appropriate Module Pass Manager in the PM Stack and
1202/// add self into that manager.
1203void ModulePass::assignPassManager(PMStack &PMS) {
1204
Devang Patel1c56a632007-01-08 19:29:38 +00001205 // Find Module Pass Manager
1206 while(!PMS.empty()) {
Devang Patelac99eca2007-01-11 19:59:06 +00001207 if (PMS.top()->getPassManagerType() > PMT_ModulePassManager)
Devang Patel1c56a632007-01-08 19:29:38 +00001208 PMS.pop(); // Pop children pass managers
Devang Patelac99eca2007-01-11 19:59:06 +00001209 else
1210 break;
Devang Patel1c56a632007-01-08 19:29:38 +00001211 }
Devang Patelac99eca2007-01-11 19:59:06 +00001212 MPPassManager *MPP = dynamic_cast<MPPassManager *>(PMS.top());
Devang Patel1c56a632007-01-08 19:29:38 +00001213
1214 assert(MPP && "Unable to find Module Pass Manager");
Devang Patelf85793d2007-01-12 20:07:16 +00001215 MPP->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00001216}
1217
1218/// Find appropriate Function Pass Manager or Call Graph Pass Manager
1219/// in the PM Stack and add self into that manager.
1220void FunctionPass::assignPassManager(PMStack &PMS) {
1221
Devang Patel15701b52007-01-11 00:19:00 +00001222 // Find Module Pass Manager (TODO : Or Call Graph Pass Manager)
Devang Patel1c56a632007-01-08 19:29:38 +00001223 while(!PMS.empty()) {
Devang Patelac99eca2007-01-11 19:59:06 +00001224 if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
1225 PMS.pop();
Devang Patel1c56a632007-01-08 19:29:38 +00001226 else
Devang Patelac99eca2007-01-11 19:59:06 +00001227 break;
Devang Patel1c56a632007-01-08 19:29:38 +00001228 }
Devang Patelac99eca2007-01-11 19:59:06 +00001229 FPPassManager *FPP = dynamic_cast<FPPassManager *>(PMS.top());
Devang Patel1c56a632007-01-08 19:29:38 +00001230
Devang Patel15701b52007-01-11 00:19:00 +00001231 // Create new Function Pass Manager
Devang Patel1c56a632007-01-08 19:29:38 +00001232 if (!FPP) {
Devang Patel1c56a632007-01-08 19:29:38 +00001233 assert(!PMS.empty() && "Unable to create Function Pass Manager");
Devang Patel1c56a632007-01-08 19:29:38 +00001234 PMDataManager *PMD = PMS.top();
Devang Patel1c56a632007-01-08 19:29:38 +00001235
Devang Patel15701b52007-01-11 00:19:00 +00001236 // [1] Create new Function Pass Manager
Devang Patel1c56a632007-01-08 19:29:38 +00001237 FPP = new FPPassManager(PMD->getDepth() + 1);
Devang Patel15701b52007-01-11 00:19:00 +00001238
1239 // [2] Set up new manager's top level manager
1240 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1241 TPM->addIndirectPassManager(FPP);
1242
1243 // [3] Assign manager to manage this new manager. This may create
1244 // and push new managers into PMS
1245 Pass *P = dynamic_cast<Pass *>(FPP);
1246 P->assignPassManager(PMS);
1247
1248 // [4] Push new manager into PMS
Devang Patel1c56a632007-01-08 19:29:38 +00001249 PMS.push(FPP);
1250 }
1251
Devang Patel15701b52007-01-11 00:19:00 +00001252 // Assign FPP as the manager of this pass.
Devang Patelf85793d2007-01-12 20:07:16 +00001253 FPP->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00001254}
1255
1256/// Find appropriate Basic Pass Manager or Call Graph Pass Manager
1257/// in the PM Stack and add self into that manager.
1258void BasicBlockPass::assignPassManager(PMStack &PMS) {
1259
1260 BBPassManager *BBP = NULL;
1261
Devang Patel15701b52007-01-11 00:19:00 +00001262 // Basic Pass Manager is a leaf pass manager. It does not handle
1263 // any other pass manager.
1264 if (!PMS.empty()) {
Devang Patel1c56a632007-01-08 19:29:38 +00001265 BBP = dynamic_cast<BBPassManager *>(PMS.top());
Devang Patel1c56a632007-01-08 19:29:38 +00001266 }
1267
Devang Patel15701b52007-01-11 00:19:00 +00001268 // If leaf manager is not Basic Block Pass manager then create new
1269 // basic Block Pass manager.
1270
Devang Patel1c56a632007-01-08 19:29:38 +00001271 if (!BBP) {
Devang Patel1c56a632007-01-08 19:29:38 +00001272 assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
Devang Patel1c56a632007-01-08 19:29:38 +00001273 PMDataManager *PMD = PMS.top();
Devang Patel1c56a632007-01-08 19:29:38 +00001274
Devang Patel15701b52007-01-11 00:19:00 +00001275 // [1] Create new Basic Block Manager
Devang Patel1c56a632007-01-08 19:29:38 +00001276 BBP = new BBPassManager(PMD->getDepth() + 1);
Devang Patel15701b52007-01-11 00:19:00 +00001277
1278 // [2] Set up new manager's top level manager
1279 // Basic Block Pass Manager does not live by itself
1280 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1281 TPM->addIndirectPassManager(BBP);
1282
1283 // [3] Assign manager to manage this new manager. This may create
1284 // and push new managers into PMS
1285 Pass *P = dynamic_cast<Pass *>(BBP);
1286 P->assignPassManager(PMS);
1287
1288 // [4] Push new manager into PMS
Devang Patel1c56a632007-01-08 19:29:38 +00001289 PMS.push(BBP);
1290 }
1291
Devang Patel15701b52007-01-11 00:19:00 +00001292 // Assign BBP as the manager of this pass.
Devang Patelf85793d2007-01-12 20:07:16 +00001293 BBP->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00001294}
1295
Devang Patelc6b5a552007-01-05 20:16:23 +00001296