[C++11] Add predecessors(BasicBlock *) / successors(BasicBlock *) iterator ranges.
Summary: This patch introduces two new iterator ranges and updates existing code to use it. No functional change intended.
Test Plan: All tests (make check-all) still pass.
Reviewers: dblaikie
Reviewed By: dblaikie
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D4481
llvm-svn: 213474
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index 46c0eaa..a6d8b55 100644
--- a/llvm/lib/Analysis/LoopInfo.cpp
+++ b/llvm/lib/Analysis/LoopInfo.cpp
@@ -336,9 +336,8 @@
SmallVector<BasicBlock *, 4> ExitBlocks;
getExitBlocks(ExitBlocks);
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
- for (pred_iterator PI = pred_begin(ExitBlocks[i]),
- PE = pred_end(ExitBlocks[i]); PI != PE; ++PI)
- if (!contains(*PI))
+ for (BasicBlock *Pred : predecessors(ExitBlocks[i]))
+ if (!contains(Pred))
return false;
// All the requirements are met.
return true;
@@ -360,12 +359,12 @@
BasicBlock *current = *BI;
switchExitBlocks.clear();
- for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I) {
+ for (BasicBlock *Succ : successors(*BI)) {
// If block is inside the loop then it is not a exit block.
- if (contains(*I))
+ if (contains(Succ))
continue;
- pred_iterator PI = pred_begin(*I);
+ pred_iterator PI = pred_begin(Succ);
BasicBlock *firstPred = *PI;
// If current basic block is this exit block's first predecessor
@@ -379,17 +378,17 @@
// then it is possible that there are multiple edges from current block
// to one exit block.
if (std::distance(succ_begin(current), succ_end(current)) <= 2) {
- ExitBlocks.push_back(*I);
+ ExitBlocks.push_back(Succ);
continue;
}
// In case of multiple edges from current block to exit block, collect
// only one edge in ExitBlocks. Use switchExitBlocks to keep track of
// duplicate edges.
- if (std::find(switchExitBlocks.begin(), switchExitBlocks.end(), *I)
+ if (std::find(switchExitBlocks.begin(), switchExitBlocks.end(), Succ)
== switchExitBlocks.end()) {
- switchExitBlocks.push_back(*I);
- ExitBlocks.push_back(*I);
+ switchExitBlocks.push_back(Succ);
+ ExitBlocks.push_back(Succ);
}
}
}