From 1a2abd4a907811c736e349173ecc5a06d9c73fc1 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 7 Jul 2015 16:42:50 +0000 Subject: [PATCH] Revert r241570, it caused PR24053 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241602 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/BasicBlock.cpp | 51 ++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp index 0a0449434a7..77cb10d5b6b 100644 --- a/lib/IR/BasicBlock.cpp +++ b/lib/IR/BasicBlock.cpp @@ -163,40 +163,47 @@ CallInst *BasicBlock::getTerminatingMustTailCall() { } Instruction* BasicBlock::getFirstNonPHI() { - for (Instruction &I : *this) - if (!isa(I)) - return &I; - return nullptr; + BasicBlock::iterator i = begin(); + // All valid basic blocks should have a terminator, + // which is not a PHINode. If we have an invalid basic + // block we'll get an assertion failure when dereferencing + // a past-the-end iterator. + while (isa(i)) ++i; + return &*i; } Instruction* BasicBlock::getFirstNonPHIOrDbg() { - for (Instruction &I : *this) - if (!isa(I) && !isa(I)) - return &I; - return nullptr; + BasicBlock::iterator i = begin(); + // All valid basic blocks should have a terminator, + // which is not a PHINode. If we have an invalid basic + // block we'll get an assertion failure when dereferencing + // a past-the-end iterator. + while (isa(i) || isa(i)) ++i; + return &*i; } Instruction* BasicBlock::getFirstNonPHIOrDbgOrLifetime() { - for (Instruction &I : *this) { - if (isa(I) || isa(I)) + // All valid basic blocks should have a terminator, + // which is not a PHINode. If we have an invalid basic + // block we'll get an assertion failure when dereferencing + // a past-the-end iterator. + BasicBlock::iterator i = begin(); + for (;; ++i) { + if (isa(i) || isa(i)) continue; - if (auto *II = dyn_cast(&I)) - if (II->getIntrinsicID() == Intrinsic::lifetime_start || - II->getIntrinsicID() == Intrinsic::lifetime_end) - continue; - - return &I; + const IntrinsicInst *II = dyn_cast(i); + if (!II) + break; + if (II->getIntrinsicID() != Intrinsic::lifetime_start && + II->getIntrinsicID() != Intrinsic::lifetime_end) + break; } - return nullptr; + return &*i; } BasicBlock::iterator BasicBlock::getFirstInsertionPt() { - Instruction *FirstNonPHI = getFirstNonPHI(); - if (!FirstNonPHI) - return end(); - - iterator InsertPt = FirstNonPHI; + iterator InsertPt = getFirstNonPHI(); if (isa(InsertPt)) ++InsertPt; return InsertPt; } -- 2.34.1