blob: 8f895c81bcc37d404cc1daa8c77e8ee7d27be290 [file] [log] [blame]
Devang Patel6e5a1132006-11-07 21:31:57 +00001//===- PassManager.cpp - LLVM Pass Infrastructure Implementation ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Devang Patel6e5a1132006-11-07 21:31:57 +00007//
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"
David Greene9b063df2010-04-02 23:17:14 +000016#include "llvm/Assembly/PrintModulePass.h"
Dan Gohman4dbb3012009-09-28 00:27:48 +000017#include "llvm/Assembly/Writer.h"
Devang Patelf1567a52006-12-13 20:03:48 +000018#include "llvm/Support/CommandLine.h"
David Greene994e1bb2010-01-05 01:30:02 +000019#include "llvm/Support/Debug.h"
Devang Patel1c3633e2007-01-29 23:10:37 +000020#include "llvm/Support/Timer.h"
Devang Patel6e5a1132006-11-07 21:31:57 +000021#include "llvm/Module.h"
Torok Edwin6dd27302009-07-08 18:01:40 +000022#include "llvm/Support/ErrorHandling.h"
Devang Patelb8817b92006-12-14 00:59:42 +000023#include "llvm/Support/ManagedStatic.h"
David Greene9b063df2010-04-02 23:17:14 +000024#include "llvm/Support/PassNameParser.h"
Chris Lattner4c1e9542009-03-06 06:45:05 +000025#include "llvm/Support/raw_ostream.h"
Owen Anderson0dd39fd2009-06-17 21:28:54 +000026#include "llvm/System/Mutex.h"
Owen Anderson7d42b952009-06-18 16:54:52 +000027#include "llvm/System/Threading.h"
Jeff Cohenb622c112007-03-05 00:00:42 +000028#include <algorithm>
Duncan Sands26ff6f92008-10-08 07:23:46 +000029#include <cstdio>
Devang Patelf60b5d92006-11-14 01:59:59 +000030#include <map>
Dan Gohman8c43e412007-10-03 19:04:09 +000031using namespace llvm;
Devang Patelffca9102006-12-15 19:39:30 +000032
Devang Patele7599552007-01-12 18:52:44 +000033// See PassManagers.h for Pass Manager infrastructure overview.
Devang Patel6fea2852006-12-07 18:23:30 +000034
Devang Patelf1567a52006-12-13 20:03:48 +000035namespace llvm {
36
37//===----------------------------------------------------------------------===//
38// Pass debugging information. Often it is useful to find out what pass is
39// running when a crash occurs in a utility. When this library is compiled with
40// debugging on, a command line option (--debug-pass) is enabled that causes the
41// pass name to be printed before it executes.
42//
43
Devang Patel03fb5872006-12-13 21:13:31 +000044// Different debug levels that can be enabled...
45enum PassDebugLevel {
46 None, Arguments, Structure, Executions, Details
47};
48
Devang Patelf1567a52006-12-13 20:03:48 +000049static cl::opt<enum PassDebugLevel>
Devang Patelfd4184322007-01-17 20:33:36 +000050PassDebugging("debug-pass", cl::Hidden,
Devang Patelf1567a52006-12-13 20:03:48 +000051 cl::desc("Print PassManager debugging information"),
52 cl::values(
Devang Patel03fb5872006-12-13 21:13:31 +000053 clEnumVal(None , "disable debug output"),
54 clEnumVal(Arguments , "print pass arguments to pass to 'opt'"),
55 clEnumVal(Structure , "print pass structure before run()"),
56 clEnumVal(Executions, "print pass name before it is executed"),
57 clEnumVal(Details , "print pass details when it is executed"),
Devang Patelf1567a52006-12-13 20:03:48 +000058 clEnumValEnd));
David Greene9b063df2010-04-02 23:17:14 +000059
60typedef llvm::cl::list<const llvm::PassInfo *, bool, PassNameParser>
61PassOptionList;
62
63// Print IR out before/after specified passes.
64static PassOptionList
65PrintBefore("print-before",
66 llvm::cl::desc("Print IR before specified passes"));
67
68static PassOptionList
69PrintAfter("print-after",
70 llvm::cl::desc("Print IR after specified passes"));
71
72static cl::opt<bool>
73PrintBeforeAll("print-before-all",
74 llvm::cl::desc("Print IR before each pass"),
75 cl::init(false));
76static cl::opt<bool>
77PrintAfterAll("print-after-all",
78 llvm::cl::desc("Print IR after each pass"),
79 cl::init(false));
80
81/// This is a helper to determine whether to print IR before or
82/// after a pass.
83
Owen Andersona7aed182010-08-06 18:33:48 +000084static bool ShouldPrintBeforeOrAfterPass(const void *PassID,
David Greene9b063df2010-04-02 23:17:14 +000085 PassOptionList &PassesToPrint) {
Owen Andersona7aed182010-08-06 18:33:48 +000086 if (const llvm::PassInfo *PI =
87 PassRegistry::getPassRegistry()->getPassInfo(PassID)) {
88 for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) {
89 const llvm::PassInfo *PassInf = PassesToPrint[i];
90 if (PassInf)
91 if (PassInf->getPassArgument() == PI->getPassArgument()) {
92 return true;
93 }
94 }
David Greene9b063df2010-04-02 23:17:14 +000095 }
96 return false;
97}
98
99
100/// This is a utility to check whether a pass should have IR dumped
101/// before it.
Owen Andersona7aed182010-08-06 18:33:48 +0000102static bool ShouldPrintBeforePass(const void *PassID) {
103 return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PassID, PrintBefore);
David Greene9b063df2010-04-02 23:17:14 +0000104}
105
106/// This is a utility to check whether a pass should have IR dumped
107/// after it.
Owen Andersona7aed182010-08-06 18:33:48 +0000108static bool ShouldPrintAfterPass(const void *PassID) {
109 return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PassID, PrintAfter);
David Greene9b063df2010-04-02 23:17:14 +0000110}
111
Devang Patelf1567a52006-12-13 20:03:48 +0000112} // End of llvm namespace
113
Chris Lattnerd4d966f2009-09-15 05:03:04 +0000114/// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions
115/// or higher is specified.
116bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
117 return PassDebugging >= Executions;
118}
119
120
121
122
Chris Lattner4c1e9542009-03-06 06:45:05 +0000123void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
124 if (V == 0 && M == 0)
125 OS << "Releasing pass '";
126 else
127 OS << "Running pass '";
128
129 OS << P->getPassName() << "'";
130
131 if (M) {
132 OS << " on module '" << M->getModuleIdentifier() << "'.\n";
133 return;
134 }
135 if (V == 0) {
136 OS << '\n';
137 return;
138 }
139
Dan Gohman79fc0e92009-03-10 18:47:59 +0000140 OS << " on ";
Chris Lattner4c1e9542009-03-06 06:45:05 +0000141 if (isa<Function>(V))
Dan Gohman79fc0e92009-03-10 18:47:59 +0000142 OS << "function";
Chris Lattner4c1e9542009-03-06 06:45:05 +0000143 else if (isa<BasicBlock>(V))
Dan Gohman79fc0e92009-03-10 18:47:59 +0000144 OS << "basic block";
Chris Lattner4c1e9542009-03-06 06:45:05 +0000145 else
Dan Gohman79fc0e92009-03-10 18:47:59 +0000146 OS << "value";
147
148 OS << " '";
149 WriteAsOperand(OS, V, /*PrintTy=*/false, M);
150 OS << "'\n";
Chris Lattner4c1e9542009-03-06 06:45:05 +0000151}
152
153
Devang Patelffca9102006-12-15 19:39:30 +0000154namespace {
Devang Patelafb1f3622006-12-12 22:35:25 +0000155
Devang Patelf33f3eb2006-12-07 19:21:29 +0000156//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000157// BBPassManager
Devang Patel10c2ca62006-12-12 22:47:13 +0000158//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000159/// BBPassManager manages BasicBlockPass. It batches all the
Devang Patelca58e352006-11-08 10:05:38 +0000160/// pass together and sequence them to process one basic block before
161/// processing next basic block.
Nick Lewycky02d5f772009-10-25 06:33:48 +0000162class BBPassManager : public PMDataManager, public FunctionPass {
Devang Patelca58e352006-11-08 10:05:38 +0000163
164public:
Devang Patel8c78a0b2007-05-03 01:11:54 +0000165 static char ID;
Dan Gohman13ab93e2007-10-08 15:08:41 +0000166 explicit BBPassManager(int Depth)
Owen Andersona7aed182010-08-06 18:33:48 +0000167 : PMDataManager(Depth), FunctionPass(ID) {}
Devang Patelca58e352006-11-08 10:05:38 +0000168
Devang Patelca58e352006-11-08 10:05:38 +0000169 /// Execute all of the passes scheduled for execution. Keep track of
170 /// whether any of the passes modifies the function, and if so, return true.
171 bool runOnFunction(Function &F);
172
Devang Patelf9d96b92006-12-07 19:57:52 +0000173 /// Pass Manager itself does not invalidate any analysis info.
174 void getAnalysisUsage(AnalysisUsage &Info) const {
175 Info.setPreservesAll();
176 }
177
Devang Patel475c4532006-12-08 00:59:05 +0000178 bool doInitialization(Module &M);
179 bool doInitialization(Function &F);
180 bool doFinalization(Module &M);
181 bool doFinalization(Function &F);
182
Chris Lattner2fa26e52010-01-22 05:24:46 +0000183 virtual PMDataManager *getAsPMDataManager() { return this; }
184 virtual Pass *getAsPass() { return this; }
185
Devang Patele3858e62007-02-01 22:08:25 +0000186 virtual const char *getPassName() const {
Dan Gohman1e9860a2008-03-13 01:58:48 +0000187 return "BasicBlock Pass Manager";
Devang Patele3858e62007-02-01 22:08:25 +0000188 }
189
Devang Pateleda56172006-12-12 23:34:33 +0000190 // Print passes managed by this manager
191 void dumpPassStructure(unsigned Offset) {
David Greene994e1bb2010-01-05 01:30:02 +0000192 llvm::dbgs() << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +0000193 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
194 BasicBlockPass *BP = getContainedPass(Index);
195 BP->dumpPassStructure(Offset + 1);
196 dumpLastUses(BP, Offset+1);
Devang Pateleda56172006-12-12 23:34:33 +0000197 }
198 }
Devang Patelabfbe3b2006-12-16 00:56:26 +0000199
200 BasicBlockPass *getContainedPass(unsigned N) {
Chris Lattner60987362009-03-06 05:53:14 +0000201 assert(N < PassVector.size() && "Pass number out of range!");
Devang Patelabfbe3b2006-12-16 00:56:26 +0000202 BasicBlockPass *BP = static_cast<BasicBlockPass *>(PassVector[N]);
203 return BP;
204 }
Devang Patel3b3f8992007-01-11 01:10:25 +0000205
Devang Patel28349ab2007-02-27 15:00:39 +0000206 virtual PassManagerType getPassManagerType() const {
Devang Patel3b3f8992007-01-11 01:10:25 +0000207 return PMT_BasicBlockPassManager;
208 }
Devang Patelca58e352006-11-08 10:05:38 +0000209};
210
Devang Patel8c78a0b2007-05-03 01:11:54 +0000211char BBPassManager::ID = 0;
Devang Patele7599552007-01-12 18:52:44 +0000212}
Devang Patel67d6a5e2006-12-19 19:46:59 +0000213
Devang Patele7599552007-01-12 18:52:44 +0000214namespace llvm {
Devang Patelca58e352006-11-08 10:05:38 +0000215
Devang Patel10c2ca62006-12-12 22:47:13 +0000216//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000217// FunctionPassManagerImpl
Devang Patel10c2ca62006-12-12 22:47:13 +0000218//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000219/// FunctionPassManagerImpl manages FPPassManagers
220class FunctionPassManagerImpl : public Pass,
Devang Patelad98d232007-01-11 22:15:30 +0000221 public PMDataManager,
222 public PMTopLevelManager {
Torok Edwin24c78352009-06-29 18:49:09 +0000223private:
224 bool wasRun;
Devang Patel67d6a5e2006-12-19 19:46:59 +0000225public:
Devang Patel8c78a0b2007-05-03 01:11:54 +0000226 static char ID;
Dan Gohman13ab93e2007-10-08 15:08:41 +0000227 explicit FunctionPassManagerImpl(int Depth) :
Owen Andersona7aed182010-08-06 18:33:48 +0000228 Pass(PT_PassManager, ID), PMDataManager(Depth),
Torok Edwin24c78352009-06-29 18:49:09 +0000229 PMTopLevelManager(TLM_Function), wasRun(false) { }
Devang Patel67d6a5e2006-12-19 19:46:59 +0000230
231 /// add - Add a pass to the queue of passes to run. This passes ownership of
232 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
233 /// will be destroyed as well, so there is no need to delete the pass. This
234 /// implies that all passes MUST be allocated with 'new'.
235 void add(Pass *P) {
236 schedulePass(P);
237 }
238
David Greene9b063df2010-04-02 23:17:14 +0000239 /// createPrinterPass - Get a function printer pass.
240 Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
241 return createPrintFunctionPass(Banner, &O);
242 }
243
Torok Edwin24c78352009-06-29 18:49:09 +0000244 // Prepare for running an on the fly pass, freeing memory if needed
245 // from a previous run.
246 void releaseMemoryOnTheFly();
247
Devang Patel67d6a5e2006-12-19 19:46:59 +0000248 /// run - Execute all of the passes scheduled for execution. Keep track of
249 /// whether any of the passes modifies the module, and if so, return true.
250 bool run(Function &F);
251
252 /// doInitialization - Run all of the initializers for the function passes.
253 ///
254 bool doInitialization(Module &M);
255
Dan Gohmane6656eb2007-07-30 14:51:13 +0000256 /// doFinalization - Run all of the finalizers for the function passes.
Devang Patel67d6a5e2006-12-19 19:46:59 +0000257 ///
258 bool doFinalization(Module &M);
259
Chris Lattner2fa26e52010-01-22 05:24:46 +0000260
261 virtual PMDataManager *getAsPMDataManager() { return this; }
262 virtual Pass *getAsPass() { return this; }
263
Devang Patel67d6a5e2006-12-19 19:46:59 +0000264 /// Pass Manager itself does not invalidate any analysis info.
265 void getAnalysisUsage(AnalysisUsage &Info) const {
266 Info.setPreservesAll();
267 }
268
269 inline void addTopLevelPass(Pass *P) {
Chris Lattner21889d72010-01-22 04:55:08 +0000270 if (ImmutablePass *IP = P->getAsImmutablePass()) {
Devang Patel67d6a5e2006-12-19 19:46:59 +0000271 // P is a immutable pass and it will be managed by this
272 // top level manager. Set up analysis resolver to connect them.
Devang Patelb66334b2007-01-05 22:47:07 +0000273 AnalysisResolver *AR = new AnalysisResolver(*this);
Devang Patel67d6a5e2006-12-19 19:46:59 +0000274 P->setResolver(AR);
275 initializeAnalysisImpl(P);
276 addImmutablePass(IP);
277 recordAvailableAnalysis(IP);
Devang Patel0f080042007-01-12 17:23:48 +0000278 } else {
David Greene103d4b42010-05-10 20:24:27 +0000279 P->assignPassManager(activeStack, PMT_FunctionPassManager);
Devang Patel67d6a5e2006-12-19 19:46:59 +0000280 }
Devang Patel0f080042007-01-12 17:23:48 +0000281
Devang Patel67d6a5e2006-12-19 19:46:59 +0000282 }
283
284 FPPassManager *getContainedManager(unsigned N) {
Chris Lattner60987362009-03-06 05:53:14 +0000285 assert(N < PassManagers.size() && "Pass number out of range!");
Devang Patel67d6a5e2006-12-19 19:46:59 +0000286 FPPassManager *FP = static_cast<FPPassManager *>(PassManagers[N]);
287 return FP;
288 }
Devang Patel67d6a5e2006-12-19 19:46:59 +0000289};
290
Devang Patel8c78a0b2007-05-03 01:11:54 +0000291char FunctionPassManagerImpl::ID = 0;
Devang Patel67d6a5e2006-12-19 19:46:59 +0000292//===----------------------------------------------------------------------===//
293// MPPassManager
294//
295/// MPPassManager manages ModulePasses and function pass managers.
Dan Gohmandfdf2c02008-03-11 16:18:48 +0000296/// It batches all Module passes and function pass managers together and
297/// sequences them to process one module.
Devang Patel67d6a5e2006-12-19 19:46:59 +0000298class MPPassManager : public Pass, public PMDataManager {
Devang Patelca58e352006-11-08 10:05:38 +0000299public:
Devang Patel8c78a0b2007-05-03 01:11:54 +0000300 static char ID;
Dan Gohman13ab93e2007-10-08 15:08:41 +0000301 explicit MPPassManager(int Depth) :
Owen Andersona7aed182010-08-06 18:33:48 +0000302 Pass(PT_PassManager, ID), PMDataManager(Depth) { }
Devang Patel2ff44922007-04-16 20:39:59 +0000303
304 // Delete on the fly managers.
305 virtual ~MPPassManager() {
Devang Patel68f72b12007-04-26 17:50:19 +0000306 for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
Devang Patel2ff44922007-04-16 20:39:59 +0000307 I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
308 I != E; ++I) {
Devang Patel68f72b12007-04-26 17:50:19 +0000309 FunctionPassManagerImpl *FPP = I->second;
Devang Patel2ff44922007-04-16 20:39:59 +0000310 delete FPP;
311 }
312 }
313
David Greene9b063df2010-04-02 23:17:14 +0000314 /// createPrinterPass - Get a module printer pass.
315 Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
316 return createPrintModulePass(&O, false, Banner);
317 }
318
Devang Patelca58e352006-11-08 10:05:38 +0000319 /// run - Execute all of the passes scheduled for execution. Keep track of
320 /// whether any of the passes modifies the module, and if so, return true.
321 bool runOnModule(Module &M);
Devang Patelebba9702006-11-13 22:40:09 +0000322
Devang Patelf9d96b92006-12-07 19:57:52 +0000323 /// Pass Manager itself does not invalidate any analysis info.
324 void getAnalysisUsage(AnalysisUsage &Info) const {
325 Info.setPreservesAll();
326 }
327
Devang Patele64d3052007-04-16 20:12:57 +0000328 /// Add RequiredPass into list of lower level passes required by pass P.
329 /// RequiredPass is run on the fly by Pass Manager when P requests it
330 /// through getAnalysis interface.
331 virtual void addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass);
332
Devang Patel69e9f6d2007-04-16 20:27:05 +0000333 /// Return function pass corresponding to PassInfo PI, that is
334 /// required by module pass MP. Instantiate analysis pass, by using
335 /// its runOnFunction() for function F.
Owen Andersona7aed182010-08-06 18:33:48 +0000336 virtual Pass* getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F);
Devang Patel69e9f6d2007-04-16 20:27:05 +0000337
Devang Patele3858e62007-02-01 22:08:25 +0000338 virtual const char *getPassName() const {
339 return "Module Pass Manager";
340 }
341
Chris Lattner2fa26e52010-01-22 05:24:46 +0000342 virtual PMDataManager *getAsPMDataManager() { return this; }
343 virtual Pass *getAsPass() { return this; }
344
Devang Pateleda56172006-12-12 23:34:33 +0000345 // Print passes managed by this manager
346 void dumpPassStructure(unsigned Offset) {
David Greene994e1bb2010-01-05 01:30:02 +0000347 llvm::dbgs() << std::string(Offset*2, ' ') << "ModulePass Manager\n";
Devang Patelabfbe3b2006-12-16 00:56:26 +0000348 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
349 ModulePass *MP = getContainedPass(Index);
350 MP->dumpPassStructure(Offset + 1);
Dan Gohman83ff1842009-07-01 23:12:33 +0000351 std::map<Pass *, FunctionPassManagerImpl *>::const_iterator I =
352 OnTheFlyManagers.find(MP);
353 if (I != OnTheFlyManagers.end())
354 I->second->dumpPassStructure(Offset + 2);
Devang Patelabfbe3b2006-12-16 00:56:26 +0000355 dumpLastUses(MP, Offset+1);
Devang Pateleda56172006-12-12 23:34:33 +0000356 }
357 }
358
Devang Patelabfbe3b2006-12-16 00:56:26 +0000359 ModulePass *getContainedPass(unsigned N) {
Chris Lattner60987362009-03-06 05:53:14 +0000360 assert(N < PassVector.size() && "Pass number out of range!");
361 return static_cast<ModulePass *>(PassVector[N]);
Devang Patelabfbe3b2006-12-16 00:56:26 +0000362 }
363
Devang Patel28349ab2007-02-27 15:00:39 +0000364 virtual PassManagerType getPassManagerType() const {
365 return PMT_ModulePassManager;
366 }
Devang Patel69e9f6d2007-04-16 20:27:05 +0000367
368 private:
369 /// Collection of on the fly FPPassManagers. These managers manage
370 /// function passes that are required by module passes.
Devang Patel68f72b12007-04-26 17:50:19 +0000371 std::map<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
Devang Patelca58e352006-11-08 10:05:38 +0000372};
373
Devang Patel8c78a0b2007-05-03 01:11:54 +0000374char MPPassManager::ID = 0;
Devang Patel10c2ca62006-12-12 22:47:13 +0000375//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +0000376// PassManagerImpl
Devang Patel10c2ca62006-12-12 22:47:13 +0000377//
Devang Patel09f162c2007-05-01 21:15:47 +0000378
Devang Patel67d6a5e2006-12-19 19:46:59 +0000379/// PassManagerImpl manages MPPassManagers
380class PassManagerImpl : public Pass,
Devang Patelad98d232007-01-11 22:15:30 +0000381 public PMDataManager,
382 public PMTopLevelManager {
Devang Patel376fefa2006-11-08 10:29:57 +0000383
384public:
Devang Patel8c78a0b2007-05-03 01:11:54 +0000385 static char ID;
Dan Gohman13ab93e2007-10-08 15:08:41 +0000386 explicit PassManagerImpl(int Depth) :
Owen Andersona7aed182010-08-06 18:33:48 +0000387 Pass(PT_PassManager, ID), PMDataManager(Depth),
Chris Lattnerc7a8eaf2010-01-22 06:03:06 +0000388 PMTopLevelManager(TLM_Pass) { }
Devang Patel4c36e6b2006-12-07 23:24:58 +0000389
Devang Patel376fefa2006-11-08 10:29:57 +0000390 /// add - Add a pass to the queue of passes to run. This passes ownership of
391 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
392 /// will be destroyed as well, so there is no need to delete the pass. This
393 /// implies that all passes MUST be allocated with 'new'.
Devang Patel31217af2006-12-07 21:32:57 +0000394 void add(Pass *P) {
Devang Pateldf6c9ae2006-12-08 22:34:02 +0000395 schedulePass(P);
Devang Patel31217af2006-12-07 21:32:57 +0000396 }
Devang Patel376fefa2006-11-08 10:29:57 +0000397
David Greene9b063df2010-04-02 23:17:14 +0000398 /// createPrinterPass - Get a module printer pass.
399 Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
400 return createPrintModulePass(&O, false, Banner);
401 }
402
Devang Patel376fefa2006-11-08 10:29:57 +0000403 /// run - Execute all of the passes scheduled for execution. Keep track of
404 /// whether any of the passes modifies the module, and if so, return true.
405 bool run(Module &M);
406
Devang Patelf9d96b92006-12-07 19:57:52 +0000407 /// Pass Manager itself does not invalidate any analysis info.
408 void getAnalysisUsage(AnalysisUsage &Info) const {
409 Info.setPreservesAll();
410 }
411
Devang Patelabcd1d32006-12-07 21:27:23 +0000412 inline void addTopLevelPass(Pass *P) {
Chris Lattner21889d72010-01-22 04:55:08 +0000413 if (ImmutablePass *IP = P->getAsImmutablePass()) {
Devang Pateld440cd92006-12-08 23:53:00 +0000414 // P is a immutable pass and it will be managed by this
415 // top level manager. Set up analysis resolver to connect them.
Devang Patelb66334b2007-01-05 22:47:07 +0000416 AnalysisResolver *AR = new AnalysisResolver(*this);
Devang Pateld440cd92006-12-08 23:53:00 +0000417 P->setResolver(AR);
Devang Patel95257542006-12-12 22:21:37 +0000418 initializeAnalysisImpl(P);
Devang Patelfa971cd2006-12-08 23:57:43 +0000419 addImmutablePass(IP);
Devang Patel95257542006-12-12 22:21:37 +0000420 recordAvailableAnalysis(IP);
Devang Patel0f080042007-01-12 17:23:48 +0000421 } else {
David Greene103d4b42010-05-10 20:24:27 +0000422 P->assignPassManager(activeStack, PMT_ModulePassManager);
Devang Pateld440cd92006-12-08 23:53:00 +0000423 }
Devang Patelabcd1d32006-12-07 21:27:23 +0000424 }
425
Chris Lattner2fa26e52010-01-22 05:24:46 +0000426 virtual PMDataManager *getAsPMDataManager() { return this; }
427 virtual Pass *getAsPass() { return this; }
428
Devang Patel67d6a5e2006-12-19 19:46:59 +0000429 MPPassManager *getContainedManager(unsigned N) {
Chris Lattner60987362009-03-06 05:53:14 +0000430 assert(N < PassManagers.size() && "Pass number out of range!");
Devang Patel67d6a5e2006-12-19 19:46:59 +0000431 MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
432 return MP;
433 }
Devang Patel376fefa2006-11-08 10:29:57 +0000434};
435
Devang Patel8c78a0b2007-05-03 01:11:54 +0000436char PassManagerImpl::ID = 0;
Devang Patel1c3633e2007-01-29 23:10:37 +0000437} // End of llvm namespace
438
439namespace {
440
441//===----------------------------------------------------------------------===//
Chris Lattner4c1e9542009-03-06 06:45:05 +0000442/// TimingInfo Class - This class is used to calculate information about the
443/// amount of time each pass takes to execute. This only happens when
444/// -time-passes is enabled on the command line.
445///
Owen Anderson0dd39fd2009-06-17 21:28:54 +0000446
Owen Anderson5a6960f2009-06-18 20:51:00 +0000447static ManagedStatic<sys::SmartMutex<true> > TimingInfoMutex;
Owen Anderson0dd39fd2009-06-17 21:28:54 +0000448
Nick Lewycky02d5f772009-10-25 06:33:48 +0000449class TimingInfo {
Chris Lattner707431c2010-03-30 04:03:22 +0000450 DenseMap<Pass*, Timer*> TimingData;
Devang Patel1c3633e2007-01-29 23:10:37 +0000451 TimerGroup TG;
Devang Patel1c3633e2007-01-29 23:10:37 +0000452public:
453 // Use 'create' member to get this.
454 TimingInfo() : TG("... Pass execution timing report ...") {}
455
456 // TimingDtor - Print out information about timing information
457 ~TimingInfo() {
Chris Lattner707431c2010-03-30 04:03:22 +0000458 // Delete all of the timers, which accumulate their info into the
459 // TimerGroup.
460 for (DenseMap<Pass*, Timer*>::iterator I = TimingData.begin(),
461 E = TimingData.end(); I != E; ++I)
462 delete I->second;
Devang Patel1c3633e2007-01-29 23:10:37 +0000463 // TimerGroup is deleted next, printing the report.
464 }
465
466 // createTheTimeInfo - This method either initializes the TheTimeInfo pointer
467 // to a non null value (if the -time-passes option is enabled) or it leaves it
468 // null. It may be called multiple times.
469 static void createTheTimeInfo();
470
Chris Lattner707431c2010-03-30 04:03:22 +0000471 /// getPassTimer - Return the timer for the specified pass if it exists.
472 Timer *getPassTimer(Pass *P) {
Chris Lattner2fa26e52010-01-22 05:24:46 +0000473 if (P->getAsPMDataManager())
Dan Gohman277e7672009-09-28 00:07:05 +0000474 return 0;
Devang Patel1c3633e2007-01-29 23:10:37 +0000475
Owen Anderson5c96ef72009-07-07 18:33:04 +0000476 sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
Chris Lattner707431c2010-03-30 04:03:22 +0000477 Timer *&T = TimingData[P];
478 if (T == 0)
479 T = new Timer(P->getPassName(), TG);
Chris Lattnerec8ef9b2010-03-30 03:57:00 +0000480 return T;
Devang Patel1c3633e2007-01-29 23:10:37 +0000481 }
482};
483
Devang Patel1c3633e2007-01-29 23:10:37 +0000484} // End of anon namespace
Devang Patelca58e352006-11-08 10:05:38 +0000485
Dan Gohmand78c4002008-05-13 00:00:25 +0000486static TimingInfo *TheTimeInfo;
487
Devang Patela1514cb2006-12-07 19:39:39 +0000488//===----------------------------------------------------------------------===//
Devang Patelafb1f3622006-12-12 22:35:25 +0000489// PMTopLevelManager implementation
490
Devang Patel4268fc02007-01-16 02:00:38 +0000491/// Initialize top level manager. Create first pass manager.
Chris Lattner4c1e9542009-03-06 06:45:05 +0000492PMTopLevelManager::PMTopLevelManager(enum TopLevelManagerType t) {
Devang Patel4268fc02007-01-16 02:00:38 +0000493 if (t == TLM_Pass) {
494 MPPassManager *MPP = new MPPassManager(1);
495 MPP->setTopLevelManager(this);
496 addPassManager(MPP);
497 activeStack.push(MPP);
Chris Lattner4c1e9542009-03-06 06:45:05 +0000498 } else if (t == TLM_Function) {
Devang Patel4268fc02007-01-16 02:00:38 +0000499 FPPassManager *FPP = new FPPassManager(1);
500 FPP->setTopLevelManager(this);
501 addPassManager(FPP);
502 activeStack.push(FPP);
503 }
504}
505
Devang Patelafb1f3622006-12-12 22:35:25 +0000506/// Set pass P as the last user of the given analysis passes.
Devang Patel8adae862007-07-20 18:04:54 +0000507void PMTopLevelManager::setLastUser(SmallVector<Pass *, 12> &AnalysisPasses,
Devang Patelafb1f3622006-12-12 22:35:25 +0000508 Pass *P) {
Devang Patel8adae862007-07-20 18:04:54 +0000509 for (SmallVector<Pass *, 12>::iterator I = AnalysisPasses.begin(),
Devang Patelafb1f3622006-12-12 22:35:25 +0000510 E = AnalysisPasses.end(); I != E; ++I) {
511 Pass *AP = *I;
512 LastUser[AP] = P;
Devang Patel01919d22007-03-08 19:05:01 +0000513
514 if (P == AP)
515 continue;
516
Devang Patelafb1f3622006-12-12 22:35:25 +0000517 // If AP is the last user of other passes then make P last user of
518 // such passes.
Devang Patelc68a0b62008-08-12 00:26:16 +0000519 for (DenseMap<Pass *, Pass *>::iterator LUI = LastUser.begin(),
Devang Patelafb1f3622006-12-12 22:35:25 +0000520 LUE = LastUser.end(); LUI != LUE; ++LUI) {
521 if (LUI->second == AP)
Devang Patelc68a0b62008-08-12 00:26:16 +0000522 // DenseMap iterator is not invalidated here because
523 // this is just updating exisitng entry.
Devang Patelafb1f3622006-12-12 22:35:25 +0000524 LastUser[LUI->first] = P;
525 }
526 }
Devang Patelafb1f3622006-12-12 22:35:25 +0000527}
528
529/// Collect passes whose last user is P
Devang Patel8adae862007-07-20 18:04:54 +0000530void PMTopLevelManager::collectLastUses(SmallVector<Pass *, 12> &LastUses,
Devang Patelc68a0b62008-08-12 00:26:16 +0000531 Pass *P) {
532 DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator DMI =
533 InversedLastUser.find(P);
534 if (DMI == InversedLastUser.end())
535 return;
536
537 SmallPtrSet<Pass *, 8> &LU = DMI->second;
538 for (SmallPtrSet<Pass *, 8>::iterator I = LU.begin(),
539 E = LU.end(); I != E; ++I) {
540 LastUses.push_back(*I);
541 }
542
Devang Patelafb1f3622006-12-12 22:35:25 +0000543}
544
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000545AnalysisUsage *PMTopLevelManager::findAnalysisUsage(Pass *P) {
546 AnalysisUsage *AnUsage = NULL;
547 DenseMap<Pass *, AnalysisUsage *>::iterator DMI = AnUsageMap.find(P);
548 if (DMI != AnUsageMap.end())
549 AnUsage = DMI->second;
550 else {
551 AnUsage = new AnalysisUsage();
552 P->getAnalysisUsage(*AnUsage);
553 AnUsageMap[P] = AnUsage;
554 }
555 return AnUsage;
556}
557
Devang Patelafb1f3622006-12-12 22:35:25 +0000558/// Schedule pass P for execution. Make sure that passes required by
559/// P are run before P is run. Update analysis info maintained by
560/// the manager. Remove dead passes. This is a recursive function.
561void PMTopLevelManager::schedulePass(Pass *P) {
562
Devang Patel3312f752007-01-16 21:43:18 +0000563 // TODO : Allocate function manager for this pass, other wise required set
564 // may be inserted into previous function manager
Devang Patelafb1f3622006-12-12 22:35:25 +0000565
Devang Pateld74ede72007-03-06 01:06:16 +0000566 // Give pass a chance to prepare the stage.
567 P->preparePassManager(activeStack);
568
Devang Patel864970e2008-03-18 00:39:19 +0000569 // If P is an analysis pass and it is available then do not
570 // generate the analysis again. Stale analysis info should not be
571 // available at this point.
Owen Andersona7aed182010-08-06 18:33:48 +0000572 const PassInfo *PI =
573 PassRegistry::getPassRegistry()->getPassInfo(P->getPassID());
574 if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) {
Nuno Lopes0460bb22008-11-04 23:03:58 +0000575 delete P;
Devang Patelaf75ab82008-03-19 00:48:41 +0000576 return;
Nuno Lopes0460bb22008-11-04 23:03:58 +0000577 }
Devang Patel864970e2008-03-18 00:39:19 +0000578
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000579 AnalysisUsage *AnUsage = findAnalysisUsage(P);
580
Devang Patelfdee7032008-08-14 23:07:48 +0000581 bool checkAnalysis = true;
582 while (checkAnalysis) {
583 checkAnalysis = false;
584
585 const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
586 for (AnalysisUsage::VectorType::const_iterator I = RequiredSet.begin(),
587 E = RequiredSet.end(); I != E; ++I) {
588
589 Pass *AnalysisPass = findAnalysisPass(*I);
590 if (!AnalysisPass) {
Owen Andersona7aed182010-08-06 18:33:48 +0000591 const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(*I);
592 AnalysisPass = PI->createPass();
Devang Patelfdee7032008-08-14 23:07:48 +0000593 if (P->getPotentialPassManagerType () ==
594 AnalysisPass->getPotentialPassManagerType())
595 // Schedule analysis pass that is managed by the same pass manager.
596 schedulePass(AnalysisPass);
597 else if (P->getPotentialPassManagerType () >
598 AnalysisPass->getPotentialPassManagerType()) {
599 // Schedule analysis pass that is managed by a new manager.
600 schedulePass(AnalysisPass);
601 // Recheck analysis passes to ensure that required analysises that
602 // are already checked are still available.
603 checkAnalysis = true;
604 }
605 else
606 // Do not schedule this analysis. Lower level analsyis
607 // passes are run on the fly.
608 delete AnalysisPass;
609 }
Devang Patelafb1f3622006-12-12 22:35:25 +0000610 }
611 }
612
613 // Now all required passes are available.
614 addTopLevelPass(P);
615}
616
617/// Find the pass that implements Analysis AID. Search immutable
618/// passes and all pass managers. If desired pass is not found
619/// then return NULL.
620Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
621
622 Pass *P = NULL;
Devang Patelcd6ba152006-12-12 22:50:05 +0000623 // Check pass managers
Devang Patel0d29ae02008-08-12 15:44:31 +0000624 for (SmallVector<PMDataManager *, 8>::iterator I = PassManagers.begin(),
Devang Patelcd6ba152006-12-12 22:50:05 +0000625 E = PassManagers.end(); P == NULL && I != E; ++I) {
Dan Gohman73caf5f2008-03-13 01:48:32 +0000626 PMDataManager *PMD = *I;
Devang Patelcd6ba152006-12-12 22:50:05 +0000627 P = PMD->findAnalysisPass(AID, false);
628 }
629
630 // Check other pass managers
Chris Lattner60987362009-03-06 05:53:14 +0000631 for (SmallVector<PMDataManager *, 8>::iterator
632 I = IndirectPassManagers.begin(),
Devang Patelcd6ba152006-12-12 22:50:05 +0000633 E = IndirectPassManagers.end(); P == NULL && I != E; ++I)
634 P = (*I)->findAnalysisPass(AID, false);
635
Devang Patel0d29ae02008-08-12 15:44:31 +0000636 for (SmallVector<ImmutablePass *, 8>::iterator I = ImmutablePasses.begin(),
Devang Patelafb1f3622006-12-12 22:35:25 +0000637 E = ImmutablePasses.end(); P == NULL && I != E; ++I) {
Owen Andersona7aed182010-08-06 18:33:48 +0000638 AnalysisID PI = (*I)->getPassID();
Devang Patelafb1f3622006-12-12 22:35:25 +0000639 if (PI == AID)
640 P = *I;
641
642 // If Pass not found then check the interfaces implemented by Immutable Pass
643 if (!P) {
Owen Andersona7aed182010-08-06 18:33:48 +0000644 const PassInfo *PassInf =
645 PassRegistry::getPassRegistry()->getPassInfo(PI);
Owen Anderson3183ef12010-07-20 16:55:05 +0000646 const std::vector<const PassInfo*> &ImmPI =
Owen Andersona7aed182010-08-06 18:33:48 +0000647 PassInf->getInterfacesImplemented();
648 for (std::vector<const PassInfo*>::const_iterator II = ImmPI.begin(),
649 EE = ImmPI.end(); II != EE; ++II) {
650 if ((*II)->getTypeInfo() == AID)
651 P = *I;
652 }
Devang Patelafb1f3622006-12-12 22:35:25 +0000653 }
654 }
655
Devang Patelafb1f3622006-12-12 22:35:25 +0000656 return P;
657}
658
Devang Pateleda56172006-12-12 23:34:33 +0000659// Print passes managed by this top level manager.
Devang Patel991aeba2006-12-15 20:13:01 +0000660void PMTopLevelManager::dumpPasses() const {
Devang Pateleda56172006-12-12 23:34:33 +0000661
Devang Patelfd4184322007-01-17 20:33:36 +0000662 if (PassDebugging < Structure)
Devang Patel67d6a5e2006-12-19 19:46:59 +0000663 return;
664
Devang Pateleda56172006-12-12 23:34:33 +0000665 // Print out the immutable passes
666 for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i) {
667 ImmutablePasses[i]->dumpPassStructure(0);
668 }
669
Dan Gohman73caf5f2008-03-13 01:48:32 +0000670 // Every class that derives from PMDataManager also derives from Pass
671 // (sometimes indirectly), but there's no inheritance relationship
Chris Lattner2fa26e52010-01-22 05:24:46 +0000672 // between PMDataManager and Pass, so we have to getAsPass to get
Dan Gohman73caf5f2008-03-13 01:48:32 +0000673 // from a PMDataManager* to a Pass*.
Devang Patel0d29ae02008-08-12 15:44:31 +0000674 for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(),
Devang Pateleda56172006-12-12 23:34:33 +0000675 E = PassManagers.end(); I != E; ++I)
Chris Lattner2fa26e52010-01-22 05:24:46 +0000676 (*I)->getAsPass()->dumpPassStructure(1);
Devang Pateleda56172006-12-12 23:34:33 +0000677}
678
Devang Patel991aeba2006-12-15 20:13:01 +0000679void PMTopLevelManager::dumpArguments() const {
Devang Patelcfd70c42006-12-13 22:10:00 +0000680
Devang Patelfd4184322007-01-17 20:33:36 +0000681 if (PassDebugging < Arguments)
Devang Patelcfd70c42006-12-13 22:10:00 +0000682 return;
683
David Greene994e1bb2010-01-05 01:30:02 +0000684 dbgs() << "Pass Arguments: ";
Devang Patel0d29ae02008-08-12 15:44:31 +0000685 for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(),
Chris Lattner4c1e9542009-03-06 06:45:05 +0000686 E = PassManagers.end(); I != E; ++I)
687 (*I)->dumpPassArguments();
David Greene994e1bb2010-01-05 01:30:02 +0000688 dbgs() << "\n";
Devang Patelcfd70c42006-12-13 22:10:00 +0000689}
690
Devang Patele3068402006-12-21 00:16:50 +0000691void PMTopLevelManager::initializeAllAnalysisInfo() {
Devang Patel0d29ae02008-08-12 15:44:31 +0000692 for (SmallVector<PMDataManager *, 8>::iterator I = PassManagers.begin(),
Chris Lattner4c1e9542009-03-06 06:45:05 +0000693 E = PassManagers.end(); I != E; ++I)
694 (*I)->initializeAnalysisInfo();
Devang Patele3068402006-12-21 00:16:50 +0000695
696 // Initailize other pass managers
Devang Patel0d29ae02008-08-12 15:44:31 +0000697 for (SmallVector<PMDataManager *, 8>::iterator I = IndirectPassManagers.begin(),
Devang Patele3068402006-12-21 00:16:50 +0000698 E = IndirectPassManagers.end(); I != E; ++I)
699 (*I)->initializeAnalysisInfo();
Devang Patelc68a0b62008-08-12 00:26:16 +0000700
Chris Lattner60987362009-03-06 05:53:14 +0000701 for (DenseMap<Pass *, Pass *>::iterator DMI = LastUser.begin(),
Devang Patelc68a0b62008-08-12 00:26:16 +0000702 DME = LastUser.end(); DMI != DME; ++DMI) {
703 DenseMap<Pass *, SmallPtrSet<Pass *, 8> >::iterator InvDMI =
704 InversedLastUser.find(DMI->second);
705 if (InvDMI != InversedLastUser.end()) {
706 SmallPtrSet<Pass *, 8> &L = InvDMI->second;
707 L.insert(DMI->first);
708 } else {
709 SmallPtrSet<Pass *, 8> L; L.insert(DMI->first);
710 InversedLastUser[DMI->second] = L;
711 }
712 }
Devang Patele3068402006-12-21 00:16:50 +0000713}
714
Devang Patele7599552007-01-12 18:52:44 +0000715/// Destructor
716PMTopLevelManager::~PMTopLevelManager() {
Devang Patel0d29ae02008-08-12 15:44:31 +0000717 for (SmallVector<PMDataManager *, 8>::iterator I = PassManagers.begin(),
Devang Patele7599552007-01-12 18:52:44 +0000718 E = PassManagers.end(); I != E; ++I)
719 delete *I;
720
Devang Patel0d29ae02008-08-12 15:44:31 +0000721 for (SmallVector<ImmutablePass *, 8>::iterator
Devang Patele7599552007-01-12 18:52:44 +0000722 I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
723 delete *I;
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000724
725 for (DenseMap<Pass *, AnalysisUsage *>::iterator DMI = AnUsageMap.begin(),
Chris Lattner60987362009-03-06 05:53:14 +0000726 DME = AnUsageMap.end(); DMI != DME; ++DMI)
727 delete DMI->second;
Devang Patele7599552007-01-12 18:52:44 +0000728}
729
Devang Patelafb1f3622006-12-12 22:35:25 +0000730//===----------------------------------------------------------------------===//
Devang Pateldbe4a1e2006-12-07 18:36:24 +0000731// PMDataManager implementation
Devang Patelf68a3492006-11-07 22:35:17 +0000732
Devang Patel643676c2006-11-11 01:10:19 +0000733/// Augement AvailableAnalysis by adding analysis made available by pass P.
Devang Patele9976aa2006-12-07 19:33:53 +0000734void PMDataManager::recordAvailableAnalysis(Pass *P) {
Owen Andersona7aed182010-08-06 18:33:48 +0000735 AnalysisID PI = P->getPassID();
Chris Lattner60987362009-03-06 05:53:14 +0000736
737 AvailableAnalysis[PI] = P;
Owen Andersona7aed182010-08-06 18:33:48 +0000738
739 assert(AvailableAnalysis.size());
Devang Patel643676c2006-11-11 01:10:19 +0000740
Chris Lattner60987362009-03-06 05:53:14 +0000741 //This pass is the current implementation of all of the interfaces it
742 //implements as well.
Owen Andersona7aed182010-08-06 18:33:48 +0000743 const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI);
744 if (PInf == 0) return;
745 const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
Owen Anderson3183ef12010-07-20 16:55:05 +0000746 for (unsigned i = 0, e = II.size(); i != e; ++i)
Owen Andersona7aed182010-08-06 18:33:48 +0000747 AvailableAnalysis[II[i]->getTypeInfo()] = P;
Devang Patel643676c2006-11-11 01:10:19 +0000748}
749
Devang Patel9d9fc902007-03-06 17:52:53 +0000750// Return true if P preserves high level analysis used by other
751// passes managed by this manager
752bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000753 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000754 if (AnUsage->getPreservesAll())
Devang Patel9d9fc902007-03-06 17:52:53 +0000755 return true;
756
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000757 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
Devang Patel0d29ae02008-08-12 15:44:31 +0000758 for (SmallVector<Pass *, 8>::iterator I = HigherLevelAnalysis.begin(),
Devang Patel9d9fc902007-03-06 17:52:53 +0000759 E = HigherLevelAnalysis.end(); I != E; ++I) {
760 Pass *P1 = *I;
Chris Lattner21889d72010-01-22 04:55:08 +0000761 if (P1->getAsImmutablePass() == 0 &&
Dan Gohman929391a2008-01-29 12:09:55 +0000762 std::find(PreservedSet.begin(), PreservedSet.end(),
Owen Andersona7aed182010-08-06 18:33:48 +0000763 P1->getPassID()) ==
Devang Patel01919d22007-03-08 19:05:01 +0000764 PreservedSet.end())
765 return false;
Devang Patel9d9fc902007-03-06 17:52:53 +0000766 }
767
768 return true;
769}
770
Chris Lattner02eb94c2008-08-07 07:34:50 +0000771/// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
Devang Patela273d1c2007-07-19 18:02:32 +0000772void PMDataManager::verifyPreservedAnalysis(Pass *P) {
Chris Lattner02eb94c2008-08-07 07:34:50 +0000773 // Don't do this unless assertions are enabled.
774#ifdef NDEBUG
775 return;
776#endif
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000777 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
778 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
Devang Patelf68a3492006-11-07 22:35:17 +0000779
Devang Patelef432532007-07-19 05:36:09 +0000780 // Verify preserved analysis
Chris Lattnercbd160f2008-08-08 05:33:04 +0000781 for (AnalysisUsage::VectorType::const_iterator I = PreservedSet.begin(),
Devang Patela273d1c2007-07-19 18:02:32 +0000782 E = PreservedSet.end(); I != E; ++I) {
783 AnalysisID AID = *I;
Dan Gohman4dbb3012009-09-28 00:27:48 +0000784 if (Pass *AP = findAnalysisPass(AID, true)) {
Chris Lattner707431c2010-03-30 04:03:22 +0000785 TimeRegion PassTimer(getPassTimer(AP));
Devang Patela273d1c2007-07-19 18:02:32 +0000786 AP->verifyAnalysis();
Dan Gohman4dbb3012009-09-28 00:27:48 +0000787 }
Devang Patel9dbe4d12008-07-01 17:44:24 +0000788 }
789}
790
Devang Patel67c79a42008-07-01 19:50:56 +0000791/// Remove Analysis not preserved by Pass P
Devang Patela273d1c2007-07-19 18:02:32 +0000792void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000793 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
794 if (AnUsage->getPreservesAll())
Devang Patel2e169c32006-12-07 20:03:49 +0000795 return;
796
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000797 const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
Devang Patelf60b5d92006-11-14 01:59:59 +0000798 for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
Devang Patelbe6bd55e2006-12-12 23:07:44 +0000799 E = AvailableAnalysis.end(); I != E; ) {
Devang Patel56d48ec2006-12-15 22:57:49 +0000800 std::map<AnalysisID, Pass*>::iterator Info = I++;
Chris Lattner21889d72010-01-22 04:55:08 +0000801 if (Info->second->getAsImmutablePass() == 0 &&
802 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
Devang Patelbb4720c2008-06-03 01:02:16 +0000803 PreservedSet.end()) {
Devang Patel349170f2006-11-11 01:24:55 +0000804 // Remove this analysis
Devang Patelbb4720c2008-06-03 01:02:16 +0000805 if (PassDebugging >= Details) {
806 Pass *S = Info->second;
David Greene994e1bb2010-01-05 01:30:02 +0000807 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
808 dbgs() << S->getPassName() << "'\n";
Devang Patelbb4720c2008-06-03 01:02:16 +0000809 }
Dan Gohman193e4c02008-11-06 21:57:17 +0000810 AvailableAnalysis.erase(Info);
Devang Patelbb4720c2008-06-03 01:02:16 +0000811 }
Devang Patel349170f2006-11-11 01:24:55 +0000812 }
Owen Andersona7aed182010-08-06 18:33:48 +0000813
Devang Patel42dd1e92007-03-06 01:55:46 +0000814 // Check inherited analysis also. If P is not preserving analysis
815 // provided by parent manager then remove it here.
816 for (unsigned Index = 0; Index < PMT_Last; ++Index) {
817
818 if (!InheritedAnalysis[Index])
819 continue;
820
821 for (std::map<AnalysisID, Pass*>::iterator
822 I = InheritedAnalysis[Index]->begin(),
823 E = InheritedAnalysis[Index]->end(); I != E; ) {
824 std::map<AnalysisID, Pass *>::iterator Info = I++;
Chris Lattner21889d72010-01-22 04:55:08 +0000825 if (Info->second->getAsImmutablePass() == 0 &&
Dan Gohman929391a2008-01-29 12:09:55 +0000826 std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
Andreas Neustifter46651412009-12-04 06:58:24 +0000827 PreservedSet.end()) {
Devang Patel42dd1e92007-03-06 01:55:46 +0000828 // Remove this analysis
Andreas Neustifter46651412009-12-04 06:58:24 +0000829 if (PassDebugging >= Details) {
830 Pass *S = Info->second;
David Greene994e1bb2010-01-05 01:30:02 +0000831 dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
832 dbgs() << S->getPassName() << "'\n";
Andreas Neustifter46651412009-12-04 06:58:24 +0000833 }
Devang Patel01919d22007-03-08 19:05:01 +0000834 InheritedAnalysis[Index]->erase(Info);
Andreas Neustifter46651412009-12-04 06:58:24 +0000835 }
Devang Patel42dd1e92007-03-06 01:55:46 +0000836 }
837 }
Devang Patelf68a3492006-11-07 22:35:17 +0000838}
839
Devang Patelca189262006-11-14 03:05:08 +0000840/// Remove analysis passes that are not used any longer
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000841void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
Devang Patel003a5592007-03-05 20:01:30 +0000842 enum PassDebuggingString DBG_STR) {
Devang Patel17ad0962006-12-08 00:37:52 +0000843
Devang Patel8adae862007-07-20 18:04:54 +0000844 SmallVector<Pass *, 12> DeadPasses;
Devang Patel69e9f6d2007-04-16 20:27:05 +0000845
Devang Patel2ff44922007-04-16 20:39:59 +0000846 // If this is a on the fly manager then it does not have TPM.
Devang Patel69e9f6d2007-04-16 20:27:05 +0000847 if (!TPM)
848 return;
849
Devang Patel17ad0962006-12-08 00:37:52 +0000850 TPM->collectLastUses(DeadPasses, P);
851
Devang Patel656a9172008-06-06 17:50:36 +0000852 if (PassDebugging >= Details && !DeadPasses.empty()) {
David Greene994e1bb2010-01-05 01:30:02 +0000853 dbgs() << " -*- '" << P->getPassName();
854 dbgs() << "' is the last user of following pass instances.";
855 dbgs() << " Free these instances\n";
Evan Cheng93af6ce2008-06-04 09:13:31 +0000856 }
857
Devang Patel8adae862007-07-20 18:04:54 +0000858 for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(),
Dan Gohman5e8ba5d2009-09-27 23:38:27 +0000859 E = DeadPasses.end(); I != E; ++I)
860 freePass(*I, Msg, DBG_STR);
861}
Devang Patel200d3052006-12-13 23:50:44 +0000862
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000863void PMDataManager::freePass(Pass *P, StringRef Msg,
Dan Gohman5e8ba5d2009-09-27 23:38:27 +0000864 enum PassDebuggingString DBG_STR) {
865 dumpPassInfo(P, FREEING_MSG, DBG_STR, Msg);
Devang Patel200d3052006-12-13 23:50:44 +0000866
Dan Gohman5e8ba5d2009-09-27 23:38:27 +0000867 {
868 // If the pass crashes releasing memory, remember this.
869 PassManagerPrettyStackEntry X(P);
Chris Lattner707431c2010-03-30 04:03:22 +0000870 TimeRegion PassTimer(getPassTimer(P));
871
Dan Gohman5e8ba5d2009-09-27 23:38:27 +0000872 P->releaseMemory();
Dan Gohman5e8ba5d2009-09-27 23:38:27 +0000873 }
874
Owen Andersona7aed182010-08-06 18:33:48 +0000875 AnalysisID PI = P->getPassID();
876 if (const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI)) {
Dan Gohman5e8ba5d2009-09-27 23:38:27 +0000877 // Remove the pass itself (if it is not already removed).
878 AvailableAnalysis.erase(PI);
879
880 // Remove all interfaces this pass implements, for which it is also
881 // listed as the available implementation.
Owen Andersona7aed182010-08-06 18:33:48 +0000882 const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
Owen Anderson3183ef12010-07-20 16:55:05 +0000883 for (unsigned i = 0, e = II.size(); i != e; ++i) {
Devang Patelc3e3ca92008-10-06 20:36:36 +0000884 std::map<AnalysisID, Pass*>::iterator Pos =
Owen Andersona7aed182010-08-06 18:33:48 +0000885 AvailableAnalysis.find(II[i]->getTypeInfo());
Dan Gohman5e8ba5d2009-09-27 23:38:27 +0000886 if (Pos != AvailableAnalysis.end() && Pos->second == P)
Devang Patelc3e3ca92008-10-06 20:36:36 +0000887 AvailableAnalysis.erase(Pos);
Devang Patelc3e3ca92008-10-06 20:36:36 +0000888 }
Devang Patel17ad0962006-12-08 00:37:52 +0000889 }
Devang Patelca189262006-11-14 03:05:08 +0000890}
891
Devang Patel8f677ce2006-12-07 18:47:25 +0000892/// Add pass P into the PassVector. Update
Devang Patel90b05e02006-11-11 02:04:19 +0000893/// AvailableAnalysis appropriately if ProcessAnalysis is true.
Chris Lattner60987362009-03-06 05:53:14 +0000894void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
Devang Pateld440cd92006-12-08 23:53:00 +0000895 // This manager is going to manage pass P. Set up analysis resolver
896 // to connect them.
Devang Patelb66334b2007-01-05 22:47:07 +0000897 AnalysisResolver *AR = new AnalysisResolver(*this);
Devang Pateld440cd92006-12-08 23:53:00 +0000898 P->setResolver(AR);
899
Devang Patelec2b9a72007-03-05 22:57:49 +0000900 // If a FunctionPass F is the last user of ModulePass info M
901 // then the F's manager, not F, records itself as a last user of M.
Devang Patel8adae862007-07-20 18:04:54 +0000902 SmallVector<Pass *, 12> TransferLastUses;
Devang Patelec2b9a72007-03-05 22:57:49 +0000903
Chris Lattner60987362009-03-06 05:53:14 +0000904 if (!ProcessAnalysis) {
905 // Add pass
906 PassVector.push_back(P);
907 return;
Devang Patel90b05e02006-11-11 02:04:19 +0000908 }
Devang Patel8cad70d2006-11-11 01:51:02 +0000909
Chris Lattner60987362009-03-06 05:53:14 +0000910 // At the moment, this pass is the last user of all required passes.
911 SmallVector<Pass *, 12> LastUses;
912 SmallVector<Pass *, 8> RequiredPasses;
913 SmallVector<AnalysisID, 8> ReqAnalysisNotAvailable;
914
915 unsigned PDepth = this->getDepth();
916
917 collectRequiredAnalysis(RequiredPasses,
918 ReqAnalysisNotAvailable, P);
919 for (SmallVector<Pass *, 8>::iterator I = RequiredPasses.begin(),
920 E = RequiredPasses.end(); I != E; ++I) {
921 Pass *PRequired = *I;
922 unsigned RDepth = 0;
923
924 assert(PRequired->getResolver() && "Analysis Resolver is not set");
925 PMDataManager &DM = PRequired->getResolver()->getPMDataManager();
926 RDepth = DM.getDepth();
927
928 if (PDepth == RDepth)
929 LastUses.push_back(PRequired);
930 else if (PDepth > RDepth) {
931 // Let the parent claim responsibility of last use
932 TransferLastUses.push_back(PRequired);
933 // Keep track of higher level analysis used by this manager.
934 HigherLevelAnalysis.push_back(PRequired);
935 } else
Torok Edwinfbcc6632009-07-14 16:55:14 +0000936 llvm_unreachable("Unable to accomodate Required Pass");
Chris Lattner60987362009-03-06 05:53:14 +0000937 }
938
939 // Set P as P's last user until someone starts using P.
940 // However, if P is a Pass Manager then it does not need
941 // to record its last user.
Chris Lattner2fa26e52010-01-22 05:24:46 +0000942 if (P->getAsPMDataManager() == 0)
Chris Lattner60987362009-03-06 05:53:14 +0000943 LastUses.push_back(P);
944 TPM->setLastUser(LastUses, P);
945
946 if (!TransferLastUses.empty()) {
Chris Lattner2fa26e52010-01-22 05:24:46 +0000947 Pass *My_PM = getAsPass();
Chris Lattner60987362009-03-06 05:53:14 +0000948 TPM->setLastUser(TransferLastUses, My_PM);
949 TransferLastUses.clear();
950 }
951
952 // Now, take care of required analysises that are not available.
953 for (SmallVector<AnalysisID, 8>::iterator
954 I = ReqAnalysisNotAvailable.begin(),
955 E = ReqAnalysisNotAvailable.end() ;I != E; ++I) {
Owen Andersona7aed182010-08-06 18:33:48 +0000956 const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(*I);
957 Pass *AnalysisPass = PI->createPass();
Chris Lattner60987362009-03-06 05:53:14 +0000958 this->addLowerLevelRequiredPass(P, AnalysisPass);
959 }
960
961 // Take a note of analysis required and made available by this pass.
962 // Remove the analysis not preserved by this pass
963 removeNotPreservedAnalysis(P);
964 recordAvailableAnalysis(P);
965
Devang Patel8cad70d2006-11-11 01:51:02 +0000966 // Add pass
967 PassVector.push_back(P);
Devang Patel8cad70d2006-11-11 01:51:02 +0000968}
969
Devang Patele64d3052007-04-16 20:12:57 +0000970
971/// Populate RP with analysis pass that are required by
972/// pass P and are available. Populate RP_NotAvail with analysis
973/// pass that are required by pass P but are not available.
974void PMDataManager::collectRequiredAnalysis(SmallVector<Pass *, 8>&RP,
975 SmallVector<AnalysisID, 8> &RP_NotAvail,
976 Pass *P) {
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000977 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
978 const AnalysisUsage::VectorType &RequiredSet = AnUsage->getRequiredSet();
Chris Lattnercbd160f2008-08-08 05:33:04 +0000979 for (AnalysisUsage::VectorType::const_iterator
Chris Lattner60987362009-03-06 05:53:14 +0000980 I = RequiredSet.begin(), E = RequiredSet.end(); I != E; ++I) {
Devang Patele64d3052007-04-16 20:12:57 +0000981 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
982 RP.push_back(AnalysisPass);
983 else
Chris Lattner60987362009-03-06 05:53:14 +0000984 RP_NotAvail.push_back(*I);
Devang Patel1d6267c2006-12-07 23:05:44 +0000985 }
Devang Patelf58183d2006-12-12 23:09:32 +0000986
Devang Patelec9e1a60a2008-08-11 21:13:39 +0000987 const AnalysisUsage::VectorType &IDs = AnUsage->getRequiredTransitiveSet();
Chris Lattnercbd160f2008-08-08 05:33:04 +0000988 for (AnalysisUsage::VectorType::const_iterator I = IDs.begin(),
Devang Patelf58183d2006-12-12 23:09:32 +0000989 E = IDs.end(); I != E; ++I) {
Devang Patele64d3052007-04-16 20:12:57 +0000990 if (Pass *AnalysisPass = findAnalysisPass(*I, true))
991 RP.push_back(AnalysisPass);
992 else
Chris Lattner60987362009-03-06 05:53:14 +0000993 RP_NotAvail.push_back(*I);
Devang Patelf58183d2006-12-12 23:09:32 +0000994 }
Devang Patel1d6267c2006-12-07 23:05:44 +0000995}
996
Devang Patel07f4f582006-11-14 21:49:36 +0000997// All Required analyses should be available to the pass as it runs! Here
998// we fill in the AnalysisImpls member of the pass so that it can
999// successfully use the getAnalysis() method to retrieve the
1000// implementations it needs.
1001//
Devang Pateldbe4a1e2006-12-07 18:36:24 +00001002void PMDataManager::initializeAnalysisImpl(Pass *P) {
Devang Patelec9e1a60a2008-08-11 21:13:39 +00001003 AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
1004
Chris Lattnercbd160f2008-08-08 05:33:04 +00001005 for (AnalysisUsage::VectorType::const_iterator
Devang Patelec9e1a60a2008-08-11 21:13:39 +00001006 I = AnUsage->getRequiredSet().begin(),
1007 E = AnUsage->getRequiredSet().end(); I != E; ++I) {
Devang Patel640c5bb2006-12-08 22:30:11 +00001008 Pass *Impl = findAnalysisPass(*I, true);
Devang Patel07f4f582006-11-14 21:49:36 +00001009 if (Impl == 0)
Devang Patel56a5c622007-04-16 20:44:16 +00001010 // This may be analysis pass that is initialized on the fly.
1011 // If that is not the case then it will raise an assert when it is used.
1012 continue;
Devang Patelb66334b2007-01-05 22:47:07 +00001013 AnalysisResolver *AR = P->getResolver();
Chris Lattner60987362009-03-06 05:53:14 +00001014 assert(AR && "Analysis Resolver is not set");
Devang Patel984698a2006-12-09 01:11:34 +00001015 AR->addAnalysisImplsPair(*I, Impl);
Devang Patel07f4f582006-11-14 21:49:36 +00001016 }
1017}
1018
Devang Patel640c5bb2006-12-08 22:30:11 +00001019/// Find the pass that implements Analysis AID. If desired pass is not found
1020/// then return NULL.
1021Pass *PMDataManager::findAnalysisPass(AnalysisID AID, bool SearchParent) {
1022
1023 // Check if AvailableAnalysis map has one entry.
1024 std::map<AnalysisID, Pass*>::const_iterator I = AvailableAnalysis.find(AID);
1025
1026 if (I != AvailableAnalysis.end())
1027 return I->second;
1028
1029 // Search Parents through TopLevelManager
1030 if (SearchParent)
1031 return TPM->findAnalysisPass(AID);
1032
Devang Patel9d759b82006-12-09 00:09:12 +00001033 return NULL;
Devang Patel640c5bb2006-12-08 22:30:11 +00001034}
1035
Devang Patel991aeba2006-12-15 20:13:01 +00001036// Print list of passes that are last used by P.
1037void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
1038
Devang Patel8adae862007-07-20 18:04:54 +00001039 SmallVector<Pass *, 12> LUses;
Devang Patel2ff44922007-04-16 20:39:59 +00001040
1041 // If this is a on the fly manager then it does not have TPM.
1042 if (!TPM)
1043 return;
1044
Devang Patel991aeba2006-12-15 20:13:01 +00001045 TPM->collectLastUses(LUses, P);
1046
Devang Patel8adae862007-07-20 18:04:54 +00001047 for (SmallVector<Pass *, 12>::iterator I = LUses.begin(),
Devang Patel991aeba2006-12-15 20:13:01 +00001048 E = LUses.end(); I != E; ++I) {
David Greene994e1bb2010-01-05 01:30:02 +00001049 llvm::dbgs() << "--" << std::string(Offset*2, ' ');
Devang Patel991aeba2006-12-15 20:13:01 +00001050 (*I)->dumpPassStructure(0);
1051 }
1052}
1053
1054void PMDataManager::dumpPassArguments() const {
Chris Lattner60987362009-03-06 05:53:14 +00001055 for (SmallVector<Pass *, 8>::const_iterator I = PassVector.begin(),
Devang Patel991aeba2006-12-15 20:13:01 +00001056 E = PassVector.end(); I != E; ++I) {
Chris Lattner2fa26e52010-01-22 05:24:46 +00001057 if (PMDataManager *PMD = (*I)->getAsPMDataManager())
Devang Patel991aeba2006-12-15 20:13:01 +00001058 PMD->dumpPassArguments();
1059 else
Owen Andersona7aed182010-08-06 18:33:48 +00001060 if (const PassInfo *PI =
1061 PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID()))
Devang Patel991aeba2006-12-15 20:13:01 +00001062 if (!PI->isAnalysisGroup())
David Greene994e1bb2010-01-05 01:30:02 +00001063 dbgs() << " -" << PI->getPassArgument();
Devang Patel991aeba2006-12-15 20:13:01 +00001064 }
1065}
1066
Chris Lattnerdd6304f2007-08-10 06:17:04 +00001067void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
1068 enum PassDebuggingString S2,
Daniel Dunbarad36e8a2009-11-06 10:58:06 +00001069 StringRef Msg) {
Devang Patelfd4184322007-01-17 20:33:36 +00001070 if (PassDebugging < Executions)
Devang Patel991aeba2006-12-15 20:13:01 +00001071 return;
David Greene994e1bb2010-01-05 01:30:02 +00001072 dbgs() << (void*)this << std::string(getDepth()*2+1, ' ');
Devang Patel003a5592007-03-05 20:01:30 +00001073 switch (S1) {
1074 case EXECUTION_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001075 dbgs() << "Executing Pass '" << P->getPassName();
Devang Patel003a5592007-03-05 20:01:30 +00001076 break;
1077 case MODIFICATION_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001078 dbgs() << "Made Modification '" << P->getPassName();
Devang Patel003a5592007-03-05 20:01:30 +00001079 break;
1080 case FREEING_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001081 dbgs() << " Freeing Pass '" << P->getPassName();
Devang Patel003a5592007-03-05 20:01:30 +00001082 break;
1083 default:
1084 break;
1085 }
1086 switch (S2) {
1087 case ON_BASICBLOCK_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001088 dbgs() << "' on BasicBlock '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001089 break;
1090 case ON_FUNCTION_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001091 dbgs() << "' on Function '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001092 break;
1093 case ON_MODULE_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001094 dbgs() << "' on Module '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001095 break;
1096 case ON_LOOP_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001097 dbgs() << "' on Loop '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001098 break;
1099 case ON_CG_MSG:
David Greene994e1bb2010-01-05 01:30:02 +00001100 dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
Devang Patel003a5592007-03-05 20:01:30 +00001101 break;
1102 default:
1103 break;
1104 }
Devang Patel991aeba2006-12-15 20:13:01 +00001105}
1106
Chris Lattner4c1e9542009-03-06 06:45:05 +00001107void PMDataManager::dumpRequiredSet(const Pass *P) const {
Chris Lattner4c493d92008-08-08 15:14:09 +00001108 if (PassDebugging < Details)
1109 return;
1110
1111 AnalysisUsage analysisUsage;
1112 P->getAnalysisUsage(analysisUsage);
1113 dumpAnalysisUsage("Required", P, analysisUsage.getRequiredSet());
1114}
1115
Chris Lattner4c1e9542009-03-06 06:45:05 +00001116void PMDataManager::dumpPreservedSet(const Pass *P) const {
Chris Lattner4c493d92008-08-08 15:14:09 +00001117 if (PassDebugging < Details)
1118 return;
1119
1120 AnalysisUsage analysisUsage;
1121 P->getAnalysisUsage(analysisUsage);
1122 dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
1123}
1124
Daniel Dunbarad36e8a2009-11-06 10:58:06 +00001125void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
Chris Lattner4c1e9542009-03-06 06:45:05 +00001126 const AnalysisUsage::VectorType &Set) const {
Chris Lattner4c493d92008-08-08 15:14:09 +00001127 assert(PassDebugging >= Details);
1128 if (Set.empty())
1129 return;
David Greene994e1bb2010-01-05 01:30:02 +00001130 dbgs() << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
Chris Lattner4c1e9542009-03-06 06:45:05 +00001131 for (unsigned i = 0; i != Set.size(); ++i) {
David Greene994e1bb2010-01-05 01:30:02 +00001132 if (i) dbgs() << ',';
Owen Andersona7aed182010-08-06 18:33:48 +00001133 const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(Set[i]);
1134 dbgs() << ' ' << PInf->getPassName();
Chris Lattner4c1e9542009-03-06 06:45:05 +00001135 }
David Greene994e1bb2010-01-05 01:30:02 +00001136 dbgs() << '\n';
Devang Patel991aeba2006-12-15 20:13:01 +00001137}
Devang Patel9bdf7d42006-12-08 23:28:54 +00001138
Devang Patel004937b2007-07-27 20:06:09 +00001139/// Add RequiredPass into list of lower level passes required by pass P.
1140/// RequiredPass is run on the fly by Pass Manager when P requests it
1141/// through getAnalysis interface.
1142/// This should be handled by specific pass manager.
1143void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
1144 if (TPM) {
1145 TPM->dumpArguments();
1146 TPM->dumpPasses();
1147 }
Devang Patel8df7cc12008-02-02 01:43:30 +00001148
1149 // Module Level pass may required Function Level analysis info
1150 // (e.g. dominator info). Pass manager uses on the fly function pass manager
1151 // to provide this on demand. In that case, in Pass manager terminology,
1152 // module level pass is requiring lower level analysis info managed by
1153 // lower level pass manager.
1154
1155 // When Pass manager is not able to order required analysis info, Pass manager
1156 // checks whether any lower level manager will be able to provide this
1157 // analysis info on demand or not.
Devang Patelab85d6b2008-06-03 01:20:02 +00001158#ifndef NDEBUG
David Greene994e1bb2010-01-05 01:30:02 +00001159 dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
1160 dbgs() << "' required by '" << P->getPassName() << "'\n";
Devang Patelab85d6b2008-06-03 01:20:02 +00001161#endif
Torok Edwinfbcc6632009-07-14 16:55:14 +00001162 llvm_unreachable("Unable to schedule pass");
Devang Patel004937b2007-07-27 20:06:09 +00001163}
1164
Owen Andersona7aed182010-08-06 18:33:48 +00001165Pass *PMDataManager::getOnTheFlyPass(Pass *P, AnalysisID PI, Function &F) {
Dan Gohmanffdee302010-06-21 18:46:45 +00001166 assert(0 && "Unable to find on the fly pass");
1167 return NULL;
1168}
1169
Devang Patele7599552007-01-12 18:52:44 +00001170// Destructor
1171PMDataManager::~PMDataManager() {
Devang Patel0d29ae02008-08-12 15:44:31 +00001172 for (SmallVector<Pass *, 8>::iterator I = PassVector.begin(),
Devang Patele7599552007-01-12 18:52:44 +00001173 E = PassVector.end(); I != E; ++I)
1174 delete *I;
Devang Patele7599552007-01-12 18:52:44 +00001175}
1176
Devang Patel9bdf7d42006-12-08 23:28:54 +00001177//===----------------------------------------------------------------------===//
1178// NOTE: Is this the right place to define this method ?
Duncan Sands5a913d62009-01-28 13:14:17 +00001179// getAnalysisIfAvailable - Return analysis result or null if it doesn't exist.
1180Pass *AnalysisResolver::getAnalysisIfAvailable(AnalysisID ID, bool dir) const {
Devang Patel9bdf7d42006-12-08 23:28:54 +00001181 return PM.findAnalysisPass(ID, dir);
1182}
1183
Owen Andersona7aed182010-08-06 18:33:48 +00001184Pass *AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI,
Devang Patel92942812007-04-16 20:56:24 +00001185 Function &F) {
1186 return PM.getOnTheFlyPass(P, AnalysisPI, F);
1187}
1188
Devang Patela1514cb2006-12-07 19:39:39 +00001189//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +00001190// BBPassManager implementation
Devang Patel6e5a1132006-11-07 21:31:57 +00001191
Devang Patel6e5a1132006-11-07 21:31:57 +00001192/// Execute all of the passes scheduled for execution by invoking
1193/// runOnBasicBlock method. Keep track of whether any of the passes modifies
1194/// the function, and if so, return true.
Chris Lattner4c1e9542009-03-06 06:45:05 +00001195bool BBPassManager::runOnFunction(Function &F) {
Reid Spencer5301e7c2007-01-30 20:08:39 +00001196 if (F.isDeclaration())
Devang Patel745a6962006-12-12 23:15:28 +00001197 return false;
1198
Devang Patele9585592006-12-08 01:38:28 +00001199 bool Changed = doInitialization(F);
Devang Patel050ec722006-11-14 01:23:29 +00001200
Devang Patel6e5a1132006-11-07 21:31:57 +00001201 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
Devang Patelabfbe3b2006-12-16 00:56:26 +00001202 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1203 BasicBlockPass *BP = getContainedPass(Index);
Dan Gohman74b189f2010-03-01 17:34:28 +00001204 bool LocalChanged = false;
Devang Patelf6d1d212006-12-14 00:25:06 +00001205
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001206 dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getName());
Chris Lattner4c493d92008-08-08 15:14:09 +00001207 dumpRequiredSet(BP);
Devang Patelf6d1d212006-12-14 00:25:06 +00001208
Devang Patelabfbe3b2006-12-16 00:56:26 +00001209 initializeAnalysisImpl(BP);
Devang Patel93a197c2006-12-14 00:08:04 +00001210
Chris Lattner4c1e9542009-03-06 06:45:05 +00001211 {
1212 // If the pass crashes, remember this.
1213 PassManagerPrettyStackEntry X(BP, *I);
Chris Lattner707431c2010-03-30 04:03:22 +00001214 TimeRegion PassTimer(getPassTimer(BP));
1215
Dan Gohman74b189f2010-03-01 17:34:28 +00001216 LocalChanged |= BP->runOnBasicBlock(*I);
Chris Lattner4c1e9542009-03-06 06:45:05 +00001217 }
Devang Patel93a197c2006-12-14 00:08:04 +00001218
Dan Gohman74b189f2010-03-01 17:34:28 +00001219 Changed |= LocalChanged;
1220 if (LocalChanged)
Dan Gohman929391a2008-01-29 12:09:55 +00001221 dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001222 I->getName());
Chris Lattner4c493d92008-08-08 15:14:09 +00001223 dumpPreservedSet(BP);
Devang Patel93a197c2006-12-14 00:08:04 +00001224
Devang Patela273d1c2007-07-19 18:02:32 +00001225 verifyPreservedAnalysis(BP);
Devang Patelabfbe3b2006-12-16 00:56:26 +00001226 removeNotPreservedAnalysis(BP);
1227 recordAvailableAnalysis(BP);
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001228 removeDeadPasses(BP, I->getName(), ON_BASICBLOCK_MSG);
Devang Patel6e5a1132006-11-07 21:31:57 +00001229 }
Chris Lattnerde2aa652007-08-10 06:22:25 +00001230
Bill Wendling6ce6d262009-12-25 13:50:18 +00001231 return doFinalization(F) || Changed;
Devang Patel6e5a1132006-11-07 21:31:57 +00001232}
1233
Devang Patel475c4532006-12-08 00:59:05 +00001234// Implement doInitialization and doFinalization
Duncan Sands51495602009-02-13 09:42:34 +00001235bool BBPassManager::doInitialization(Module &M) {
Devang Patel475c4532006-12-08 00:59:05 +00001236 bool Changed = false;
1237
Chris Lattner4c1e9542009-03-06 06:45:05 +00001238 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1239 Changed |= getContainedPass(Index)->doInitialization(M);
Devang Patel475c4532006-12-08 00:59:05 +00001240
1241 return Changed;
1242}
1243
Duncan Sands51495602009-02-13 09:42:34 +00001244bool BBPassManager::doFinalization(Module &M) {
Devang Patel475c4532006-12-08 00:59:05 +00001245 bool Changed = false;
1246
Chris Lattner4c1e9542009-03-06 06:45:05 +00001247 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1248 Changed |= getContainedPass(Index)->doFinalization(M);
Devang Patel475c4532006-12-08 00:59:05 +00001249
1250 return Changed;
1251}
1252
Duncan Sands51495602009-02-13 09:42:34 +00001253bool BBPassManager::doInitialization(Function &F) {
Devang Patel475c4532006-12-08 00:59:05 +00001254 bool Changed = false;
1255
Devang Patelabfbe3b2006-12-16 00:56:26 +00001256 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1257 BasicBlockPass *BP = getContainedPass(Index);
Devang Patel475c4532006-12-08 00:59:05 +00001258 Changed |= BP->doInitialization(F);
1259 }
1260
1261 return Changed;
1262}
1263
Duncan Sands51495602009-02-13 09:42:34 +00001264bool BBPassManager::doFinalization(Function &F) {
Devang Patel475c4532006-12-08 00:59:05 +00001265 bool Changed = false;
1266
Devang Patelabfbe3b2006-12-16 00:56:26 +00001267 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1268 BasicBlockPass *BP = getContainedPass(Index);
Devang Patel475c4532006-12-08 00:59:05 +00001269 Changed |= BP->doFinalization(F);
1270 }
1271
1272 return Changed;
1273}
1274
1275
Devang Patela1514cb2006-12-07 19:39:39 +00001276//===----------------------------------------------------------------------===//
Devang Patelb67904d2006-12-13 02:36:01 +00001277// FunctionPassManager implementation
Devang Patela1514cb2006-12-07 19:39:39 +00001278
Devang Patel4e12f862006-11-08 10:44:40 +00001279/// Create new Function pass manager
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00001280FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001281 FPM = new FunctionPassManagerImpl(0);
Devang Patel9c6290c2006-12-12 22:02:16 +00001282 // FPM is the top level manager.
1283 FPM->setTopLevelManager(FPM);
Devang Patel1036b652006-12-12 23:27:37 +00001284
Dan Gohman565df952008-03-13 02:08:36 +00001285 AnalysisResolver *AR = new AnalysisResolver(*FPM);
Devang Patel1036b652006-12-12 23:27:37 +00001286 FPM->setResolver(AR);
Devang Patel1f653682006-12-08 18:57:16 +00001287}
1288
Devang Patelb67904d2006-12-13 02:36:01 +00001289FunctionPassManager::~FunctionPassManager() {
Devang Patelab97cf42006-12-13 00:09:23 +00001290 delete FPM;
1291}
1292
David Greene103d4b42010-05-10 20:24:27 +00001293/// addImpl - Add a pass to the queue of passes to run, without
1294/// checking whether to add a printer pass.
1295void FunctionPassManager::addImpl(Pass *P) {
1296 FPM->add(P);
1297}
1298
Devang Patel4e12f862006-11-08 10:44:40 +00001299/// add - Add a pass to the queue of passes to run. This passes
1300/// ownership of the Pass to the PassManager. When the
1301/// PassManager_X is destroyed, the pass will be destroyed as well, so
1302/// there is no need to delete the pass. (TODO delete passes.)
1303/// This implies that all passes MUST be allocated with 'new'.
Devang Patelb67904d2006-12-13 02:36:01 +00001304void FunctionPassManager::add(Pass *P) {
David Greene103d4b42010-05-10 20:24:27 +00001305 // If this is a not a function pass, don't add a printer for it.
Owen Andersona7aed182010-08-06 18:33:48 +00001306 const void *PassID = P->getPassID();
David Greene103d4b42010-05-10 20:24:27 +00001307 if (P->getPassKind() == PT_Function)
Owen Andersona7aed182010-08-06 18:33:48 +00001308 if (ShouldPrintBeforePass(PassID))
David Greene103d4b42010-05-10 20:24:27 +00001309 addImpl(P->createPrinterPass(dbgs(), std::string("*** IR Dump Before ")
1310 + P->getPassName() + " ***"));
David Greene9b063df2010-04-02 23:17:14 +00001311
David Greene103d4b42010-05-10 20:24:27 +00001312 addImpl(P);
1313
1314 if (P->getPassKind() == PT_Function)
Owen Andersona7aed182010-08-06 18:33:48 +00001315 if (ShouldPrintAfterPass(PassID))
David Greene103d4b42010-05-10 20:24:27 +00001316 addImpl(P->createPrinterPass(dbgs(), std::string("*** IR Dump After ")
1317 + P->getPassName() + " ***"));
Devang Patel4e12f862006-11-08 10:44:40 +00001318}
1319
Devang Patel9f3083e2006-11-15 19:39:54 +00001320/// run - Execute all of the passes scheduled for execution. Keep
1321/// track of whether any of the passes modifies the function, and if
1322/// so, return true.
1323///
Devang Patelb67904d2006-12-13 02:36:01 +00001324bool FunctionPassManager::run(Function &F) {
Nick Lewycky94e168f2010-02-15 21:27:56 +00001325 if (F.isMaterializable()) {
1326 std::string errstr;
Chris Lattnerb6166b32010-04-07 22:41:29 +00001327 if (F.Materialize(&errstr))
Benjamin Kramera6769262010-04-08 10:44:28 +00001328 report_fatal_error("Error reading bitcode file: " + Twine(errstr));
Devang Patel9f3083e2006-11-15 19:39:54 +00001329 }
Devang Patel272908d2006-12-08 22:57:48 +00001330 return FPM->run(F);
Devang Patel9f3083e2006-11-15 19:39:54 +00001331}
1332
1333
Devang Patelff631ae2006-11-15 01:27:05 +00001334/// doInitialization - Run all of the initializers for the function passes.
1335///
Devang Patelb67904d2006-12-13 02:36:01 +00001336bool FunctionPassManager::doInitialization() {
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00001337 return FPM->doInitialization(*M);
Devang Patelff631ae2006-11-15 01:27:05 +00001338}
1339
Dan Gohmane6656eb2007-07-30 14:51:13 +00001340/// doFinalization - Run all of the finalizers for the function passes.
Devang Patelff631ae2006-11-15 01:27:05 +00001341///
Devang Patelb67904d2006-12-13 02:36:01 +00001342bool FunctionPassManager::doFinalization() {
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00001343 return FPM->doFinalization(*M);
Devang Patelff631ae2006-11-15 01:27:05 +00001344}
1345
Devang Patela1514cb2006-12-07 19:39:39 +00001346//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +00001347// FunctionPassManagerImpl implementation
1348//
Duncan Sands51495602009-02-13 09:42:34 +00001349bool FunctionPassManagerImpl::doInitialization(Module &M) {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001350 bool Changed = false;
1351
Dan Gohman05ebc8f2009-11-23 16:24:18 +00001352 dumpArguments();
1353 dumpPasses();
1354
Chris Lattner4c1e9542009-03-06 06:45:05 +00001355 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1356 Changed |= getContainedManager(Index)->doInitialization(M);
Devang Patel67d6a5e2006-12-19 19:46:59 +00001357
1358 return Changed;
1359}
1360
Duncan Sands51495602009-02-13 09:42:34 +00001361bool FunctionPassManagerImpl::doFinalization(Module &M) {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001362 bool Changed = false;
1363
Chris Lattner4c1e9542009-03-06 06:45:05 +00001364 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1365 Changed |= getContainedManager(Index)->doFinalization(M);
Devang Patel67d6a5e2006-12-19 19:46:59 +00001366
1367 return Changed;
1368}
1369
Devang Patelec9c58f2009-04-01 22:34:41 +00001370/// cleanup - After running all passes, clean up pass manager cache.
1371void FPPassManager::cleanup() {
1372 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1373 FunctionPass *FP = getContainedPass(Index);
1374 AnalysisResolver *AR = FP->getResolver();
1375 assert(AR && "Analysis Resolver is not set");
1376 AR->clearAnalysisImpls();
1377 }
1378}
1379
Torok Edwin24c78352009-06-29 18:49:09 +00001380void FunctionPassManagerImpl::releaseMemoryOnTheFly() {
1381 if (!wasRun)
1382 return;
1383 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
1384 FPPassManager *FPPM = getContainedManager(Index);
1385 for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) {
1386 FPPM->getContainedPass(Index)->releaseMemory();
1387 }
1388 }
Torok Edwin896556e2009-06-29 21:05:10 +00001389 wasRun = false;
Torok Edwin24c78352009-06-29 18:49:09 +00001390}
1391
Devang Patel67d6a5e2006-12-19 19:46:59 +00001392// Execute all the passes managed by this top level manager.
1393// Return true if any function is modified by a pass.
1394bool FunctionPassManagerImpl::run(Function &F) {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001395 bool Changed = false;
Devang Patel67d6a5e2006-12-19 19:46:59 +00001396 TimingInfo::createTheTimeInfo();
1397
Devang Patele3068402006-12-21 00:16:50 +00001398 initializeAllAnalysisInfo();
Chris Lattner4c1e9542009-03-06 06:45:05 +00001399 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1400 Changed |= getContainedManager(Index)->runOnFunction(F);
Devang Patelec9c58f2009-04-01 22:34:41 +00001401
1402 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1403 getContainedManager(Index)->cleanup();
1404
Torok Edwin24c78352009-06-29 18:49:09 +00001405 wasRun = true;
Devang Patel67d6a5e2006-12-19 19:46:59 +00001406 return Changed;
1407}
1408
1409//===----------------------------------------------------------------------===//
1410// FPPassManager implementation
Devang Patel0c2012f2006-11-07 21:49:50 +00001411
Devang Patel8c78a0b2007-05-03 01:11:54 +00001412char FPPassManager::ID = 0;
Devang Patele7599552007-01-12 18:52:44 +00001413/// Print passes managed by this manager
1414void FPPassManager::dumpPassStructure(unsigned Offset) {
David Greene994e1bb2010-01-05 01:30:02 +00001415 llvm::dbgs() << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
Devang Patele7599552007-01-12 18:52:44 +00001416 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1417 FunctionPass *FP = getContainedPass(Index);
1418 FP->dumpPassStructure(Offset + 1);
1419 dumpLastUses(FP, Offset+1);
1420 }
1421}
1422
1423
Devang Patel0c2012f2006-11-07 21:49:50 +00001424/// Execute all of the passes scheduled for execution by invoking
1425/// runOnFunction method. Keep track of whether any of the passes modifies
1426/// the function, and if so, return true.
Devang Patel67d6a5e2006-12-19 19:46:59 +00001427bool FPPassManager::runOnFunction(Function &F) {
Chris Lattner60987362009-03-06 05:53:14 +00001428 if (F.isDeclaration())
1429 return false;
Devang Patel9f3083e2006-11-15 19:39:54 +00001430
1431 bool Changed = false;
Devang Patel745a6962006-12-12 23:15:28 +00001432
Devang Patelcbbf2912008-03-20 01:09:53 +00001433 // Collect inherited analysis from Module level pass manager.
1434 populateInheritedAnalysis(TPM->activeStack);
Devang Patel745a6962006-12-12 23:15:28 +00001435
Devang Patelabfbe3b2006-12-16 00:56:26 +00001436 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1437 FunctionPass *FP = getContainedPass(Index);
Dan Gohman74b189f2010-03-01 17:34:28 +00001438 bool LocalChanged = false;
Devang Patelabfbe3b2006-12-16 00:56:26 +00001439
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001440 dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getName());
Chris Lattner4c493d92008-08-08 15:14:09 +00001441 dumpRequiredSet(FP);
Devang Patel93a197c2006-12-14 00:08:04 +00001442
Devang Patelabfbe3b2006-12-16 00:56:26 +00001443 initializeAnalysisImpl(FP);
Devang Patelb8817b92006-12-14 00:59:42 +00001444
Chris Lattner4c1e9542009-03-06 06:45:05 +00001445 {
1446 PassManagerPrettyStackEntry X(FP, F);
Chris Lattner707431c2010-03-30 04:03:22 +00001447 TimeRegion PassTimer(getPassTimer(FP));
Chris Lattner4c1e9542009-03-06 06:45:05 +00001448
Dan Gohman74b189f2010-03-01 17:34:28 +00001449 LocalChanged |= FP->runOnFunction(F);
Chris Lattner4c1e9542009-03-06 06:45:05 +00001450 }
Devang Patel93a197c2006-12-14 00:08:04 +00001451
Dan Gohman74b189f2010-03-01 17:34:28 +00001452 Changed |= LocalChanged;
1453 if (LocalChanged)
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001454 dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName());
Chris Lattner4c493d92008-08-08 15:14:09 +00001455 dumpPreservedSet(FP);
Devang Patel93a197c2006-12-14 00:08:04 +00001456
Devang Patela273d1c2007-07-19 18:02:32 +00001457 verifyPreservedAnalysis(FP);
Devang Patelabfbe3b2006-12-16 00:56:26 +00001458 removeNotPreservedAnalysis(FP);
1459 recordAvailableAnalysis(FP);
Daniel Dunbar9813b0b2009-07-26 07:49:05 +00001460 removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
Devang Patel9f3083e2006-11-15 19:39:54 +00001461 }
1462 return Changed;
1463}
1464
Devang Patel67d6a5e2006-12-19 19:46:59 +00001465bool FPPassManager::runOnModule(Module &M) {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001466 bool Changed = doInitialization(M);
Devang Patel67d6a5e2006-12-19 19:46:59 +00001467
Dan Gohmane7630be2010-05-11 20:30:00 +00001468 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
Chris Lattner60987362009-03-06 05:53:14 +00001469 runOnFunction(*I);
Devang Patel67d6a5e2006-12-19 19:46:59 +00001470
Bill Wendling6ce6d262009-12-25 13:50:18 +00001471 return doFinalization(M) || Changed;
Devang Patel67d6a5e2006-12-19 19:46:59 +00001472}
1473
Duncan Sands51495602009-02-13 09:42:34 +00001474bool FPPassManager::doInitialization(Module &M) {
Devang Patelff631ae2006-11-15 01:27:05 +00001475 bool Changed = false;
1476
Chris Lattner4c1e9542009-03-06 06:45:05 +00001477 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1478 Changed |= getContainedPass(Index)->doInitialization(M);
Devang Patelff631ae2006-11-15 01:27:05 +00001479
1480 return Changed;
1481}
1482
Duncan Sands51495602009-02-13 09:42:34 +00001483bool FPPassManager::doFinalization(Module &M) {
Devang Patelff631ae2006-11-15 01:27:05 +00001484 bool Changed = false;
1485
Chris Lattner4c1e9542009-03-06 06:45:05 +00001486 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1487 Changed |= getContainedPass(Index)->doFinalization(M);
Devang Patelff631ae2006-11-15 01:27:05 +00001488
Devang Patelff631ae2006-11-15 01:27:05 +00001489 return Changed;
1490}
1491
Devang Patela1514cb2006-12-07 19:39:39 +00001492//===----------------------------------------------------------------------===//
Devang Patel67d6a5e2006-12-19 19:46:59 +00001493// MPPassManager implementation
Devang Patel05e1a972006-11-07 22:03:15 +00001494
Devang Patel05e1a972006-11-07 22:03:15 +00001495/// Execute all of the passes scheduled for execution by invoking
1496/// runOnModule method. Keep track of whether any of the passes modifies
1497/// the module, and if so, return true.
1498bool
Devang Patel67d6a5e2006-12-19 19:46:59 +00001499MPPassManager::runOnModule(Module &M) {
Devang Patel05e1a972006-11-07 22:03:15 +00001500 bool Changed = false;
Devang Patel050ec722006-11-14 01:23:29 +00001501
Torok Edwin24c78352009-06-29 18:49:09 +00001502 // Initialize on-the-fly passes
1503 for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
1504 I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
1505 I != E; ++I) {
1506 FunctionPassManagerImpl *FPP = I->second;
1507 Changed |= FPP->doInitialization(M);
1508 }
1509
Devang Patelabfbe3b2006-12-16 00:56:26 +00001510 for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
1511 ModulePass *MP = getContainedPass(Index);
Dan Gohman74b189f2010-03-01 17:34:28 +00001512 bool LocalChanged = false;
Devang Patelabfbe3b2006-12-16 00:56:26 +00001513
Benjamin Kramerdfcc2852009-12-08 13:07:38 +00001514 dumpPassInfo(MP, EXECUTION_MSG, ON_MODULE_MSG, M.getModuleIdentifier());
Chris Lattner4c493d92008-08-08 15:14:09 +00001515 dumpRequiredSet(MP);
Devang Patel93a197c2006-12-14 00:08:04 +00001516
Devang Patelabfbe3b2006-12-16 00:56:26 +00001517 initializeAnalysisImpl(MP);
Devang Patelb8817b92006-12-14 00:59:42 +00001518
Chris Lattner4c1e9542009-03-06 06:45:05 +00001519 {
1520 PassManagerPrettyStackEntry X(MP, M);
Chris Lattner707431c2010-03-30 04:03:22 +00001521 TimeRegion PassTimer(getPassTimer(MP));
1522
Dan Gohman74b189f2010-03-01 17:34:28 +00001523 LocalChanged |= MP->runOnModule(M);
Chris Lattner4c1e9542009-03-06 06:45:05 +00001524 }
Devang Patel93a197c2006-12-14 00:08:04 +00001525
Dan Gohman74b189f2010-03-01 17:34:28 +00001526 Changed |= LocalChanged;
1527 if (LocalChanged)
Dan Gohman929391a2008-01-29 12:09:55 +00001528 dumpPassInfo(MP, MODIFICATION_MSG, ON_MODULE_MSG,
Benjamin Kramerdfcc2852009-12-08 13:07:38 +00001529 M.getModuleIdentifier());
Chris Lattner4c493d92008-08-08 15:14:09 +00001530 dumpPreservedSet(MP);
Chris Lattner02eb94c2008-08-07 07:34:50 +00001531
Devang Patela273d1c2007-07-19 18:02:32 +00001532 verifyPreservedAnalysis(MP);
Devang Patelabfbe3b2006-12-16 00:56:26 +00001533 removeNotPreservedAnalysis(MP);
1534 recordAvailableAnalysis(MP);
Benjamin Kramerdfcc2852009-12-08 13:07:38 +00001535 removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
Devang Patel05e1a972006-11-07 22:03:15 +00001536 }
Torok Edwin24c78352009-06-29 18:49:09 +00001537
1538 // Finalize on-the-fly passes
1539 for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
1540 I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
1541 I != E; ++I) {
1542 FunctionPassManagerImpl *FPP = I->second;
1543 // We don't know when is the last time an on-the-fly pass is run,
1544 // so we need to releaseMemory / finalize here
1545 FPP->releaseMemoryOnTheFly();
1546 Changed |= FPP->doFinalization(M);
1547 }
Devang Patel05e1a972006-11-07 22:03:15 +00001548 return Changed;
1549}
1550
Devang Patele64d3052007-04-16 20:12:57 +00001551/// Add RequiredPass into list of lower level passes required by pass P.
1552/// RequiredPass is run on the fly by Pass Manager when P requests it
1553/// through getAnalysis interface.
1554void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
Chris Lattner60987362009-03-06 05:53:14 +00001555 assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
1556 "Unable to handle Pass that requires lower level Analysis pass");
1557 assert((P->getPotentialPassManagerType() <
1558 RequiredPass->getPotentialPassManagerType()) &&
1559 "Unable to handle Pass that requires lower level Analysis pass");
Devang Patele64d3052007-04-16 20:12:57 +00001560
Devang Patel68f72b12007-04-26 17:50:19 +00001561 FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
Devang Patel69e9f6d2007-04-16 20:27:05 +00001562 if (!FPP) {
Devang Patel68f72b12007-04-26 17:50:19 +00001563 FPP = new FunctionPassManagerImpl(0);
1564 // FPP is the top level manager.
1565 FPP->setTopLevelManager(FPP);
1566
Devang Patel69e9f6d2007-04-16 20:27:05 +00001567 OnTheFlyManagers[P] = FPP;
1568 }
Devang Patel68f72b12007-04-26 17:50:19 +00001569 FPP->add(RequiredPass);
Devang Patel69e9f6d2007-04-16 20:27:05 +00001570
Devang Patel68f72b12007-04-26 17:50:19 +00001571 // Register P as the last user of RequiredPass.
Devang Patel8adae862007-07-20 18:04:54 +00001572 SmallVector<Pass *, 12> LU;
Devang Patel68f72b12007-04-26 17:50:19 +00001573 LU.push_back(RequiredPass);
1574 FPP->setLastUser(LU, P);
Devang Patele64d3052007-04-16 20:12:57 +00001575}
Devang Patel69e9f6d2007-04-16 20:27:05 +00001576
1577/// Return function pass corresponding to PassInfo PI, that is
1578/// required by module pass MP. Instantiate analysis pass, by using
1579/// its runOnFunction() for function F.
Owen Andersona7aed182010-08-06 18:33:48 +00001580Pass* MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F){
Devang Patel68f72b12007-04-26 17:50:19 +00001581 FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
Chris Lattner60987362009-03-06 05:53:14 +00001582 assert(FPP && "Unable to find on the fly pass");
Devang Patel69e9f6d2007-04-16 20:27:05 +00001583
Torok Edwin24c78352009-06-29 18:49:09 +00001584 FPP->releaseMemoryOnTheFly();
Devang Patel68f72b12007-04-26 17:50:19 +00001585 FPP->run(F);
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001586 return ((PMTopLevelManager*)FPP)->findAnalysisPass(PI);
Devang Patel69e9f6d2007-04-16 20:27:05 +00001587}
1588
1589
Devang Patela1514cb2006-12-07 19:39:39 +00001590//===----------------------------------------------------------------------===//
1591// PassManagerImpl implementation
Devang Patelab97cf42006-12-13 00:09:23 +00001592//
Devang Patelc290c8a2006-11-07 22:23:34 +00001593/// run - Execute all of the passes scheduled for execution. Keep track of
1594/// whether any of the passes modifies the module, and if so, return true.
Devang Patel67d6a5e2006-12-19 19:46:59 +00001595bool PassManagerImpl::run(Module &M) {
Devang Patelc290c8a2006-11-07 22:23:34 +00001596 bool Changed = false;
Devang Patelb8817b92006-12-14 00:59:42 +00001597 TimingInfo::createTheTimeInfo();
1598
Devang Patelcfd70c42006-12-13 22:10:00 +00001599 dumpArguments();
Devang Patel67d6a5e2006-12-19 19:46:59 +00001600 dumpPasses();
Devang Patelf1567a52006-12-13 20:03:48 +00001601
Devang Patele3068402006-12-21 00:16:50 +00001602 initializeAllAnalysisInfo();
Chris Lattner4c1e9542009-03-06 06:45:05 +00001603 for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1604 Changed |= getContainedManager(Index)->runOnModule(M);
Devang Patelc290c8a2006-11-07 22:23:34 +00001605 return Changed;
1606}
Devang Patel376fefa2006-11-08 10:29:57 +00001607
Devang Patela1514cb2006-12-07 19:39:39 +00001608//===----------------------------------------------------------------------===//
1609// PassManager implementation
1610
Devang Patel376fefa2006-11-08 10:29:57 +00001611/// Create new pass manager
Devang Patelb67904d2006-12-13 02:36:01 +00001612PassManager::PassManager() {
Devang Patel67d6a5e2006-12-19 19:46:59 +00001613 PM = new PassManagerImpl(0);
Devang Patel9c6290c2006-12-12 22:02:16 +00001614 // PM is the top level manager
1615 PM->setTopLevelManager(PM);
Devang Patel376fefa2006-11-08 10:29:57 +00001616}
1617
Devang Patelb67904d2006-12-13 02:36:01 +00001618PassManager::~PassManager() {
Devang Patelab97cf42006-12-13 00:09:23 +00001619 delete PM;
1620}
1621
David Greene103d4b42010-05-10 20:24:27 +00001622/// addImpl - Add a pass to the queue of passes to run, without
1623/// checking whether to add a printer pass.
1624void PassManager::addImpl(Pass *P) {
1625 PM->add(P);
1626}
1627
Devang Patel376fefa2006-11-08 10:29:57 +00001628/// add - Add a pass to the queue of passes to run. This passes ownership of
1629/// the Pass to the PassManager. When the PassManager is destroyed, the pass
1630/// will be destroyed as well, so there is no need to delete the pass. This
1631/// implies that all passes MUST be allocated with 'new'.
Chris Lattner60987362009-03-06 05:53:14 +00001632void PassManager::add(Pass *P) {
Owen Andersona7aed182010-08-06 18:33:48 +00001633 const void* PassID = P->getPassID();
1634 if (ShouldPrintBeforePass(PassID))
David Greene103d4b42010-05-10 20:24:27 +00001635 addImpl(P->createPrinterPass(dbgs(), std::string("*** IR Dump Before ")
1636 + P->getPassName() + " ***"));
David Greene9b063df2010-04-02 23:17:14 +00001637
David Greene103d4b42010-05-10 20:24:27 +00001638 addImpl(P);
David Greene9b063df2010-04-02 23:17:14 +00001639
Owen Andersona7aed182010-08-06 18:33:48 +00001640 if (ShouldPrintAfterPass(PassID))
David Greene103d4b42010-05-10 20:24:27 +00001641 addImpl(P->createPrinterPass(dbgs(), std::string("*** IR Dump After ")
1642 + P->getPassName() + " ***"));
Devang Patel376fefa2006-11-08 10:29:57 +00001643}
1644
1645/// run - Execute all of the passes scheduled for execution. Keep track of
1646/// whether any of the passes modifies the module, and if so, return true.
Chris Lattner60987362009-03-06 05:53:14 +00001647bool PassManager::run(Module &M) {
Devang Patel376fefa2006-11-08 10:29:57 +00001648 return PM->run(M);
1649}
1650
Devang Patelb8817b92006-12-14 00:59:42 +00001651//===----------------------------------------------------------------------===//
1652// TimingInfo Class - This class is used to calculate information about the
1653// amount of time each pass takes to execute. This only happens with
1654// -time-passes is enabled on the command line.
1655//
1656bool llvm::TimePassesIsEnabled = false;
1657static cl::opt<bool,true>
1658EnableTiming("time-passes", cl::location(TimePassesIsEnabled),
1659 cl::desc("Time each pass, printing elapsed time for each on exit"));
1660
1661// createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
1662// a non null value (if the -time-passes option is enabled) or it leaves it
1663// null. It may be called multiple times.
1664void TimingInfo::createTheTimeInfo() {
1665 if (!TimePassesIsEnabled || TheTimeInfo) return;
1666
1667 // Constructed the first time this is called, iff -time-passes is enabled.
1668 // This guarantees that the object will be constructed before static globals,
1669 // thus it will be destroyed before them.
1670 static ManagedStatic<TimingInfo> TTI;
1671 TheTimeInfo = &*TTI;
1672}
1673
Devang Patel1c3633e2007-01-29 23:10:37 +00001674/// If TimingInfo is enabled then start pass timer.
Chris Lattner707431c2010-03-30 04:03:22 +00001675Timer *llvm::getPassTimer(Pass *P) {
Devang Patel1c3633e2007-01-29 23:10:37 +00001676 if (TheTimeInfo)
Chris Lattner707431c2010-03-30 04:03:22 +00001677 return TheTimeInfo->getPassTimer(P);
Dan Gohman277e7672009-09-28 00:07:05 +00001678 return 0;
Devang Patel1c3633e2007-01-29 23:10:37 +00001679}
1680
Devang Patel1c56a632007-01-08 19:29:38 +00001681//===----------------------------------------------------------------------===//
1682// PMStack implementation
1683//
Devang Patelad98d232007-01-11 22:15:30 +00001684
Devang Patel1c56a632007-01-08 19:29:38 +00001685// Pop Pass Manager from the stack and clear its analysis info.
1686void PMStack::pop() {
1687
1688 PMDataManager *Top = this->top();
1689 Top->initializeAnalysisInfo();
1690
1691 S.pop_back();
1692}
1693
1694// Push PM on the stack and set its top level manager.
Dan Gohman11eecd62008-03-13 01:21:31 +00001695void PMStack::push(PMDataManager *PM) {
Chris Lattner60987362009-03-06 05:53:14 +00001696 assert(PM && "Unable to push. Pass Manager expected");
Devang Patel1c56a632007-01-08 19:29:38 +00001697
Chris Lattner60987362009-03-06 05:53:14 +00001698 if (!this->empty()) {
1699 PMTopLevelManager *TPM = this->top()->getTopLevelManager();
Devang Patel1c56a632007-01-08 19:29:38 +00001700
Chris Lattner60987362009-03-06 05:53:14 +00001701 assert(TPM && "Unable to find top level manager");
Devang Patel15701b52007-01-11 00:19:00 +00001702 TPM->addIndirectPassManager(PM);
1703 PM->setTopLevelManager(TPM);
1704 }
1705
Devang Patel15701b52007-01-11 00:19:00 +00001706 S.push_back(PM);
1707}
1708
1709// Dump content of the pass manager stack.
Dan Gohman027ad432010-08-07 01:04:15 +00001710void PMStack::dump() const {
1711 for (std::vector<PMDataManager *>::const_iterator I = S.begin(),
Chris Lattner60987362009-03-06 05:53:14 +00001712 E = S.end(); I != E; ++I)
Chris Lattner2fa26e52010-01-22 05:24:46 +00001713 printf("%s ", (*I)->getAsPass()->getPassName());
Chris Lattner60987362009-03-06 05:53:14 +00001714
Devang Patel15701b52007-01-11 00:19:00 +00001715 if (!S.empty())
Chris Lattnerde2aa652007-08-10 06:22:25 +00001716 printf("\n");
Devang Patel1c56a632007-01-08 19:29:38 +00001717}
1718
Devang Patel1c56a632007-01-08 19:29:38 +00001719/// Find appropriate Module Pass Manager in the PM Stack and
1720/// add self into that manager.
Devang Pateldffca632007-01-17 20:30:17 +00001721void ModulePass::assignPassManager(PMStack &PMS,
Anton Korobeynikovfb801512007-04-16 18:10:23 +00001722 PassManagerType PreferredType) {
Devang Patel1c56a632007-01-08 19:29:38 +00001723 // Find Module Pass Manager
1724 while(!PMS.empty()) {
Devang Patel23f8aa92007-01-17 21:19:23 +00001725 PassManagerType TopPMType = PMS.top()->getPassManagerType();
1726 if (TopPMType == PreferredType)
1727 break; // We found desired pass manager
1728 else if (TopPMType > PMT_ModulePassManager)
Devang Patel1c56a632007-01-08 19:29:38 +00001729 PMS.pop(); // Pop children pass managers
Devang Patelac99eca2007-01-11 19:59:06 +00001730 else
1731 break;
Devang Patel1c56a632007-01-08 19:29:38 +00001732 }
Devang Patel18ff6362008-09-09 21:38:40 +00001733 assert(!PMS.empty() && "Unable to find appropriate Pass Manager");
Devang Patel23f8aa92007-01-17 21:19:23 +00001734 PMS.top()->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00001735}
1736
Devang Patel3312f752007-01-16 21:43:18 +00001737/// Find appropriate Function Pass Manager or Call Graph Pass Manager
1738/// in the PM Stack and add self into that manager.
Devang Pateldffca632007-01-17 20:30:17 +00001739void FunctionPass::assignPassManager(PMStack &PMS,
Anton Korobeynikovfb801512007-04-16 18:10:23 +00001740 PassManagerType PreferredType) {
Devang Patel1c56a632007-01-08 19:29:38 +00001741
Devang Patela3286902008-09-09 17:56:50 +00001742 // Find Module Pass Manager
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001743 while (!PMS.empty()) {
Devang Patelac99eca2007-01-11 19:59:06 +00001744 if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
1745 PMS.pop();
Devang Patel1c56a632007-01-08 19:29:38 +00001746 else
Devang Patel3312f752007-01-16 21:43:18 +00001747 break;
1748 }
Devang Patel3312f752007-01-16 21:43:18 +00001749
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001750 // Create new Function Pass Manager if needed.
1751 FPPassManager *FPP;
1752 if (PMS.top()->getPassManagerType() == PMT_FunctionPassManager) {
1753 FPP = (FPPassManager *)PMS.top();
1754 } else {
Devang Patel3312f752007-01-16 21:43:18 +00001755 assert(!PMS.empty() && "Unable to create Function Pass Manager");
1756 PMDataManager *PMD = PMS.top();
1757
1758 // [1] Create new Function Pass Manager
1759 FPP = new FPPassManager(PMD->getDepth() + 1);
Devang Patelcbbf2912008-03-20 01:09:53 +00001760 FPP->populateInheritedAnalysis(PMS);
Devang Patel3312f752007-01-16 21:43:18 +00001761
1762 // [2] Set up new manager's top level manager
1763 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1764 TPM->addIndirectPassManager(FPP);
1765
1766 // [3] Assign manager to manage this new manager. This may create
1767 // and push new managers into PMS
Devang Patela3286902008-09-09 17:56:50 +00001768 FPP->assignPassManager(PMS, PMD->getPassManagerType());
Devang Patel3312f752007-01-16 21:43:18 +00001769
1770 // [4] Push new manager into PMS
1771 PMS.push(FPP);
Devang Patel1c56a632007-01-08 19:29:38 +00001772 }
1773
Devang Patel3312f752007-01-16 21:43:18 +00001774 // Assign FPP as the manager of this pass.
1775 FPP->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00001776}
1777
Devang Patel3312f752007-01-16 21:43:18 +00001778/// Find appropriate Basic Pass Manager or Call Graph Pass Manager
Devang Patel1c56a632007-01-08 19:29:38 +00001779/// in the PM Stack and add self into that manager.
Devang Pateldffca632007-01-17 20:30:17 +00001780void BasicBlockPass::assignPassManager(PMStack &PMS,
Anton Korobeynikovfb801512007-04-16 18:10:23 +00001781 PassManagerType PreferredType) {
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001782 BBPassManager *BBP;
Devang Patel1c56a632007-01-08 19:29:38 +00001783
Devang Patel15701b52007-01-11 00:19:00 +00001784 // Basic Pass Manager is a leaf pass manager. It does not handle
1785 // any other pass manager.
Chris Lattner9efd4fc2010-01-22 05:37:10 +00001786 if (!PMS.empty() &&
1787 PMS.top()->getPassManagerType() == PMT_BasicBlockPassManager) {
1788 BBP = (BBPassManager *)PMS.top();
1789 } else {
1790 // If leaf manager is not Basic Block Pass manager then create new
1791 // basic Block Pass manager.
Devang Patel3312f752007-01-16 21:43:18 +00001792 assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
1793 PMDataManager *PMD = PMS.top();
1794
1795 // [1] Create new Basic Block Manager
1796 BBP = new BBPassManager(PMD->getDepth() + 1);
1797
1798 // [2] Set up new manager's top level manager
1799 // Basic Block Pass Manager does not live by itself
1800 PMTopLevelManager *TPM = PMD->getTopLevelManager();
1801 TPM->addIndirectPassManager(BBP);
1802
Devang Patel15701b52007-01-11 00:19:00 +00001803 // [3] Assign manager to manage this new manager. This may create
1804 // and push new managers into PMS
David Greene103d4b42010-05-10 20:24:27 +00001805 BBP->assignPassManager(PMS, PreferredType);
Devang Patel15701b52007-01-11 00:19:00 +00001806
Devang Patel3312f752007-01-16 21:43:18 +00001807 // [4] Push new manager into PMS
1808 PMS.push(BBP);
1809 }
Devang Patel1c56a632007-01-08 19:29:38 +00001810
Devang Patel3312f752007-01-16 21:43:18 +00001811 // Assign BBP as the manager of this pass.
1812 BBP->add(this);
Devang Patel1c56a632007-01-08 19:29:38 +00001813}
1814
Dan Gohmand3a20c92008-03-11 16:41:42 +00001815PassManagerBase::~PassManagerBase() {}