diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /clang/lib/Basic/Targets/AMDGPU.cpp | |
parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) |
Diffstat (limited to 'clang/lib/Basic/Targets/AMDGPU.cpp')
-rw-r--r-- | clang/lib/Basic/Targets/AMDGPU.cpp | 99 |
1 files changed, 66 insertions, 33 deletions
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp index 80f2601b0a24..fe50fbcf3b88 100644 --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -13,10 +13,10 @@ #include "AMDGPU.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CodeGenOptions.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetBuiltins.h" -#include "llvm/ADT/StringSwitch.h" using namespace clang; using namespace clang::targets; @@ -56,7 +56,8 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = { Private, // sycl_private Generic, // ptr32_sptr Generic, // ptr32_uptr - Generic // ptr64 + Generic, // ptr64 + Generic, // hlsl_groupshared }; const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = { @@ -72,24 +73,25 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = { Constant, // cuda_constant Local, // cuda_shared // SYCL address space values for this map are dummy - Generic, // sycl_global - Generic, // sycl_global_device - Generic, // sycl_global_host - Generic, // sycl_local - Generic, // sycl_private - Generic, // ptr32_sptr - Generic, // ptr32_uptr - Generic // ptr64 + Generic, // sycl_global + Generic, // sycl_global_device + Generic, // sycl_global_host + Generic, // sycl_local + Generic, // sycl_private + Generic, // ptr32_sptr + Generic, // ptr32_uptr + Generic, // ptr64 + Generic, // hlsl_groupshared }; } // namespace targets } // namespace clang -const Builtin::Info AMDGPUTargetInfo::BuiltinInfo[] = { +static constexpr Builtin::Info BuiltinInfo[] = { #define BUILTIN(ID, TYPE, ATTRS) \ - {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, + {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES}, #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \ - {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE}, + {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES}, #include "clang/Basic/BuiltinsAMDGPU.def" }; @@ -171,12 +173,14 @@ const char *const AMDGPUTargetInfo::GCCRegNames[] = { }; ArrayRef<const char *> AMDGPUTargetInfo::getGCCRegNames() const { - return llvm::makeArrayRef(GCCRegNames); + return llvm::ArrayRef(GCCRegNames); } bool AMDGPUTargetInfo::initFeatureMap( llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector<std::string> &FeatureVec) const { + const bool IsNullCPU = CPU.empty(); + bool IsWave32Capable = false; using namespace llvm::AMDGPU; @@ -187,14 +191,13 @@ bool AMDGPUTargetInfo::initFeatureMap( case GK_GFX1102: case GK_GFX1101: case GK_GFX1100: + IsWave32Capable = true; Features["ci-insts"] = true; - Features["dot1-insts"] = true; Features["dot5-insts"] = true; - Features["dot6-insts"] = true; Features["dot7-insts"] = true; Features["dot8-insts"] = true; + Features["dot9-insts"] = true; Features["dl-insts"] = true; - Features["flat-address-space"] = true; Features["16-bit-insts"] = true; Features["dpp"] = true; Features["gfx8-insts"] = true; @@ -210,6 +213,7 @@ bool AMDGPUTargetInfo::initFeatureMap( case GK_GFX1032: case GK_GFX1031: case GK_GFX1030: + IsWave32Capable = true; Features["ci-insts"] = true; Features["dot1-insts"] = true; Features["dot2-insts"] = true; @@ -217,7 +221,6 @@ bool AMDGPUTargetInfo::initFeatureMap( Features["dot6-insts"] = true; Features["dot7-insts"] = true; Features["dl-insts"] = true; - Features["flat-address-space"] = true; Features["16-bit-insts"] = true; Features["dpp"] = true; Features["gfx8-insts"] = true; @@ -234,12 +237,12 @@ bool AMDGPUTargetInfo::initFeatureMap( Features["dot5-insts"] = true; Features["dot6-insts"] = true; Features["dot7-insts"] = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case GK_GFX1013: case GK_GFX1010: + IsWave32Capable = true; Features["dl-insts"] = true; Features["ci-insts"] = true; - Features["flat-address-space"] = true; Features["16-bit-insts"] = true; Features["dpp"] = true; Features["gfx8-insts"] = true; @@ -251,30 +254,30 @@ bool AMDGPUTargetInfo::initFeatureMap( case GK_GFX940: Features["gfx940-insts"] = true; Features["fp8-insts"] = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case GK_GFX90A: Features["gfx90a-insts"] = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case GK_GFX908: Features["dot3-insts"] = true; Features["dot4-insts"] = true; Features["dot5-insts"] = true; Features["dot6-insts"] = true; Features["mai-insts"] = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case GK_GFX906: Features["dl-insts"] = true; Features["dot1-insts"] = true; Features["dot2-insts"] = true; Features["dot7-insts"] = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case GK_GFX90C: case GK_GFX909: case GK_GFX904: case GK_GFX902: case GK_GFX900: Features["gfx9-insts"] = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case GK_GFX810: case GK_GFX805: case GK_GFX803: @@ -284,7 +287,7 @@ bool AMDGPUTargetInfo::initFeatureMap( Features["16-bit-insts"] = true; Features["dpp"] = true; Features["s-memrealtime"] = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case GK_GFX705: case GK_GFX704: case GK_GFX703: @@ -292,8 +295,7 @@ bool AMDGPUTargetInfo::initFeatureMap( case GK_GFX701: case GK_GFX700: Features["ci-insts"] = true; - Features["flat-address-space"] = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case GK_GFX602: case GK_GFX601: case GK_GFX600: @@ -333,7 +335,32 @@ bool AMDGPUTargetInfo::initFeatureMap( } } - return TargetInfo::initFeatureMap(Features, Diags, CPU, FeatureVec); + if (!TargetInfo::initFeatureMap(Features, Diags, CPU, FeatureVec)) + return false; + + // FIXME: Not diagnosing wavefrontsize32 on wave64 only targets. + const bool HaveWave32 = + (IsWave32Capable || IsNullCPU) && Features.count("wavefrontsize32"); + const bool HaveWave64 = Features.count("wavefrontsize64"); + + // TODO: Should move this logic into TargetParser + if (HaveWave32 && HaveWave64) { + Diags.Report(diag::err_invalid_feature_combination) + << "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive"; + return false; + } + + // Don't assume any wavesize with an unknown subtarget. + if (!IsNullCPU) { + // Default to wave32 if available, or wave64 if not + if (!HaveWave32 && !HaveWave64) { + StringRef DefaultWaveSizeFeature = + IsWave32Capable ? "wavefrontsize32" : "wavefrontsize64"; + Features.insert(std::make_pair(DefaultWaveSizeFeature, true)); + } + } + + return true; } void AMDGPUTargetInfo::fillValidCPUList( @@ -364,13 +391,19 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple, !isAMDGCN(Triple)); UseAddrSpaceMapMangling = true; + if (isAMDGCN(Triple)) { + // __bf16 is always available as a load/store only type on AMDGCN. + BFloat16Width = BFloat16Align = 16; + BFloat16Format = &llvm::APFloat::BFloat(); + } + HasLegalHalfType = true; HasFloat16 = true; WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64; AllowAMDGPUUnsafeFPAtomics = Opts.AllowAMDGPUUnsafeFPAtomics; - // Set pointer width and alignment for target address space 0. - PointerWidth = PointerAlign = getPointerWidthV(Generic); + // Set pointer width and alignment for the generic address space. + PointerWidth = PointerAlign = getPointerWidthV(LangAS::Default); if (getMaxPointerWidth() == 64) { LongWidth = LongAlign = 64; SizeType = UnsignedLong; @@ -391,8 +424,8 @@ void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) { } ArrayRef<Builtin::Info> AMDGPUTargetInfo::getTargetBuiltins() const { - return llvm::makeArrayRef(BuiltinInfo, clang::AMDGPU::LastTSBuiltin - - Builtin::FirstTSBuiltin); + return llvm::ArrayRef(BuiltinInfo, + clang::AMDGPU::LastTSBuiltin - Builtin::FirstTSBuiltin); } void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts, |