Move all of the header files which are involved in modelling the LLVM IR
[oota-llvm.git] / lib / CodeGen / MachineInstr.cpp
index fff4a67e41d5942ee8e85cf5d0eb6ef860b50b8a..5239d43d7e8a565989f5fced584819067cc7c8b0 100644 (file)
 #include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/PseudoSourceValue.h"
-#include "llvm/Constants.h"
 #include "llvm/DebugInfo.h"
-#include "llvm/Function.h"
-#include "llvm/InlineAsm.h"
-#include "llvm/LLVMContext.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/IR/Value.h"
 #include "llvm/MC/MCInstrDesc.h"
 #include "llvm/MC/MCSymbol.h"
-#include "llvm/Metadata.h"
-#include "llvm/Module.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/LeakDetector.h"
@@ -39,8 +41,6 @@
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetRegisterInfo.h"
-#include "llvm/Type.h"
-#include "llvm/Value.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
@@ -568,7 +568,7 @@ MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
 MachineInstr::~MachineInstr() {
   LeakDetector::removeGarbageObject(this);
 #ifndef NDEBUG
-  for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
+  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
     assert(Operands[i].ParentMI == this && "ParentMI mismatch!");
     assert((!Operands[i].isReg() || !Operands[i].isOnRegUseList()) &&
            "Reg operand def/use list corrupted");
@@ -589,7 +589,7 @@ MachineRegisterInfo *MachineInstr::getRegInfo() {
 /// this instruction from their respective use lists.  This requires that the
 /// operands already be on their use lists.
 void MachineInstr::RemoveRegOperandsFromUseLists(MachineRegisterInfo &MRI) {
-  for (unsigned i = 0, e = Operands.size(); i != e; ++i)
+  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
     if (Operands[i].isReg())
       MRI.removeRegOperandFromUseList(&Operands[i]);
 }
@@ -598,16 +598,24 @@ void MachineInstr::RemoveRegOperandsFromUseLists(MachineRegisterInfo &MRI) {
 /// this instruction from their respective use lists.  This requires that the
 /// operands not be on their use lists yet.
 void MachineInstr::AddRegOperandsToUseLists(MachineRegisterInfo &MRI) {
-  for (unsigned i = 0, e = Operands.size(); i != e; ++i)
+  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
     if (Operands[i].isReg())
       MRI.addRegOperandToUseList(&Operands[i]);
 }
 
+void MachineInstr::addOperand(const MachineOperand &Op) {
+  MachineBasicBlock *MBB = getParent();
+  assert(MBB && "Use MachineInstrBuilder to add operands to dangling instrs");
+  MachineFunction *MF = MBB->getParent();
+  assert(MF && "Use MachineInstrBuilder to add operands to dangling instrs");
+  addOperand(*MF, Op);
+}
+
 /// addOperand - Add the specified operand to the instruction.  If it is an
 /// implicit operand, it is added to the end of the operand list.  If it is
 /// an explicit operand it is added at the end of the explicit operand list
 /// (before the first implicit operand).
-void MachineInstr::addOperand(const MachineOperand &Op) {
+void MachineInstr::addOperand(MachineFunction &MF, const MachineOperand &Op) {
   assert(MCID && "Cannot add operands before providing an instr descriptor");
   bool isImpReg = Op.isReg() && Op.isImplicit();
   MachineRegisterInfo *RegInfo = getRegInfo();
@@ -615,11 +623,11 @@ void MachineInstr::addOperand(const MachineOperand &Op) {
   // If the Operands backing store is reallocated, all register operands must
   // be removed and re-added to RegInfo.  It is storing pointers to operands.
   bool Reallocate = RegInfo &&
-    !Operands.empty() && Operands.size() == Operands.capacity();
+    !Operands.empty() && getNumOperands() == Operands.capacity();
 
   // Find the insert location for the new operand.  Implicit registers go at
   // the end, everything goes before the implicit regs.
-  unsigned OpNo = Operands.size();
+  unsigned OpNo = getNumOperands();
 
   // Remove all the implicit operands from RegInfo if they need to be shifted.
   // FIXME: Allow mixed explicit and implicit operands on inline asm.
@@ -688,7 +696,7 @@ void MachineInstr::addOperand(const MachineOperand &Op) {
 
   // Re-add all the implicit ops.
   if (RegInfo) {
-    for (unsigned i = OpNo + 1, e = Operands.size(); i != e; ++i) {
+    for (unsigned i = OpNo + 1, e = getNumOperands(); i != e; ++i) {
       assert(Operands[i].isReg() && "Should only be an implicit reg!");
       RegInfo->addRegOperandToUseList(&Operands[i]);
     }
@@ -699,25 +707,14 @@ void MachineInstr::addOperand(const MachineOperand &Op) {
 /// fewer operand than it started with.
 ///
 void MachineInstr::RemoveOperand(unsigned OpNo) {
-  assert(OpNo < Operands.size() && "Invalid operand number");
+  assert(OpNo < getNumOperands() && "Invalid operand number");
   untieRegOperand(OpNo);
   MachineRegisterInfo *RegInfo = getRegInfo();
 
-  // Special case removing the last one.
-  if (OpNo == Operands.size()-1) {
-    // If needed, remove from the reg def/use list.
-    if (RegInfo && Operands.back().isReg() && Operands.back().isOnRegUseList())
-      RegInfo->removeRegOperandFromUseList(&Operands.back());
-
-    Operands.pop_back();
-    return;
-  }
-
-  // Otherwise, we are removing an interior operand.  If we have reginfo to
-  // update, remove all operands that will be shifted down from their reg lists,
-  // move everything down, then re-add them.
+  // If we have reginfo to update, remove all operands that will be shifted
+  // down from their reg lists, move everything down, then re-add them.
   if (RegInfo) {
-    for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
+    for (unsigned i = OpNo, e = getNumOperands(); i != e; ++i) {
       if (Operands[i].isReg())
         RegInfo->removeRegOperandFromUseList(&Operands[i]);
     }
@@ -725,7 +722,7 @@ void MachineInstr::RemoveOperand(unsigned OpNo) {
 
 #ifndef NDEBUG
   // Moving tied operands would break the ties.
-  for (unsigned i = OpNo + 1, e = Operands.size(); i != e; ++i)
+  for (unsigned i = OpNo + 1, e = getNumOperands(); i != e; ++i)
     if (Operands[i].isReg())
       assert(!Operands[i].isTied() && "Cannot move tied operands");
 #endif
@@ -733,7 +730,7 @@ void MachineInstr::RemoveOperand(unsigned OpNo) {
   Operands.erase(Operands.begin()+OpNo);
 
   if (RegInfo) {
-    for (unsigned i = OpNo, e = Operands.size(); i != e; ++i) {
+    for (unsigned i = OpNo, e = getNumOperands(); i != e; ++i) {
       if (Operands[i].isReg())
         RegInfo->addRegOperandToUseList(&Operands[i]);
     }
@@ -1403,12 +1400,13 @@ bool MachineInstr::allDefsAreDead() const {
 
 /// copyImplicitOps - Copy implicit register operands from specified
 /// instruction to this instruction.
-void MachineInstr::copyImplicitOps(const MachineInstr *MI) {
+void MachineInstr::copyImplicitOps(MachineFunction &MF,
+                                   const MachineInstr *MI) {
   for (unsigned i = MI->getDesc().getNumOperands(), e = MI->getNumOperands();
        i != e; ++i) {
     const MachineOperand &MO = MI->getOperand(i);
     if (MO.isReg() && MO.isImplicit())
-      addOperand(MO);
+      addOperand(MF, MO);
   }
 }