From ca02360f4660d5e51b455e199e64416ef68408f3 Mon Sep 17 00:00:00 2001 From: Xin Tong Date: Sun, 15 Jan 2017 21:17:52 +0000 Subject: Use getLoopLatch in place of isLoopSimplifyForm Summary: Use getLoopLatch in place of isLoopSimplifyForm. we do not need to know whether the loop has a preheader nor dedicated exits. Reviewers: hfinkel, sanjoy, atrick, mkuper Subscribers: mzolotukhin, llvm-commits Differential Revision: https://reviews.llvm.org/D28724 llvm-svn: 292078 --- llvm/lib/Analysis/LoopInfo.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Analysis') diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index 714e0d5173f..e7e7612a66d 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -211,9 +211,11 @@ bool Loop::isSafeToClone() const { MDNode *Loop::getLoopID() const { MDNode *LoopID = nullptr; - if (isLoopSimplifyForm()) { - LoopID = getLoopLatch()->getTerminator()->getMetadata(LLVMContext::MD_loop); + if (BasicBlock *Latch = getLoopLatch()) { + LoopID = Latch->getTerminator()->getMetadata(LLVMContext::MD_loop); } else { + assert(!getLoopLatch() && + "The loop should have no single latch at this point"); // Go through each predecessor of the loop header and check the // terminator for the metadata. BasicBlock *H = getHeader(); @@ -248,11 +250,12 @@ void Loop::setLoopID(MDNode *LoopID) const { assert(LoopID->getNumOperands() > 0 && "Loop ID needs at least one operand"); assert(LoopID->getOperand(0) == LoopID && "Loop ID should refer to itself"); - if (isLoopSimplifyForm()) { - getLoopLatch()->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID); + if (BasicBlock *Latch = getLoopLatch()) { + Latch->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID); return; } + assert(!getLoopLatch() && "The loop should have no single latch at this point"); BasicBlock *H = getHeader(); for (BasicBlock *BB : this->blocks()) { TerminatorInst *TI = BB->getTerminator(); -- cgit v1.2.3