Add MachineOperand::setDef() and MachineOperand::setUse() so that the
[oota-llvm.git] / include / llvm / CodeGen / MachineInstr.h
index faa213bf26b5af48156c2e8ca8050203709f1f91..8f223b37bf109da9b7c3f4734f5beba6bba8a9ca 100644 (file)
@@ -1,7 +1,14 @@
-//===-- llvm/CodeGen/MachineInstr.h - MachineInstr class ---------*- C++ -*--=//
+//===-- llvm/CodeGen/MachineInstr.h - MachineInstr class --------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file contains the declaration of the MachineInstr class, which is the
-// basic representation for all target dependant machine instructions used by
+// basic representation for all target dependent machine instructions used by
 // the back end.
 //
 //===----------------------------------------------------------------------===//
@@ -12,7 +19,8 @@
 #include "llvm/Target/MRegisterInfo.h"
 #include "Support/Annotation.h"
 #include "Support/iterator"
-#include <set>
+
+namespace llvm {
 
 class Value;
 class Function;
@@ -101,15 +109,13 @@ struct MachineOperand {
 private:
   // Bit fields of the flags variable used for different operand properties
   enum {
-    DEFONLYFLAG = 0x01,       // this is a def but not a use of the operand
-    DEFUSEFLAG  = 0x02,       // this is both a def and a use
+    DEFFLAG     = 0x01,       // this is a def of the operand
+    USEFLAG     = 0x02,       // this is a use of the operand
     HIFLAG32    = 0x04,       // operand is %hi32(value_or_immedVal)
     LOFLAG32    = 0x08,       // operand is %lo32(value_or_immedVal)
     HIFLAG64    = 0x10,       // operand is %hi64(value_or_immedVal)
     LOFLAG64    = 0x20,       // operand is %lo64(value_or_immedVal)
     PCRELATIVE  = 0x40,       // Operand is relative to PC, not a global address
-  
-    USEDEFMASK = 0x03,
   };
 
 private:
@@ -149,9 +155,9 @@ private:
       opType(OpTy),
       regNum(Reg) {
     switch (UseTy) {
-    case MOTy::Use:       flags = 0; break;
-    case MOTy::Def:       flags = DEFONLYFLAG; break;
-    case MOTy::UseAndDef: flags = DEFUSEFLAG; break;
+    case MOTy::Use:       flags = USEFLAG; break;
+    case MOTy::Def:       flags = DEFFLAG; break;
+    case MOTy::UseAndDef: flags = DEFFLAG | USEFLAG; break;
     default: assert(0 && "Invalid value for UseTy!");
     }
   }
@@ -160,9 +166,9 @@ private:
                 bool isPCRelative = false)
     : value(V), opType(OpTy), regNum(-1) {
     switch (UseTy) {
-    case MOTy::Use:       flags = 0; break;
-    case MOTy::Def:       flags = DEFONLYFLAG; break;
-    case MOTy::UseAndDef: flags = DEFUSEFLAG; break;
+    case MOTy::Use:       flags = USEFLAG; break;
+    case MOTy::Def:       flags = DEFFLAG; break;
+    case MOTy::UseAndDef: flags = DEFFLAG | USEFLAG; break;
     default: assert(0 && "Invalid value for UseTy!");
     }
     if (isPCRelative) flags |= PCRELATIVE;
@@ -253,6 +259,8 @@ public:
     return regNum;
   }
   int64_t getImmedValue() const { assert(isImmediate()); return immedVal; }
+  void setImmedValue(int64_t ImmVal) { assert(isImmediate()); immedVal=ImmVal; }
+
   MachineBasicBlock *getMachineBasicBlock() const {
     assert(isMachineBasicBlock() && "Can't get MBB in non-MBB operand!");
     return MBB;
@@ -273,13 +281,15 @@ public:
     return *SymbolName;
   }
 
-  bool          opIsUse         () const { return (flags & USEDEFMASK) == 0; }
-  bool         opIsDefOnly     () const { return flags & DEFONLYFLAG; }
-  bool         opIsDefAndUse   () const { return flags & DEFUSEFLAG; }
-  bool          opHiBits32      () const { return flags & HIFLAG32; }
-  bool          opLoBits32      () const { return flags & LOFLAG32; }
-  bool          opHiBits64      () const { return flags & HIFLAG64; }
-  bool          opLoBits64      () const { return flags & LOFLAG64; }
+  bool          isUse           () const { return flags & USEFLAG; }
+  bool         isDef           () const { return flags & DEFFLAG; }
+  bool          isHiBits32      () const { return flags & HIFLAG32; }
+  bool          isLoBits32      () const { return flags & LOFLAG32; }
+  bool          isHiBits64      () const { return flags & HIFLAG64; }
+  bool          isLoBits64      () const { return flags & LOFLAG64; }
+
+  MachineOperand& setUse      () { flags |= USEFLAG; return *this; }
+  MachineOperand& setDef      () { flags |= DEFFLAG; return *this; }
 
   // used to check if a machine register has been allocated to this operand
   bool hasAllocatedReg() const {
@@ -298,6 +308,10 @@ public:
   unsigned getReg() const {
     return getAllocatedRegNum();
   }    
+  void setReg(unsigned Reg) {
+    assert(hasAllocatedReg() && "This operand cannot have a register number!");
+    regNum = Reg;
+  }    
 
   friend std::ostream& operator<<(std::ostream& os, const MachineOperand& mop);
 
@@ -346,10 +360,6 @@ class MachineInstr {
   std::vector<MachineOperand> operands; // the operands
   unsigned numImplicitRefs;             // number of implicit operands
 
-  // regsUsed - all machine registers used for this instruction, including regs
-  // used to save values across the instruction.  This is a bitset of registers.
-  std::set<int>    regsUsed;
-
   // OperandComplete - Return true if it's illegal to add a new operand
   bool OperandsComplete() const;
 
@@ -438,17 +448,6 @@ public:
                          MachineOperand::MO_VirtualRegister, V);
   }
 
-  //
-  // Information about registers used in this instruction.
-  // 
-  const std::set<int> &getRegsUsed() const {
-    return regsUsed;
-  }
-  void insertUsedReg(unsigned Reg) {
-    assert(((int) Reg) >= 0 && "Invalid register being marked as used");
-    regsUsed.insert((int) Reg);
-  }
-
   //
   // Debugging support
   //
@@ -682,9 +681,8 @@ public:
 
     inline VTy operator->() const { return operator*(); }
 
-    inline bool isUseOnly()   const { return MI->getOperand(i).opIsUse(); } 
-    inline bool isDefOnly()   const { return MI->getOperand(i).opIsDefOnly(); } 
-    inline bool isDefAndUse() const { return MI->getOperand(i).opIsDefAndUse();}
+    inline bool isUse()   const { return MI->getOperand(i).isUse(); } 
+    inline bool isDef()   const { return MI->getOperand(i).isDef(); } 
 
     inline _Self& operator++() { i++; skipToNextVal(); return *this; }
     inline _Self  operator++(int) { _Self tmp = *this; ++*this; return tmp; }
@@ -724,4 +722,6 @@ std::ostream& operator<<(std::ostream &OS, const MachineInstr &MI);
 std::ostream& operator<<(std::ostream &OS, const MachineOperand &MO);
 void PrintMachineInstructions(const Function *F);
 
+} // End llvm namespace
+
 #endif