r340292 - AMDGPU: Move target code into TargetParser
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 21 09:13:29 PDT 2018
Author: arsenm
Date: Tue Aug 21 09:13:29 2018
New Revision: 340292
URL: http://llvm.org/viewvc/llvm-project?rev=340292&view=rev
Log:
AMDGPU: Move target code into TargetParser
Modified:
cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
cfe/trunk/lib/Basic/Targets/AMDGPU.h
Modified: cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AMDGPU.cpp?rev=340292&r1=340291&r2=340292&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/AMDGPU.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/AMDGPU.cpp Tue Aug 21 09:13:29 2018
@@ -127,12 +127,14 @@ bool AMDGPUTargetInfo::initFeatureMap(
llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
const std::vector<std::string> &FeatureVec) const {
+ using namespace llvm::AMDGPU;
+
// XXX - What does the member GPU mean if device name string passed here?
if (isAMDGCN(getTriple())) {
if (CPU.empty())
CPU = "gfx600";
- switch (parseAMDGCNName(CPU).Kind) {
+ switch (llvm::AMDGPU::parseArchAMDGCN(CPU)) {
case GK_GFX906:
Features["dl-insts"] = true;
LLVM_FALLTHROUGH;
@@ -169,7 +171,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
if (CPU.empty())
CPU = "r600";
- switch (parseR600Name(CPU).Kind) {
+ switch (llvm::AMDGPU::parseArchR600(CPU)) {
case GK_CAYMAN:
case GK_CYPRESS:
case GK_RV770:
@@ -201,7 +203,7 @@ void AMDGPUTargetInfo::adjustTargetOptio
TargetOptions &TargetOpts) const {
bool hasFP32Denormals = false;
bool hasFP64Denormals = false;
- GPUInfo CGOptsGPU = parseGPUName(TargetOpts.CPU);
+
for (auto &I : TargetOpts.FeaturesAsWritten) {
if (I == "+fp32-denormals" || I == "-fp32-denormals")
hasFP32Denormals = true;
@@ -210,54 +212,20 @@ void AMDGPUTargetInfo::adjustTargetOptio
}
if (!hasFP32Denormals)
TargetOpts.Features.push_back(
- (Twine(CGOptsGPU.HasFastFMAF && CGOptsGPU.HasFullRateF32Denorms &&
- !CGOpts.FlushDenorm
- ? '+'
- : '-') +
- Twine("fp32-denormals"))
+ (Twine(hasFastFMAF() && hasFullRateDenormalsF32() && !CGOpts.FlushDenorm
+ ? '+' : '-') + Twine("fp32-denormals"))
.str());
// Always do not flush fp64 or fp16 denorms.
- if (!hasFP64Denormals && CGOptsGPU.HasFP64)
+ if (!hasFP64Denormals && hasFP64())
TargetOpts.Features.push_back("+fp64-fp16-denormals");
}
-constexpr AMDGPUTargetInfo::GPUInfo AMDGPUTargetInfo::InvalidGPU;
-constexpr AMDGPUTargetInfo::GPUInfo AMDGPUTargetInfo::R600GPUs[];
-constexpr AMDGPUTargetInfo::GPUInfo AMDGPUTargetInfo::AMDGCNGPUs[];
-
-AMDGPUTargetInfo::GPUInfo AMDGPUTargetInfo::parseR600Name(StringRef Name) {
- const auto *Result = llvm::find_if(
- R600GPUs, [Name](const GPUInfo &GPU) { return GPU.Name == Name; });
-
- if (Result == std::end(R600GPUs))
- return InvalidGPU;
- return *Result;
-}
-
-AMDGPUTargetInfo::GPUInfo AMDGPUTargetInfo::parseAMDGCNName(StringRef Name) {
- const auto *Result = llvm::find_if(
- AMDGCNGPUs, [Name](const GPUInfo &GPU) { return GPU.Name == Name; });
-
- if (Result == std::end(AMDGCNGPUs))
- return InvalidGPU;
- return *Result;
-}
-
-AMDGPUTargetInfo::GPUInfo AMDGPUTargetInfo::parseGPUName(StringRef Name) const {
- if (isAMDGCN(getTriple()))
- return parseAMDGCNName(Name);
- else
- return parseR600Name(Name);
-}
-
void AMDGPUTargetInfo::fillValidCPUList(
SmallVectorImpl<StringRef> &Values) const {
if (isAMDGCN(getTriple()))
- llvm::for_each(AMDGCNGPUs, [&Values](const GPUInfo &GPU) {
- Values.emplace_back(GPU.Name);});
+ llvm::AMDGPU::fillValidArchListAMDGCN(Values);
else
- llvm::for_each(R600GPUs, [&Values](const GPUInfo &GPU) {
- Values.emplace_back(GPU.Name);});
+ llvm::AMDGPU::fillValidArchListR600(Values);
}
void AMDGPUTargetInfo::setAddressSpaceMap(bool DefaultIsPrivate) {
@@ -267,7 +235,12 @@ void AMDGPUTargetInfo::setAddressSpaceMa
AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: TargetInfo(Triple),
- GPU(isAMDGCN(Triple) ? AMDGCNGPUs[0] : parseR600Name(Opts.CPU)) {
+ GPUKind(isAMDGCN(Triple) ?
+ llvm::AMDGPU::parseArchAMDGCN(Opts.CPU) :
+ llvm::AMDGPU::parseArchR600(Opts.CPU)),
+ GPUFeatures(isAMDGCN(Triple) ?
+ llvm::AMDGPU::getArchAttrAMDGCN(GPUKind) :
+ llvm::AMDGPU::getArchAttrR600(GPUKind)) {
resetDataLayout(isAMDGCN(getTriple()) ? DataLayoutStringAMDGCN
: DataLayoutStringR600);
assert(DataLayout->getAllocaAddrSpace() == Private);
@@ -312,19 +285,22 @@ void AMDGPUTargetInfo::getTargetDefines(
else
Builder.defineMacro("__R600__");
- if (GPU.Kind != GK_NONE)
- Builder.defineMacro(Twine("__") + Twine(GPU.CanonicalName) + Twine("__"));
+ if (GPUKind != llvm::AMDGPU::GK_NONE) {
+ StringRef CanonName = isAMDGCN(getTriple()) ?
+ getArchNameAMDGCN(GPUKind) : getArchNameR600(GPUKind);
+ Builder.defineMacro(Twine("__") + Twine(CanonName) + Twine("__"));
+ }
// TODO: __HAS_FMAF__, __HAS_LDEXPF__, __HAS_FP64__ are deprecated and will be
// removed in the near future.
- if (GPU.HasFMAF)
+ if (hasFMAF())
Builder.defineMacro("__HAS_FMAF__");
- if (GPU.HasFastFMAF)
+ if (hasFastFMAF())
Builder.defineMacro("FP_FAST_FMAF");
- if (GPU.HasLDEXPF)
+ if (hasLDEXPF())
Builder.defineMacro("__HAS_LDEXPF__");
- if (GPU.HasFP64)
+ if (hasFP64())
Builder.defineMacro("__HAS_FP64__");
- if (GPU.HasFastFMA)
+ if (hasFastFMA())
Builder.defineMacro("FP_FAST_FMA");
}
Modified: cfe/trunk/lib/Basic/Targets/AMDGPU.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AMDGPU.h?rev=340292&r1=340291&r2=340292&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/AMDGPU.h (original)
+++ cfe/trunk/lib/Basic/Targets/AMDGPU.h Tue Aug 21 09:13:29 2018
@@ -19,6 +19,7 @@
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/TargetParser.h"
namespace clang {
namespace targets {
@@ -38,148 +39,47 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTarg
static const LangASMap AMDGPUDefIsGenMap;
static const LangASMap AMDGPUDefIsPrivMap;
- /// GPU kinds supported by the AMDGPU target.
- enum GPUKind : uint32_t {
- // Not specified processor.
- GK_NONE = 0,
-
- // R600-based processors.
- GK_R600,
- GK_R630,
- GK_RS880,
- GK_RV670,
- GK_RV710,
- GK_RV730,
- GK_RV770,
- GK_CEDAR,
- GK_CYPRESS,
- GK_JUNIPER,
- GK_REDWOOD,
- GK_SUMO,
- GK_BARTS,
- GK_CAICOS,
- GK_CAYMAN,
- GK_TURKS,
-
- GK_R600_FIRST = GK_R600,
- GK_R600_LAST = GK_TURKS,
-
- // AMDGCN-based processors.
- GK_GFX600,
- GK_GFX601,
- GK_GFX700,
- GK_GFX701,
- GK_GFX702,
- GK_GFX703,
- GK_GFX704,
- GK_GFX801,
- GK_GFX802,
- GK_GFX803,
- GK_GFX810,
- GK_GFX900,
- GK_GFX902,
- GK_GFX904,
- GK_GFX906,
+ llvm::AMDGPU::GPUKind GPUKind;
+ unsigned GPUFeatures;
- GK_AMDGCN_FIRST = GK_GFX600,
- GK_AMDGCN_LAST = GK_GFX906,
- };
- struct GPUInfo {
- llvm::StringLiteral Name;
- llvm::StringLiteral CanonicalName;
- AMDGPUTargetInfo::GPUKind Kind;
- bool HasFMAF;
- bool HasFastFMAF;
- bool HasLDEXPF;
- bool HasFP64;
- bool HasFastFMA;
- bool HasFullRateF32Denorms;
- };
+ bool hasFP64() const {
+ return getTriple().getArch() == llvm::Triple::amdgcn ||
+ !!(GPUFeatures & llvm::AMDGPU::FEATURE_FP64);
+ }
- static constexpr GPUInfo InvalidGPU =
- {{""}, {""}, GK_NONE, false, false, false, false, false, false};
- static constexpr GPUInfo R600GPUs[26] = {
- // Name Canonical Kind Has Has Has Has Has Has
- // Name FMAF Fast LDEXPF FP64 Fast Fast
- // FMAF FMA Denorm
- {{"r600"}, {"r600"}, GK_R600, false, false, false, false, false, false},
- {{"rv630"}, {"r600"}, GK_R600, false, false, false, false, false, false},
- {{"rv635"}, {"r600"}, GK_R600, false, false, false, false, false, false},
- {{"r630"}, {"r630"}, GK_R630, false, false, false, false, false, false},
- {{"rs780"}, {"rs880"}, GK_RS880, false, false, false, false, false, false},
- {{"rs880"}, {"rs880"}, GK_RS880, false, false, false, false, false, false},
- {{"rv610"}, {"rs880"}, GK_RS880, false, false, false, false, false, false},
- {{"rv620"}, {"rs880"}, GK_RS880, false, false, false, false, false, false},
- {{"rv670"}, {"rv670"}, GK_RV670, false, false, false, false, false, false},
- {{"rv710"}, {"rv710"}, GK_RV710, false, false, false, false, false, false},
- {{"rv730"}, {"rv730"}, GK_RV730, false, false, false, false, false, false},
- {{"rv740"}, {"rv770"}, GK_RV770, false, false, false, false, false, false},
- {{"rv770"}, {"rv770"}, GK_RV770, false, false, false, false, false, false},
- {{"cedar"}, {"cedar"}, GK_CEDAR, false, false, false, false, false, false},
- {{"palm"}, {"cedar"}, GK_CEDAR, false, false, false, false, false, false},
- {{"cypress"}, {"cypress"}, GK_CYPRESS, true, false, false, false, false, false},
- {{"hemlock"}, {"cypress"}, GK_CYPRESS, true, false, false, false, false, false},
- {{"juniper"}, {"juniper"}, GK_JUNIPER, false, false, false, false, false, false},
- {{"redwood"}, {"redwood"}, GK_REDWOOD, false, false, false, false, false, false},
- {{"sumo"}, {"sumo"}, GK_SUMO, false, false, false, false, false, false},
- {{"sumo2"}, {"sumo"}, GK_SUMO, false, false, false, false, false, false},
- {{"barts"}, {"barts"}, GK_BARTS, false, false, false, false, false, false},
- {{"caicos"}, {"caicos"}, GK_CAICOS, false, false, false, false, false, false},
- {{"aruba"}, {"cayman"}, GK_CAYMAN, true, false, false, false, false, false},
- {{"cayman"}, {"cayman"}, GK_CAYMAN, true, false, false, false, false, false},
- {{"turks"}, {"turks"}, GK_TURKS, false, false, false, false, false, false},
- };
- static constexpr GPUInfo AMDGCNGPUs[32] = {
- // Name Canonical Kind Has Has Has Has Has Has
- // Name FMAF Fast LDEXPF FP64 Fast Fast
- // FMAF FMA Denorm
- {{"gfx600"}, {"gfx600"}, GK_GFX600, true, true, true, true, true, false},
- {{"tahiti"}, {"gfx600"}, GK_GFX600, true, true, true, true, true, false},
- {{"gfx601"}, {"gfx601"}, GK_GFX601, true, false, true, true, true, false},
- {{"hainan"}, {"gfx601"}, GK_GFX601, true, false, true, true, true, false},
- {{"oland"}, {"gfx601"}, GK_GFX601, true, false, true, true, true, false},
- {{"pitcairn"}, {"gfx601"}, GK_GFX601, true, false, true, true, true, false},
- {{"verde"}, {"gfx601"}, GK_GFX601, true, false, true, true, true, false},
- {{"gfx700"}, {"gfx700"}, GK_GFX700, true, false, true, true, true, false},
- {{"kaveri"}, {"gfx700"}, GK_GFX700, true, false, true, true, true, false},
- {{"gfx701"}, {"gfx701"}, GK_GFX701, true, true, true, true, true, false},
- {{"hawaii"}, {"gfx701"}, GK_GFX701, true, true, true, true, true, false},
- {{"gfx702"}, {"gfx702"}, GK_GFX702, true, true, true, true, true, false},
- {{"gfx703"}, {"gfx703"}, GK_GFX703, true, false, true, true, true, false},
- {{"kabini"}, {"gfx703"}, GK_GFX703, true, false, true, true, true, false},
- {{"mullins"}, {"gfx703"}, GK_GFX703, true, false, true, true, true, false},
- {{"gfx704"}, {"gfx704"}, GK_GFX704, true, false, true, true, true, false},
- {{"bonaire"}, {"gfx704"}, GK_GFX704, true, false, true, true, true, false},
- {{"gfx801"}, {"gfx801"}, GK_GFX801, true, true, true, true, true, true},
- {{"carrizo"}, {"gfx801"}, GK_GFX801, true, true, true, true, true, true},
- {{"gfx802"}, {"gfx802"}, GK_GFX802, true, false, true, true, true, true},
- {{"iceland"}, {"gfx802"}, GK_GFX802, true, false, true, true, true, true},
- {{"tonga"}, {"gfx802"}, GK_GFX802, true, false, true, true, true, true},
- {{"gfx803"}, {"gfx803"}, GK_GFX803, true, false, true, true, true, true},
- {{"fiji"}, {"gfx803"}, GK_GFX803, true, false, true, true, true, true},
- {{"polaris10"}, {"gfx803"}, GK_GFX803, true, false, true, true, true, true},
- {{"polaris11"}, {"gfx803"}, GK_GFX803, true, false, true, true, true, true},
- {{"gfx810"}, {"gfx810"}, GK_GFX810, true, false, true, true, true, true},
- {{"stoney"}, {"gfx810"}, GK_GFX810, true, false, true, true, true, true},
- {{"gfx900"}, {"gfx900"}, GK_GFX900, true, true, true, true, true, true},
- {{"gfx902"}, {"gfx902"}, GK_GFX902, true, true, true, true, true, true},
- {{"gfx904"}, {"gfx904"}, GK_GFX904, true, true, true, true, true, true},
- {{"gfx906"}, {"gfx906"}, GK_GFX906, true, true, true, true, true, true},
- };
+ /// Has fast fma f32
+ bool hasFastFMAF() const {
+ return !!(GPUFeatures & llvm::AMDGPU::FEATURE_FAST_FMA_F32);
+ }
- static GPUInfo parseR600Name(StringRef Name);
+ /// Has fast fma f64
+ bool hasFastFMA() const {
+ return getTriple().getArch() == llvm::Triple::amdgcn;
+ }
- static GPUInfo parseAMDGCNName(StringRef Name);
+ bool hasFMAF() const {
+ return getTriple().getArch() == llvm::Triple::amdgcn ||
+ !!(GPUFeatures & llvm::AMDGPU::FEATURE_FMA);
+ }
- GPUInfo parseGPUName(StringRef Name) const;
+ bool hasFullRateDenormalsF32() const {
+ return !!(GPUFeatures & llvm::AMDGPU::FEATURE_FAST_DENORMAL_F32);
+ }
- GPUInfo GPU;
+ bool hasLDEXPF() const {
+ return getTriple().getArch() == llvm::Triple::amdgcn ||
+ !!(GPUFeatures & llvm::AMDGPU::FEATURE_LDEXP);
+ }
static bool isAMDGCN(const llvm::Triple &TT) {
return TT.getArch() == llvm::Triple::amdgcn;
}
+ static bool isR600(const llvm::Triple &TT) {
+ return TT.getArch() == llvm::Triple::r600;
+ }
+
public:
AMDGPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
@@ -188,10 +88,12 @@ public:
void adjust(LangOptions &Opts) override;
uint64_t getPointerWidthV(unsigned AddrSpace) const override {
- if (GPU.Kind <= GK_R600_LAST)
+ if (isR600(getTriple()))
return 32;
+
if (AddrSpace == Private || AddrSpace == Local)
return 32;
+
return 64;
}
@@ -322,20 +224,22 @@ public:
bool isValidCPUName(StringRef Name) const override {
if (getTriple().getArch() == llvm::Triple::amdgcn)
- return GK_NONE != parseAMDGCNName(Name).Kind;
- else
- return GK_NONE != parseR600Name(Name).Kind;
+ return llvm::AMDGPU::parseArchAMDGCN(Name) != llvm::AMDGPU::GK_NONE;
+ return llvm::AMDGPU::parseArchR600(Name) != llvm::AMDGPU::GK_NONE;
}
void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
bool setCPU(const std::string &Name) override {
- if (getTriple().getArch() == llvm::Triple::amdgcn)
- GPU = parseAMDGCNName(Name);
- else
- GPU = parseR600Name(Name);
+ if (getTriple().getArch() == llvm::Triple::amdgcn) {
+ GPUKind = llvm::AMDGPU::parseArchAMDGCN(Name);
+ GPUFeatures = llvm::AMDGPU::getArchAttrAMDGCN(GPUKind);
+ } else {
+ GPUKind = llvm::AMDGPU::parseArchR600(Name);
+ GPUFeatures = llvm::AMDGPU::getArchAttrR600(GPUKind);
+ }
- return GK_NONE != GPU.Kind;
+ return GPUKind != llvm::AMDGPU::GK_NONE;
}
void setSupportedOpenCLOpts() override {
@@ -343,16 +247,20 @@ public:
Opts.support("cl_clang_storage_class_specifiers");
Opts.support("cl_khr_icd");
- if (GPU.HasFP64)
+ bool IsAMDGCN = isAMDGCN(getTriple());
+
+ if (hasFP64())
Opts.support("cl_khr_fp64");
- if (GPU.Kind >= GK_CEDAR) {
+
+ if (IsAMDGCN || GPUKind >= llvm::AMDGPU::GK_CEDAR) {
Opts.support("cl_khr_byte_addressable_store");
Opts.support("cl_khr_global_int32_base_atomics");
Opts.support("cl_khr_global_int32_extended_atomics");
Opts.support("cl_khr_local_int32_base_atomics");
Opts.support("cl_khr_local_int32_extended_atomics");
}
- if (GPU.Kind >= GK_AMDGCN_FIRST) {
+
+ if (IsAMDGCN) {
Opts.support("cl_khr_fp16");
Opts.support("cl_khr_int64_base_atomics");
Opts.support("cl_khr_int64_extended_atomics");
More information about the cfe-commits
mailing list