27constexpr unsigned NumAMDGPUSubArches =
32 StringTable::Offset AltName;
38 StringTable::Offset Name;
40 unsigned ArchFeatures;
43 StringTable::Offset FamilyName;
48 StringTable::Offset Name;
52#define GET_AMDGPU_NAME_TABLE
53#define GET_AMDGPU_GPU_TABLE
54#define GET_AMDGPU_GPU_ALIAS_TABLE
55#define GET_AMDGPU_MAJOR_SUBARCH
56#define GET_AMDGPU_SUBARCH_NAME
57#define GET_AMDGPU_FEATURE_NAME_TABLE
58#include "llvm/TargetParser/AMDGPUTargetParserDef.inc"
60#define GET_R600_NAME_TABLE
61#define GET_R600_GPU_TABLE
62#define GET_R600_GPU_ALIAS_TABLE
63#include "llvm/TargetParser/R600TargetParserDef.inc"
67constexpr StringTable AMDGPUNameStrTab = AMDGPUNameTable;
68constexpr StringTable R600NameStrTab = R600NameTable;
72const GPUInfo *getAMDGPUInfo(
GPUKind AK) {
73 if (AK < AMDGPUFirstGPUKind)
75 unsigned Idx = AK - AMDGPUFirstGPUKind;
76 if (Idx >= std::size(AMDGPUGPUTable))
78 return &AMDGPUGPUTable[Idx];
82const R600Info *getR600Info(
GPUKind AK) {
83 if (AK < R600FirstGPUKind)
85 unsigned Idx = AK - R600FirstGPUKind;
86 if (Idx >= std::size(R600GPUTable))
88 return &R600GPUTable[Idx];
92template <
typename InfoT,
size_t N,
size_t M>
95 const GPUNameAlias (&Aliases)[M]) {
96 for (
unsigned I = 0;
I !=
N; ++
I) {
97 if (CPU == StrTab[
Table[
I].Name])
98 return static_cast<GPUKind>(FirstKind +
I);
101 for (
const GPUNameAlias &
A : Aliases) {
102 if (CPU == StrTab[
A.AltName])
111constexpr std::array<GPUKind, NumAMDGPUSubArches> AMDGPUSubArchToGPUKind = [] {
112 std::array<GPUKind, NumAMDGPUSubArches>
Map{};
114 for (
unsigned I = 0;
I < std::size(AMDGPUGPUTable); ++
I) {
118 static_cast<GPUKind>(AMDGPUFirstGPUKind +
I);
125constexpr std::array<Triple::SubArchType, NumAMDGPUSubArches>
126 AMDGPUMajorFamilies = [] {
127 std::array<Triple::SubArchType, NumAMDGPUSubArches>
Map{};
129 for (
unsigned I = 0;
I < NumAMDGPUSubArches; ++
I) {
134 for (
const AMDGPUMajorSubArchEntry &Entry : AMDGPUMajorSubArch)
141constexpr std::array<StringTable::Offset, NumAMDGPUSubArches>
142 AMDGPUSubArchNameOffsets = [] {
143 std::array<StringTable::Offset, NumAMDGPUSubArches>
Map{};
144 for (
const AMDGPUSubArchNameEntry &Entry : AMDGPUSubArchNames)
151constexpr std::array<StringTable::Offset, NumAMDGPUSubArches>
152 AMDGPUSubArchTripleNameOffsets = [] {
153 std::array<StringTable::Offset, NumAMDGPUSubArches>
Map{};
154 for (
const AMDGPUSubArchNameEntry &Entry : AMDGPUSubArchNames)
156 Entry.TripleNameOffset;
162 const GPUInfo *Info = getAMDGPUInfo(AK);
163 return Info ? AMDGPUNameStrTab[Info->FamilyName] :
"";
167 const GPUInfo *Info = getAMDGPUInfo(AK);
194 return MajorA == MajorB;
196 return MajorA == MajorB;
222 const GPUInfo *Info = getAMDGPUInfo(AK);
236 return A.getArchName().size() == 6;
239 return B.getArchName().size() == 6;
254 if (
A.getSubArch() == MajorA) {
255 if (MajorA == MajorB)
259 if (
B.getSubArch() == MajorB) {
260 if (MajorA == MajorB)
269 const GPUInfo *Info = getAMDGPUInfo(AK);
270 return Info ? AMDGPUNameStrTab[Info->Name] :
"";
277 return AMDGPUNameStrTab[AMDGPUSubArchNameOffsets[SubArch -
283 return AMDGPUNameStrTab[AMDGPUNoSubArchNameOffset];
287 "expected an AMDGPU subarch or NoSubArch");
288 return AMDGPUNameStrTab
293 const R600Info *Info = getR600Info(AK);
294 return Info ? R600NameStrTab[Info->Name] :
"";
298 return parseArchImpl(CPU, AMDGPUGPUTable, AMDGPUFirstGPUKind,
299 AMDGPUNameStrTab, AMDGPUGPUAliases);
303 return parseArchImpl(CPU, R600GPUTable, R600FirstGPUKind, R600NameStrTab,
308 const GPUInfo *Info = getAMDGPUInfo(AK);
317 const R600Info *Info = getR600Info(AK);
323 const GPUInfo *Info = getAMDGPUInfo(AK);
324 return Info ? Info->Features :
Empty;
329 for (
unsigned I = 0;
I != NUM_FEATURES; ++
I) {
330 if (Features.
test(
I))
331 Names.
push_back(AMDGPUNameStrTab[AMDGPUFeatureNames[
I]]);
339 for (
unsigned I = 0;
I != std::size(AMDGPUGPUTable); ++
I) {
343 Values.push_back(AMDGPUNameStrTab[AMDGPUGPUTable[
I].Name]);
346 for (
const GPUNameAlias &
A : AMDGPUGPUAliases) {
348 Values.push_back(AMDGPUNameStrTab[
A.AltName]);
353 for (
const R600Info &Info : R600GPUTable)
354 Values.push_back(R600NameStrTab[Info.Name]);
355 for (
const GPUNameAlias &
A : R600GPUAliases)
356 Values.push_back(R600NameStrTab[
A.AltName]);
361 return Info ? Info->Version :
IsaVersion{0, 0, 0};
366 return Info ? Info->Version :
IsaVersion{0, 0, 0};
442 Features[Name] =
true;
444 Features.
insert({Name,
true});
450static std::pair<FeatureError, StringRef>
457 const GPUInfo *Info = getAMDGPUInfo(Kind);
463 const bool TargetHasWave32 =
464 Info && Info->Features.test(FEAT_WAVEFRONTSIZE32);
465 const bool TargetHasWave64 =
466 Info && Info->Features.test(FEAT_WAVEFRONTSIZE64);
468 auto Wave32Itr = Features.
find(
"wavefrontsize32");
469 auto Wave64Itr = Features.
find(
"wavefrontsize64");
470 const bool EnableWave32 =
471 Wave32Itr != Features.
end() && Wave32Itr->getValue();
472 const bool EnableWave64 =
473 Wave64Itr != Features.
end() && Wave64Itr->getValue();
474 const bool DisableWave32 =
475 Wave32Itr != Features.
end() && !Wave32Itr->getValue();
476 const bool DisableWave64 =
477 Wave64Itr != Features.
end() && !Wave64Itr->getValue();
479 if (EnableWave32 && EnableWave64)
481 "'+wavefrontsize32' and '+wavefrontsize64' are mutually exclusive"};
482 if (DisableWave32 && DisableWave64)
484 "'-wavefrontsize32' and '-wavefrontsize64' are mutually exclusive"};
487 if (TargetHasWave64) {
494 if (TargetHasWave32) {
504 if (!IsNullGPU && !EnableWave32 && !EnableWave64 && !TargetHasWave32 &&
506 Features.
insert({
"wavefrontsize32",
true});
518std::pair<FeatureError, StringRef>
529 Features[
"wavefrontsize32"] =
true;
530 Features[
"wavefrontsize64"] =
true;
531 }
else if (
T.isAMDGCN()) {
567 TargetTripleString(TT.normalize(
Triple::CanonicalForm::FOUR_IDENT)),
568 XnackSetting(XnackSetting), SramEccSetting(SramEccSetting),
569 IsAMDHSA(TT.getOS() ==
Triple::AMDHSA) {}
575 return TargetIDSetting::On;
577 return TargetIDSetting::Off;
579 return TargetIDSetting::Unsupported;
586 return (CPUName.
empty() || CPUName ==
"generic")
601 ? TargetIDSetting::Any
602 : TargetIDSetting::Unsupported;
604 : TargetIDSetting::Unsupported;
609 TargetIDStr.
split(Split,
':');
610 bool SeenXnack =
false;
611 bool SeenSramEcc =
false;
613 for (
unsigned I = 1,
E = Split.size();
I !=
E; ++
I) {
617 if (SeenXnack ||
XnackSetting == TargetIDSetting::Unsupported ||
618 Sign == TargetIDSetting::Unsupported)
625 if (SeenSramEcc ||
SramEccSetting == TargetIDSetting::Unsupported ||
626 Sign == TargetIDSetting::Unsupported)
660 if (!CPUName.
empty() && CPUName !=
"generic" &&
672 return TargetID(Arch, TT, XnackSetting, SramEccSetting);
675std::optional<TargetID>
681 TargetIDDirective.
split(Parts,
'-', 4);
682 if (Parts.
size() < 5)
685 return parse(
Triple(Parts[0], Parts[1], Parts[2], Parts[3]), Parts[4]);
692 if (SramEcc == TargetIDSetting::Off)
694 else if (SramEcc == TargetIDSetting::On)
697 if (Xnack == TargetIDSetting::Off)
699 else if (Xnack == TargetIDSetting::On)
730 return Arch ==
Other.Arch && XnackSetting ==
Other.XnackSetting &&
731 SramEccSetting ==
Other.SramEccSetting && IsAMDHSA ==
Other.IsAMDHSA &&
732 TargetTripleString ==
Other.TargetTripleString;
737 return Provided == TargetIDSetting::Any ||
738 Provided == TargetIDSetting::Unsupported || Provided == Requested;
743 if (Arch !=
Other.Arch || XnackSetting !=
Other.XnackSetting ||
744 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.
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 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.
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
@ 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 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.