[llvm-commits] CVS: llvm/lib/Target/X86/X86AsmPrinter.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Oct 14 21:45:04 PDT 2004



Changes in directory llvm/lib/Target/X86:

X86AsmPrinter.cpp updated: 1.124 -> 1.125
---
Log message:

Give the X86 asm printer the ability to print out addressing modes that have
constant displacements from global variables.  Patch by Jeff Cohen!


---
Diffs of the changes:  (+53 -25)

Index: llvm/lib/Target/X86/X86AsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86AsmPrinter.cpp:1.124 llvm/lib/Target/X86/X86AsmPrinter.cpp:1.125
--- llvm/lib/Target/X86/X86AsmPrinter.cpp:1.124	Mon Oct  4 02:31:08 2004
+++ llvm/lib/Target/X86/X86AsmPrinter.cpp	Thu Oct 14 23:44:53 2004
@@ -61,7 +61,8 @@
   if (MI->getOperand(Op).isConstantPoolIndex()) return true;
   return Op+4 <= MI->getNumOperands() &&
     MI->getOperand(Op  ).isRegister() && isScale(MI->getOperand(Op+1)) &&
-    MI->getOperand(Op+2).isRegister() && MI->getOperand(Op+3).isImmediate();
+    MI->getOperand(Op+2).isRegister() && (MI->getOperand(Op+3).isImmediate() ||
+        MI->getOperand(Op+3).isGlobalAddress());
 }
 
 // SwitchSection - Switch to the specified section of the executable if we are
@@ -289,11 +290,17 @@
     std::cerr << "Shouldn't use addPCDisp() when building X86 MachineInstrs";
     abort ();
     return;
-  case MachineOperand::MO_GlobalAddress:
+  case MachineOperand::MO_GlobalAddress: {
     if (!elideOffsetKeyword)
       O << "OFFSET ";
     O << Mang->getValueName(MO.getGlobal());
+    int Offset = MO.getOffset();
+    if (Offset > 0)
+      O << " + " << Offset;
+    else if (Offset < 0)
+      O << " - " << -Offset;
     return;
+  }
   case MachineOperand::MO_ExternalSymbol:
     O << MO.getSymbolName();
     return;
@@ -323,12 +330,12 @@
   const MachineOperand &BaseReg  = MI->getOperand(Op);
   int ScaleVal                   = MI->getOperand(Op+1).getImmedValue();
   const MachineOperand &IndexReg = MI->getOperand(Op+2);
-  int DispVal                    = MI->getOperand(Op+3).getImmedValue();
+  const MachineOperand &DispSpec = MI->getOperand(Op+3);
 
   O << "[";
   bool NeedPlus = false;
   if (BaseReg.getReg()) {
-    printOp(BaseReg);
+    printOp(BaseReg, true);
     NeedPlus = true;
   }
 
@@ -340,15 +347,22 @@
     NeedPlus = true;
   }
 
-  if (DispVal) {
+  if (DispSpec.isGlobalAddress()) {
     if (NeedPlus)
-      if (DispVal > 0)
-        O << " + ";
-      else {
-        O << " - ";
-        DispVal = -DispVal;
-      }
-    O << DispVal;
+      O << " + ";
+    printOp(DispSpec, true);
+  } else {
+    int DispVal = DispSpec.getImmedValue();
+    if (DispVal) {
+      if (NeedPlus)
+        if (DispVal > 0)
+          O << " + ";
+        else {
+          O << " - ";
+          DispVal = -DispVal;
+        }
+      O << DispVal;
+    }
   }
   O << "]";
 }
@@ -484,10 +498,16 @@
     std::cerr << "Shouldn't use addPCDisp() when building X86 MachineInstrs";
     abort ();
     return;
-  case MachineOperand::MO_GlobalAddress:
+  case MachineOperand::MO_GlobalAddress: {
     if (!isCallOp) O << '$';
     O << Mang->getValueName(MO.getGlobal());
+    int Offset = MO.getOffset();
+    if (Offset > 0)
+      O << "+" << Offset;
+    else if (Offset < 0)
+      O << Offset;
     return;
+  }
   case MachineOperand::MO_ExternalSymbol:
     if (!isCallOp) O << '$';
     O << MO.getSymbolName();
@@ -517,22 +537,30 @@
   const MachineOperand &BaseReg  = MI->getOperand(Op);
   int ScaleVal                   = MI->getOperand(Op+1).getImmedValue();
   const MachineOperand &IndexReg = MI->getOperand(Op+2);
-  int DispVal                    = MI->getOperand(Op+3).getImmedValue();
+  const MachineOperand &DispSpec = MI->getOperand(Op+3);
+
+  if (DispSpec.isGlobalAddress()) {
+    printOp(DispSpec, true);
+  } else {
+    int DispVal = DispSpec.getImmedValue();
+    if (DispVal)
+      O << DispVal;
+  }
 
-  if (DispVal) O << DispVal;
+  if (IndexReg.getReg() || BaseReg.getReg()) {
+    O << "(";
+    if (BaseReg.getReg())
+      printOp(BaseReg);
 
-  O << "(";
-  if (BaseReg.getReg())
-    printOp(BaseReg);
+    if (IndexReg.getReg()) {
+      O << ",";
+      printOp(IndexReg);
+      if (ScaleVal != 1)
+        O << "," << ScaleVal;
+    }
 
-  if (IndexReg.getReg()) {
-    O << ",";
-    printOp(IndexReg);
-    if (ScaleVal != 1)
-      O << "," << ScaleVal;
+    O << ")";
   }
-
-  O << ")";
 }
 
 






More information about the llvm-commits mailing list