[llvm-commits] CVS: llvm/lib/Target/X86/X86CodeEmitter.cpp X86FloatingPoint.cpp X86RegisterInfo.cpp

Evan Cheng evan.cheng at apple.com
Thu Nov 9 17:29:03 PST 2006



Changes in directory llvm/lib/Target/X86:

X86CodeEmitter.cpp updated: 1.121 -> 1.122
X86FloatingPoint.cpp updated: 1.55 -> 1.56
X86RegisterInfo.cpp updated: 1.173 -> 1.174
---
Log message:

Use TargetInstrInfo::getNumOperands() instead of MachineInstr::getNumOperands(). In preparation for implicit reg def/use changes.

---
Diffs of the changes:  (+50 -34)

 X86CodeEmitter.cpp   |   42 ++++++++++++++++++++++--------------------
 X86FloatingPoint.cpp |   22 ++++++++++++++++------
 X86RegisterInfo.cpp  |   20 ++++++++++++--------
 3 files changed, 50 insertions(+), 34 deletions(-)


Index: llvm/lib/Target/X86/X86CodeEmitter.cpp
diff -u llvm/lib/Target/X86/X86CodeEmitter.cpp:1.121 llvm/lib/Target/X86/X86CodeEmitter.cpp:1.122
--- llvm/lib/Target/X86/X86CodeEmitter.cpp:1.121	Wed Nov  8 20:22:54 2006
+++ llvm/lib/Target/X86/X86CodeEmitter.cpp	Thu Nov  9 19:28:43 2006
@@ -469,14 +469,15 @@
   if (Desc.TSFlags & X86II::REX_W)
     REX |= 1 << 3;
 
