radeon/llvm: Use a custom inserter to lower RESERVE_REG
authorTom Stellard <thomas.stellard@amd.com>
Tue, 8 May 2012 15:33:05 +0000 (11:33 -0400)
committerTom Stellard <thomas.stellard@amd.com>
Tue, 8 May 2012 19:47:46 +0000 (15:47 -0400)
src/gallium/drivers/r600/r600_llvm.c
src/gallium/drivers/radeon/AMDGPUInstructions.td
src/gallium/drivers/radeon/AMDGPUIntrinsics.td
src/gallium/drivers/radeon/Makefile.sources
src/gallium/drivers/radeon/R600ISelLowering.cpp
src/gallium/drivers/radeon/R600Instructions.td
src/gallium/drivers/radeon/R600LowerShaderInstructions.cpp
src/gallium/drivers/radeon/R600MachineFunctionInfo.cpp [new file with mode: 0644]
src/gallium/drivers/radeon/R600MachineFunctionInfo.h [new file with mode: 0644]
src/gallium/drivers/radeon/R600RegisterInfo.cpp

index 2f8300958839515e53f9b3b4d77878cc3628ab89..b01cb7a161d8af5abfae539c0a5dfdeb32ba24bc 100644 (file)
@@ -93,17 +93,13 @@ static void llvm_emit_prologue(struct lp_build_tgsi_context * bld_base)
        for (i = 0; i < ctx->reserved_reg_count; i++) {
                unsigned chan;
                for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
-                       LLVMValueRef reg;
                        LLVMValueRef reg_index = lp_build_const_int32(
                                        base->gallivm,
                                        radeon_llvm_reg_index_soa(i, chan));
-                       reg = lp_build_intrinsic_unary(base->gallivm->builder,
-                                               "llvm.AMDGPU.reserve.reg",
-                                               base->elem_type, reg_index);
                        lp_build_intrinsic_unary(base->gallivm->builder,
-                               "llvm.AMDGPU.export.reg",
+                               "llvm.AMDGPU.reserve.reg",
                                LLVMVoidTypeInContext(base->gallivm->context),
-                               reg);
+                               reg_index);
                }
        }
 }
index abe90a4f12ffba6adb453b0071063dc0fa1e5019..a5ac9cdd409c1183014ee1623280b8a8ab283a13 100644 (file)
@@ -48,13 +48,6 @@ let isCodeGenOnly = 1 in {
     "MASK_WRITE $src",
     []
   >;
-
-  def RESERVE_REG : AMDGPUShaderInst <
-    (outs GPRF32:$dst),
-    (ins i32imm:$src),
-    "RESERVE_REG $dst, $src",
-    [(set GPRF32:$dst, (int_AMDGPU_reserve_reg imm:$src))]
-  >;
 }
 
 /* Generic helper patterns for intrinsics */
index 089d3b66f610c7efac6ed98654445c7019fada29..09bddb58e17caeb1667b1e49ead04e883a46c065 100644 (file)
@@ -16,7 +16,7 @@ let TargetPrefix = "AMDGPU", isTarget = 1 in {
   def int_AMDGPU_export_reg : Intrinsic<[], [llvm_float_ty], []>;
   def int_AMDGPU_load_const : Intrinsic<[llvm_float_ty], [llvm_i32_ty], []>;
   def int_AMDGPU_load_imm : Intrinsic<[llvm_v4f32_ty], [llvm_i32_ty], []>;
-  def int_AMDGPU_reserve_reg : Intrinsic<[llvm_float_ty], [llvm_i32_ty], []>;
+  def int_AMDGPU_reserve_reg : Intrinsic<[], [llvm_i32_ty], []>;
   def int_AMDGPU_store_output : Intrinsic<[llvm_float_ty], [llvm_float_ty, llvm_i32_ty], []>;
   def int_AMDGPU_swizzle : Intrinsic<[llvm_v4f32_ty], [llvm_v4f32_ty, llvm_i32_ty], []>;
 
index 43aa1e119b3d866abf07564705e7dca716c87778..a1fafbbb68514d7ddaf75713cea84ac88bf1db62 100644 (file)
@@ -51,6 +51,7 @@ CPP_SOURCES := \
        R600KernelParameters.cpp        \
        R600LowerInstructions.cpp       \
        R600LowerShaderInstructions.cpp \
+       R600MachineFunctionInfo.cpp     \
        R600RegisterInfo.cpp            \
        SIAssignInterpRegs.cpp          \
        SICodeEmitter.cpp               \
index 9870b7ba82008713630ae3c9594d03bec7505590..7e1c17dfcaf2e0e0e2dcafaa544bbd1ad2144470 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "R600ISelLowering.h"
 #include "R600InstrInfo.h"
+#include "R600MachineFunctionInfo.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 
 using namespace llvm;
@@ -112,7 +113,19 @@ MachineBasicBlock * R600TargetLowering::EmitInstrWithCustomInserter(
       MI->eraseFromParent();
       break;
     }
+
+  case AMDIL::RESERVE_REG:
+    {
+      R600MachineFunctionInfo * MFI = MF->getInfo<R600MachineFunctionInfo>();
+      int64_t ReservedIndex = MI->getOperand(0).getImm();
+      unsigned ReservedReg =
+                          AMDIL::R600_TReg32RegClass.getRegister(ReservedIndex);
+      MFI->ReservedRegs.push_back(ReservedReg);
+      MI->eraseFromParent();
+      break;
+    }
   }
