From 9570bfd349bf3f4e2d0adcb0296dc171ab236977 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Wed, 27 Jul 2016 05:02:15 +0000 Subject: [PATCH] add function isLoopLatch Differential Revision: https://reviews.llvm.org/D22817 llvm-svn: 276837 --- llvm/include/llvm/Analysis/LoopInfo.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h index a7d9ac5..0888530 100644 --- a/llvm/include/llvm/Analysis/LoopInfo.h +++ b/llvm/include/llvm/Analysis/LoopInfo.h @@ -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 >::child_begin(Header); + auto PredEnd = GraphTraits >::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; -- 2.7.4