27constexpr unsigned NumAMDGPUSubArches =
32 StringTable::Offset AltName;
38 StringTable::Offset Name;
40 unsigned ArchFeatures;
43 StringTable::Offset FamilyName;
44 StringTable::Offset BaseName;
45 uint8_t MaxWavesPerEU;
46 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);
175 const GPUInfo *Info = getAMDGPUInfo(AK);
176 return Info ? AMDGPUNameStrTab[Info->BaseName] :
"";
202 return MajorA == MajorB;
204 return MajorA == MajorB;
230 const GPUInfo *Info = getAMDGPUInfo(AK);
244 return A.getArchName().size() == 6;
247 return B.getArchName().size() == 6;
262 if (
A.getSubArch() == MajorA) {
263 if (MajorA == MajorB)
267 if (
B.getSubArch() == MajorB) {
268 if (MajorA == MajorB)
277 const GPUInfo *Info = getAMDGPUInfo(AK);
278 return Info ? AMDGPUNameStrTab[Info->Name] :
"";
285 return AMDGPUNameStrTab[AMDGPUSubArchNameOffsets[SubArch -
291 return AMDGPUNameStrTab[AMDGPUNoSubArchNameOffset];
295 "expected an AMDGPU subarch or NoSubArch");
296 return AMDGPUNameStrTab
301 const R600Info *Info = getR600Info(AK);
302 return Info ? R600NameStrTab[Info->Name] :
"";
306 return parseArchImpl(CPU, AMDGPUGPUTable, AMDGPUFirstGPUKind,
307 AMDGPUNameStrTab, AMDGPUGPUAliases);
311 return parseArchImpl(CPU, R600GPUTable, R600FirstGPUKind, R600NameStrTab,
316 const GPUInfo *Info = getAMDGPUInfo(AK);
326 const R600Info *Info = getR600Info(AK);
332 const GPUInfo *Info = getAMDGPUInfo(AK);
333 return Info ? Info->Features :
Empty;
338 for (
unsigned I = 0;
I != NUM_FEATURES; ++
I) {
339 if (Features.
test(
I))
340 Names.
push_back(AMDGPUNameStrTab[AMDGPUFeatureNames[
I]]);
348 for (
unsigned I = 0;
I != std::size(AMDGPUGPUTable); ++
I) {
352 Values.push_back(AMDGPUNameStrTab[AMDGPUGPUTable[
I].Name]);
355 for (
const GPUNameAlias &
A : AMDGPUGPUAliases) {
357 Values.push_back(AMDGPUNameStrTab[
A.AltName]);
362 for (
const R600Info &Info : R600GPUTable)
363 Values.push_back(R600NameStrTab[Info.Name]);
364 for (
const GPUNameAlias &
A : R600GPUAliases)
365 Values.push_back(R600NameStrTab[
A.AltName]);
370 return Info ? Info->Version :
IsaVersion{0, 0, 0};
375 return Info ? Info->Version :
IsaVersion{0, 0, 0};
435 const GPUInfo *Info = getAMDGPUInfo(AK);
436 return Info ? Info->MaxHWAddressableLocalMemorySize : 32768;
445 const GPUInfo *Info = getAMDGPUInfo(AK);
446 return Info ? Info->MaxWavesPerEU : 10;
468 FEAT_FAST_FMAF, FEAT_FAST_DENORMAL_F32, FEAT_SUPPORTS_WAVE32,
469 FEAT_SUPPORTS_WGP, FEAT_XNACK_SUPPORT, FEAT_SRAMECC_SUPPORT,
470 FEAT_XNACK_ON_OFF_MODES};
480 Features[Name] =
true;
482 Features.
insert({Name,
true});
488static std::pair<FeatureError, StringRef>
495 const GPUInfo *Info = getAMDGPUInfo(Kind);
501 const bool TargetHasWave32 =
502 Info && Info->Features.test(FEAT_WAVEFRONTSIZE32);
503 const bool TargetHasWave64 =
504 Info && Info->Features.test(FEAT_WAVEFRONTSIZE64);
506 auto Wave32Itr = Features.
find(
"wavefrontsize32");
507 auto Wave64Itr = Features.
find(
"wavefrontsize64");
508 const bool EnableWave32 =
509 Wave32Itr != Features.
end() && Wave32Itr->getValue();
510 const bool EnableWave64 =
511 Wave64Itr != Features.
end() && Wave64Itr->getValue();
512 const bool DisableWave32 =
513 Wave32Itr != Features.
end() && !Wave32Itr->getValue();
514 const bool DisableWave64 =
515 Wave64Itr != Features.
end() && !Wave64Itr->getValue();
517 if (EnableWave32 && EnableWave64)
519 "'+wavefrontsize32' and '+wavefrontsize64' are mutually exclusive"};
520 if (DisableWave32 && DisableWave64)
522 "'-wavefrontsize32' and '-wavefrontsize64' are mutually exclusive"};
525 if (TargetHasWave64) {
532 if (TargetHasWave32) {
542 if (!IsNullGPU && !EnableWave32 && !EnableWave64 && !TargetHasWave32 &&
544 Features.
insert({
"wavefrontsize32",
true});
556std::pair<FeatureError, StringRef>
567 Features[
"wavefrontsize32"] =
true;
568 Features[
"wavefrontsize64"] =
true;
569 }
else if (
T.isAMDGCN()) {
605 TargetTripleString(TT.normalize(
Triple::CanonicalForm::FOUR_IDENT)),
606 XnackSetting(XnackSetting), SramEccSetting(SramEccSetting),
607 IsAMDHSA(TT.getOS() ==
Triple::AMDHSA) {}
613 return TargetIDSetting::On;
615 return TargetIDSetting::Off;
617 return TargetIDSetting::Unsupported;
624 return (CPUName.
empty() || CPUName ==
"generic")
639 ? TargetIDSetting::Any
640 : TargetIDSetting::Unsupported;
642 ? TargetIDSetting::Any
643 : TargetIDSetting::Unsupported;
648 TargetIDStr.
split(Split,
':');
649 bool SeenXnack =
false;
650 bool SeenSramEcc =
false;
652 for (
unsigned I = 1,
E = Split.size();
I !=
E; ++
I) {
656 if (SeenXnack ||
XnackSetting == TargetIDSetting::Unsupported ||
657 Sign == TargetIDSetting::Unsupported)
664 if (SeenSramEcc ||
SramEccSetting == TargetIDSetting::Unsupported ||
665 Sign == TargetIDSetting::Unsupported)
699 if (!CPUName.
empty() && CPUName !=
"generic" &&
711 return TargetID(Arch, TT, XnackSetting, SramEccSetting);
714std::optional<TargetID>
720 TargetIDDirective.
split(Parts,
'-', 4);
721 if (Parts.
size() < 5)
724 return parse(
Triple(Parts[0], Parts[1], Parts[2], Parts[3]), Parts[4]);
731 if (SramEcc == TargetIDSetting::Off)
733 else if (SramEcc == TargetIDSetting::On)
736 if (Xnack == TargetIDSetting::Off)
738 else if (Xnack == TargetIDSetting::On)
769 return Arch ==
Other.Arch && XnackSetting ==
Other.XnackSetting &&
770 SramEccSetting ==
Other.SramEccSetting && IsAMDHSA ==
Other.IsAMDHSA &&
771 TargetTripleString ==
Other.TargetTripleString;
776 return Provided == TargetIDSetting::Any ||
777 Provided == TargetIDSetting::Unsupported || Provided == Requested;
782 if (Arch !=
Other.Arch || XnackSetting !=
Other.XnackSetting ||
783 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 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 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 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.