Add BuildMI variants that take a MBB::iterator


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11975 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/CodeGen/MachineInstrBuilder.h b/include/llvm/CodeGen/MachineInstrBuilder.h
index b4b491e..9f06678 100644
--- a/include/llvm/CodeGen/MachineInstrBuilder.h
+++ b/include/llvm/CodeGen/MachineInstrBuilder.h
@@ -23,7 +23,7 @@
 #ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H
 #define LLVM_CODEGEN_MACHINEINSTRBUILDER_H
 
-#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
 
 namespace llvm {
 
@@ -150,12 +150,33 @@
 }
 
 
+/// BuildMI - Insert the instruction before a specified location in the basic
+/// block.
+inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
+                                   MachineBasicBlock::iterator I,
+                                   int Opcode, unsigned NumOperands,
+                                   unsigned DestReg) {
+  MachineInstr *MI = new MachineInstr(Opcode, NumOperands+1, true, true);
+  BB.insert(I, MI);
+  return MachineInstrBuilder(MI).addReg(DestReg, MachineOperand::Def);
+}
+
+/// BMI - A special BuildMI variant that takes an iterator to insert the
+/// instruction at as well as a basic block.
+inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
+                                   MachineBasicBlock::iterator I,
+                                   int Opcode, unsigned NumOperands) {
+  MachineInstr *MI = new MachineInstr(Opcode, NumOperands, true, true);
+  BB.insert(I, MI);
+  return MachineInstrBuilder(MI);
+}
+
 /// BuildMI - This version of the builder inserts the built MachineInstr into
 /// the specified MachineBasicBlock.
 ///
 inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, int Opcode,
                                    unsigned NumOperands) {
-  return MachineInstrBuilder(new MachineInstr(BB, Opcode, NumOperands));
+  return BuildMI(*BB, BB->end(), Opcode, NumOperands);
 }
 
 /// BuildMI - This version of the builder inserts the built MachineInstr into
@@ -165,9 +186,7 @@
 ///
 inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, int Opcode,
                                    unsigned NumOperands, unsigned DestReg) {
-  return MachineInstrBuilder(
-    new MachineInstr(BB, Opcode, NumOperands+1))
-      .addReg(DestReg, MachineOperand::Def);
+  return BuildMI(*BB, BB->end(), Opcode, NumOperands, DestReg);
 }
 
 } // End llvm namespace