[llvm] r276837 - add function isLoopLatch

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 26 22:02:15 PDT 2016


Author: spop
Date: Wed Jul 27 00:02:15 2016
New Revision: 276837

URL: http://llvm.org/viewvc/llvm-project?rev=276837&view=rev
Log:
add function isLoopLatch

Differential Revision: https://reviews.llvm.org/D22817

Modified:
    llvm/trunk/include/llvm/Analysis/LoopInfo.h

Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=276837&r1=276836&r2=276837&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Wed Jul 27 00:02:15 2016
@@ -168,6 +168,19 @@ public:
     return false;
   }
 
+  /// Returns true if \p BB is a loop-latch.
+  /// A latch block is a block that contains a branch back to the header.
+  /// This function is useful when there are multiple latches in a loop
+  /// because \fn getLoopLatch will return nullptr in that case.
+  bool isLoopLatch(const BlockT *BB) const {
+    assert(contains(BB) && "block does not belong to the loop");
+
+    BlockT *Header = getHeader();
+    auto PredBegin = GraphTraits<Inverse<BlockT*> >::child_begin(Header);
+    auto PredEnd = GraphTraits<Inverse<BlockT*> >::child_end(Header);
+    return std::find(PredBegin, PredEnd, BB) != PredEnd;
+  }
+
   /// Calculate the number of back edges to the loop header.
   unsigned getNumBackEdges() const {
     unsigned NumBackEdges = 0;




More information about the llvm-commits mailing list