Add code enough for emission of reg-reg and reg-imm moves. This allows us to compile...
authorAnton Korobeynikov <asl@math.spbu.ru>
Sun, 3 May 2009 13:02:04 +0000 (13:02 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Sun, 3 May 2009 13:02:04 +0000 (13:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70710 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/MSP430/MSP430AsmPrinter.cpp
lib/Target/MSP430/MSP430ISelLowering.cpp
lib/Target/MSP430/MSP430InstrInfo.cpp
lib/Target/MSP430/MSP430InstrInfo.h
lib/Target/MSP430/MSP430InstrInfo.td
lib/Target/MSP430/MSP430RegisterInfo.cpp
lib/Target/MSP430/MSP430RegisterInfo.td

index 6b0f5100c30d2a088bc1173837e2caf238e88c36..e8004a7d1b42c592bbf10711911247a7b24a6431 100644 (file)
@@ -47,6 +47,7 @@ namespace {
       return "MSP430 Assembly Printer";
     }
 
+    void printOperand(const MachineInstr *MI, int OpNum);
     bool printInstruction(const MachineInstr *MI);  // autogenerated.
     void printMachineInstruction(const MachineInstr * MI);
     bool runOnMachineFunction(MachineFunction &F);
@@ -108,7 +109,7 @@ bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   return false;
 }
 
-void MSP430AsmPrinter::printMachineInstruction(const MachineInstr * MI) {
+void MSP430AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   ++EmittedInsts;
 
   // Call the autogenerated instruction printer routines.
@@ -117,3 +118,23 @@ void MSP430AsmPrinter::printMachineInstruction(const MachineInstr * MI) {
 
   assert(0 && "Should not happen");
 }
+
+void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum) {
+  const MachineOperand &MO = MI->getOperand(OpNum);
+  switch (MO.getType()) {
+  case MachineOperand::MO_Register:
+    if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
+      O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
+    else
+      assert(0 && "not implemented");
+    break;
+  case MachineOperand::MO_Immediate:
+     O << "#" << MO.getImm();
+    break;
+  case MachineOperand::MO_MachineBasicBlock:
+    printBasicBlockLabel(MO.getMBB());
+    break;
+  default:
+    assert(0 && "Not implemented yet!");
+  }
+}
index 7577a53b8f2ba37a8c12f6eec3f12ae453efce49..c4b3993237a7827d4b5c06a948681dfd151e2608 100644 (file)
@@ -39,7 +39,7 @@ MSP430TargetLowering::MSP430TargetLowering(MSP430TargetMachine &tm) :
   TargetLowering(tm), Subtarget(*tm.getSubtargetImpl()), TM(tm) {
 
   // Set up the register classes.
-  addRegisterClass(MVT::i16, MSP430::MSP430RegsRegisterClass);
+  addRegisterClass(MVT::i16, MSP430::GR16RegisterClass);
 
   // Compute derived properties from the register classes
   computeRegisterProperties();
@@ -111,7 +111,7 @@ SDValue MSP430TargetLowering::LowerCCCArguments(SDValue Op,
         abort();
       case MVT::i16:
         unsigned VReg =
-          RegInfo.createVirtualRegister(MSP430::MSP430RegsRegisterClass);
+          RegInfo.createVirtualRegister(MSP430::GR16RegisterClass);
         RegInfo.addLiveIn(VA.getLocReg(), VReg);
         SDValue ArgValue = DAG.getCopyFromReg(Root, dl, VReg, RegVT);
 
index d644e63adeefa9ad40e928f56f8a23c5c8530211..c84c96e6569f6887159ecb5a42f9ddaa25550eca 100644 (file)
@@ -26,3 +26,40 @@ using namespace llvm;
 MSP430InstrInfo::MSP430InstrInfo(MSP430TargetMachine &tm)
   : TargetInstrInfoImpl(MSP430Insts, array_lengthof(MSP430Insts)),
     RI(*this), TM(tm) {}
+
+bool MSP430InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
+                                   MachineBasicBlock::iterator I,
+                                   unsigned DestReg, unsigned SrcReg,
+                                   const TargetRegisterClass *DestRC,
+                                   const TargetRegisterClass *SrcRC) const {
+  if (DestRC != SrcRC) {
+    // Not yet supported!
+    return false;
+  }
+
+  DebugLoc DL = DebugLoc::getUnknownLoc();
+  if (I != MBB.end()) DL = I->getDebugLoc();
+
+  BuildMI(MBB, I, DL, get(MSP430::MOV16rr), DestReg).addReg(SrcReg);
+  return true;
+}
+
+bool
+MSP430InstrInfo::isMoveInstr(const MachineInstr& MI,
+                             unsigned &SrcReg, unsigned &DstReg,
+                             unsigned &SrcSubIdx, unsigned &DstSubIdx) const {
+  SrcSubIdx = DstSubIdx = 0; // No sub-registers yet.
+
+  switch (MI.getOpcode()) {
+  default:
+    return false;
+  case MSP430::MOV16rr:
+    assert(MI.getNumOperands() >= 2 &&
+           MI.getOperand(0).isReg() &&
+           MI.getOperand(1).isReg() &&
+           "invalid register-register move instruction");
+    SrcReg = MI.getOperand(1).getReg();
+    DstReg = MI.getOperand(0).getReg();
+    return true;
+  }
+}
index ddca76209af737d65740e6af7bbcf20c9db523b1..0ed2944f4c2d6769f55550bc3a03e2b75e815c2f 100644 (file)
@@ -32,6 +32,15 @@ public:
   /// always be able to get register info as well (through this method).
   ///
   virtual const TargetRegisterInfo &getRegisterInfo() const { return RI; }
+
+  bool copyRegToReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
+                    unsigned DestReg, unsigned SrcReg,
+                    const TargetRegisterClass *DestRC,
+                    const TargetRegisterClass *SrcRC) const;
+
+  bool isMoveInstr(const MachineInstr& MI,
+                   unsigned &SrcReg, unsigned &DstReg,
+                   unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
 };
 
 }
