Implement the new InsertInstBeforeInst function
authorChris Lattner <sabre@nondot.org>
Thu, 21 Mar 2002 06:24:00 +0000 (06:24 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 21 Mar 2002 06:24:00 +0000 (06:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1930 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/TransformInternals.cpp

index c09ad3d29833d635818af9afaaa4133e6c7914fe..9ea053e040b0cfb248a3e370da1b23d6fb49add1 100644 (file)
@@ -67,6 +67,20 @@ void ReplaceInstWithInst(Instruction *From, Instruction *To) {
   ReplaceInstWithInst(BIL, BI, To);
 }
 
+// InsertInstBeforeInst - Insert 'NewInst' into the basic block that 'Existing'
+// is already in, and put it right before 'Existing'.  This instruction should
+// only be used when there is no iterator to Existing already around.  The 
+// returned iterator points to the new instruction.
+//
+BasicBlock::iterator InsertInstBeforeInst(Instruction *NewInst,
+                                          Instruction *Existing) {
+  BasicBlock *BB = Existing->getParent();
+  BasicBlock::InstListType &BIL = BB->getInstList();
+  BasicBlock::iterator BI = find(BIL.begin(), BIL.end(), Existing);
+  assert(BI != BIL.end() && "Inst not in it's parents BB!");
+  return BIL.insert(BI, NewInst);
+}
+
 
 
 // getStructOffsetType - Return a vector of offsets that are to be used to index