-  if (MI.getNumOperands()) {
-    bool isTwoAddr = II->getNumOperands(Opcode) > 1 &&
+  unsigned NumOps = II->getNumOperands(Opcode);
+  if (NumOps) {
+    bool isTwoAddr = NumOps > 1 &&
       II->getOperandConstraint(Opcode, 1, TargetInstrInfo::TIED_TO) != -1;
 
     // If it accesses SPL, BPL, SIL, or DIL, then it requires a 0x40 REX prefix.
     bool isTrunc8 = isX86_64TruncToByte(Opcode);
     unsigned i = isTwoAddr ? 1 : 0;
-    for (unsigned e = MI.getNumOperands(); i != e; ++i) {
+    for (unsigned e = NumOps; i != e; ++i) {
       const MachineOperand& MO = MI.getOperand(i);
       if (MO.isRegister()) {
 	unsigned Reg = MO.getReg();
@@ -498,7 +499,7 @@
       if (isX86_64ExtendedReg(MI.getOperand(0)))
         REX |= 1 << 2;
       i = isTwoAddr ? 2 : 1;
-      for (unsigned e = MI.getNumOperands(); i != e; ++i) {
+      for (unsigned e = NumOps; i != e; ++i) {
         const MachineOperand& MO = MI.getOperand(i);
         if (isX86_64ExtendedReg(MO))
           REX |= 1 << 0;
@@ -510,7 +511,7 @@
         REX |= 1 << 2;
       unsigned Bit = 0;
       i = isTwoAddr ? 2 : 1;
-      for (; i != MI.getNumOperands(); ++i) {
+      for (; i != NumOps; ++i) {
         const MachineOperand& MO = MI.getOperand(i);
         if (MO.isRegister()) {
           if (isX86_64ExtendedReg(MO))
@@ -527,7 +528,7 @@
     case X86II::MRMDestMem: {
       unsigned e = isTwoAddr ? 5 : 4;
       i = isTwoAddr ? 1 : 0;
-      if (MI.getNumOperands() > e && isX86_64ExtendedReg(MI.getOperand(e)))
+      if (NumOps > e && isX86_64ExtendedReg(MI.getOperand(e)))
         REX |= 1 << 2;
       unsigned Bit = 0;
       for (; i != e; ++i) {
@@ -544,7 +545,7 @@
       if (isX86_64ExtendedReg(MI.getOperand(0)))
         REX |= 1 << 0;
       i = isTwoAddr ? 2 : 1;
-      for (unsigned e = MI.getNumOperands(); i != e; ++i) {
+      for (unsigned e = NumOps; i != e; ++i) {
         const MachineOperand& MO = MI.getOperand(i);
         if (isX86_64ExtendedReg(MO))
           REX |= 1 << 2;
@@ -607,8 +608,9 @@
     MCE.emitByte(0x0F);
 
   // If this is a two-address instruction, skip one of the register operands.
+  unsigned NumOps = II->getNumOperands(Opcode);
   unsigned CurOp = 0;
-  if (II->getNumOperands(Opcode) > 1 &&
+  if (NumOps > 1 &&
       II->getOperandConstraint(Opcode, 1, TargetInstrInfo::TIED_TO) != -1)
     CurOp++;
   
@@ -637,12 +639,12 @@
       break;
     }
 #endif
-    CurOp = MI.getNumOperands();
+    CurOp = NumOps;
     break;
 
   case X86II::RawFrm:
     MCE.emitByte(BaseOpcode);
-    if (CurOp != MI.getNumOperands()) {
+    if (CurOp != NumOps) {
       const MachineOperand &MO = MI.getOperand(CurOp++);
       if (MO.isMachineBasicBlock()) {
         emitPCRelativeBlockAddress(MO.getMachineBasicBlock());
@@ -663,7 +665,7 @@
   case X86II::AddRegFrm:
     MCE.emitByte(BaseOpcode + getX86RegNum(MI.getOperand(CurOp++).getReg()));
     
-    if (CurOp != MI.getNumOperands()) {
+    if (CurOp != NumOps) {
       const MachineOperand &MO1 = MI.getOperand(CurOp++);
       if (MO1.isGlobalAddress()) {
         assert(sizeOfImm(Desc) == TD->getPointerSize() &&
@@ -688,7 +690,7 @@
     emitRegModRMByte(MI.getOperand(CurOp).getReg(),
                      getX86RegNum(MI.getOperand(CurOp+1).getReg()));
     CurOp += 2;
-    if (CurOp != MI.getNumOperands())
+    if (CurOp != NumOps)
       emitConstant(MI.getOperand(CurOp++).getImm(), sizeOfImm(Desc));
     break;
   }
@@ -696,7 +698,7 @@
     MCE.emitByte(BaseOpcode);
     emitMemModRMByte(MI, CurOp, getX86RegNum(MI.getOperand(CurOp+4).getReg()));
     CurOp += 5;
-    if (CurOp != MI.getNumOperands())
+    if (CurOp != NumOps)
       emitConstant(MI.getOperand(CurOp++).getImm(), sizeOfImm(Desc));
     break;
   }
@@ -706,18 +708,18 @@
     emitRegModRMByte(MI.getOperand(CurOp+1).getReg(),
                      getX86RegNum(MI.getOperand(CurOp).getReg()));
     CurOp += 2;
-    if (CurOp != MI.getNumOperands())
+    if (CurOp != NumOps)
       emitConstant(MI.getOperand(CurOp++).getImm(), sizeOfImm(Desc));
     break;
 
   case X86II::MRMSrcMem: {
-    unsigned PCAdj = (CurOp+5 != MI.getNumOperands()) ? sizeOfImm(Desc) : 0;
+    unsigned PCAdj = (CurOp+5 != NumOps) ? sizeOfImm(Desc) : 0;
 
     MCE.emitByte(BaseOpcode);
     emitMemModRMByte(MI, CurOp+1, getX86RegNum(MI.getOperand(CurOp).getReg()),
                      PCAdj);
     CurOp += 5;
-    if (CurOp != MI.getNumOperands())
+    if (CurOp != NumOps)
       emitConstant(MI.getOperand(CurOp++).getImm(), sizeOfImm(Desc));
     break;
   }
@@ -730,7 +732,7 @@
     emitRegModRMByte(MI.getOperand(CurOp++).getReg(),
                      (Desc.TSFlags & X86II::FormMask)-X86II::MRM0r);
 
-    if (CurOp != MI.getNumOperands() && MI.getOperand(CurOp).isImmediate())
+    if (CurOp != NumOps && MI.getOperand(CurOp).isImmediate())
       emitConstant(MI.getOperand(CurOp++).getImm(), sizeOfImm(Desc));
     break;
 
@@ -738,7 +740,7 @@
   case X86II::MRM2m: case X86II::MRM3m:
   case X86II::MRM4m: case X86II::MRM5m:
   case X86II::MRM6m: case X86II::MRM7m: {
-    unsigned PCAdj = (CurOp+4 != MI.getNumOperands()) ?
+    unsigned PCAdj = (CurOp+4 != NumOps) ?
       (MI.getOperand(CurOp+4).isImmediate() ? sizeOfImm(Desc) : 4) : 0;
 
     MCE.emitByte(BaseOpcode);
@@ -746,7 +748,7 @@
                      PCAdj);
     CurOp += 4;
 
-    if (CurOp != MI.getNumOperands()) {
+    if (CurOp != NumOps) {
       const MachineOperand &MO = MI.getOperand(CurOp++);
       if (MO.isImmediate())
         emitConstant(MO.getImm(), sizeOfImm(Desc));
@@ -770,5 +772,5 @@
   }
 
   assert((Desc.Flags & M_VARIABLE_OPS) != 0 ||
-         CurOp == MI.getNumOperands() && "Unknown encoding!");
+         CurOp == NumOps && "Unknown encoding!");
 }


Index: llvm/lib/Target/X86/X86FloatingPoint.cpp
diff -u llvm/lib/Target/X86/X86FloatingPoint.cpp:1.55 llvm/lib/Target/X86/X86FloatingPoint.cpp:1.56
--- llvm/lib/Target/X86/X86FloatingPoint.cpp:1.55	Thu Nov  2 14:25:49 2006
+++ llvm/lib/Target/X86/X86FloatingPoint.cpp	Thu Nov  9 19:28:43 2006
@@ -500,11 +500,14 @@
 ///
 void FPS::handleOneArgFP(MachineBasicBlock::iterator &I) {
   MachineInstr *MI = I;
-  assert((MI->getNumOperands() == 5 || MI->getNumOperands() == 1) &&
+  MachineFunction *MF = MI->getParent()->getParent();
+  const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();
+  unsigned NumOps = TII.getNumOperands(MI->getOpcode());
+  assert((NumOps == 5 || NumOps == 1) &&
          "Can only handle fst* & ftst instructions!");
 
   // Is this the last use of the source register?
-  unsigned Reg = getFPReg(MI->getOperand(MI->getNumOperands()-1));
+  unsigned Reg = getFPReg(MI->getOperand(NumOps-1));
   bool KillsSrc = LV->KillsRegister(MI, X86::FP0+Reg);
 
   // FISTP64m is strange because there isn't a non-popping versions.
@@ -524,7 +527,7 @@
   }
   
   // Convert from the pseudo instruction to the concrete instruction.
-  MI->RemoveOperand(MI->getNumOperands()-1);    // Remove explicit ST(0) operand
+  MI->RemoveOperand(NumOps-1);    // Remove explicit ST(0) operand
   MI->setOpcode(getConcreteOpcode(MI->getOpcode()));
 
   if (MI->getOpcode() == X86::FISTP64m ||
@@ -549,7 +552,10 @@
 ///
 void FPS::handleOneArgFPRW(MachineBasicBlock::iterator &I) {
   MachineInstr *MI = I;
-  assert(MI->getNumOperands() >= 2 && "FPRW instructions must have 2 ops!!");
+  MachineFunction *MF = MI->getParent()->getParent();
+  const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();
+  unsigned NumOps = TII.getNumOperands(MI->getOpcode());
+  assert(NumOps >= 2 && "FPRW instructions must have 2 ops!!");
 
   // Is this the last use of the source register?
   unsigned Reg = getFPReg(MI->getOperand(1));
@@ -625,7 +631,9 @@
   ASSERT_SORTED(ForwardSTiTable); ASSERT_SORTED(ReverseSTiTable);
   MachineInstr *MI = I;
 
-  unsigned NumOperands = MI->getNumOperands();
+  MachineFunction *MF = MI->getParent()->getParent();
+  const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();
+  unsigned NumOperands = TII.getNumOperands(MI->getOpcode());
   assert(NumOperands == 3 && "Illegal TwoArgFP instruction!");
   unsigned Dest = getFPReg(MI->getOperand(0));
   unsigned Op0 = getFPReg(MI->getOperand(NumOperands-2));
@@ -722,7 +730,9 @@
   ASSERT_SORTED(ForwardSTiTable); ASSERT_SORTED(ReverseSTiTable);
   MachineInstr *MI = I;
 
-  unsigned NumOperands = MI->getNumOperands();
+  MachineFunction *MF = MI->getParent()->getParent();
+  const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();
+  unsigned NumOperands = TII.getNumOperands(MI->getOpcode());
   assert(NumOperands == 2 && "Illegal FUCOM* instruction!");
   unsigned Op0 = getFPReg(MI->getOperand(NumOperands-2));
   unsigned Op1 = getFPReg(MI->getOperand(NumOperands-1));


Index: llvm/lib/Target/X86/X86RegisterInfo.cpp
diff -u llvm/lib/Target/X86/X86RegisterInfo.cpp:1.173 llvm/lib/Target/X86/X86RegisterInfo.cpp:1.174
--- llvm/lib/Target/X86/X86RegisterInfo.cpp:1.173	Wed Nov  8 20:22:54 2006
+++ llvm/lib/Target/X86/X86RegisterInfo.cpp	Thu Nov  9 19:28:43 2006
@@ -161,8 +161,9 @@
 }
 
 static MachineInstr *FuseTwoAddrInst(unsigned Opcode, unsigned FrameIndex,
-                                     MachineInstr *MI) {
-  unsigned NumOps = MI->getNumOperands()-2;
+                                     MachineInstr *MI,
+                                     const TargetInstrInfo &TII) {
+  unsigned NumOps = TII.getNumOperands(MI->getOpcode())-2;
   // Create the base instruction with the memory operand as the first part.
   MachineInstrBuilder MIB = addFrameReference(BuildMI(Opcode, 4+NumOps),
                                               FrameIndex);
@@ -185,7 +186,8 @@
 }
 
 static MachineInstr *FuseInst(unsigned Opcode, unsigned OpNo,
-                              unsigned FrameIndex, MachineInstr *MI) {
+                              unsigned FrameIndex, MachineInstr *MI,
+                              const TargetInstrInfo &TII) {
   MachineInstrBuilder MIB = BuildMI(Opcode, MI->getNumOperands()+3);
   
   for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
@@ -284,14 +286,16 @@
   const TableEntry *OpcodeTablePtr = NULL;
   unsigned OpcodeTableSize = 0;
   bool isTwoAddrFold = false;
-  bool isTwoAddr = TII.getNumOperands(MI->getOpcode()) > 1 &&
+  unsigned NumOps = TII.getNumOperands(MI->getOpcode());
+  bool isTwoAddr = NumOps > 1 &&
     TII.getOperandConstraint(MI->getOpcode(), 1,TargetInstrInfo::TIED_TO) != -1;
 
   // Folding a memory location into the two-address part of a two-address
   // instruction is different than folding it other places.  It requires
   // replacing the *two* registers with the memory location.
-  if (isTwoAddr && MI->getNumOperands() >= 2 && MI->getOperand(0).isReg() && 
-      MI->getOperand(1).isReg() && i < 2 &&
+  if (isTwoAddr && NumOps >= 2 && i < 2 &&
+      MI->getOperand(0).isReg() && 
+      MI->getOperand(1).isReg() &&
       MI->getOperand(0).getReg() == MI->getOperand(1).getReg()) {
     static const TableEntry OpcodeTable[] = {
       { X86::ADC32ri,     X86::ADC32mi },
@@ -823,9 +827,9 @@
     if (const TableEntry *Entry = TableLookup(OpcodeTablePtr, OpcodeTableSize,
                                               fromOpcode)) {
       if (isTwoAddrFold)
-        return FuseTwoAddrInst(Entry->to, FrameIndex, MI);
+        return FuseTwoAddrInst(Entry->to, FrameIndex, MI, TII);
       
-      return FuseInst(Entry->to, i, FrameIndex, MI);
+      return FuseInst(Entry->to, i, FrameIndex, MI, TII);
     }
   }
   






More information about the llvm-commits mailing list