diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-08-16 20:42:52 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-08-16 20:42:52 +0000 |
commit | ee1c2d2437a0918b17bf39b92296cb43c0394eb3 (patch) | |
tree | 8451cdf3c2fd3b289a5c7452516ab81d3332fcee | |
parent | 55d875fa1c1903ab9292c84f188e2028fb7a6469 (diff) | |
download | bcm5719-llvm-ee1c2d2437a0918b17bf39b92296cb43c0394eb3.tar.gz bcm5719-llvm-ee1c2d2437a0918b17bf39b92296cb43c0394eb3.zip |
Add getFirstInsertionPt() method.
getFirstInsertionPt() returns an iterator to the first insertion point in a
basic block. This is after all PHIs and any other instruction which is required
to be at the top of the basic block (like LandingPadInst).
llvm-svn: 137744
-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(); |