llvm.org GIT mirror llvm / 9450b0e
Move the dominator verification code out of special code embedded within the PassManager code into a regular verifyAnalysis method. Also, reorganize loop verification. Make the LoopPass infrastructure call verifyLoop as needed instead of having LoopInfo::verifyAnalysis check every loop in the function after each looop pass. Add a new command-line argument, -verify-loop-info, to enable the expensive full checking. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82952 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
10 changed file(s) with 80 addition(s) and 65 deletion(s). Raw diff Collapse all Expand all
733733
734734 virtual bool runOnFunction(Function &F);
735735
736 virtual void verifyAnalysis() const;
737
736738 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
737739 AU.setPreservesAll();
738740 }
989991 calculate(DT, DT[Roots[0]]);
990992 return false;
991993 }
994
995 virtual void verifyAnalysis() const;
992996
993997 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
994998 AU.setPreservesAll();
279279 /// verifyPreservedAnalysis -- Verify analysis presreved by pass P.
280280 void verifyPreservedAnalysis(Pass *P);
281281
282 /// verifyDomInfo -- Verify dominator information if it is available.
283 void verifyDomInfo(Pass &P, Function &F);
284
285282 /// Remove Analysis that is not preserved by the pass
286283 void removeNotPreservedAnalysis(Pass *P);
287284
1919 #include "llvm/Analysis/Dominators.h"
2020 #include "llvm/Assembly/Writer.h"
2121 #include "llvm/Support/CFG.h"
22 #include "llvm/Support/CommandLine.h"
2223 #include "llvm/ADT/DepthFirstIterator.h"
2324 #include "llvm/ADT/SmallPtrSet.h"
2425 #include
2526 using namespace llvm;
27
28 // Always verify loopinfo if expensive checking is enabled.
29 #ifdef XDEBUG
30 bool VerifyLoopInfo = true;
31 #else
32 bool VerifyLoopInfo = false;
33 #endif
34 static cl::opt
35 VerifyLoopInfoX("verify-loop-info", cl::location(VerifyLoopInfo),
36 cl::desc("Verify loop info (time consuming)"));
2637
2738 char LoopInfo::ID = 0;
2839 static RegisterPass
374385 }
375386
376387 void LoopInfo::verifyAnalysis() const {
388 // LoopInfo is a FunctionPass, but verifying every loop in the function
389 // each time verifyAnalysis is called is very expensive. The
390 // -verify-loop-info option can enable this. In order to perform some
391 // checking by default, LoopPass has been taught to call verifyLoop
392 // manually during loop pass sequences.
393
394 if (!VerifyLoopInfo) return;
395
377396 for (iterator I = begin(), E = end(); I != E; ++I) {
378397 assert(!(*I)->getParentLoop() && "Top-level loop has a parent!");
379398 (*I)->verifyLoopNest();
380399 }
400
401 // TODO: check BBMap consistency.
381402 }
382403
383404 void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
241241 dumpPassInfo(P, MODIFICATION_MSG, ON_LOOP_MSG, "");
242242 dumpPreservedSet(P);
243243
244 if (!skipThisLoop)
244 if (!skipThisLoop) {
245 // Manually check that this loop is still healthy. This is done
246 // instead of relying on LoopInfo::verifyLoop since LoopInfo
247 // is a function pass and it's really expensive to verify every
248 // loop in the function every time. That level of checking can be
249 // enabled with the -verify-loop-info option.
250 Timer *T = StartPassTimer(LI);
251 CurrentLoop->verifyLoop();
252 StopPassTimer(LI, T);
253
254 // Then call the regular verifyAnalysis functions.
245255 verifyPreservedAnalysis(LP);
256 }
246257
247258 removeNotPreservedAnalysis(P);
248259 recordAvailableAnalysis(P);
249260 removeDeadPasses(P, "", ON_LOOP_MSG);
250
251 // If dominator information is available then verify the info if requested.
252 verifyDomInfo(*LP, F);
253261
254262 if (skipThisLoop)
255263 // Do not run other passes on this loop.
2323 #include "llvm/Analysis/DominatorInternals.h"
2424 #include "llvm/Instructions.h"
2525 #include "llvm/Support/raw_ostream.h"
26 #include "llvm/Support/CommandLine.h"
2627 #include
2728 using namespace llvm;
29
30 // Always verify dominfo if expensive checking is enabled.
31 #ifdef XDEBUG
32 bool VerifyDomInfo = true;
33 #else
34 bool VerifyDomInfo = false;
35 #endif
36 static cl::opt
37 VerifyDomInfoX("verify-dom-info", cl::location(VerifyDomInfo),
38 cl::desc("Verify dominator info (time consuming)"));
2839
2940 //===----------------------------------------------------------------------===//
3041 // DominatorTree Implementation
4556 bool DominatorTree::runOnFunction(Function &F) {
4657 DT->recalculate(F);
4758 return false;
59 }
60
61 void DominatorTree::verifyAnalysis() const {
62 if (!VerifyDomInfo || true /* fixme */) return;
63
64 Function &F = *getRoot()->getParent();
65
66 DominatorTree OtherDT;
67 OtherDT.getBase().recalculate(F);
68 assert(!compare(OtherDT) && "Invalid DominatorTree info!");
4869 }
4970
5071 void DominatorTree::print(raw_ostream &OS, const Module *) const {
85106 char DominanceFrontier::ID = 0;
86107 static RegisterPass
87108 G("domfrontier", "Dominance Frontier Construction", true, true);
109
110 void DominanceFrontier::verifyAnalysis() const {
111 if (!VerifyDomInfo) return;
112
113 DominatorTree &DT = getAnalysis();
114
115 DominanceFrontier OtherDF;
116 const std::vector &DTRoots = DT.getRoots();
117 OtherDF.calculate(DT, DT.getNode(DTRoots[0]));
118 assert(!compare(OtherDF) && "Invalid DominanceFrontier info!");
119 }
88120
89121 // NewBB is split and now it has one successor. Update dominace frontier to
90122 // reflect this change.
1212
1313
1414 #include "llvm/PassManagers.h"
15 #include "llvm/Assembly/Writer.h"
1516 #include "llvm/Support/CommandLine.h"
1617 #include "llvm/Support/Timer.h"
1718 #include "llvm/Module.h"
2122 #include "llvm/Support/raw_ostream.h"
2223 #include "llvm/System/Mutex.h"
2324 #include "llvm/System/Threading.h"
24 #include "llvm/Analysis/Dominators.h"
2525 #include "llvm-c/Core.h"
2626 #include
2727 #include
4343 enum PassDebugLevel {
4444 None, Arguments, Structure, Executions, Details
4545 };
46
47 // Always verify dominfo if expensive checking is enabled.
48 #ifdef XDEBUG
49 bool VerifyDomInfo = true;
50 #else
51 bool VerifyDomInfo = false;
52 #endif
53 static cl::opt
54 VerifyDomInfoX("verify-dom-info", cl::location(VerifyDomInfo),
55 cl::desc("Verify dominator info (time consuming)"));
5646
5747 static cl::opt
5848 PassDebugging("debug-pass", cl::Hidden,
702692 for (AnalysisUsage::VectorType::const_iterator I = PreservedSet.begin(),
703693 E = PreservedSet.end(); I != E; ++I) {
704694 AnalysisID AID = *I;
705 if (Pass *AP = findAnalysisPass(AID, true))
695 if (Pass *AP = findAnalysisPass(AID, true)) {
696
697 Timer *T = 0;
698 if (TheTimeInfo) T = TheTimeInfo->passStarted(AP);
706699 AP->verifyAnalysis();
707 }
708 }
709
710 /// verifyDomInfo - Verify dominator information if it is available.
711 void PMDataManager::verifyDomInfo(Pass &P, Function &F) {
712 if (!VerifyDomInfo || !P.getResolver())
713 return;
714
715 DominatorTree *DT = P.getAnalysisIfAvailable();
716 if (!DT)
717 return;
718
719 DominatorTree OtherDT;
720 OtherDT.getBase().recalculate(F);
721 if (DT->compare(OtherDT)) {
722 errs() << "Dominator Information for " << F.getName() << "\n";
723 errs() << "Pass '" << P.getPassName() << "'\n";
724 errs() << "----- Valid -----\n";
725 OtherDT.dump();
726 errs() << "----- Invalid -----\n";
727 DT->dump();
728 llvm_unreachable("Invalid dominator info");
729 }
730
731 DominanceFrontier *DF = P.getAnalysisIfAvailable();
732 if (!DF)
733 return;
734
735 DominanceFrontier OtherDF;
736 std::vector DTRoots = DT->getRoots();
737 OtherDF.calculate(*DT, DT->getNode(DTRoots[0]));
738 if (DF->compare(OtherDF)) {
739 errs() << "Dominator Information for " << F.getName() << "\n";
740 errs() << "Pass '" << P.getPassName() << "'\n";
741 errs() << "----- Valid -----\n";
742 OtherDF.dump();
743 errs() << "----- Invalid -----\n";
744 DF->dump();
745 llvm_unreachable("Invalid dominator info");
700 if (T) T->stopTimer();
701 }
746702 }
747703 }
748704
13831339 removeNotPreservedAnalysis(FP);
13841340 recordAvailableAnalysis(FP);
13851341 removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
1386
1387 // If dominator information is available then verify the info if requested.
1388 verifyDomInfo(*FP, F);
13891342 }
13901343 return Changed;
13911344 }
None ; RUN: llc %s -o /dev/null -verify-dom-info
0 ; RUN: llc %s -o /dev/null -verify-dom-info -verify-loop-info
11 %llvm.dbg.anchor.type = type { i32, i32 }
22 %llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32, i8*, i8* }
33 %llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8* }
None ; RUN: opt < %s -lcssa -disable-output -verify-dom-info
0 ; RUN: opt < %s -lcssa -disable-output -verify-dom-info -verify-loop-info
11 ; PR977
22 ; END.
33 declare i32 @opost_block()
None ; RUN: opt < %s -scalarrepl -loopsimplify -licm -disable-output -verify-dom-info
0 ; RUN: opt < %s -scalarrepl -loopsimplify -licm -disable-output -verify-dom-info -verify-loop-info
11
22 define void @inflate() {
33 entry:
None ; RUN: opt -loop-unswitch %s -disable-output
0 ; RUN: opt -loop-unswitch -verify-loop-info -verify-dom-info %s -disable-output
11
22 ; Loop unswitch should be able to unswitch these loops and
33 ; preserve LCSSA and LoopSimplify forms.