[llvm] r255650 - AMDGPU/SI: Add getShaderType() function to Utils/

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 08:26:19 PST 2015


Author: tstellar
Date: Tue Dec 15 10:26:16 2015
New Revision: 255650

URL: http://llvm.org/viewvc/llvm-project?rev=255650&view=rev
Log:
AMDGPU/SI: Add getShaderType() function to Utils/

Reviewers: arsenm

Subscribers: arsenm, llvm-commits

Differential Revision: http://reviews.llvm.org/D15424

Modified:
    llvm/trunk/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp
    llvm/trunk/lib/Target/AMDGPU/SITypeRewriter.cpp
    llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
    llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
    llvm/trunk/lib/Target/AMDGPU/Utils/LLVMBuild.txt

Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp?rev=255650&r1=255649&r2=255650&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp Tue Dec 15 10:26:16 2015
@@ -1,11 +1,10 @@
 #include "AMDGPUMachineFunction.h"
 #include "AMDGPU.h"
+#include "Utils/AMDGPUBaseInfo.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/Function.h"
 using namespace llvm;
 
-static const char *const ShaderTypeAttribute = "ShaderType";
-
 // Pin the vtable to this file.
 void AMDGPUMachineFunction::anchor() {}
 
@@ -16,11 +15,6 @@ AMDGPUMachineFunction::AMDGPUMachineFunc
   ABIArgOffset(0),
   ScratchSize(0),
   IsKernel(true) {
-  Attribute A = MF.getFunction()->getFnAttribute(ShaderTypeAttribute);
 
-  if (A.isStringAttribute()) {
-    StringRef Str = A.getValueAsString();
-    if (Str.getAsInteger(0, ShaderType))
-      llvm_unreachable("Can't parse shader type!");
-  }
+  ShaderType = AMDGPU::getShaderType(*MF.getFunction());
 }

Modified: llvm/trunk/lib/Target/AMDGPU/SITypeRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SITypeRewriter.cpp?rev=255650&r1=255649&r2=255650&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SITypeRewriter.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SITypeRewriter.cpp Tue Dec 15 10:26:16 2015
@@ -22,6 +22,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "AMDGPU.h"
+#include "Utils/AMDGPUBaseInfo.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InstVisitor.h"
 
@@ -61,14 +62,7 @@ bool SITypeRewriter::doInitialization(Mo
 }
 
 bool SITypeRewriter::runOnFunction(Function &F) {
-  Attribute A = F.getFnAttribute("ShaderType");
-
-  unsigned ShaderType = ShaderType::COMPUTE;
-  if (A.isStringAttribute()) {
-    StringRef Str = A.getValueAsString();
-    Str.getAsInteger(0, ShaderType);
-  }
-  if (ShaderType == ShaderType::COMPUTE)
+  if (AMDGPU::getShaderType(F) == ShaderType::COMPUTE)
     return false;
 
   visit(F);

Modified: llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp?rev=255650&r1=255649&r2=255650&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp Tue Dec 15 10:26:16 2015
@@ -8,6 +8,8 @@
 //===----------------------------------------------------------------------===//
 #include "AMDGPUBaseInfo.h"
 #include "AMDGPU.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCSectionELF.h"
@@ -99,5 +101,21 @@ bool isReadOnlySegment(const GlobalValue
   return GV->getType()->getAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS;
 }
 
+static const char ShaderTypeAttribute[] = "ShaderType";
+
+unsigned getShaderType(const Function &F) {
+  Attribute A = F.getFnAttribute(ShaderTypeAttribute);
+  unsigned ShaderType = ShaderType::COMPUTE;
+
+  if (A.isStringAttribute()) {
+    StringRef Str = A.getValueAsString();
+    if (Str.getAsInteger(0, ShaderType)) {
+      LLVMContext &Ctx = F.getContext();
+      Ctx.emitError("can't parse shader type");
+    }
+  }
+  return ShaderType;
+}
+
 } // End namespace AMDGPU
 } // End namespace llvm

Modified: llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h?rev=255650&r1=255649&r2=255650&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h (original)
+++ llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h Tue Dec 15 10:26:16 2015
@@ -15,6 +15,7 @@
 namespace llvm {
 
 class FeatureBitset;
+class Function;
 class GlobalValue;
 class MCContext;
 class MCSection;
@@ -42,6 +43,8 @@ bool isGroupSegment(const GlobalValue *G
 bool isGlobalSegment(const GlobalValue *GV);
 bool isReadOnlySegment(const GlobalValue *GV);
 
+unsigned getShaderType(const Function &F);
+
 } // end namespace AMDGPU
 } // end namespace llvm
 

Modified: llvm/trunk/lib/Target/AMDGPU/Utils/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/Utils/LLVMBuild.txt?rev=255650&r1=255649&r2=255650&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/Utils/LLVMBuild.txt (original)
+++ llvm/trunk/lib/Target/AMDGPU/Utils/LLVMBuild.txt Tue Dec 15 10:26:16 2015
@@ -19,5 +19,5 @@
 type = Library
 name = AMDGPUUtils
 parent = AMDGPU
-required_libraries = MC Support
+required_libraries = Core MC Support
 add_to_library_groups = AMDGPU




More information about the llvm-commits mailing list