26constexpr unsigned NumAMDGPUSubArches =
31 StringTable::Offset AltName;
37 StringTable::Offset Name;
39 unsigned ArchFeatures;
42 StringTable::Offset FamilyName;
43 StringTable::Offset BaseName;
44 uint8_t MaxWavesPerEU;
45 uint32_t MaxHWAddressableLocalMemorySize;
51 StringTable::Offset Name;
55#define GET_AMDGPU_NAME_TABLE
56#define GET_AMDGPU_GPU_TABLE
57#define GET_AMDGPU_GPU_ALIAS_TABLE
58#define GET_AMDGPU_MAJOR_SUBARCH
59#define GET_AMDGPU_SUBARCH_NAME
60#define GET_AMDGPU_FEATURE_NAME_TABLE
61#include "llvm/TargetParser/AMDGPUTargetParserDef.inc"
63#define GET_R600_NAME_TABLE
64#define GET_R600_GPU_TABLE
65#define GET_R600_GPU_ALIAS_TABLE
66#include "llvm/TargetParser/R600TargetParserDef.inc"
70constexpr StringTable AMDGPUNameStrTab = AMDGPUNameTable;
71constexpr StringTable R600NameStrTab = R600NameTable;
75const GPUInfo *getAMDGPUInfo(
GPUKind AK) {
76 if (AK < AMDGPUFirstGPUKind)
78 unsigned Idx = AK - AMDGPUFirstGPUKind;
79 if (Idx >= std::size(AMDGPUGPUTable))
81 return &AMDGPUGPUTable[Idx];
85const R600Info *getR600Info(
GPUKind AK) {
86 if (AK < R600FirstGPUKind)
88 unsigned Idx = AK - R600FirstGPUKind;
89 if (Idx >= std::size(R600GPUTable))
91 return &R600GPUTable[Idx];
95template <
typename InfoT,
size_t N,
size_t M>
98 const GPUNameAlias (&Aliases)[M]) {
99 for (
unsigned I = 0;
I !=
N; ++
I) {
100 if (CPU == StrTab[
Table[
I].Name])
101 return static_cast<GPUKind>(FirstKind +
I);
104 for (
const GPUNameAlias &
A : Aliases) {
105 if (CPU == StrTab[
A.AltName])
114constexpr std::array<GPUKind, NumAMDGPUSubArches> AMDGPUSubArchToGPUKind = [] {
115 std::array<GPUKind, NumAMDGPUSubArches>
Map{};
117 for (
unsigned I = 0;
I < std::size(AMDGPUGPUTable); ++
I) {
121 static_cast<GPUKind>(AMDGPUFirstGPUKind +
I);
128constexpr std::array<Triple::SubArchType, NumAMDGPUSubArches>
129 AMDGPUMajorFamilies = [] {
130 std::array<Triple::SubArchType, NumAMDGPUSubArches>
Map{};
132 for (
unsigned I = 0;
I < NumAMDGPUSubArches; ++
I) {
137 for (
const AMDGPUMajorSubArchEntry &Entry : AMDGPUMajorSubArch)
144constexpr std::array<StringTable::Offset, NumAMDGPUSubArches>
145 AMDGPUSubArchNameOffsets = [] {
146 std::array<StringTable::Offset, NumAMDGPUSubArches>
Map{};
147 for (
const AMDGPUSubArchNameEntry &Entry : AMDGPUSubArchNames)
154constexpr std::array<StringTable::Offset, NumAMDGPUSubArches>
155 AMDGPUSubArchTripleNameOffsets = [] {
156 std::array<StringTable::Offset, NumAMDGPUSubArches>
Map{};
157 for (
const AMDGPUSubArchNameEntry &Entry : AMDGPUSubArchNames)
159 Entry.TripleNameOffset;
165 const GPUInfo *Info = getAMDGPUInfo(AK);
166 return Info ? AMDGPUNameStrTab[Info->FamilyName] :
"";
170 const GPUInfo *Info = getAMDGPUInfo(AK);
179 const GPUInfo *Info = getAMDGPUInfo(AK);
180 return Info ? AMDGPUNameStrTab[Info->BaseName] :
"";
206 return MajorA == MajorB;
208 return MajorA == MajorB;
234 const GPUInfo *Info = getAMDGPUInfo(AK);
248 return A.getArchName().size() == 6;
251 return B.getArchName().size() == 6;
266 if (
A.getSubArch() == MajorA) {
267 if (MajorA == MajorB)
271 if (
B.getSubArch() == MajorB) {
272 if (MajorA == MajorB)
281 const GPUInfo *Info = getAMDGPUInfo(AK);
282 return Info ? AMDGPUNameStrTab[Info->Name] :
"";
289 return AMDGPUNameStrTab[AMDGPUSubArchNameOffsets[SubArch -
295 return AMDGPUNameStrTab[AMDGPUNoSubArchNameOffset];
299 "expected an AMDGPU subarch or NoSubArch");
300 return AMDGPUNameStrTab
305 const R600Info *Info = getR600Info(AK);
306 return Info ? R600NameStrTab[Info->Name] :
"";
310 return parseArchImpl(CPU, AMDGPUGPUTable, AMDGPUFirstGPUKind,
311 AMDGPUNameStrTab, AMDGPUGPUAliases);
315 return parseArchImpl(CPU, R600GPUTable, R600FirstGPUKind, R600NameStrTab,
320 const GPUInfo *Info = getAMDGPUInfo(AK);
330 const R600Info *Info = getR600Info(AK);
336 const GPUInfo *Info = getAMDGPUInfo(AK);
337 return Info ? Info->Features :
Empty;
342 for (
unsigned I = 0;
I != NUM_FEATURES; ++
I) {
343 if (Features.
test(
I))
344 Names.
push_back(AMDGPUNameStrTab[AMDGPUFeatureNames[
I]]);
352 for (
unsigned I = 0;
I != std::size(AMDGPUGPUTable); ++
I) {
356 Values.push_back(AMDGPUNameStrTab[AMDGPUGPUTable[
I].Name]);
359 for (
const GPUNameAlias &
A : AMDGPUGPUAliases) {
361 Values.push_back(AMDGPUNameStrTab[
A.AltName]);
366 for (
const R600Info &Info : R600GPUTable)
367 Values.push_back(R600NameStrTab[Info.Name]);
368 for (
const GPUNameAlias &
A : R600GPUAliases)
369 Values.push_back(R600NameStrTab[
A.AltName]);
374 return Info ? Info->Version :
IsaVersion{0, 0, 0};
379 return Info ? Info->Version :
IsaVersion{0, 0, 0};
440 if (Features.
test(FEAT_GFX90A_INSTS))
442 if (Features.
test(FEAT_1536_PHYSICAL_VGPRS))
443 return IsWave32 ? 24 : 12;
444 if (Features.
test(FEAT_GFX10_3_INSTS))
445 return IsWave32 ? 16 : 8;
446 return IsWave32 ? 8 : 4;
455 const GPUInfo *Info = getAMDGPUInfo(AK);
456 return Info ? Info->MaxHWAddressableLocalMemorySize : 32768;
465 const GPUInfo *Info = getAMDGPUInfo(AK);
466 return Info ? Info->LDSBankCount : 32;
474 const GPUInfo *Info = getAMDGPUInfo(AK);
475 return Info ? Info->MaxWavesPerEU : 10;
497 FEAT_FAST_FMAF, FEAT_FAST_DENORMAL_F32,
498 FEAT_SUPPORTS_WAVE32, FEAT_SUPPORTS_WGP,
499 FEAT_XNACK_SUPPORT, FEAT_SRAMECC_SUPPORT,
500 FEAT_XNACK_ON_OFF_MODES, FEAT_APERTURE_REGS,
501 FEAT_GET_DOORBELL_ID, FEAT_AGPR_ALLOC,
502 FEAT_1536_PHYSICAL_VGPRS, FEAT_HALF_ADDRESSABLE_PHYSICAL_LOCAL_MEMORY};
512 Features[Name] =
true;
514 Features.
insert({Name,
true});
520static std::pair<FeatureError, StringRef>
527 const GPUInfo *Info = getAMDGPUInfo(Kind);
533 const bool TargetHasWave32 =
534 Info && Info->Features.test(FEAT_WAVEFRONTSIZE32);
535 const bool TargetHasWave64 =
536 Info && Info->Features.test(FEAT_WAVEFRONTSIZE64);
538 auto Wave32Itr = Features.
find(
"wavefrontsize32");
539 auto Wave64Itr = Features.
find(
"wavefrontsize64");
540 const bool EnableWave32 =
541 Wave32Itr != Features.
end() && Wave32Itr->getValue();
542 const bool EnableWave64 =
543 Wave64Itr != Features.
end() && Wave64Itr->getValue();
544 const bool DisableWave32 =
545 Wave32Itr != Features.
end() && !Wave32Itr->getValue();
546 const bool DisableWave64 =
547 Wave64Itr != Features.
end() && !Wave64Itr->getValue();
549 if (EnableWave32 && EnableWave64)
551 "'+wavefrontsize32' and '+wavefrontsize64' are mutually exclusive"};
552 if (DisableWave32 && DisableWave64)
554 "'-wavefrontsize32' and '-wavefrontsize64' are mutually exclusive"};
557 if (TargetHasWave64) {
564 if (TargetHasWave32) {
574 if (!IsNullGPU && !EnableWave32 && !EnableWave64 && !TargetHasWave32 &&
576 Features.
insert({
"wavefrontsize32",
true});
588std::pair<FeatureError, StringRef>
599 Features[
"wavefrontsize32"] =
true;
600 Features[
"wavefrontsize64"] =
true;
601 }
else if (
T.isAMDGCN()) {
637 TargetTripleString(TT.normalize(
Triple::CanonicalForm::FOUR_IDENT)),
638 XnackSetting(XnackSetting), SramEccSetting(SramEccSetting),
639 IsAMDHSA(TT.getOS() ==
Triple::AMDHSA) {}
645 return TargetIDSetting::On;
647 return TargetIDSetting::Off;
649 return TargetIDSetting::Unsupported;
656 return (CPUName.
empty() || CPUName ==
"generic")
671 ? TargetIDSetting::Any
672 : TargetIDSetting::Unsupported;
674 ? TargetIDSetting::Any
675 : TargetIDSetting::Unsupported;
680 TargetIDStr.
split(Split,
':');
681 bool SeenXnack =
false;
682 bool SeenSramEcc =
false;
684 for (
unsigned I = 1,
E = Split.size();
I !=
E; ++
I) {
688 if (SeenXnack ||
XnackSetting == TargetIDSetting::Unsupported ||
689 Sign == TargetIDSetting::Unsupported)
696 if (SeenSramEcc ||
SramEccSetting == TargetIDSetting::Unsupported ||
697 Sign == TargetIDSetting::Unsupported)
731 if (!CPUName.
empty() && CPUName !=
"generic" &&
743 return TargetID(Arch, TT, XnackSetting, SramEccSetting);
746std::optional<TargetID>
752 TargetIDDirective.
split(Parts,
'-', 4);
753 if (Parts.
size() < 5)
756 return parse(
Triple(Parts[0], Parts[1], Parts[2], Parts[3]), Parts[4]);
763 if (SramEcc == TargetIDSetting::Off)
765 else if (SramEcc == TargetIDSetting::On)
768 if (Xnack == TargetIDSetting::Off)
770 else if (Xnack == TargetIDSetting::On)
801 return Arch ==
Other.Arch && XnackSetting ==
Other.XnackSetting &&
802 SramEccSetting ==
Other.SramEccSetting && IsAMDHSA ==
Other.IsAMDHSA &&
803 TargetTripleString ==
Other.TargetTripleString;
808 return Provided == TargetIDSetting::Any ||
809 Provided == TargetIDSetting::Unsupported || Provided == Requested;
814 if (Arch !=
Other.Arch || XnackSetting !=
Other.XnackSetting ||
815 SramEccSetting !=
Other.SramEccSetting)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > SramEccSetting("amdgpu-sramecc", cl::desc("Force amdgpu.sramecc for testing"), cl::ReallyHidden)
static cl::opt< bool > XnackSetting("amdgpu-xnack", cl::desc("Force amdgpu.xnack value for testing"), cl::ReallyHidden)
static GPUKind getGPUKindFromTargetID(const Triple &TT, StringRef TargetIDStr)
static std::pair< FeatureError, StringRef > fillAMDGCNFeatureMap(StringRef GPU, const Triple &T, StringMap< bool > &Features)
Add a GPU's default features to Features (preserving user overrides) and validate any requested waves...
static bool computeTargetIDFeatures(GPUKind Arch, StringRef TargetIDStr, TargetIDSetting &XnackSetting, TargetIDSetting &SramEccSetting)
static TargetIDSetting getTargetIDSettingFromFeatureString(StringRef Sign)
static void printFeatureModifiers(raw_ostream &OS, TargetIDSetting SramEcc, TargetIDSetting Xnack)
static bool featureProvidesFor(TargetIDSetting Provided, TargetIDSetting Requested)
static void addGPUFeatures(const GPUInfo &Info, bool Overwrite, StringMap< bool > &Features)
static const AMDGPUFeatureBitset FrontendOnlyFeatures
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the SmallVector class.
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
void printCanonicalTargetIDString(raw_ostream &OS) const
Print the canonical processor name followed by any explicit xnack and sramecc feature modifiers (e....
static std::optional< TargetID > parseTargetIDString(StringRef TargetIDDirective)
Parse and validate a TargetID from a full "<triple>-<processor>:<features>" directive string.
void print(raw_ostream &OS) const
TargetIDSetting getXnackSetting() const
bool isEquivalent(const TargetID &Other) const
Returns true if Other denotes the same target as *this, i.e.
bool operator==(const TargetID &Other) const
bool providesFor(const TargetID &Other) const
Returns true if a device image for *this can provide the device code for a request for Other.
StringRef getTargetTripleString() const
std::string getCanonicalFeatureString() const
TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting, TargetIDSetting SramEccSetting)
static std::optional< TargetID > parse(const Triple &TT, StringRef ProcAndFeatures)
Parse and validate a TargetID for triple TT from the processor+features string ProcAndFeatures (e....
std::string toString() const
TargetIDSetting getSramEccSetting() const
constexpr bool test(unsigned I) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr bool empty() const
Check if the string is empty.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
A table of densely packed, null-terminated strings indexed by offset.
Triple - Helper class for working with autoconf configuration names.
LLVM_ABI bool isCompatibleWith(const Triple &Other) const
Test whether target triples are compatible.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI StringRef getArchNameR600(GPUKind AK)
@ FIXED_NUM_SGPRS_FOR_INIT_BUG
LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl< StringRef > &Values, Triple::SubArchType SubArch=Triple::NoSubArch)
Append the valid AMDGCN GPU names to Values.
LLVM_ABI unsigned getMaxWavesPerEU(GPUKind AK)
LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch)
LLVM_ABI StringRef getBaseArchNameAMDGCN(GPUKind AK)
The canonical GPU name for a variant name.
LLVM_ABI void fillValidArchListR600(SmallVectorImpl< StringRef > &Values)
LLVM_ABI R600FeatureKind getArchAttrR600(GPUKind AK)
LLVM_ABI std::string mergeSubArch(const Triple &A, const Triple &B)
Returns the effective triple appropriate to use when linking B into A by merging the subarches in cas...
LLVM_ABI bool isCPUValidForSubArch(Triple::SubArchType SubArch, GPUKind AK)
Return true if the GPU AK is usable with the triple subarch SubArch.
LLVM_ABI bool isSubArchCompatible(const Triple &A, const Triple &B)
Return true if subarch A is compatible with subarch B, i.e.
LLVM_ABI unsigned getLDSBankCount(GPUKind AK)
LLVM_ABI unsigned getMaxHWAddressableLocalMemorySize(GPUKind AK)
LLVM_ABI StringRef getArchFamilyNameAMDGCN(GPUKind AK)
LLVM_ABI StringRef getSubArchName(Triple::SubArchType SubArch)
Returns the triple subarch name for an AMDGPU subarch, e.g.
LLVM_ABI unsigned getAddressableNumSGPRs(GPUKind AK)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
LLVM_ABI unsigned getTotalNumSGPRs(GPUKind AK)
GPUKind
GPU kinds supported by the AMDGPU target.
Bitset< NUM_FEATURES > AMDGPUFeatureBitset
LLVM_ABI Triple::SubArchType getSubArchFromGPUName(StringRef CPU)
Returns the preferred subarch for a GPU name CPU, or NoSubArch if unrecognized.
LLVM_ABI unsigned getSGPRAllocGranule(GPUKind AK)
LLVM_ABI Triple::SubArchType getSubArch(GPUKind AK)
LLVM_ABI StringRef getArchNameFromSubArch(Triple::SubArchType SubArch)
Returns the canonical GPU name for an AMDGPU subarch, e.g.
LLVM_ABI unsigned getVGPRAllocGranule(GPUKind AK, bool IsWave32)
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
LLVM_ABI bool isPseudoTarget(GPUKind AK)
Return true if AK is a pseudo target (e.g.
@ UNSUPPORTED_TARGET_FEATURE
@ INVALID_FEATURE_COMBINATION
LLVM_ABI GPUKind getGPUKindFromSubArch(Triple::SubArchType SubArch)
AMDGPU::TargetID TargetID
LLVM_ABI std::pair< FeatureError, StringRef > fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap< bool > &Features)
Fills Features map with default values for given target GPU.
LLVM_ABI void getFeatureNames(const AMDGPUFeatureBitset &Features, SmallVectorImpl< StringRef > &Names)
Appends the feature name of each bit set in Features to Names.
LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK)
LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK)
LLVM_ABI Triple::SubArchType getMajorSubArch(Triple::SubArchType SubArch)
LLVM_ABI const AMDGPUFeatureBitset & getFeatureBitset(GPUKind AK)
Returns AK's feature bitset, or an empty bitset if unknown.
LLVM_ABI GPUKind parseArchR600(StringRef CPU)
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Instruction set architecture version.