Add basic addressing mode support and one load.
authorChris Lattner <sabre@nondot.org>
Sat, 17 Dec 2005 20:04:49 +0000 (20:04 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Dec 2005 20:04:49 +0000 (20:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24782 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Sparc/SparcAsmPrinter.cpp
lib/Target/Sparc/SparcISelDAGToDAG.cpp
lib/Target/Sparc/SparcInstrInfo.td
lib/Target/SparcV8/SparcV8AsmPrinter.cpp
lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp
lib/Target/SparcV8/SparcV8InstrInfo.td

index 1d0cbac38411dca161a4821b05ceb2eec9c06f46..592588bdbe221f54445a9d0d1792b41dcb7792bc 100644 (file)
@@ -54,6 +54,7 @@ namespace {
     }
 
     void printOperand(const MachineInstr *MI, int opNum);
+    void printMemOperand(const MachineInstr *MI, int opNum);
     bool printInstruction(const MachineInstr *MI);  // autogenerated.
     bool runOnMachineFunction(MachineFunction &F);
     bool doInitialization(Module &M);
@@ -182,6 +183,13 @@ void SparcV8AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
   if (CloseParen) O << ")";
 }
 
+void SparcV8AsmPrinter::printMemOperand(const MachineInstr *MI, int opNum) {
+  printOperand(MI, opNum);
+  O << "+";
+  printOperand(MI, opNum+1);
+}
+
+
 bool SparcV8AsmPrinter::doInitialization(Module &M) {
   Mang = new Mangler(M);
   return false; // success
index 15a28f22ab8bb5c4b77a3998f316732782dd9c09..21943a902d7a3785d9da1ae749f05aada97f09de 100644 (file)
@@ -187,6 +187,10 @@ public:
 
   SDOperand Select(SDOperand Op);
 
+  // Complex Pattern Selectors.
+  bool SelectADDRrr(SDOperand N, SDOperand &R1, SDOperand &R2);
+  bool SelectADDRri(SDOperand N, SDOperand &Base, SDOperand &Offset);
+  
   /// InstructionSelectBasicBlock - This callback is invoked by
   /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
   virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
@@ -214,6 +218,22 @@ void SparcV8DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
   ScheduleAndEmitDAG(DAG);
 }
 
+bool SparcV8DAGToDAGISel::SelectADDRrr(SDOperand N, SDOperand &R1, 
+                                       SDOperand &R2) {
+  // FIXME: This should obviously be smarter.
+  R1 = Select(N);
+  R2 = CurDAG->getRegister(V8::G0, MVT::i32);
+  return true;
+}
+
+bool SparcV8DAGToDAGISel::SelectADDRri(SDOperand N, SDOperand &Base,
+                                       SDOperand &Offset) {
+  // FIXME: This should obviously be smarter.
+  Base = Select(N);
+  Offset = CurDAG->getTargetConstant(0, MVT::i32);
+  return true;
+}
+
 
 SDOperand SparcV8DAGToDAGISel::Select(SDOperand Op) {
   SDNode *N = Op.Val;
index dee37544ef5278df43422965180b140a86614101..583513d66576cc4530d513533e4c252da15dfa97 100644 (file)
@@ -52,6 +52,22 @@ def SETHIimm : PatLeaf<(imm), [{
   return (((unsigned)N->getValue() >> 10) << 10) == (unsigned)N->getValue();
 }], HI22>;
 
+// Addressing modes.
+def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", []>;
+def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", []>;
+
+// Address operands
+def MEMrr : Operand<i32> {
+  let PrintMethod = "printMemOperand";
+  let NumMIOperands = 2;
+  let MIOperandInfo = (ops IntRegs, IntRegs);
+}
+def MEMri : Operand<i32> {
+  let PrintMethod = "printMemOperand";
+  let NumMIOperands = 2;
+  let MIOperandInfo = (ops IntRegs, i32imm);
+}
+
 //===----------------------------------------------------------------------===//
 // Instructions
 //===----------------------------------------------------------------------===//
@@ -104,8 +120,9 @@ def LDUH: F3_2<3, 0b000010,
                (ops IntRegs:$dst, IntRegs:$b, i32imm:$c),
                "lduh [$b+$c], $dst", []>;
 def LD  : F3_2<3, 0b000000,
-               (ops IntRegs:$dst, IntRegs:$b, i32imm:$c),
-               "ld [$b+$c], $dst", []>;
+               (ops IntRegs:$dst, MEMri:$addr),
+               "ld [$addr], $dst",
+               [(set IntRegs:$dst, (load ADDRri:$addr))]>;
 def LDD : F3_2<3, 0b000011,
                (ops IntRegs:$dst, IntRegs:$b, i32imm:$c),
                "ldd [$b+$c], $dst", []>;
@@ -586,4 +603,4 @@ def : Pat<(i32 simm13:$val),
           (ORri G0, imm:$val)>;
 // Arbitrary immediates.
 def : Pat<(i32 imm:$val),
-          (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
\ No newline at end of file
+          (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
index 1d0cbac38411dca161a4821b05ceb2eec9c06f46..592588bdbe221f54445a9d0d1792b41dcb7792bc 100644 (file)
@@ -54,6 +54,7 @@ namespace {
     }
 
     void printOperand(const MachineInstr *MI, int opNum);
+    void printMemOperand(const MachineInstr *MI, int opNum);
     bool printInstruction(const MachineInstr *MI);  // autogenerated.
     bool runOnMachineFunction(MachineFunction &F);
     bool doInitialization(Module &M);
@@ -182,6 +183,13 @@ void SparcV8AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
   if (CloseParen) O << ")";
 }
 
+void SparcV8AsmPrinter::printMemOperand(const MachineInstr *MI, int opNum) {
+  printOperand(MI, opNum);
+  O << "+";
+  printOperand(MI, opNum+1);
+}
+
+
 bool SparcV8AsmPrinter::doInitialization(Module &M) {
   Mang = new Mangler(M);
   return false; // success
index 15a28f22ab8bb5c4b77a3998f316732782dd9c09..21943a902d7a3785d9da1ae749f05aada97f09de 100644 (file)
@@ -187,6 +187,10 @@ public:
 
   SDOperand Select(SDOperand Op);
 
+  // Complex Pattern Selectors.
+  bool SelectADDRrr(SDOperand N, SDOperand &R1, SDOperand &R2);
+  bool SelectADDRri(SDOperand N, SDOperand &Base, SDOperand &Offset);
+  
   /// InstructionSelectBasicBlock - This callback is invoked by
   /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
   virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
@@ -214,6 +218,22 @@ void SparcV8DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
   ScheduleAndEmitDAG(DAG);
 }
 
+bool SparcV8DAGToDAGISel::SelectADDRrr(SDOperand N, SDOperand &R1, 
+                                       SDOperand &R2) {
+  // FIXME: This should obviously be smarter.
+  R1 = Select(N);
+  R2 = CurDAG->getRegister(V8::G0, MVT::i32);
+  return true;
+}
+
+bool SparcV8DAGToDAGISel::SelectADDRri(SDOperand N, SDOperand &Base,
+                                       SDOperand &Offset) {
+  // FIXME: This should obviously be smarter.
+  Base = Select(N);
+  Offset = CurDAG->getTargetConstant(0, MVT::i32);
+  return true;
+}
+
 
 SDOperand SparcV8DAGToDAGISel::Select(SDOperand Op) {
   SDNode *N = Op.Val;
index dee37544ef5278df43422965180b140a86614101..583513d66576cc4530d513533e4c252da15dfa97 100644 (file)
@@ -52,6 +52,22 @@ def SETHIimm : PatLeaf<(imm), [{
   return (((unsigned)N->getValue() >> 10) << 10) == (unsigned)N->getValue();
 }], HI22>;
 
+// Addressing modes.
+def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", []>;
+def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", []>;
+
+// Address operands
+def MEMrr : Operand<i32> {
+  let PrintMethod = "printMemOperand";
+  let NumMIOperands = 2;
+  let MIOperandInfo = (ops IntRegs, IntRegs);
+}
+def MEMri : Operand<i32> {
+  let PrintMethod = "printMemOperand";
+  let NumMIOperands = 2;
+  let MIOperandInfo = (ops IntRegs, i32imm);
+}
+
 //===----------------------------------------------------------------------===//
 // Instructions
 //===----------------------------------------------------------------------===//
@@ -104,8 +120,9 @@ def LDUH: F3_2<3, 0b000010,
                (ops IntRegs:$dst, IntRegs:$b, i32imm:$c),
                "lduh [$b+$c], $dst", []>;
 def LD  : F3_2<3, 0b000000,
-               (ops IntRegs:$dst, IntRegs:$b, i32imm:$c),
-               "ld [$b+$c], $dst", []>;
+               (ops IntRegs:$dst, MEMri:$addr),
+               "ld [$addr], $dst",
+               [(set IntRegs:$dst, (load ADDRri:$addr))]>;
 def LDD : F3_2<3, 0b000011,
                (ops IntRegs:$dst, IntRegs:$b, i32imm:$c),
                "ldd [$b+$c], $dst", []>;
@@ -586,4 +603,4 @@ def : Pat<(i32 simm13:$val),
           (ORri G0, imm:$val)>;
 // Arbitrary immediates.
 def : Pat<(i32 imm:$val),
-          (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
\ No newline at end of file
+          (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;