forked from OSchip/llvm-project
Enhance verifyLoop so that it can reliably verify that every block in a loop is reachable from the loop header.
llvm-svn: 144166
This commit is contained in:
parent
6e46ca2c10
commit
b3c8febd1e
|
@ -416,14 +416,26 @@ public:
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
assert(!Blocks.empty() && "Loop header is missing");
|
assert(!Blocks.empty() && "Loop header is missing");
|
||||||
|
|
||||||
|
// Setup for using a depth-first iterator to visit every block in the loop.
|
||||||
|
SmallVector<BlockT*, 8> ExitBBs;
|
||||||
|
getExitBlocks(ExitBBs);
|
||||||
|
llvm::SmallPtrSet<BlockT*, 8> VisitSet;
|
||||||
|
VisitSet.insert(ExitBBs.begin(), ExitBBs.end());
|
||||||
|
df_ext_iterator<BlockT*, llvm::SmallPtrSet<BlockT*, 8> >
|
||||||
|
BI = df_ext_begin(getHeader(), VisitSet),
|
||||||
|
BE = df_ext_end(getHeader(), VisitSet);
|
||||||
|
|
||||||
|
// Keep track of the number of BBs visited.
|
||||||
|
unsigned NumVisited = 0;
|
||||||
|
|
||||||
// Sort the blocks vector so that we can use binary search to do quick
|
// Sort the blocks vector so that we can use binary search to do quick
|
||||||
// lookups.
|
// lookups.
|
||||||
SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
|
SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
|
||||||
std::sort(LoopBBs.begin(), LoopBBs.end());
|
std::sort(LoopBBs.begin(), LoopBBs.end());
|
||||||
|
|
||||||
// Check the individual blocks.
|
// Check the individual blocks.
|
||||||
for (block_iterator I = block_begin(), E = block_end(); I != E; ++I) {
|
for ( ; BI != BE; ++BI) {
|
||||||
BlockT *BB = *I;
|
BlockT *BB = *BI;
|
||||||
bool HasInsideLoopSuccs = false;
|
bool HasInsideLoopSuccs = false;
|
||||||
bool HasInsideLoopPreds = false;
|
bool HasInsideLoopPreds = false;
|
||||||
SmallVector<BlockT *, 2> OutsideLoopPreds;
|
SmallVector<BlockT *, 2> OutsideLoopPreds;
|
||||||
|
@ -440,7 +452,7 @@ public:
|
||||||
for (typename InvBlockTraits::ChildIteratorType PI =
|
for (typename InvBlockTraits::ChildIteratorType PI =
|
||||||
InvBlockTraits::child_begin(BB), PE = InvBlockTraits::child_end(BB);
|
InvBlockTraits::child_begin(BB), PE = InvBlockTraits::child_end(BB);
|
||||||
PI != PE; ++PI) {
|
PI != PE; ++PI) {
|
||||||
typename InvBlockTraits::NodeType *N = *PI;
|
BlockT *N = *PI;
|
||||||
if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), N))
|
if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), N))
|
||||||
HasInsideLoopPreds = true;
|
HasInsideLoopPreds = true;
|
||||||
else
|
else
|
||||||
|
@ -464,8 +476,12 @@ public:
|
||||||
assert(HasInsideLoopSuccs && "Loop block has no in-loop successors!");
|
assert(HasInsideLoopSuccs && "Loop block has no in-loop successors!");
|
||||||
assert(BB != getHeader()->getParent()->begin() &&
|
assert(BB != getHeader()->getParent()->begin() &&
|
||||||
"Loop contains function entry block!");
|
"Loop contains function entry block!");
|
||||||
|
|
||||||
|
NumVisited++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(NumVisited == getNumBlocks() && "Unreachable block in loop");
|
||||||
|
|
||||||
// Check the subloops.
|
// Check the subloops.
|
||||||
for (iterator I = begin(), E = end(); I != E; ++I)
|
for (iterator I = begin(), E = end(); I != E; ++I)
|
||||||
// Each block in each subloop should be contained within this loop.
|
// Each block in each subloop should be contained within this loop.
|
||||||
|
|
Loading…
Reference in New Issue