Simple copyConstantToReg support, SETHIi and ORri
authorBrian Gaeke <gaeke@uiuc.edu>
Thu, 4 Mar 2004 00:56:25 +0000 (00:56 +0000)
committerBrian Gaeke <gaeke@uiuc.edu>
Thu, 4 Mar 2004 00:56:25 +0000 (00:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12107 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Sparc/InstSelectSimple.cpp
lib/Target/Sparc/SparcInstrInfo.td
lib/Target/Sparc/SparcV8ISelSimple.cpp
lib/Target/SparcV8/InstSelectSimple.cpp
lib/Target/SparcV8/SparcV8ISelSimple.cpp
lib/Target/SparcV8/SparcV8InstrInfo.td

index 63d3dcc4904a451de8cbb791db0374878e190667..95ff31ec75be3475d42312ff10a873cb8198b7d7 100644 (file)
@@ -167,11 +167,27 @@ void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB,
                                     Constant *C, unsigned R) {
   if (C->getType()->isIntegral()) {
     unsigned Class = getClass(C->getType());
-
     ConstantInt *CI = cast<ConstantInt>(C);
-    // cByte: or %g0, <imm>, <dest>
-    // cShort or cInt: sethi, then or
-    // BuildMI(*MBB, IP, <opcode>, <#regs>, R).addImm(CI->getRawValue());
+    switch (Class) {
+      case cByte:
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addImm ((uint8_t) CI->getRawValue ());
+        return;
+      case cShort: {
+        unsigned TmpReg = makeAnotherReg (C->getType ());
+        BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addImm (((uint16_t) CI->getRawValue ()) >> 10);
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg).addImm (((uint16_t) CI->getRawValue ()) & 0x03ff);
+        return;
+      }
+      case cInt: {
+        unsigned TmpReg = makeAnotherReg (C->getType ());
+        BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addImm (((uint32_t) CI->getRawValue ()) >> 10);
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg).addImm (((uint32_t) CI->getRawValue ()) & 0x03ff);
+        return;
+      }
+      default:
+        assert (0 && "Can't move this kind of constant");
+        return;
+    }
   }
 
   assert (0 && "Can't copy constants into registers yet");
index 96e2dd197567a0f88582169df58cd91bcd41634b..7a544047d423e1289e065fba10cfa1f98b738c7b 100644 (file)
@@ -62,9 +62,13 @@ def CALL : InstV8 {
   let Name = "call";
 }
 
+// Section B.9 - SETHI Instruction, p. 102
+def SETHIi: F2_1<0b100, "sethi">;
+
 // Section B.11 - Logical Instructions, p. 106
 def ANDri : F3_2<2, 0b000001, "and">;
 def ORrr  : F3_1<2, 0b000010, "or">;
+def ORri  : F3_2<2, 0b000010, "or">;
 
 // Section B.12 - Shift Instructions, p. 107
 def SLLri : F3_1<2, 0b100101, "sll">;
index 63d3dcc4904a451de8cbb791db0374878e190667..95ff31ec75be3475d42312ff10a873cb8198b7d7 100644 (file)
@@ -167,11 +167,27 @@ void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB,
                                     Constant *C, unsigned R) {
   if (C->getType()->isIntegral()) {
     unsigned Class = getClass(C->getType());
-
     ConstantInt *CI = cast<ConstantInt>(C);
-    // cByte: or %g0, <imm>, <dest>
-    // cShort or cInt: sethi, then or
-    // BuildMI(*MBB, IP, <opcode>, <#regs>, R).addImm(CI->getRawValue());
+    switch (Class) {
+      case cByte:
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addImm ((uint8_t) CI->getRawValue ());
+        return;
+      case cShort: {
+        unsigned TmpReg = makeAnotherReg (C->getType ());
+        BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addImm (((uint16_t) CI->getRawValue ()) >> 10);
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg).addImm (((uint16_t) CI->getRawValue ()) & 0x03ff);
+        return;
+      }
+      case cInt: {
+        unsigned TmpReg = makeAnotherReg (C->getType ());
+        BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addImm (((uint32_t) CI->getRawValue ()) >> 10);
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg).addImm (((uint32_t) CI->getRawValue ()) & 0x03ff);
+        return;
+      }
+      default:
+        assert (0 && "Can't move this kind of constant");
+        return;
+    }
   }
 
   assert (0 && "Can't copy constants into registers yet");
