From d2e103daf8a093e0e25ddbaa7549c083887196e8 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 16 Aug 2011 20:42:52 +0000 Subject: [PATCH] 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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137744 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/BasicBlock.h | 9 +++++++++ lib/VMCore/BasicBlock.cpp | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index d5966290a14..a031650bb30 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -145,6 +145,15 @@ public: return const_cast(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(this)->getFirstInsertionPt(); + } + /// 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 3e29f05d51d..d0aa275c8fe 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -167,6 +167,12 @@ Instruction* BasicBlock::getFirstNonPHIOrDbgOrLifetime() { return &*i; } +BasicBlock::iterator BasicBlock::getFirstInsertionPt() { + iterator InsertPt = getFirstNonPHI(); + if (isa(InsertPt)) ++InsertPt; + return InsertPt; +} + void BasicBlock::dropAllReferences() { for(iterator I = begin(), E = end(); I != E; ++I) I->dropAllReferences(); -- 2.34.1