[llvm] r354218 - [NFC] Factor out a function for future reuse

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 17 07:04:10 PST 2019


Author: mkazantsev
Date: Sun Feb 17 07:04:09 2019
New Revision: 354218

URL: http://llvm.org/viewvc/llvm-project?rev=354218&view=rev
Log:
[NFC] Factor out a function for future reuse

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp?rev=354218&r1=354217&r2=354218&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp Sun Feb 17 07:04:09 2019
@@ -90,6 +90,20 @@ static void removeBlockFromLoops(BasicBl
     Current->removeBlockFromLoop(BB);
 }
 
+/// Find innermost loop that is reachable from \p BBs and contains loop \p L.
+static Loop *getInnermostSuccessorLoop(SmallPtrSetImpl<BasicBlock *> &BBs,
+                                       Loop &L, LoopInfo &LI) {
+  Loop *StillReachable = nullptr;
+  for (BasicBlock *BB : BBs) {
+    Loop *BBL = LI.getLoopFor(BB);
+    if (BBL && BBL->contains(L.getHeader()))
+      if (!StillReachable ||
+          BBL->getLoopDepth() > StillReachable->getLoopDepth())
+        StillReachable = BBL;
+  }
+  return StillReachable;
+}
+
 namespace {
 /// Helper class that can turn branches and switches with constant conditions
 /// into unconditional branches.
@@ -369,14 +383,7 @@ private:
       // the current loop. We need to fix loop info accordingly. For this, we
       // find the most nested loop that still contains L and remove L from all
       // loops that are inside of it.
-      Loop *StillReachable = nullptr;
-      for (BasicBlock *BB : LiveExitBlocks) {
-        Loop *BBL = LI.getLoopFor(BB);
-        if (BBL && BBL->contains(L.getHeader()))
-          if (!StillReachable ||
-              BBL->getLoopDepth() > StillReachable->getLoopDepth())
-            StillReachable = BBL;
-      }
+      Loop *StillReachable = getInnermostSuccessorLoop(LiveExitBlocks, L, LI);
 
       // Okay, our loop is no longer in the outer loop (and maybe not in some of
       // its parents as well). Make the fixup.




More information about the llvm-commits mailing list