AMDGPU/SI: Add getShaderType() function to Utils/
authorTom Stellard <thomas.stellard@amd.com>
Tue, 15 Dec 2015 16:26:16 +0000 (16:26 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Tue, 15 Dec 2015 16:26:16 +0000 (16:26 +0000)
Reviewers: arsenm

Subscribers: arsenm, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255650 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AMDGPU/AMDGPUMachineFunction.cpp
lib/Target/AMDGPU/SITypeRewriter.cpp
lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
lib/Target/AMDGPU/Utils/LLVMBuild.txt

index 7c595d5a83e43d612e4bb2c2236c0c9da77a8483..54137177e4c0a62272ac6588e751e6e4a1d4ed88 100644 (file)
@@ -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::AMDGPUMachineFunction(const MachineFunction &MF) :
   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());
 }
index 591ce857cc7d645be4e58c9e3c3020536f29936c..dbdc76b917f3a968c8db69698d46801564caf338 100644 (file)
@@ -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(Module &M) {
 }
 
 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);
index 441baed9b4342e9715ee52b288b65e2795bcc57b..a90e11feb49f8c8bae6dc825277c8ffa05f67746 100644 (file)
@@ -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 *GV) {
   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
index 7b3c858e7c3630dd4a032d91c6fba91575daa3ec..e4ed73cd0689c4e8a84fb98c1b11baef85a28fe7 100644 (file)
@@ -15,6 +15,7 @@
 namespace llvm {
 
 class FeatureBitset;
+class Function;
 class GlobalValue;
 class MCContext;
 class MCSection;
@@ -42,6 +43,8 @@ bool isGroupSegment(const GlobalValue *GV);
 bool isGlobalSegment(const GlobalValue *GV);
 bool isReadOnlySegment(const GlobalValue *GV);
 
+unsigned getShaderType(const Function &F);
+
 } // end namespace AMDGPU
 } // end namespace llvm
 
index f8d78165d9e36766338e6aa4d826dbc10c13bf07..2453bc546b99fc7284a817c68a3b1d88411e8bff 100644 (file)
@@ -19,5 +19,5 @@
 type = Library
 name = AMDGPUUtils
 parent = AMDGPU
-required_libraries = MC Support
+required_libraries = Core MC Support
 add_to_library_groups = AMDGPU