index cd70fd3c13629aafefcf731071efc776f98988b3..308a8d0f87bc763d456bb0051441905ccfdc6873 100644 (file)
@@ -41,5 +41,22 @@ def NOP : Pseudo<(outs), (ins), "nop", []>;
 
 // FIXME: Provide proper encoding!
 let isReturn = 1, isTerminator = 1 in {
-  def RETI: Pseudo<(outs), (ins), "reti", [(retflag)]>;
+  def RETI : Pseudo<(outs), (ins), "reti", [(retflag)]>;
+}
+
+//===----------------------------------------------------------------------===//
+// Move Instructions
+
+// FIXME: Provide proper encoding!
+let neverHasSideEffects = 1 in {
+def MOV16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src),
+                     "mov.w\t{$src, $dst|$dst, $src}",
+                     []>;
+}
+
+// FIXME: Provide proper encoding!
+let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
+def MOV16ri : Pseudo<(outs GR16:$dst), (ins i16imm:$src),
+                     "mov.w\t{$src, $dst|$dst, $src}",
+                     [(set GR16:$dst, imm:$src)]>;
 }
index 42e98979a84a0d83152449d557813b835fb99599..ff6d531cfde84f1dae34f18d89a675c9fa103148 100644 (file)
@@ -42,10 +42,10 @@ MSP430RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
 const TargetRegisterClass* const*
 MSP430RegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const {
   static const TargetRegisterClass * const CalleeSavedRegClasses[] = {
-    &MSP430::MSP430RegsRegClass, &MSP430::MSP430RegsRegClass,
-    &MSP430::MSP430RegsRegClass, &MSP430::MSP430RegsRegClass,
-    &MSP430::MSP430RegsRegClass, &MSP430::MSP430RegsRegClass,
-    &MSP430::MSP430RegsRegClass, &MSP430::MSP430RegsRegClass,
+    &MSP430::GR16RegClass, &MSP430::GR16RegClass,
+    &MSP430::GR16RegClass, &MSP430::GR16RegClass,
+    &MSP430::GR16RegClass, &MSP430::GR16RegClass,
+    &MSP430::GR16RegClass, &MSP430::GR16RegClass,
     0
   };
 
index 27a9842cfa2cb4fd1e88cc91f834d862df88480e..fd7816162000df4fa389f95090f3f4d860ae70eb 100644 (file)
@@ -37,7 +37,9 @@ def R13 : MSP430Reg<13, "R13">;
 def R14 : MSP430Reg<14, "R14">;
 def R15 : MSP430Reg<15, "R15">;
 
-def MSP430Regs : RegisterClass<"MSP430", [i16], 16,
+// FIXME: we need subregs & special handling for 8 bit stuff
+
+def GR16 : RegisterClass<"MSP430", [i16], 16,
    // Volatile registers
   [R12, R13, R14, R15, R11, R10, R9, R8, R7, R6, R5,
    // Frame pointer, sometimes allocable
@@ -49,8 +51,8 @@ def MSP430Regs : RegisterClass<"MSP430", [i16], 16,
     iterator allocation_order_end(const MachineFunction &MF) const;
   }];
   let MethodBodies = [{
-    MSP430RegsClass::iterator
-    MSP430RegsClass::allocation_order_end(const MachineFunction &MF) const {
+    GR16Class::iterator
+    GR16Class::allocation_order_end(const MachineFunction &MF) const {
       const TargetMachine &TM = MF.getTarget();
       const TargetRegisterInfo *RI = TM.getRegisterInfo();
       // Depending on whether the function uses frame pointer or not, last 5 or 4