+
   return BB;
 }
 
index 99e4b4fd0b89de461a13f664a4223b1e91a820d0..a9d04db9ad9d031f2f35d60befee8081c80be76d 100644 (file)
@@ -998,6 +998,13 @@ def LOAD_INPUT : AMDGPUShaderInst <
   [(set R600_Reg32:$dst, (int_R600_load_input imm:$src))]
 >;
 
+def RESERVE_REG : AMDGPUShaderInst <
+  (outs),
+  (ins i32imm:$src),
+  "RESERVE_REG $src",
+  [(int_AMDGPU_reserve_reg imm:$src)]
+>;
+
 def STORE_OUTPUT: AMDGPUShaderInst <
   (outs R600_Reg32:$dst),
   (ins R600_Reg32:$src0, i32imm:$src1),
index f3dd65b47e76ec887e5ceb3ec481bfb36425b808..edbc6f7a4e66188cfa484eb77198482cd08a3659 100644 (file)
@@ -72,7 +72,6 @@ bool R600LowerShaderInstructionsPass::runOnMachineFunction(MachineFunction &MF)
 
       default: break;
 
-      case AMDIL::RESERVE_REG:
       case AMDIL::EXPORT_REG:
         deleteInstr = true;
         break;
diff --git a/src/gallium/drivers/radeon/R600MachineFunctionInfo.cpp b/src/gallium/drivers/radeon/R600MachineFunctionInfo.cpp
new file mode 100644 (file)
index 0000000..c88623b
--- /dev/null
@@ -0,0 +1,20 @@
+//===-- R600MachineFunctionInfo.cpp - TODO: Add brief description -------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// TODO: Add full description
+//
+//===----------------------------------------------------------------------===//
+
+#include "R600MachineFunctionInfo.h"
+
+using namespace llvm;
+
+R600MachineFunctionInfo::R600MachineFunctionInfo(const MachineFunction &MF)
+  : MachineFunctionInfo()
+  { }
diff --git a/src/gallium/drivers/radeon/R600MachineFunctionInfo.h b/src/gallium/drivers/radeon/R600MachineFunctionInfo.h
new file mode 100644 (file)
index 0000000..e7a4261
--- /dev/null
@@ -0,0 +1,32 @@
+//===-- R600MachineFunctionInfo.h - TODO: Add brief description ---*- C++ -*-=//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// TODO: Add full description
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef R600MACHINEFUNCTIONINFO_H
+#define R600MACHINEFUNCTIONINFO_H
+
+#include "llvm/CodeGen/MachineFunction.h"
+#include <vector>
+
+namespace llvm {
+
+class R600MachineFunctionInfo : public MachineFunctionInfo {
+
+public:
+  R600MachineFunctionInfo(const MachineFunction &MF);
+  std::vector<unsigned> ReservedRegs;
+
+};
+
+} // End llvm namespace
+
+#endif //R600MACHINEFUNCTIONINFO_H
index 96507b104cf494189a6c3a4eef68ec388bba2ead..29a7c7cfd46301f6ac3371dafe893207be371826 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "R600RegisterInfo.h"
 #include "AMDGPUTargetMachine.h"
+#include "R600MachineFunctionInfo.h"
 
 using namespace llvm;
 
@@ -26,6 +27,8 @@ R600RegisterInfo::R600RegisterInfo(AMDGPUTargetMachine &tm,
 BitVector R600RegisterInfo::getReservedRegs(const MachineFunction &MF) const
 {
   BitVector Reserved(getNumRegs());
+  const R600MachineFunctionInfo * MFI = MF.getInfo<R600MachineFunctionInfo>();
+
   Reserved.set(AMDIL::ZERO);
   Reserved.set(AMDIL::HALF);
   Reserved.set(AMDIL::ONE);
@@ -40,19 +43,11 @@ BitVector R600RegisterInfo::getReservedRegs(const MachineFunction &MF) const
     Reserved.set(*I);
   }
 
-  for (MachineFunction::const_iterator BB = MF.begin(),
-                                 BB_E = MF.end(); BB != BB_E; ++BB) {
-    const MachineBasicBlock &MBB = *BB;
-    for (MachineBasicBlock::const_iterator I = MBB.begin(), E = MBB.end();
-                                                                  I != E; ++I) {
-      const MachineInstr &MI = *I;
-      if (MI.getOpcode() == AMDIL::RESERVE_REG) {
-        if (!TargetRegisterInfo::isVirtualRegister(MI.getOperand(0).getReg())) {
-          Reserved.set(MI.getOperand(0).getReg());
-        }
-      }
-    }
+  for (std::vector<unsigned>::const_iterator I = MFI->ReservedRegs.begin(),
+                                    E = MFI->ReservedRegs.end(); I != E; ++I) {
+    Reserved.set(*I);
   }
+
   return Reserved;
 }