radeon/llvm: Use a custom inserter to lower STORE_OUTPUT
authorTom Stellard <thomas.stellard@amd.com>
Tue, 8 May 2012 14:27:30 +0000 (10:27 -0400)
committerTom Stellard <thomas.stellard@amd.com>
Tue, 8 May 2012 19:47:46 +0000 (15:47 -0400)
src/gallium/drivers/radeon/AMDGPUInstructions.td
src/gallium/drivers/radeon/R600ISelLowering.cpp
src/gallium/drivers/radeon/R600Instructions.td
src/gallium/drivers/radeon/R600LowerShaderInstructions.cpp

index d126c7902aa543072490a331d364db796b0fdfd9..abe90a4f12ffba6adb453b0071063dc0fa1e5019 100644 (file)
@@ -55,13 +55,6 @@ let isCodeGenOnly = 1 in {
     "RESERVE_REG $dst, $src",
     [(set GPRF32:$dst, (int_AMDGPU_reserve_reg imm:$src))]
   >;
-
-  def STORE_OUTPUT: AMDGPUShaderInst <
-    (outs GPRF32:$dst),
-    (ins GPRF32:$src0, i32imm:$src1),
-    "STORE_OUTPUT $dst, $src0, $src1",
-    [(set GPRF32:$dst, (int_AMDGPU_store_output GPRF32:$src0, imm:$src1))]
-  >;
 }
 
 /* Generic helper patterns for intrinsics */
index d35669e117412be3aab2fc659cfcbefc6add904b..9870b7ba82008713630ae3c9594d03bec7505590 100644 (file)
@@ -96,6 +96,22 @@ MachineBasicBlock * R600TargetLowering::EmitInstrWithCustomInserter(
       MI->eraseFromParent();
       break;
     }
+  case AMDIL::STORE_OUTPUT:
+    {
+      MachineBasicBlock::iterator I = *MI;
+      int64_t OutputIndex = MI->getOperand(2).getImm();
+      unsigned OutputReg = AMDIL::R600_TReg32RegClass.getRegister(OutputIndex);
+
+      BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDIL::COPY), OutputReg)
+                  .addOperand(MI->getOperand(1));
+
+      MRI.replaceRegWith(MI->getOperand(0).getReg(), OutputReg);
+      if (!MRI.isLiveOut(OutputReg)) {
+        MRI.addLiveOut(OutputReg);
+      }
+      MI->eraseFromParent();
+      break;
+    }
   }
   return BB;
 }
index b462a05ea24033638686c15955d6f78218cd2953..99e4b4fd0b89de461a13f664a4223b1e91a820d0 100644 (file)
@@ -998,6 +998,13 @@ def LOAD_INPUT : AMDGPUShaderInst <
   [(set R600_Reg32:$dst, (int_R600_load_input imm:$src))]
 >;
 
+def STORE_OUTPUT: AMDGPUShaderInst <
+  (outs R600_Reg32:$dst),
+  (ins R600_Reg32:$src0, i32imm:$src1),
+  "STORE_OUTPUT $dst, $src0, $src1",
+  [(set R600_Reg32:$dst, (int_AMDGPU_store_output R600_Reg32:$src0, imm:$src1))]
+>;
+
 } // End usesCustomInserter = 1, isPseudo = 1
 
 } // End isCodeGenOnly = 1
index 58b1f0824d70ec26a605affa115d8db854b2cf07..f3dd65b47e76ec887e5ceb3ec481bfb36425b808 100644 (file)
@@ -31,8 +31,6 @@ namespace {
 
     void lowerEXPORT_REG_FAKE(MachineInstr &MI, MachineBasicBlock &MBB,
         MachineBasicBlock::iterator I);
-    bool lowerSTORE_OUTPUT(MachineInstr & MI, MachineBasicBlock &MBB,
-        MachineBasicBlock::iterator I);
 
   public:
     R600LowerShaderInstructionsPass(TargetMachine &tm) :
@@ -79,10 +77,6 @@ bool R600LowerShaderInstructionsPass::runOnMachineFunction(MachineFunction &MF)
         deleteInstr = true;
         break;
 
-      case AMDIL::STORE_OUTPUT:
-        deleteInstr = lowerSTORE_OUTPUT(MI, MBB, I);
-        break;
-
       }
 
       ++I;
@@ -95,24 +89,3 @@ bool R600LowerShaderInstructionsPass::runOnMachineFunction(MachineFunction &MF)
 
   return false;
 }
-
-bool R600LowerShaderInstructionsPass::lowerSTORE_OUTPUT(MachineInstr &MI,
-    MachineBasicBlock &MBB, MachineBasicBlock::iterator I)
-{
-  MachineOperand &valueOp = MI.getOperand(1);
-  MachineOperand &indexOp = MI.getOperand(2);
-  unsigned valueReg = valueOp.getReg();
-  int64_t outputIndex = indexOp.getImm();
-  const TargetRegisterClass * outputClass = TM.getRegisterInfo()->getRegClass(AMDIL::R600_TReg32RegClassID);
-  unsigned newRegister = outputClass->getRegister(outputIndex);
-
-  BuildMI(MBB, I, MBB.findDebugLoc(I), TM.getInstrInfo()->get(AMDIL::COPY),
-                  newRegister)
-                  .addReg(valueReg);
-
-  if (!MRI->isLiveOut(newRegister))
-    MRI->addLiveOut(newRegister);
-
-  return true;
-
-}