[llvm] r354227 - [NFC] Teach getInnermostLoopFor walk up the loop trees

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


Author: mkazantsev
Date: Sun Feb 17 10:21:51 2019
New Revision: 354227

URL: http://llvm.org/viewvc/llvm-project?rev=354227&view=rev
Log:
[NFC] Teach getInnermostLoopFor walk up the loop trees

This should be NFC in current use case of this method, but it will
help to use it for solving more compex tasks in follow-up patches.

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=354227&r1=354226&r2=354227&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp Sun Feb 17 10:21:51 2019
@@ -94,15 +94,19 @@ static void removeBlockFromLoops(BasicBl
 /// contains the header of loop \p L.
 static Loop *getInnermostLoopFor(SmallPtrSetImpl<BasicBlock *> &BBs,
                                  Loop &L, LoopInfo &LI) {
-  Loop *StillReachable = nullptr;
+  Loop *Innermost = nullptr;
   for (BasicBlock *BB : BBs) {
     Loop *BBL = LI.getLoopFor(BB);
-    if (BBL && BBL->contains(L.getHeader()))
-      if (!StillReachable ||
-          BBL->getLoopDepth() > StillReachable->getLoopDepth())
-        StillReachable = BBL;
+    while (BBL && !BBL->contains(L.getHeader()))
+      BBL = BBL->getParentLoop();
+    if (BBL == &L)
+      BBL = BBL->getParentLoop();
+    if (!BBL)
+      continue;
+    if (!Innermost || BBL->getLoopDepth() > Innermost->getLoopDepth())
+      Innermost = BBL;
   }
-  return StillReachable;
+  return Innermost;
 }
 
 namespace {




More information about the llvm-commits mailing list