index 63d3dcc4904a451de8cbb791db0374878e190667..95ff31ec75be3475d42312ff10a873cb8198b7d7 100644 (file)
@@ -167,11 +167,27 @@ void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB,
                                     Constant *C, unsigned R) {
   if (C->getType()->isIntegral()) {
     unsigned Class = getClass(C->getType());
-
     ConstantInt *CI = cast<ConstantInt>(C);
-    // cByte: or %g0, <imm>, <dest>
-    // cShort or cInt: sethi, then or
-    // BuildMI(*MBB, IP, <opcode>, <#regs>, R).addImm(CI->getRawValue());
+    switch (Class) {
+      case cByte:
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addImm ((uint8_t) CI->getRawValue ());
+        return;
+      case cShort: {
+        unsigned TmpReg = makeAnotherReg (C->getType ());
+        BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addImm (((uint16_t) CI->getRawValue ()) >> 10);
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg).addImm (((uint16_t) CI->getRawValue ()) & 0x03ff);
+        return;
+      }
+      case cInt: {
+        unsigned TmpReg = makeAnotherReg (C->getType ());
+        BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addImm (((uint32_t) CI->getRawValue ()) >> 10);
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg).addImm (((uint32_t) CI->getRawValue ()) & 0x03ff);
+        return;
+      }
+      default:
+        assert (0 && "Can't move this kind of constant");
+        return;
+    }
   }
 
   assert (0 && "Can't copy constants into registers yet");
index 63d3dcc4904a451de8cbb791db0374878e190667..95ff31ec75be3475d42312ff10a873cb8198b7d7 100644 (file)
@@ -167,11 +167,27 @@ void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB,
                                     Constant *C, unsigned R) {
   if (C->getType()->isIntegral()) {
     unsigned Class = getClass(C->getType());
-
     ConstantInt *CI = cast<ConstantInt>(C);
-    // cByte: or %g0, <imm>, <dest>
-    // cShort or cInt: sethi, then or
-    // BuildMI(*MBB, IP, <opcode>, <#regs>, R).addImm(CI->getRawValue());
+    switch (Class) {
+      case cByte:
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addImm ((uint8_t) CI->getRawValue ());
+        return;
+      case cShort: {
+        unsigned TmpReg = makeAnotherReg (C->getType ());
+        BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addImm (((uint16_t) CI->getRawValue ()) >> 10);
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg).addImm (((uint16_t) CI->getRawValue ()) & 0x03ff);
+        return;
+      }
+      case cInt: {
+        unsigned TmpReg = makeAnotherReg (C->getType ());
+        BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addImm (((uint32_t) CI->getRawValue ()) >> 10);
+        BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg).addImm (((uint32_t) CI->getRawValue ()) & 0x03ff);
+        return;
+      }
+      default:
+        assert (0 && "Can't move this kind of constant");
+        return;
+    }
   }
 
   assert (0 && "Can't copy constants into registers yet");
index 96e2dd197567a0f88582169df58cd91bcd41634b..7a544047d423e1289e065fba10cfa1f98b738c7b 100644 (file)
@@ -62,9 +62,13 @@ def CALL : InstV8 {
   let Name = "call";
 }
 
+// Section B.9 - SETHI Instruction, p. 102
+def SETHIi: F2_1<0b100, "sethi">;
+
 // Section B.11 - Logical Instructions, p. 106
 def ANDri : F3_2<2, 0b000001, "and">;
 def ORrr  : F3_1<2, 0b000010, "or">;
+def ORri  : F3_2<2, 0b000010, "or">;
 
 // Section B.12 - Shift Instructions, p. 107
 def SLLri : F3_1<2, 0b100101, "sll">;