radeon/llvm: Add SHADER_TYPE instruction
authorTom Stellard <thomas.stellard@amd.com>
Fri, 7 Sep 2012 13:11:59 +0000 (09:11 -0400)
committerTom Stellard <thomas.stellard@amd.com>
Tue, 11 Sep 2012 18:53:47 +0000 (14:53 -0400)
This allows the program to specify the type of shader being compiled
(e.g. PXEL, VERTEX, etc.)

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/radeon/AMDGPU.h
src/gallium/drivers/radeon/AMDGPUInstructions.td
src/gallium/drivers/radeon/AMDGPUIntrinsics.td
src/gallium/drivers/radeon/R600ISelLowering.cpp
src/gallium/drivers/radeon/SIAssignInterpRegs.cpp
src/gallium/drivers/radeon/SIISelLowering.cpp
src/gallium/drivers/radeon/SIMachineFunctionInfo.cpp
src/gallium/drivers/radeon/SIMachineFunctionInfo.h

index ab6871c1da49ce10d80fa8153438d8541880395a..fe36545a1650579e6134bbc86f52fb20f6498687 100644 (file)
@@ -33,4 +33,13 @@ FunctionPass *createAMDGPUConvertToISAPass(TargetMachine &tm);
 
 } // End namespace llvm
 
+namespace ShaderType {
+  enum Type {
+    PIXEL = 0,
+    VERTEX = 1,
+    GEOMETRY = 2,
+    COMPUTE = 3
+  };
+}
+
 #endif // AMDGPU_H
index c8a7db6c7726eb60055df1274a8e445ab10919ee..6f47445b07cd3aa1f2fd0f7897a654775334907a 100644 (file)
@@ -114,6 +114,13 @@ class FNEG <RegisterClass rc> : AMDGPUShaderInst <
   [(set rc:$dst, (fneg rc:$src0))]
 >;
 
+def SHADER_TYPE : AMDGPUShaderInst <
+  (outs),
+  (ins i32imm:$type),
+  "SHADER_TYPE $type",
+  [(int_AMDGPU_shader_type imm:$type)]
+>;
+
 } // End isCodeGenOnly = 1, isPseudo = 1, hasCustomInserter = 1
 
 /* Generic helper patterns for intrinsics */
index 89cc7e10d745bae2fab203ee53d84a0c7e14ce3e..958e0bd73f71a4a49cfbea936e994a1054d50593 100644 (file)
@@ -54,6 +54,8 @@ let TargetPrefix = "AMDGPU", isTarget = 1 in {
   def int_AMDGPU_umax : Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
   def int_AMDGPU_umin : Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
   def int_AMDGPU_cube : Intrinsic<[llvm_v4f32_ty], [llvm_v4f32_ty], [IntrNoMem]>;
+
+  def int_AMDGPU_shader_type : Intrinsic<[], [llvm_i32_ty], []>;
 }
 
 let TargetPrefix = "TGSI", isTarget = 1 in {
index 5642ee8fff3570646355ee1c8f5312cc05ed5d05..5a82920c3774d6709afbca04cd46930c775b1c27 100644 (file)
@@ -61,6 +61,7 @@ MachineBasicBlock * R600TargetLowering::EmitInstrWithCustomInserter(
 
   switch (MI->getOpcode()) {
   default: return AMDGPUTargetLowering::EmitInstrWithCustomInserter(MI, BB);
+  case AMDGPU::SHADER_TYPE: break;
   case AMDGPU::CLAMP_R600:
     {
       MachineInstr *NewMI =
index 3ee03ae74c557614a64f56c1beb6db1c54881149..447eff6f5acc003aecd21fdd66877db01e17467d 100644 (file)
@@ -87,6 +87,10 @@ bool SIAssignInterpRegsPass::runOnMachineFunction(MachineFunction &MF)
   };
 
   SIMachineFunctionInfo * MFI = MF.getInfo<SIMachineFunctionInfo>();
+  // This pass is only needed for pixel shaders.
+  if (MFI->ShaderType != ShaderType::PIXEL) {
+    return false;
+  }
   MachineRegisterInfo &MRI = MF.getRegInfo();
 
   /* First pass, mark the interpolation values that are used. */
index ebe9514a2b94843d510753f94d43c59967a810b4..42c2e7f7ceb6cb7ee26cbc86bcba172244e73903 100644 (file)
@@ -16,6 +16,7 @@
 #include "AMDIL.h"
 #include "AMDILIntrinsicInfo.h"
 #include "SIInstrInfo.h"
+#include "SIMachineFunctionInfo.h"
 #include "SIRegisterInfo.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
@@ -122,6 +123,11 @@ MachineBasicBlock * SITargetLowering::EmitInstrWithCustomInserter(
                  .addImm(1); // NEG
     MI->eraseFromParent();
     break;
+  case AMDGPU::SHADER_TYPE:
+    BB->getParent()->getInfo<SIMachineFunctionInfo>()->ShaderType =
+                                        MI->getOperand(0).getImm();
+    MI->eraseFromParent();
+    break;
 
   case AMDGPU::SI_INTERP:
     LowerSI_INTERP(MI, *BB, I, MRI);
index 40ba76f1f86d703bf1450572a78a911c5617a4e0..f1a8c1f6e1b8b125afcad888b953092cbba33a0b 100644 (file)
@@ -14,5 +14,6 @@ using namespace llvm;
 
 SIMachineFunctionInfo::SIMachineFunctionInfo(const MachineFunction &MF)
   : MachineFunctionInfo(),
-    spi_ps_input_addr(0)
+    spi_ps_input_addr(0),
+    ShaderType(0)
   { }
index 46a021f361303429cc2345d4a8c1c3034d60bb73..b60822e2e7a4fd87a06e41c5eb5e420f967b3d65 100644 (file)
@@ -28,6 +28,7 @@ class SIMachineFunctionInfo : public MachineFunctionInfo {
   public:
     SIMachineFunctionInfo(const MachineFunction &MF);
     unsigned spi_ps_input_addr;
+    unsigned ShaderType;
 
 };