summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-11-09 04:16:01 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-11-09 04:16:01 +0000
commit5786b4cdc118a7fbcdae238e264a884691ab43b7 (patch)
treee71d436d7dbfc94563bfdce2d8cfafb2ca503d7e /include
parentfd22883a345b2e04d0bdb4d4b9ed64ceebdc0601 (diff)
downloadllvm-5786b4cdc118a7fbcdae238e264a884691ab43b7.tar.gz
llvm-5786b4cdc118a7fbcdae238e264a884691ab43b7.tar.bz2
llvm-5786b4cdc118a7fbcdae238e264a884691ab43b7.tar.xz
Enhance verifyLoop so that it can reliably verify that every block in a loop is reachable from the loop header.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144166 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Analysis/LoopInfo.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h
index 12cb6c5cc4..535d2055e5 100644
--- a/include/llvm/Analysis/LoopInfo.h
+++ b/include/llvm/Analysis/LoopInfo.h
@@ -416,14 +416,26 @@ public:
#ifndef NDEBUG
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
// lookups.
SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
std::sort(LoopBBs.begin(), LoopBBs.end());
// Check the individual blocks.
- for (block_iterator I = block_begin(), E = block_end(); I != E; ++I) {
- BlockT *BB = *I;
+ for ( ; BI != BE; ++BI) {
+ BlockT *BB = *BI;
bool HasInsideLoopSuccs = false;
bool HasInsideLoopPreds = false;
SmallVector<BlockT *, 2> OutsideLoopPreds;
@@ -440,7 +452,7 @@ public:
for (typename InvBlockTraits::ChildIteratorType PI =
InvBlockTraits::child_begin(BB), PE = InvBlockTraits::child_end(BB);
PI != PE; ++PI) {
- typename InvBlockTraits::NodeType *N = *PI;
+ BlockT *N = *PI;
if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), N))
HasInsideLoopPreds = true;
else
@@ -464,8 +476,12 @@ public:
assert(HasInsideLoopSuccs && "Loop block has no in-loop successors!");
assert(BB != getHeader()->getParent()->begin() &&
"Loop contains function entry block!");
+
+ NumVisited++;
}
+ assert(NumVisited == getNumBlocks() && "Unreachable block in loop");
+
// Check the subloops.
for (iterator I = begin(), E = end(); I != E; ++I)
// Each block in each subloop should be contained within this loop.