28constexpr unsigned NumAMDGPUSubArches =
33enum AMDGPUFeature :
unsigned {
34#define GET_AMDGPU_FEATURE_ENUM
35#include "llvm/TargetParser/AMDGPUTargetParserDef.inc"
42 StringTable::Offset AltName;
48 StringTable::Offset Name;
50 unsigned ArchFeatures;
51 AMDGPUFeatureBitset Features;
53 StringTable::Offset FamilyName;
58 StringTable::Offset Name;
62#define GET_AMDGPU_NAME_TABLE
63#define GET_AMDGPU_GPU_TABLE
64#define GET_AMDGPU_GPU_ALIAS_TABLE
65#define GET_AMDGPU_MAJOR_SUBARCH
66#define GET_AMDGPU_SUBARCH_NAME
67#define GET_AMDGPU_FEATURE_NAME_TABLE
68#include "llvm/TargetParser/AMDGPUTargetParserDef.inc"
70#define GET_R600_NAME_TABLE
71#define GET_R600_GPU_TABLE
72#define GET_R600_GPU_ALIAS_TABLE
73#include "llvm/TargetParser/R600TargetParserDef.inc"
77constexpr StringTable AMDGPUNameStrTab = AMDGPUNameTable;
78constexpr StringTable R600NameStrTab = R600NameTable;
82const GPUInfo *getAMDGPUInfo(
GPUKind AK) {
83 if (AK < AMDGPUFirstGPUKind)
85 unsigned Idx = AK - AMDGPUFirstGPUKind;
86 if (Idx >= std::size(AMDGPUGPUTable))
88 return &AMDGPUGPUTable[Idx];
92const R600Info *getR600Info(
GPUKind AK) {
93 if (AK < R600FirstGPUKind)
95 unsigned Idx = AK - R600FirstGPUKind;
96 if (Idx >= std::size(R600GPUTable))
98 return &R600GPUTable[Idx];
102template <
typename InfoT,
size_t N,
size_t M>
105 const GPUNameAlias (&Aliases)[M]) {
106 for (
unsigned I = 0;
I !=
N; ++
I) {
107 if (CPU == StrTab[
Table[
I].Name])
108 return static_cast<GPUKind>(FirstKind +
I);
111 for (
const GPUNameAlias &
A : Aliases) {
112 if (CPU == StrTab[
A.AltName])
121constexpr std::array<GPUKind, NumAMDGPUSubArches> AMDGPUSubArchToGPUKind = [] {
122 std::array<GPUKind, NumAMDGPUSubArches>
Map{};
124 for (
unsigned I = 0;
I < std::size(AMDGPUGPUTable); ++
I) {
128 static_cast<GPUKind>(AMDGPUFirstGPUKind +
I);
135constexpr std::array<Triple::SubArchType, NumAMDGPUSubArches>
136 AMDGPUMajorFamilies = [] {
137 std::array<Triple::SubArchType, NumAMDGPUSubArches>
Map{};
139 for (
unsigned I = 0;
I < NumAMDGPUSubArches; ++
I) {
144 for (
const AMDGPUMajorSubArchEntry &Entry : AMDGPUMajorSubArch)
151constexpr std::array<StringTable::Offset, NumAMDGPUSubArches>
152 AMDGPUSubArchNameOffsets = [] {
153 std::array<StringTable::Offset, NumAMDGPUSubArches>
Map{};
154 for (
const AMDGPUSubArchNameEntry &Entry : AMDGPUSubArchNames)
161constexpr std::array<StringTable::Offset, NumAMDGPUSubArches>
162 AMDGPUSubArchTripleNameOffsets = [] {
163 std::array<StringTable::Offset, NumAMDGPUSubArches>
Map{};
164 for (
const AMDGPUSubArchNameEntry &Entry : AMDGPUSubArchNames)
166 Entry.TripleNameOffset;
172 const GPUInfo *Info = getAMDGPUInfo(AK);
173 return Info ? AMDGPUNameStrTab[Info->FamilyName] :
"";
177 const GPUInfo *Info = getAMDGPUInfo(AK);
204 return MajorA == MajorB;
206 return MajorA == MajorB;
232 const GPUInfo *Info = getAMDGPUInfo(AK);
246 return A.getArchName().size() == 6;
249 return B.getArchName().size() == 6;
264 if (
A.getSubArch() == MajorA) {
265 if (MajorA == MajorB)
269 if (
B.getSubArch() == MajorB) {
270 if (MajorA == MajorB)
279 const GPUInfo *Info = getAMDGPUInfo(AK);
280 return Info ? AMDGPUNameStrTab[Info->Name] :
"";
287 return AMDGPUNameStrTab[AMDGPUSubArchNameOffsets[SubArch -
293 return AMDGPUNameStrTab[AMDGPUNoSubArchNameOffset];
297 "expected an AMDGPU subarch or NoSubArch");
298 return AMDGPUNameStrTab
303 const R600Info *Info = getR600Info(AK);
304 return Info ? R600NameStrTab[Info->Name] :
"";
308 return parseArchImpl(CPU, AMDGPUGPUTable, AMDGPUFirstGPUKind,
309 AMDGPUNameStrTab, AMDGPUGPUAliases);
313 return parseArchImpl(CPU, R600GPUTable, R600FirstGPUKind, R600NameStrTab,
318 const GPUInfo *Info = getAMDGPUInfo(AK);
327 const R600Info *Info = getR600Info(AK);
335 for (
unsigned I = 0;
I != std::size(AMDGPUGPUTable); ++
I) {
339 Values.push_back(AMDGPUNameStrTab[AMDGPUGPUTable[
I].Name]);
342 for (
const GPUNameAlias &
A : AMDGPUGPUAliases) {
344 Values.push_back(AMDGPUNameStrTab[
A.AltName]);
349 for (
const R600Info &Info : R600GPUTable)
350 Values.push_back(R600NameStrTab[Info.Name]);
351 for (
const GPUNameAlias &
A : R600GPUAliases)
352 Values.push_back(R600NameStrTab[
A.AltName]);
357 return Info ? Info->Version :
IsaVersion{0, 0, 0};
362 return Info ? Info->Version :
IsaVersion{0, 0, 0};
434 for (
unsigned I = 0;
I != NUM_FEATURES; ++
I) {
435 if (!Info.Features.test(
I))
437 StringRef Name = AMDGPUNameStrTab[AMDGPUFeatureNames[
I]];
439 Features[Name] =
true;
441 Features.
insert({Name,
true});
447static std::pair<FeatureError, StringRef>
454 const GPUInfo *Info = getAMDGPUInfo(Kind);
460 const bool TargetHasWave32 =
461 Info && Info->Features.test(FEATURE_WAVEFRONTSIZE32);
462 const bool TargetHasWave64 =
463 Info && Info->Features.test(FEATURE_WAVEFRONTSIZE64);
465 auto Wave32Itr = Features.
find(
"wavefrontsize32");
466 auto Wave64Itr = Features.
find(
"wavefrontsize64");
467 const bool EnableWave32 =
468 Wave32Itr != Features.
end() && Wave32Itr->getValue();
469 const bool EnableWave64 =
470 Wave64Itr != Features.
end() && Wave64Itr->getValue();
471 const bool DisableWave32 =
472 Wave32Itr != Features.
end() && !Wave32Itr->getValue();
473 const bool DisableWave64 =
474 Wave64Itr != Features.
end() && !Wave64Itr->getValue();
476 if (EnableWave32 && EnableWave64)
478 "'+wavefrontsize32' and '+wavefrontsize64' are mutually exclusive"};
479 if (DisableWave32 && DisableWave64)
481 "'-wavefrontsize32' and '-wavefrontsize64' are mutually exclusive"};
484 if (TargetHasWave64) {
491 if (TargetHasWave32) {
501 if (!IsNullGPU && !EnableWave32 && !EnableWave64 && !TargetHasWave32 &&
503 Features.
insert({
"wavefrontsize32",
true});
515std::pair<FeatureError, StringRef>
526 Features[
"wavefrontsize32"] =
true;
527 Features[
"wavefrontsize64"] =
true;
528 }
else if (
T.isAMDGCN()) {
564 TargetTripleString(TT.normalize(
Triple::CanonicalForm::FOUR_IDENT)),
565 XnackSetting(XnackSetting), SramEccSetting(SramEccSetting),
566 IsAMDHSA(TT.getOS() ==
Triple::AMDHSA) {}
572 return TargetIDSetting::On;
574 return TargetIDSetting::Off;
576 return TargetIDSetting::Unsupported;
583 return (CPUName.
empty() || CPUName ==
"generic")
598 ? TargetIDSetting::Any
599 : TargetIDSetting::Unsupported;
601 : TargetIDSetting::Unsupported;
606 TargetIDStr.
split(Split,
':');
607 bool SeenXnack =
false;
608 bool SeenSramEcc =
false;
610 for (
unsigned I = 1,
E = Split.size();
I !=
E; ++
I) {
614 if (SeenXnack ||
XnackSetting == TargetIDSetting::Unsupported ||
615 Sign == TargetIDSetting::Unsupported)
622 if (SeenSramEcc ||
SramEccSetting == TargetIDSetting::Unsupported ||
623 Sign == TargetIDSetting::Unsupported)
657 if (!CPUName.
empty() && CPUName !=
"generic" &&
669 return TargetID(Arch, TT, XnackSetting, SramEccSetting);
672std::optional<TargetID>
678 TargetIDDirective.
split(Parts,
'-', 4);
679 if (Parts.
size() < 5)
682 return parse(
Triple(Parts[0], Parts[1], Parts[2], Parts[3]), Parts[4]);
689 if (SramEcc == TargetIDSetting::Off)
691 else if (SramEcc == TargetIDSetting::On)
694 if (Xnack == TargetIDSetting::Off)
696 else if (Xnack == TargetIDSetting::On)
727 return Arch ==
Other.Arch && XnackSetting ==
Other.XnackSetting &&
728 SramEccSetting ==
Other.SramEccSetting && IsAMDHSA ==
Other.IsAMDHSA &&
729 TargetTripleString ==
Other.TargetTripleString;
734 return Provided == TargetIDSetting::Any ||
735 Provided == TargetIDSetting::Unsupported || Provided == Requested;
740 if (Arch !=
Other.Arch || XnackSetting !=
Other.XnackSetting ||
741 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 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.
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.
std::string getCanonicalTargetIDString() const
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
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
This is a constexpr reimplementation of a subset of std::bitset.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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 StringRef getCanonicalArchName(const Triple &T, StringRef Arch)
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 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.
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
@ FEATURE_XNACK_ON_OFF_MODES
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 StringRef getArchNameAMDGCN(GPUKind AK)
LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK)
LLVM_ABI Triple::SubArchType getMajorSubArch(Triple::SubArchType SubArch)
LLVM_ABI GPUKind parseArchR600(StringRef CPU)
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Instruction set architecture version.