summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MustExecute.cpp
diff options
context:
space:
mode:
authorMax Kazantsev <max.kazantsev@azul.com>2018-08-21 07:15:06 +0000
committerMax Kazantsev <max.kazantsev@azul.com>2018-08-21 07:15:06 +0000
commitbfbd4d1fb6a9afec4ab050ef3e0cee2b540ea19c (patch)
tree211ef66ba17de9898c3fcb4d31dba24e3c68362f /llvm/lib/Analysis/MustExecute.cpp
parent09ab5067983477e206532f4fdcf7dadcbc54b724 (diff)
downloadbcm5719-llvm-bfbd4d1fb6a9afec4ab050ef3e0cee2b540ea19c.tar.gz
bcm5719-llvm-bfbd4d1fb6a9afec4ab050ef3e0cee2b540ea19c.zip
[NFC] Factor out predecessors collection into a separate method
It may be reused in a different piece of logic. Differential Revision: https://reviews.llvm.org/D50890 Reviewed By: reames llvm-svn: 340250
Diffstat (limited to 'llvm/lib/Analysis/MustExecute.cpp')
-rw-r--r--llvm/lib/Analysis/MustExecute.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp
index ab091005a20..79ec8e400c0 100644
--- a/llvm/lib/Analysis/MustExecute.cpp
+++ b/llvm/lib/Analysis/MustExecute.cpp
@@ -98,19 +98,13 @@ static bool CanProveNotTakenFirstIteration(const BasicBlock *ExitBlock,
return SimpleCst->isAllOnesValue();
}
-
-bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop,
- const BasicBlock *BB,
- const DominatorTree *DT) const {
+void LoopSafetyInfo::collectTransitivePredecessors(
+ const Loop *CurLoop, const BasicBlock *BB,
+ SmallPtrSetImpl<const BasicBlock *> &Predecessors) const {
+ assert(Predecessors.empty() && "Garbage in predecessors set?");
assert(CurLoop->contains(BB) && "Should only be called for loop blocks!");
-
- // Fast path: header is always reached once the loop is entered.
if (BB == CurLoop->getHeader())
- return true;
-
- // Collect all transitive predecessors of BB in the same loop. This set will
- // be a subset of the blocks within the loop.
- SmallPtrSet<const BasicBlock *, 4> Predecessors;
+ return;
SmallVector<const BasicBlock *, 4> WorkList;
for (auto *Pred : predecessors(BB)) {
Predecessors.insert(Pred);
@@ -132,6 +126,21 @@ bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop,
if (Predecessors.insert(PredPred).second)
WorkList.push_back(PredPred);
}
+}
+
+bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop,
+ const BasicBlock *BB,
+ const DominatorTree *DT) const {
+ assert(CurLoop->contains(BB) && "Should only be called for loop blocks!");
+
+ // Fast path: header is always reached once the loop is entered.
+ if (BB == CurLoop->getHeader())
+ return true;
+
+ // Collect all transitive predecessors of BB in the same loop. This set will
+ // be a subset of the blocks within the loop.
+ SmallPtrSet<const BasicBlock *, 4> Predecessors;
+ collectTransitivePredecessors(CurLoop, BB, Predecessors);
// Make sure that all successors of all predecessors of BB are either:
// 1) BB,
OpenPOWER on IntegriCloud