Verify loop info.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40062 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2007-07-19 18:02:32 +00:00
parent 6b8337392c
commit 58e0ef1e90
9 changed files with 51 additions and 28 deletions

View File

@@ -217,6 +217,9 @@ public:
/// the mapping in the LoopInfo class. /// the mapping in the LoopInfo class.
void removeBlockFromLoop(BasicBlock *BB); void removeBlockFromLoop(BasicBlock *BB);
/// verifyLoop - Verify loop structure
void verifyLoop() const;
void print(std::ostream &O, unsigned Depth = 0) const; void print(std::ostream &O, unsigned Depth = 0) const;
void print(std::ostream *O, unsigned Depth = 0) const { void print(std::ostream *O, unsigned Depth = 0) const {
if (O) print(*O, Depth); if (O) print(*O, Depth);

View File

@@ -115,10 +115,6 @@ public:
// utility may send LPPassManager into infinite loops so use caution. // utility may send LPPassManager into infinite loops so use caution.
void redoLoop(Loop *L); void redoLoop(Loop *L);
private:
/// verifyLoopInfo - Verify loop nest.
void verifyLoopInfo();
private: private:
std::deque<Loop *> LQ; std::deque<Loop *> LQ;
bool skipThisLoop; bool skipThisLoop;

View File

@@ -163,7 +163,7 @@ public:
/// verifyAnalysis() - This member can be implemented by a analysis pass to /// verifyAnalysis() - This member can be implemented by a analysis pass to
/// check state of analysis information. /// check state of analysis information.
virtual void verifyAnalysis() {} virtual void verifyAnalysis() const {}
// dumpPassStructure - Implement the -debug-passes=PassStructure option // dumpPassStructure - Implement the -debug-passes=PassStructure option
virtual void dumpPassStructure(unsigned Offset = 0); virtual void dumpPassStructure(unsigned Offset = 0);

View File

@@ -211,6 +211,9 @@ public:
/// Augment AvailableAnalysis by adding analysis made available by pass P. /// Augment AvailableAnalysis by adding analysis made available by pass P.
void recordAvailableAnalysis(Pass *P); void recordAvailableAnalysis(Pass *P);
/// verifyPreservedAnalysis -- Verify analysis presreved by pass P.
void verifyPreservedAnalysis(Pass *P);
/// Remove Analysis that is not preserved by the pass /// Remove Analysis that is not preserved by the pass
void removeNotPreservedAnalysis(Pass *P); void removeNotPreservedAnalysis(Pass *P);

View File

@@ -118,6 +118,7 @@ bool CGPassManager::runOnModule(Module &M) {
dumpPassInfo(P, MODIFICATION_MSG, ON_CG_MSG, ""); dumpPassInfo(P, MODIFICATION_MSG, ON_CG_MSG, "");
dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet()); dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet());
verifyPreservedAnalysis(P);
removeNotPreservedAnalysis(P); removeNotPreservedAnalysis(P);
recordAvailableAnalysis(P); recordAvailableAnalysis(P);
removeDeadPasses(P, "", ON_CG_MSG); removeDeadPasses(P, "", ON_CG_MSG);

View File

@@ -81,6 +81,18 @@ void Loop::print(std::ostream &OS, unsigned Depth) const {
(*I)->print(OS, Depth+2); (*I)->print(OS, Depth+2);
} }
/// verifyLoop - Verify loop structure
void Loop::verifyLoop() const {
#ifndef NDEBUG
assert (getHeader() && "Loop header is missing");
assert (getLoopPreheader() && "Loop preheader is missing");
assert (getLoopLatch() && "Loop latch is missing");
for (std::vector<Loop*>::const_iterator I = SubLoops.begin(), E = SubLoops.end();
I != E; ++I)
(*I)->verifyLoop();
#endif
}
void Loop::dump() const { void Loop::dump() const {
print(cerr); print(cerr);
} }
@@ -104,7 +116,6 @@ void LoopInfo::releaseMemory() {
TopLevelLoops.clear(); TopLevelLoops.clear();
} }
void LoopInfo::Calculate(DominatorTree &DT) { void LoopInfo::Calculate(DominatorTree &DT) {
BasicBlock *RootNode = DT.getRootNode()->getBlock(); BasicBlock *RootNode = DT.getRootNode()->getBlock();

View File

@@ -157,18 +157,6 @@ void LPPassManager::getAnalysisUsage(AnalysisUsage &Info) const {
Info.setPreservesAll(); Info.setPreservesAll();
} }
/// verifyLoopInfo - Verify loop nest.
void LPPassManager::verifyLoopInfo() {
assert (LI && "Loop Info is missing");
for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) {
Loop *L = *I;
assert (L->getHeader() && "Loop header is missing");
assert (L->getLoopPreheader() && "Loop preheader is missing");
assert (L->getLoopLatch() && "Loop latch is missing");
}
}
/// run - Execute all of the passes scheduled for execution. Keep track of /// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the function, and if so, return true. /// whether any of the passes modifies the function, and if so, return true.
bool LPPassManager::runOnFunction(Function &F) { bool LPPassManager::runOnFunction(Function &F) {
@@ -214,13 +202,13 @@ bool LPPassManager::runOnFunction(Function &F) {
LoopPass *LP = dynamic_cast<LoopPass *>(P); LoopPass *LP = dynamic_cast<LoopPass *>(P);
assert (LP && "Invalid LPPassManager member"); assert (LP && "Invalid LPPassManager member");
LP->runOnLoop(CurrentLoop, *this); LP->runOnLoop(CurrentLoop, *this);
verifyLoopInfo();
StopPassTimer(P); StopPassTimer(P);
if (Changed) if (Changed)
dumpPassInfo(P, MODIFICATION_MSG, ON_LOOP_MSG, ""); dumpPassInfo(P, MODIFICATION_MSG, ON_LOOP_MSG, "");
dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet()); dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet());
verifyPreservedAnalysis(LP);
removeNotPreservedAnalysis(P); removeNotPreservedAnalysis(P);
recordAvailableAnalysis(P); recordAvailableAnalysis(P);
removeDeadPasses(P, "", ON_LOOP_MSG); removeDeadPasses(P, "", ON_LOOP_MSG);

View File

@@ -74,6 +74,16 @@ namespace {
AU.addPreserved<DominanceFrontier>(); AU.addPreserved<DominanceFrontier>();
AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added. AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added.
} }
/// verifyAnalysis() - Verify loop nest.
void verifyAnalysis() const {
#ifndef NDEBUG
LoopInfo *NLI = &getAnalysis<LoopInfo>();
for (LoopInfo::iterator I = NLI->begin(), E = NLI->end(); I != E; ++I)
(*I)->verifyLoop();
#endif
}
private: private:
bool ProcessLoop(Loop *L); bool ProcessLoop(Loop *L);
BasicBlock *SplitBlockPredecessors(BasicBlock *BB, const char *Suffix, BasicBlock *SplitBlockPredecessors(BasicBlock *BB, const char *Suffix,

View File

@@ -594,22 +594,30 @@ bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
return true; return true;
} }
/// Remove Analyss not preserved by Pass P /// verifyPreservedAnalysis -- Verify analysis presreved by pass P.
void PMDataManager::removeNotPreservedAnalysis(Pass *P) { void PMDataManager::verifyPreservedAnalysis(Pass *P) {
AnalysisUsage AnUsage; AnalysisUsage AnUsage;
P->getAnalysisUsage(AnUsage); P->getAnalysisUsage(AnUsage);
const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet(); const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
// Verify preserved analysis // Verify preserved analysis
for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(), for (std::vector<AnalysisID>::const_iterator I = PreservedSet.begin(),
E = AvailableAnalysis.end(); I != E; ++I) { E = PreservedSet.end(); I != E; ++I) {
Pass *AP = I->second; AnalysisID AID = *I;
Pass *AP = findAnalysisPass(AID, true);
if (AP)
AP->verifyAnalysis(); AP->verifyAnalysis();
} }
}
/// Remove Analyss not preserved by Pass P
void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
AnalysisUsage AnUsage;
P->getAnalysisUsage(AnUsage);
if (AnUsage.getPreservesAll()) if (AnUsage.getPreservesAll())
return; return;
const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(), for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
E = AvailableAnalysis.end(); I != E; ) { E = AvailableAnalysis.end(); I != E; ) {
std::map<AnalysisID, Pass*>::iterator Info = I++; std::map<AnalysisID, Pass*>::iterator Info = I++;
@@ -954,6 +962,7 @@ BBPassManager::runOnFunction(Function &F) {
dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG, (*I).getName()); dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG, (*I).getName());
dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet()); dumpAnalysisSetInfo("Preserved", BP, AnUsage.getPreservedSet());
verifyPreservedAnalysis(BP);
removeNotPreservedAnalysis(BP); removeNotPreservedAnalysis(BP);
recordAvailableAnalysis(BP); recordAvailableAnalysis(BP);
removeDeadPasses(BP, (*I).getName(), ON_BASICBLOCK_MSG); removeDeadPasses(BP, (*I).getName(), ON_BASICBLOCK_MSG);
@@ -1151,6 +1160,7 @@ bool FPPassManager::runOnFunction(Function &F) {
dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName()); dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName());
dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet()); dumpAnalysisSetInfo("Preserved", FP, AnUsage.getPreservedSet());
verifyPreservedAnalysis(FP);
removeNotPreservedAnalysis(FP); removeNotPreservedAnalysis(FP);
recordAvailableAnalysis(FP); recordAvailableAnalysis(FP);
removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG); removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
@@ -1220,6 +1230,7 @@ MPPassManager::runOnModule(Module &M) {
M.getModuleIdentifier()); M.getModuleIdentifier());
dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet()); dumpAnalysisSetInfo("Preserved", MP, AnUsage.getPreservedSet());
verifyPreservedAnalysis(MP);
removeNotPreservedAnalysis(MP); removeNotPreservedAnalysis(MP);
recordAvailableAnalysis(MP); recordAvailableAnalysis(MP);
removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG); removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);