[PATCH] D22817: Utility to print all the basic blocks of a loop.

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rL276837: add function isLoopLatch (authored by spop).

Changed prior to commit:
  https://reviews.llvm.org/D22817?vs=65579&id=65662#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22817

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

Index: llvm/trunk/include/llvm/Analysis/LoopInfo.h
===================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h
@@ -168,6 +168,19 @@
     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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22817.65662.patch
Type: text/x-patch
Size: 1014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160727/ccfbbfc4/attachment.bin>


More information about the llvm-commits mailing list