[block-freq] Add a method to loop info for returning all loop latches for a specific...
authorMichael Gottesman <mgottesman@apple.com>
Fri, 22 Nov 2013 05:00:48 +0000 (05:00 +0000)
committerMichael Gottesman <mgottesman@apple.com>
Fri, 22 Nov 2013 05:00:48 +0000 (05:00 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195410 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopInfo.h

index 62f5acad5668915371dd594cc3a850fcf41f06b3..582c97cf5692f3ebce4636c41099a0a866461449 100644 (file)
@@ -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
   //