From: Vladimir Prus Date: Thu, 8 Jun 2006 15:46:18 +0000 (+0000) Subject: New method BasicBlock::getFirstNonPHI. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=dd49dbfe44098eb53b1ac29f017e422147572bbb;p=oota-llvm.git New method BasicBlock::getFirstNonPHI. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28724 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 7fcf8847bd5..0f7b3e077e4 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -91,7 +91,14 @@ public: /// TerminatorInst *getTerminator(); const TerminatorInst *const getTerminator() const; - + + /// Returns a pointer to the first instructon in this block that is not a + /// PHINode instruction. When adding instruction to the beginning of the + /// basic block, they should be added before the returned value, not before + /// the first instruction, which might be PHI. + /// Returns 0 is there's no non-PHI instruction. + Instruction* getFirstNonPHI(); + /// removeFromParent - This method unlinks 'this' from the containing /// function, but does not delete it. /// diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index ab7798c3866..c93f5584d27 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -121,6 +121,17 @@ const TerminatorInst *const BasicBlock::getTerminator() const { return dyn_cast(&InstList.back()); } +Instruction* BasicBlock::getFirstNonPHI() +{ + BasicBlock::iterator i = begin(), e = end(); + // All valid basic blocks should have a terminator, + // which is not a PHINode. If we have invalid basic + // block we'll get assert when dereferencing past-the-end + // iterator. + while (isa(i)) ++i; + return &*i; +} + void BasicBlock::dropAllReferences() { for(iterator I = begin(), E = end(); I != E; ++I) I->dropAllReferences();