From 83cae3be106f9b2089e20ee4a7dd2b187672df17 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 15 Dec 2015 16:26:16 +0000 Subject: [PATCH] AMDGPU/SI: Add getShaderType() function to Utils/ 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 | 10 ++-------- lib/Target/AMDGPU/SITypeRewriter.cpp | 10 ++-------- lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp | 18 ++++++++++++++++++ lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 3 +++ lib/Target/AMDGPU/Utils/LLVMBuild.txt | 2 +- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp b/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp index 7c595d5a83e..54137177e4c 100644 --- a/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp +++ b/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp @@ -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()); } diff --git a/lib/Target/AMDGPU/SITypeRewriter.cpp b/lib/Target/AMDGPU/SITypeRewriter.cpp index 591ce857cc7..dbdc76b917f 100644 --- a/lib/Target/AMDGPU/SITypeRewriter.cpp +++ b/lib/Target/AMDGPU/SITypeRewriter.cpp @@ -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); diff --git a/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp index 441baed9b43..a90e11feb49 100644 --- a/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp +++ b/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp @@ -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 diff --git a/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h b/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h index 7b3c858e7c3..e4ed73cd068 100644 --- a/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h +++ b/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h @@ -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 diff --git a/lib/Target/AMDGPU/Utils/LLVMBuild.txt b/lib/Target/AMDGPU/Utils/LLVMBuild.txt index f8d78165d9e..2453bc546b9 100644 --- a/lib/Target/AMDGPU/Utils/LLVMBuild.txt +++ b/lib/Target/AMDGPU/Utils/LLVMBuild.txt @@ -19,5 +19,5 @@ type = Library name = AMDGPUUtils parent = AMDGPU -required_libraries = MC Support +required_libraries = Core MC Support add_to_library_groups = AMDGPU -- 2.34.1