llvm.org GIT mirror llvm / 11e4329
Add pass printer passes in the right place. The pass pointer should never be referenced after sending it to schedulePass(), which may delete the pass. To fix this bug I had to clean up the design leading to more goodness. You may notice now that any non-analysis pass is printed. So things like loop-simplify and lcssa show up, while target lib, target data, alias analysis do not show up. Normally, analysis don't mutate the IR, but you can now check this by using both -print-after and -print-before. The effects of analysis will now show up in between the two. The llc path is still in bad shape. But I'll be improving it in my next checkin. Meanwhile, print-machineinstrs still works the same way. With print-before/after, many llc passes that were not printed before now are, some of these should be converted to analysis. A few very important passes, isel and scheduler, are not properly initialized, so not printed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149480 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 7 years ago
3 changed file(s) with 50 addition(s) and 94 deletion(s). Raw diff Collapse all Expand all
5858 bool run(Module &M);
5959
6060 private:
61 /// addImpl - Add a pass to the queue of passes to run, without
62 /// checking whether to add a printer pass.
63 void addImpl(Pass *P);
64
6561 /// PassManagerImpl_New is the actual class. PassManager is just the
6662 /// wraper to publish simple pass manager interface
6763 PassManagerImpl *PM;
7874 /// add - Add a pass to the queue of passes to run. This passes
7975 /// ownership of the Pass to the PassManager. When the
8076 /// PassManager_X is destroyed, the pass will be destroyed as well, so
81 /// there is no need to delete the pass. (TODO delete passes.)
77 /// there is no need to delete the pass.
8278 /// This implies that all passes MUST be allocated with 'new'.
8379 void add(Pass *P);
8480
9793 bool doFinalization();
9894
9995 private:
100 /// addImpl - Add a pass to the queue of passes to run, without
101 /// checking whether to add a printer pass.
102 void addImpl(Pass *P);
103
10496 FunctionPassManagerImpl *FPM;
10597 Module *M;
10698 };
8181 // relies on PassManagerImpl to do all the tasks.
8282 //
8383 // [o] class PassManagerImpl : public Pass, public PMDataManager,
84 // public PMDTopLevelManager
84 // public PMTopLevelManager
8585 //
8686 // PassManagerImpl is a top level pass manager responsible for managing
8787 // MPPassManagers.
173173 void initializeAllAnalysisInfo();
174174
175175 private:
176 /// This is implemented by top level pass manager and used by
177 /// schedulePass() to add analysis info passes that are not available.
178 virtual void addTopLevelPass(Pass *P) = 0;
176 virtual PMDataManager *getAsPMDataManager() = 0;
177 virtual PassManagerType getTopLevelPassManagerType() = 0;
179178
180179 public:
181180 /// Schedule pass P for execution. Make sure that passes required by
8383 /// This is a helper to determine whether to print IR before or
8484 /// after a pass.
8585
86 static bool ShouldPrintBeforeOrAfterPass(const void *PassID,
86 static bool ShouldPrintBeforeOrAfterPass(const PassInfo *PI,
8787 PassOptionList &PassesToPrint) {
88 if (const llvm::PassInfo *PI =
89 PassRegistry::getPassRegistry()->getPassInfo(PassID)) {
90 for (unsigned i = 0, ie = PassesToPrint.size(); i < ie; ++i) {
91 const llvm::PassInfo *PassInf = PassesToPrint[i];
92 if (PassInf)
93 if (PassInf->getPassArgument() == PI->getPassArgument()) {
94 return true;
95 }
96 }
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 }
9794 }
9895 return false;
9996 }
100
10197
10298 /// This is a utility to check whether a pass should have IR dumped
10399 /// before it.
104 static bool ShouldPrintBeforePass(const void *PassID) {
105 return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PassID, PrintBefore);
100 static bool ShouldPrintBeforePass(const PassInfo *PI) {
101 return PrintBeforeAll || ShouldPrintBeforeOrAfterPass(PI, PrintBefore);
106102 }
107103
108104 /// This is a utility to check whether a pass should have IR dumped
109105 /// after it.
110 static bool ShouldPrintAfterPass(const void *PassID) {
111 return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PassID, PrintAfter);
106 static bool ShouldPrintAfterPass(const PassInfo *PI) {
107 return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter);
112108 }
113109
114110 } // End of llvm namespace
263259
264260 virtual PMDataManager *getAsPMDataManager() { return this; }
265261 virtual Pass *getAsPass() { return this; }
262 virtual PassManagerType getTopLevelPassManagerType() {
263 return PMT_FunctionPassManager;
264 }
266265
267266 /// Pass Manager itself does not invalidate any analysis info.
268267 void getAnalysisUsage(AnalysisUsage &Info) const {
269268 Info.setPreservesAll();
270 }
271
272 void addTopLevelPass(Pass *P) {
273 if (ImmutablePass *IP = P->getAsImmutablePass()) {
274 // P is a immutable pass and it will be managed by this
275 // top level manager. Set up analysis resolver to connect them.
276 AnalysisResolver *AR = new AnalysisResolver(*this);
277 P->setResolver(AR);
278 initializeAnalysisImpl(P);
279 addImmutablePass(IP);
280 recordAvailableAnalysis(IP);
281 } else {
282 P->assignPassManager(activeStack, PMT_FunctionPassManager);
283 }
284
285269 }
286270
287271 FPPassManager *getContainedManager(unsigned N) {
416400 Info.setPreservesAll();
417401 }
418402
419 void addTopLevelPass(Pass *P) {
420 if (ImmutablePass *IP = P->getAsImmutablePass()) {
421 // P is a immutable pass and it will be managed by this
422 // top level manager. Set up analysis resolver to connect them.
423 AnalysisResolver *AR = new AnalysisResolver(*this);
424 P->setResolver(AR);
425 initializeAnalysisImpl(P);
426 addImmutablePass(IP);
427 recordAvailableAnalysis(IP);
428 } else {
429 P->assignPassManager(activeStack, PMT_ModulePassManager);
430 }
431 }
432
433403 virtual PMDataManager *getAsPMDataManager() { return this; }
434404 virtual Pass *getAsPass() { return this; }
405 virtual PassManagerType getTopLevelPassManagerType() {
406 return PMT_ModulePassManager;
407 }
435408
436409 MPPassManager *getContainedManager(unsigned N) {
437410 assert(N < PassManagers.size() && "Pass number out of range!");
659632 }
660633
661634 // Now all required passes are available.
662 addTopLevelPass(P);
635 if (ImmutablePass *IP = P->getAsImmutablePass()) {
636 // P is a immutable pass and it will be managed by this
637 // top level manager. Set up analysis resolver to connect them.
638 PMDataManager *DM = getAsPMDataManager();
639 AnalysisResolver *AR = new AnalysisResolver(*DM);
640 P->setResolver(AR);
641 DM->initializeAnalysisImpl(P);
642 addImmutablePass(IP);
643 DM->recordAvailableAnalysis(IP);
644 return;
645 }
646
647 if (PI && !PI->isAnalysis() && ShouldPrintBeforePass(PI)) {
648 Pass *PP = P->createPrinterPass(
649 dbgs(), std::string("*** IR Dump Before ") + P->getPassName() + " ***");
650 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
651 }
652
653 // Add the requested pass to the best available pass manager.
654 P->assignPassManager(activeStack, getTopLevelPassManagerType());
655
656 if (PI && !PI->isAnalysis() && ShouldPrintAfterPass(PI)) {
657 Pass *PP = P->createPrinterPass(
658 dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***");
659 PP->assignPassManager(activeStack, getTopLevelPassManagerType());
660 }
663661 }
664662
665663 /// Find the pass that implements Analysis AID. Search immutable
13561354 delete FPM;
13571355 }
13581356
1359 /// addImpl - Add a pass to the queue of passes to run, without
1360 /// checking whether to add a printer pass.
1361 void FunctionPassManager::addImpl(Pass *P) {
1362 FPM->add(P);
1363 }
1364
13651357 /// add - Add a pass to the queue of passes to run. This passes
13661358 /// ownership of the Pass to the PassManager. When the
13671359 /// PassManager_X is destroyed, the pass will be destroyed as well, so
13681360 /// there is no need to delete the pass. (TODO delete passes.)
13691361 /// This implies that all passes MUST be allocated with 'new'.
13701362 void FunctionPassManager::add(Pass *P) {
1371 // If this is a not a function pass, don't add a printer for it.
1372 const void *PassID = P->getPassID();
1373 if (P->getPassKind() == PT_Function)
1374 if (ShouldPrintBeforePass(PassID))
1375 addImpl(P->createPrinterPass(dbgs(), std::string("*** IR Dump Before ")
1376 + P->getPassName() + " ***"));
1377
1378 addImpl(P);
1379
1380 if (P->getPassKind() == PT_Function)
1381 if (ShouldPrintAfterPass(PassID))
1382 addImpl(P->createPrinterPass(dbgs(), std::string("*** IR Dump After ")
1383 + P->getPassName() + " ***"));
1363 FPM->add(P);
13841364 }
13851365
13861366 /// run - Execute all of the passes scheduled for execution. Keep
16921672 delete PM;
16931673 }
16941674
1695 /// addImpl - Add a pass to the queue of passes to run, without
1696 /// checking whether to add a printer pass.
1697 void PassManager::addImpl(Pass *P) {
1698 PM->add(P);
1699 }
1700
17011675 /// add - Add a pass to the queue of passes to run. This passes ownership of
17021676 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
17031677 /// will be destroyed as well, so there is no need to delete the pass. This
17041678 /// implies that all passes MUST be allocated with 'new'.
17051679 void PassManager::add(Pass *P) {
1706 const void* PassID = P->getPassID();
1707 if (ShouldPrintBeforePass(PassID))
1708 addImpl(P->createPrinterPass(dbgs(), std::string("*** IR Dump Before ")
1709 + P->getPassName() + " ***"));
1710
1711 addImpl(P);
1712
1713 if (ShouldPrintAfterPass(PassID))
1714 addImpl(P->createPrinterPass(dbgs(), std::string("*** IR Dump After ")
1715 + P->getPassName() + " ***"));
1680 PM->add(P);
17161681 }
17171682
17181683 /// run - Execute all of the passes scheduled for execution. Keep track of
18221787 void FunctionPass::assignPassManager(PMStack &PMS,
18231788 PassManagerType PreferredType) {
18241789
1825 // Find Module Pass Manager
1790 // Find Function Pass Manager
18261791 while (!PMS.empty()) {
18271792 if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
18281793 PMS.pop();