diff options
-rw-r--r-- | llvm/include/llvm/BasicBlock.h | 9 | ||||
-rw-r--r-- | llvm/lib/VMCore/BasicBlock.cpp | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/llvm/include/llvm/BasicBlock.h b/llvm/include/llvm/BasicBlock.h index d5966290a14..a031650bb30 100644 --- a/llvm/include/llvm/BasicBlock.h +++ b/llvm/include/llvm/BasicBlock.h @@ -145,6 +145,15 @@ public: return const_cast<BasicBlock*>(this)->getFirstNonPHIOrDbgOrLifetime(); } + /// getFirstInsertionPt - Returns an iterator to the first instruction in this + /// block that is suitable for inserting a non-PHI instruction. In particular, + /// it skips all PHIs and LandingPad instructions. Returns 0 if there are no + /// non-PHI instructions. + iterator getFirstInsertionPt(); + const_iterator getFirstInsertionPt() const { + return const_cast<BasicBlock*>(this)->getFirstInsertionPt(); + } + /// removeFromParent - This method unlinks 'this' from the containing /// function, but does not delete it. /// diff --git a/llvm/lib/VMCore/BasicBlock.cpp b/llvm/lib/VMCore/BasicBlock.cpp index 3e29f05d51d..d0aa275c8fe 100644 --- a/llvm/lib/VMCore/BasicBlock.cpp +++ b/llvm/lib/VMCore/BasicBlock.cpp @@ -167,6 +167,12 @@ Instruction* BasicBlock::getFirstNonPHIOrDbgOrLifetime() { return &*i; } +BasicBlock::iterator BasicBlock::getFirstInsertionPt() { + iterator InsertPt = getFirstNonPHI(); + if (isa<LandingPadInst>(InsertPt)) ++InsertPt; + return InsertPt; +} + void BasicBlock::dropAllReferences() { for(iterator I = begin(), E = end(); I != E; ++I) I->dropAllReferences(); |