[PATCH] D50890: [NFC] Factor out predecessors collection into a separate method

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 17 03:59:16 PDT 2018


mkazantsev created this revision.
mkazantsev added a reviewer: reames.

It may be reused in a different piece of logic.


https://reviews.llvm.org/D50890

Files:
  include/llvm/Analysis/MustExecute.h
  lib/Analysis/MustExecute.cpp


Index: lib/Analysis/MustExecute.cpp
===================================================================
--- lib/Analysis/MustExecute.cpp
+++ lib/Analysis/MustExecute.cpp
@@ -89,19 +89,13 @@
   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);
@@ -123,6 +117,21 @@
       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,
Index: include/llvm/Analysis/MustExecute.h
===================================================================
--- include/llvm/Analysis/MustExecute.h
+++ include/llvm/Analysis/MustExecute.h
@@ -48,6 +48,14 @@
                                // may throw.
   // Contains information about implicit control flow in this loop's blocks.
   mutable ImplicitControlFlowTracking ICF;
+
+  /// Collect all blocks from \p CurLoop which lie on all possible paths from
+  /// the header of \p CurLoop (inclusive) to BB (exclusive) into the set
+  /// \p Predecessors. If \p BB is the header, \p Predecessors will be empty.
+  void collectTransitivePredecessors(
+      const Loop *CurLoop, const BasicBlock *BB,
+      SmallPtrSetImpl<const BasicBlock *> &Predecessors) const;
+
 public:
   // Used to update funclet bundle operands.
   DenseMap<BasicBlock *, ColorVector> BlockColors;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50890.161205.patch
Type: text/x-patch
Size: 2943 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180817/973c13db/attachment-0001.bin>


More information about the llvm-commits mailing list