[llvm-commits] [llvm] r70732 - in /llvm/trunk/lib/Target/MSP430: MSP430AsmPrinter.cpp MSP430ISelDAGToDAG.cpp

Anton Korobeynikov asl at math.spbu.ru
Sun May 3 06:09:10 PDT 2009


Author: asl
Date: Sun May  3 08:09:10 2009
New Revision: 70732

URL: http://llvm.org/viewvc/llvm-project?rev=70732&view=rev
Log:
Correct asmprinting of memory operands

Modified:
    llvm/trunk/lib/Target/MSP430/MSP430AsmPrinter.cpp
    llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp

Modified: llvm/trunk/lib/Target/MSP430/MSP430AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/MSP430AsmPrinter.cpp?rev=70732&r1=70731&r2=70732&view=diff

==============================================================================
--- llvm/trunk/lib/Target/MSP430/MSP430AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/MSP430AsmPrinter.cpp Sun May  3 08:09:10 2009
@@ -162,17 +162,23 @@
 void MSP430AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum,
                                           const char* Modifier) {
   const MachineOperand &Disp = MI->getOperand(OpNum);
-  assert(Disp.isImm() && "Displacement can be only immediate!");
+  const MachineOperand &Base = MI->getOperand(OpNum+1);
 
-  // Special case: 0(Reg) -> @Reg
-  if (Disp.getImm() == 0) {
-    O << "@";
-    printOperand(MI, OpNum + 1);
-  } else {
-    printOperand(MI, OpNum, "nohash");
-    O << '(';
-    printOperand(MI, OpNum + 1);
-    O << ')';
-  }
+  if (Disp.isGlobal())
+    printOperand(MI, OpNum, "mem");
+  else if (Disp.isImm() && !Base.getReg())
+    printOperand(MI, OpNum);
+  else if (Base.getReg()) {
+    if (Disp.getImm()) {
+      printOperand(MI, OpNum, "nohash");
+      O << '(';
+      printOperand(MI, OpNum + 1);
+      O << ')';
+    } else {
+      O << '@';
+      printOperand(MI, OpNum + 1);
+    }
+  } else
+    assert(0 && "Unsupported memory operand");
 }
 

Modified: llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp?rev=70732&r1=70731&r2=70732&view=diff

==============================================================================
--- llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp Sun May  3 08:09:10 2009
@@ -72,6 +72,7 @@
   return new MSP430DAGToDAGISel(TM);
 }
 
+// FIXME: This is pretty dummy routine and needs to be rewritten in the future.
 bool MSP430DAGToDAGISel::SelectAddr(SDValue Op, SDValue Addr,
                                     SDValue &Disp, SDValue &Base) {
   // We don't support frame index stuff yet.
@@ -99,20 +100,17 @@
   case MSP430ISD::Wrapper:
     SDValue N0 = Addr.getOperand(0);
     if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) {
-      // We can match addresses of globals without any offsets
-      if (!G->getOffset()) {
-        Base = CurDAG->getTargetGlobalAddress(G->getGlobal(),
-                                              MVT::i16, 0);
-        Disp = CurDAG->getTargetConstant(0, MVT::i16);
+      Base = CurDAG->getRegister(0, MVT::i16);
+      Disp = CurDAG->getTargetGlobalAddress(G->getGlobal(),
+                                            MVT::i16, G->getOffset());
 
-        return true;
-      }
+      return true;
     }
     break;
   };
 
-  Base = Addr;
-  Disp = CurDAG->getTargetConstant(0, MVT::i16);
+  Base = CurDAG->getRegister(0, MVT::i16);
+  Disp = Addr;
 
   return true;
 }





More information about the llvm-commits mailing list