[llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineInstrBuilder.h MachineInstr.h

Alkis Evlogimenos alkis at cs.uiuc.edu
Sun Feb 22 13:27:26 PST 2004


Changes in directory llvm/include/llvm/CodeGen:

MachineInstrBuilder.h updated: 1.17 -> 1.18
MachineInstr.h updated: 1.139 -> 1.140

---
Log message:

Move MOTy::UseType enum into MachineOperand. This eliminates the
switch statements in the constructors and simplifies the
implementation of the getUseType() member function. You will have to
specify defs using MachineOperand::Def instead of MOTy::Def though
(similarly for Use and UseAndDef).


---
Diffs of the changes:  (+89 -91)

Index: llvm/include/llvm/CodeGen/MachineInstrBuilder.h
diff -u llvm/include/llvm/CodeGen/MachineInstrBuilder.h:1.17 llvm/include/llvm/CodeGen/MachineInstrBuilder.h:1.18
--- llvm/include/llvm/CodeGen/MachineInstrBuilder.h:1.17	Wed Feb  4 16:17:40 2004
+++ llvm/include/llvm/CodeGen/MachineInstrBuilder.h	Sun Feb 22 13:23:26 2004
@@ -38,33 +38,36 @@
 
   /// addReg - Add a new virtual register operand...
   ///
-  const MachineInstrBuilder &addReg(int RegNo,
-                                    MOTy::UseType Ty = MOTy::Use) const {
+  const MachineInstrBuilder &addReg(
+    int RegNo,
+    MachineOperand::UseType Ty = MachineOperand::Use) const {
     MI->addRegOperand(RegNo, Ty);
     return *this;
   }
 
   /// addReg - Add an LLVM value that is to be used as a register...
   ///
-  const MachineInstrBuilder &addReg(Value *V,
-                                    MOTy::UseType Ty = MOTy::Use) const {
+  const MachineInstrBuilder &addReg(
+    Value *V,
+    MachineOperand::UseType Ty = MachineOperand::Use) const {
     MI->addRegOperand(V, Ty);
     return *this;
   }
 
   /// addReg - Add an LLVM value that is to be used as a register...
   ///
-  const MachineInstrBuilder &addCCReg(Value *V,
-                                      MOTy::UseType Ty = MOTy::Use) const {
+  const MachineInstrBuilder &addCCReg(
+    Value *V,
+    MachineOperand::UseType Ty = MachineOperand::Use) const {
     MI->addCCRegOperand(V, Ty);
     return *this;
   }
 
   /// addRegDef - Add an LLVM value that is to be defined as a register... this
-  /// is the same as addReg(V, MOTy::Def).
+  /// is the same as addReg(V, MachineOperand::Def).
   ///
   const MachineInstrBuilder &addRegDef(Value *V) const {
-    return addReg(V, MOTy::Def);
+    return addReg(V, MachineOperand::Def);
   }
 
   /// addPCDisp - Add an LLVM value to be treated as a PC relative
@@ -77,8 +80,9 @@
 
   /// addMReg - Add a machine register operand...
   ///
-  const MachineInstrBuilder &addMReg(int Reg,
-                                     MOTy::UseType Ty = MOTy::Use) const {
+  const MachineInstrBuilder &addMReg(
+    int Reg,
+    MachineOperand::UseType Ty = MachineOperand::Use) const {
     MI->addMachineRegOperand(Reg, Ty);
     return *this;
   }
@@ -137,9 +141,10 @@
 /// destination virtual register.  NumOperands is the number of additional add*
 /// calls that are expected, it does not include the destination register.
 ///
-inline MachineInstrBuilder BuildMI(int Opcode, unsigned NumOperands,
-                                   unsigned DestReg,
-                                   MOTy::UseType useType = MOTy::Def) {
+inline MachineInstrBuilder BuildMI(
+  int Opcode, unsigned NumOperands,
+  unsigned DestReg,
+  MachineOperand::UseType useType = MachineOperand::Def) {
   return MachineInstrBuilder(new MachineInstr(Opcode, NumOperands+1,
                                    true, true)).addReg(DestReg, useType);
 }
@@ -160,9 +165,9 @@
 ///
 inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, int Opcode,
                                    unsigned NumOperands, unsigned DestReg) {
-  return MachineInstrBuilder(new MachineInstr(BB, Opcode,
-                                              NumOperands+1)).addReg(DestReg,
-                                                                     MOTy::Def);
+  return MachineInstrBuilder(
+    new MachineInstr(BB, Opcode, NumOperands+1))
+      .addReg(DestReg, MachineOperand::Def);
 }
 
 } // End llvm namespace


Index: llvm/include/llvm/CodeGen/MachineInstr.h
diff -u llvm/include/llvm/CodeGen/MachineInstr.h:1.139 llvm/include/llvm/CodeGen/MachineInstr.h:1.140
--- llvm/include/llvm/CodeGen/MachineInstr.h:1.139	Sun Feb 22 01:24:19 2004
+++ llvm/include/llvm/CodeGen/MachineInstr.h	Sun Feb 22 13:23:26 2004
@@ -34,21 +34,6 @@
 typedef short MachineOpCode;
 
 //===----------------------------------------------------------------------===//
-/// MOTy - MachineOperandType - This namespace contains an enum that describes
-/// how the machine operand is used by the instruction: is it read, defined, or
-/// both?  Note that the MachineInstr/Operator class currently uses bool
-/// arguments to represent this information instead of an enum.  Eventually this
-/// should change over to use this _easier to read_ representation instead.
-///
-namespace MOTy {
-  enum UseType {
-    Use,             /// This machine operand is only read by the instruction
-    Def,             /// This machine operand is only written by the instruction
-    UseAndDef        /// This machine operand is read AND written
-  };
-}
-
-//===----------------------------------------------------------------------===//
 // class MachineOperand 
 // 
 // Purpose:
@@ -84,6 +69,31 @@
 //===----------------------------------------------------------------------===//
 
 struct MachineOperand {
+private:
+  // Bit fields of the flags variable used for different operand properties
+  enum {
+    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
+  };
+
+public:
+  // UseType - This enum describes how the machine operand is used by
+  // the instruction. Note that the MachineInstr/Operator class
+  // currently uses bool arguments to represent this information
+  // instead of an enum.  Eventually this should change over to use
+  // this _easier to read_ representation instead.
+  //
+  enum UseType {
+    Use = USEFLAG,        /// only read
+    Def = DEFFLAG,        /// only written
+    UseAndDef = Use | Def /// read AND written
+  };
+
   enum MachineOperandType {
     MO_VirtualRegister,		// virtual register for *value
     MO_MachineRegister,		// pre-assigned machine register `regNum'
@@ -99,18 +109,6 @@
   };
   
 private:
-  // Bit fields of the flags variable used for different operand properties
-  enum {
-    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
-  };
-
-private:
   union {
     Value*	value;		// BasicBlockVal for a label operand.
 				// ConstantVal for a non-address immediate.
@@ -136,32 +134,19 @@
       opType(OpTy),
       regNum(-1) {}
 
-  MachineOperand(int Reg, MachineOperandType OpTy, MOTy::UseType UseTy)
-    : immedVal(0),
-      opType(OpTy),
-      regNum(Reg) {
-    switch (UseTy) {
-    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!");
-    }
-  }
+  MachineOperand(int Reg, MachineOperandType OpTy, UseType UseTy)
+    : immedVal(0), flags(UseTy), opType(OpTy), regNum(Reg) { }
 
-  MachineOperand(Value *V, MachineOperandType OpTy, MOTy::UseType UseTy,
+  MachineOperand(Value *V, MachineOperandType OpTy, UseType UseTy,
 		 bool isPCRelative = false)
-    : value(V), opType(OpTy), regNum(-1) {
-    switch (UseTy) {
-    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;
+    : value(V),
+      flags(UseTy | (isPCRelative ? PCRELATIVE : 0)),
+      opType(OpTy),
+      regNum(-1) {
   }
 
   MachineOperand(MachineBasicBlock *mbb)
-    : MBB(mbb), flags(0), opType(MO_MachineBasicBlock), regNum(-1) {}
+    : MBB(mbb), flags(0), opType(MO_MachineBasicBlock), regNum(-1) { }
 
   MachineOperand(const std::string &SymName, bool isPCRelative)
     : SymbolName(new std::string(SymName)), flags(isPCRelative ? PCRELATIVE :0),
@@ -199,9 +184,8 @@
 
   /// getUseType - Returns the MachineOperandUseType of this operand.
   ///
-  MOTy::UseType getUseType() const {
-      return isUse() & isDef() ? MOTy::UseAndDef :
-          (isUse() ? MOTy::Use : MOTy::Def);
+  UseType getUseType() const {
+      return UseType(flags & (USEFLAG|DEFFLAG));
   }
 
   /// isPCRelative - This returns the value of the PCRELATIVE flag, which
@@ -461,19 +445,24 @@
   void addRegOperand(Value *V, bool isDef, bool isDefAndUse=false) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand(V, MachineOperand::MO_VirtualRegister,
-             !isDef ? MOTy::Use : (isDefAndUse ? MOTy::UseAndDef : MOTy::Def)));
+    operands.push_back(
+      MachineOperand(V, MachineOperand::MO_VirtualRegister,
+                     !isDef ? MachineOperand::Use :
+                     (isDefAndUse ? MachineOperand::UseAndDef :
+                      MachineOperand::Def)));
   }
 
-  void addRegOperand(Value *V, MOTy::UseType UTy = MOTy::Use,
-		     bool isPCRelative = false) {
+  void addRegOperand(Value *V,
+                     MachineOperand::UseType UTy = MachineOperand::Use,
+                     bool isPCRelative = false) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
     operands.push_back(MachineOperand(V, MachineOperand::MO_VirtualRegister,
                                       UTy, isPCRelative));
   }
 
-  void addCCRegOperand(Value *V, MOTy::UseType UTy = MOTy::Use) {
+  void addCCRegOperand(Value *V,
+                       MachineOperand::UseType UTy = MachineOperand::Use) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
     operands.push_back(MachineOperand(V, MachineOperand::MO_CCRegister, UTy,
@@ -486,17 +475,19 @@
   void addRegOperand(int reg, bool isDef) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand(reg, MachineOperand::MO_VirtualRegister,
-                                      isDef ? MOTy::Def : MOTy::Use));
+    operands.push_back(
+      MachineOperand(reg, MachineOperand::MO_VirtualRegister,
+                     isDef ? MachineOperand::Def : MachineOperand::Use));
   }
 
   /// addRegOperand - Add a symbolic virtual register reference...
   ///
-  void addRegOperand(int reg, MOTy::UseType UTy = MOTy::Use) {
+  void addRegOperand(int reg,
+                     MachineOperand::UseType UTy = MachineOperand::Use) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand(reg, MachineOperand::MO_VirtualRegister,
-                                      UTy));
+    operands.push_back(
+      MachineOperand(reg, MachineOperand::MO_VirtualRegister, UTy));
   }
 
   /// addPCDispOperand - Add a PC relative displacement operand to the MI
@@ -504,8 +495,8 @@
   void addPCDispOperand(Value *V) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand(V, MachineOperand::MO_PCRelativeDisp,
-                                      MOTy::Use));
+    operands.push_back(
+      MachineOperand(V, MachineOperand::MO_PCRelativeDisp,MachineOperand::Use));
   }
 
   /// addMachineRegOperand - Add a virtual register operand to this MachineInstr
@@ -513,17 +504,19 @@
   void addMachineRegOperand(int reg, bool isDef) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand(reg, MachineOperand::MO_MachineRegister,
-                                      isDef ? MOTy::Def : MOTy::Use));
+    operands.push_back(
+      MachineOperand(reg, MachineOperand::MO_MachineRegister,
+                     isDef ? MachineOperand::Def : MachineOperand::Use));
   }
 
   /// addMachineRegOperand - Add a virtual register operand to this MachineInstr
   ///
-  void addMachineRegOperand(int reg, MOTy::UseType UTy = MOTy::Use) {
+  void addMachineRegOperand(int reg,
+                            MachineOperand::UseType UTy = MachineOperand::Use) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand(reg, MachineOperand::MO_MachineRegister,
-                                      UTy));
+    operands.push_back(
+      MachineOperand(reg, MachineOperand::MO_MachineRegister, UTy));
   }
 
   /// addZeroExtImmOperand - Add a zero extended constant argument to the
@@ -532,8 +525,8 @@
   void addZeroExtImmOperand(int64_t intValue) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand(intValue,
-                                      MachineOperand::MO_UnextendedImmed));
+    operands.push_back(
+      MachineOperand(intValue, MachineOperand::MO_UnextendedImmed));
   }
 
   /// addSignExtImmOperand - Add a zero extended constant argument to the
@@ -542,8 +535,8 @@
   void addSignExtImmOperand(int64_t intValue) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand(intValue,
-                                      MachineOperand::MO_SignExtendedImmed));
+    operands.push_back(
+      MachineOperand(intValue, MachineOperand::MO_SignExtendedImmed));
   }
 
   void addMachineBasicBlockOperand(MachineBasicBlock *MBB) {
@@ -572,9 +565,9 @@
   void addGlobalAddressOperand(GlobalValue *GV, bool isPCRelative) {
     assert(!OperandsComplete() &&
            "Trying to add an operand to a machine instr that is already done!");
-    operands.push_back(MachineOperand((Value*)GV,
-				      MachineOperand::MO_GlobalAddress,
-                                      MOTy::Use, isPCRelative));
+    operands.push_back(
+      MachineOperand((Value*)GV, MachineOperand::MO_GlobalAddress,
+                     MachineOperand::Use, isPCRelative));
   }
 
   /// addExternalSymbolOperand - Add an external symbol operand to this instr





More information about the llvm-commits mailing list