[llvm] r195410 - [block-freq] Add a method to loop info for returning all loop latches for a specific loop.

Michael Gottesman mgottesman at apple.com
Thu Nov 21 21:00:48 PST 2013


Author: mgottesman
Date: Thu Nov 21 23:00:48 2013
New Revision: 195410

URL: http://llvm.org/viewvc/llvm-project?rev=195410&view=rev
Log:
[block-freq] Add a method to loop info for returning all loop latches for a specific loop.

We already have a method for returning one loop latch but for some
reason no one has committed one for returning loop latches in the case
where there are multiple latches.

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=195410&r1=195409&r2=195410&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Thu Nov 21 23:00:48 2013
@@ -228,6 +228,18 @@ public:
   /// A latch block is a block that contains a branch back to the header.
   BlockT *getLoopLatch() const;
 
+  /// getLoopLatches - Return all loop latch blocks of this loop. A latch block
+  /// is a block that contains a branch back to the header.
+  void getLoopLatches(SmallVectorImpl<BlockT *> &LoopLatches) const {
+    BlockT *H = getHeader();
+    typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
+    for (typename InvBlockTraits::ChildIteratorType I =
+         InvBlockTraits::child_begin(H),
+         E = InvBlockTraits::child_end(H); I != E; ++I)
+      if (contains(*I))
+        LoopLatches.push_back(*I);
+  }
+
   //===--------------------------------------------------------------------===//
   // APIs for updating loop information after changing the CFG
   //





More information about the llvm-commits mailing list