1//===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements a target parser to recognise hardware features such as
10// FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/TargetParser/TargetParser.h"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/TargetParser/Triple.h"
17
18using namespace llvm;
19using namespace AMDGPU;
20
21namespace {
22
23struct GPUInfo {
24 StringLiteral Name;
25 StringLiteral CanonicalName;
26 AMDGPU::GPUKind Kind;
27 unsigned Features;
28};
29
30constexpr GPUInfo R600GPUs[] = {
31 // Name Canonical Kind Features
32 // Name
33 {.Name: {"r600"}, .CanonicalName: {"r600"}, .Kind: GK_R600, .Features: FEATURE_NONE },
34 {.Name: {"rv630"}, .CanonicalName: {"r600"}, .Kind: GK_R600, .Features: FEATURE_NONE },
35 {.Name: {"rv635"}, .CanonicalName: {"r600"}, .Kind: GK_R600, .Features: FEATURE_NONE },
36 {.Name: {"r630"}, .CanonicalName: {"r630"}, .Kind: GK_R630, .Features: FEATURE_NONE },
37 {.Name: {"rs780"}, .CanonicalName: {"rs880"}, .Kind: GK_RS880, .Features: FEATURE_NONE },
38 {.Name: {"rs880"}, .CanonicalName: {"rs880"}, .Kind: GK_RS880, .Features: FEATURE_NONE },
39 {.Name: {"rv610"}, .CanonicalName: {"rs880"}, .Kind: GK_RS880, .Features: FEATURE_NONE },
40 {.Name: {"rv620"}, .CanonicalName: {"rs880"}, .Kind: GK_RS880, .Features: FEATURE_NONE },
41 {.Name: {"rv670"}, .CanonicalName: {"rv670"}, .Kind: GK_RV670, .Features: FEATURE_NONE },
42 {.Name: {"rv710"}, .CanonicalName: {"rv710"}, .Kind: GK_RV710, .Features: FEATURE_NONE },
43 {.Name: {"rv730"}, .CanonicalName: {"rv730"}, .Kind: GK_RV730, .Features: FEATURE_NONE },
44 {.Name: {"rv740"}, .CanonicalName: {"rv770"}, .Kind: GK_RV770, .Features: FEATURE_NONE },
45 {.Name: {"rv770"}, .CanonicalName: {"rv770"}, .Kind: GK_RV770, .Features: FEATURE_NONE },
46 {.Name: {"cedar"}, .CanonicalName: {"cedar"}, .Kind: GK_CEDAR, .Features: FEATURE_NONE },
47 {.Name: {"palm"}, .CanonicalName: {"cedar"}, .Kind: GK_CEDAR, .Features: FEATURE_NONE },
48 {.Name: {"cypress"}, .CanonicalName: {"cypress"}, .Kind: GK_CYPRESS, .Features: FEATURE_FMA },
49 {.Name: {"hemlock"}, .CanonicalName: {"cypress"}, .Kind: GK_CYPRESS, .Features: FEATURE_FMA },
50 {.Name: {"juniper"}, .CanonicalName: {"juniper"}, .Kind: GK_JUNIPER, .Features: FEATURE_NONE },
51 {.Name: {"redwood"}, .CanonicalName: {"redwood"}, .Kind: GK_REDWOOD, .Features: FEATURE_NONE },
52 {.Name: {"sumo"}, .CanonicalName: {"sumo"}, .Kind: GK_SUMO, .Features: FEATURE_NONE },
53 {.Name: {"sumo2"}, .CanonicalName: {"sumo"}, .Kind: GK_SUMO, .Features: FEATURE_NONE },
54 {.Name: {"barts"}, .CanonicalName: {"barts"}, .Kind: GK_BARTS, .Features: FEATURE_NONE },
55 {.Name: {"caicos"}, .CanonicalName: {"caicos"}, .Kind: GK_CAICOS, .Features: FEATURE_NONE },
56 {.Name: {"aruba"}, .CanonicalName: {"cayman"}, .Kind: GK_CAYMAN, .Features: FEATURE_FMA },
57 {.Name: {"cayman"}, .CanonicalName: {"cayman"}, .Kind: GK_CAYMAN, .Features: FEATURE_FMA },
58 {.Name: {"turks"}, .CanonicalName: {"turks"}, .Kind: GK_TURKS, .Features: FEATURE_NONE }
59};
60
61// This table should be sorted by the value of GPUKind
62// Don't bother listing the implicitly true features
63constexpr GPUInfo AMDGCNGPUs[] = {
64 // clang-format off
65 // Name Canonical Kind Features
66 // Name
67 {.Name: {"gfx600"}, .CanonicalName: {"gfx600"}, .Kind: GK_GFX600, .Features: FEATURE_FAST_FMA_F32},
68 {.Name: {"tahiti"}, .CanonicalName: {"gfx600"}, .Kind: GK_GFX600, .Features: FEATURE_FAST_FMA_F32},
69 {.Name: {"gfx601"}, .CanonicalName: {"gfx601"}, .Kind: GK_GFX601, .Features: FEATURE_NONE},
70 {.Name: {"pitcairn"}, .CanonicalName: {"gfx601"}, .Kind: GK_GFX601, .Features: FEATURE_NONE},
71 {.Name: {"verde"}, .CanonicalName: {"gfx601"}, .Kind: GK_GFX601, .Features: FEATURE_NONE},
72 {.Name: {"gfx602"}, .CanonicalName: {"gfx602"}, .Kind: GK_GFX602, .Features: FEATURE_NONE},
73 {.Name: {"hainan"}, .CanonicalName: {"gfx602"}, .Kind: GK_GFX602, .Features: FEATURE_NONE},
74 {.Name: {"oland"}, .CanonicalName: {"gfx602"}, .Kind: GK_GFX602, .Features: FEATURE_NONE},
75 {.Name: {"gfx700"}, .CanonicalName: {"gfx700"}, .Kind: GK_GFX700, .Features: FEATURE_NONE},
76 {.Name: {"kaveri"}, .CanonicalName: {"gfx700"}, .Kind: GK_GFX700, .Features: FEATURE_NONE},
77 {.Name: {"gfx701"}, .CanonicalName: {"gfx701"}, .Kind: GK_GFX701, .Features: FEATURE_FAST_FMA_F32},
78 {.Name: {"hawaii"}, .CanonicalName: {"gfx701"}, .Kind: GK_GFX701, .Features: FEATURE_FAST_FMA_F32},
79 {.Name: {"gfx702"}, .CanonicalName: {"gfx702"}, .Kind: GK_GFX702, .Features: FEATURE_FAST_FMA_F32},
80 {.Name: {"gfx703"}, .CanonicalName: {"gfx703"}, .Kind: GK_GFX703, .Features: FEATURE_NONE},
81 {.Name: {"kabini"}, .CanonicalName: {"gfx703"}, .Kind: GK_GFX703, .Features: FEATURE_NONE},
82 {.Name: {"mullins"}, .CanonicalName: {"gfx703"}, .Kind: GK_GFX703, .Features: FEATURE_NONE},
83 {.Name: {"gfx704"}, .CanonicalName: {"gfx704"}, .Kind: GK_GFX704, .Features: FEATURE_NONE},
84 {.Name: {"bonaire"}, .CanonicalName: {"gfx704"}, .Kind: GK_GFX704, .Features: FEATURE_NONE},
85 {.Name: {"gfx705"}, .CanonicalName: {"gfx705"}, .Kind: GK_GFX705, .Features: FEATURE_NONE},
86 {.Name: {"gfx801"}, .CanonicalName: {"gfx801"}, .Kind: GK_GFX801, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
87 {.Name: {"carrizo"}, .CanonicalName: {"gfx801"}, .Kind: GK_GFX801, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
88 {.Name: {"gfx802"}, .CanonicalName: {"gfx802"}, .Kind: GK_GFX802, .Features: FEATURE_FAST_DENORMAL_F32},
89 {.Name: {"iceland"}, .CanonicalName: {"gfx802"}, .Kind: GK_GFX802, .Features: FEATURE_FAST_DENORMAL_F32},
90 {.Name: {"tonga"}, .CanonicalName: {"gfx802"}, .Kind: GK_GFX802, .Features: FEATURE_FAST_DENORMAL_F32},
91 {.Name: {"gfx803"}, .CanonicalName: {"gfx803"}, .Kind: GK_GFX803, .Features: FEATURE_FAST_DENORMAL_F32},
92 {.Name: {"fiji"}, .CanonicalName: {"gfx803"}, .Kind: GK_GFX803, .Features: FEATURE_FAST_DENORMAL_F32},
93 {.Name: {"polaris10"}, .CanonicalName: {"gfx803"}, .Kind: GK_GFX803, .Features: FEATURE_FAST_DENORMAL_F32},
94 {.Name: {"polaris11"}, .CanonicalName: {"gfx803"}, .Kind: GK_GFX803, .Features: FEATURE_FAST_DENORMAL_F32},
95 {.Name: {"gfx805"}, .CanonicalName: {"gfx805"}, .Kind: GK_GFX805, .Features: FEATURE_FAST_DENORMAL_F32},
96 {.Name: {"tongapro"}, .CanonicalName: {"gfx805"}, .Kind: GK_GFX805, .Features: FEATURE_FAST_DENORMAL_F32},
97 {.Name: {"gfx810"}, .CanonicalName: {"gfx810"}, .Kind: GK_GFX810, .Features: FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
98 {.Name: {"stoney"}, .CanonicalName: {"gfx810"}, .Kind: GK_GFX810, .Features: FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
99 {.Name: {"gfx900"}, .CanonicalName: {"gfx900"}, .Kind: GK_GFX900, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
100 {.Name: {"gfx902"}, .CanonicalName: {"gfx902"}, .Kind: GK_GFX902, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
101 {.Name: {"gfx904"}, .CanonicalName: {"gfx904"}, .Kind: GK_GFX904, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
102 {.Name: {"gfx906"}, .CanonicalName: {"gfx906"}, .Kind: GK_GFX906, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
103 {.Name: {"gfx908"}, .CanonicalName: {"gfx908"}, .Kind: GK_GFX908, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
104 {.Name: {"gfx909"}, .CanonicalName: {"gfx909"}, .Kind: GK_GFX909, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
105 {.Name: {"gfx90a"}, .CanonicalName: {"gfx90a"}, .Kind: GK_GFX90A, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
106 {.Name: {"gfx90c"}, .CanonicalName: {"gfx90c"}, .Kind: GK_GFX90C, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
107 {.Name: {"gfx940"}, .CanonicalName: {"gfx940"}, .Kind: GK_GFX940, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
108 {.Name: {"gfx941"}, .CanonicalName: {"gfx941"}, .Kind: GK_GFX941, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
109 {.Name: {"gfx942"}, .CanonicalName: {"gfx942"}, .Kind: GK_GFX942, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
110 {.Name: {"gfx1010"}, .CanonicalName: {"gfx1010"}, .Kind: GK_GFX1010, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
111 {.Name: {"gfx1011"}, .CanonicalName: {"gfx1011"}, .Kind: GK_GFX1011, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
112 {.Name: {"gfx1012"}, .CanonicalName: {"gfx1012"}, .Kind: GK_GFX1012, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
113 {.Name: {"gfx1013"}, .CanonicalName: {"gfx1013"}, .Kind: GK_GFX1013, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
114 {.Name: {"gfx1030"}, .CanonicalName: {"gfx1030"}, .Kind: GK_GFX1030, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
115 {.Name: {"gfx1031"}, .CanonicalName: {"gfx1031"}, .Kind: GK_GFX1031, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
116 {.Name: {"gfx1032"}, .CanonicalName: {"gfx1032"}, .Kind: GK_GFX1032, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
117 {.Name: {"gfx1033"}, .CanonicalName: {"gfx1033"}, .Kind: GK_GFX1033, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
118 {.Name: {"gfx1034"}, .CanonicalName: {"gfx1034"}, .Kind: GK_GFX1034, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
119 {.Name: {"gfx1035"}, .CanonicalName: {"gfx1035"}, .Kind: GK_GFX1035, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
120 {.Name: {"gfx1036"}, .CanonicalName: {"gfx1036"}, .Kind: GK_GFX1036, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
121 {.Name: {"gfx1100"}, .CanonicalName: {"gfx1100"}, .Kind: GK_GFX1100, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
122 {.Name: {"gfx1101"}, .CanonicalName: {"gfx1101"}, .Kind: GK_GFX1101, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
123 {.Name: {"gfx1102"}, .CanonicalName: {"gfx1102"}, .Kind: GK_GFX1102, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
124 {.Name: {"gfx1103"}, .CanonicalName: {"gfx1103"}, .Kind: GK_GFX1103, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
125 {.Name: {"gfx1150"}, .CanonicalName: {"gfx1150"}, .Kind: GK_GFX1150, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
126 {.Name: {"gfx1151"}, .CanonicalName: {"gfx1151"}, .Kind: GK_GFX1151, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
127 {.Name: {"gfx1200"}, .CanonicalName: {"gfx1200"}, .Kind: GK_GFX1200, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
128 {.Name: {"gfx1201"}, .CanonicalName: {"gfx1201"}, .Kind: GK_GFX1201, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
129
130 {.Name: {"gfx9-generic"}, .CanonicalName: {"gfx9-generic"}, .Kind: GK_GFX9_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
131 {.Name: {"gfx10-1-generic"}, .CanonicalName: {"gfx10-1-generic"}, .Kind: GK_GFX10_1_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
132 {.Name: {"gfx10-3-generic"}, .CanonicalName: {"gfx10-3-generic"}, .Kind: GK_GFX10_3_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
133 {.Name: {"gfx11-generic"}, .CanonicalName: {"gfx11-generic"}, .Kind: GK_GFX11_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
134 // clang-format on
135};
136
137const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef<GPUInfo> Table) {
138 GPUInfo Search = { .Name: {""}, .CanonicalName: {""}, .Kind: AK, .Features: AMDGPU::FEATURE_NONE };
139
140 auto I =
141 llvm::lower_bound(Range&: Table, Value&: Search, C: [](const GPUInfo &A, const GPUInfo &B) {
142 return A.Kind < B.Kind;
143 });
144
145 if (I == Table.end() || I->Kind != Search.Kind)
146 return nullptr;
147 return I;
148}
149
150} // namespace
151
152StringRef llvm::AMDGPU::getArchFamilyNameAMDGCN(GPUKind AK) {
153 switch (AK) {
154 case AMDGPU::GK_GFX9_GENERIC:
155 return "gfx9";
156 case AMDGPU::GK_GFX10_1_GENERIC:
157 case AMDGPU::GK_GFX10_3_GENERIC:
158 return "gfx10";
159 case AMDGPU::GK_GFX11_GENERIC:
160 return "gfx11";
161 default: {
162 StringRef ArchName = getArchNameAMDGCN(AK);
163 return ArchName.empty() ? "" : ArchName.drop_back(N: 2);
164 }
165 }
166}
167
168StringRef llvm::AMDGPU::getArchNameAMDGCN(GPUKind AK) {
169 if (const auto *Entry = getArchEntry(AK, Table: AMDGCNGPUs))
170 return Entry->CanonicalName;
171 return "";
172}
173
174StringRef llvm::AMDGPU::getArchNameR600(GPUKind AK) {
175 if (const auto *Entry = getArchEntry(AK, Table: R600GPUs))
176 return Entry->CanonicalName;
177 return "";
178}
179
180AMDGPU::GPUKind llvm::AMDGPU::parseArchAMDGCN(StringRef CPU) {
181 for (const auto &C : AMDGCNGPUs) {
182 if (CPU == C.Name)
183 return C.Kind;
184 }
185
186 return AMDGPU::GPUKind::GK_NONE;
187}
188
189AMDGPU::GPUKind llvm::AMDGPU::parseArchR600(StringRef CPU) {
190 for (const auto &C : R600GPUs) {
191 if (CPU == C.Name)
192 return C.Kind;
193 }
194
195 return AMDGPU::GPUKind::GK_NONE;
196}
197
198unsigned AMDGPU::getArchAttrAMDGCN(GPUKind AK) {
199 if (const auto *Entry = getArchEntry(AK, Table: AMDGCNGPUs))
200 return Entry->Features;
201 return FEATURE_NONE;
202}
203
204unsigned AMDGPU::getArchAttrR600(GPUKind AK) {
205 if (const auto *Entry = getArchEntry(AK, Table: R600GPUs))
206 return Entry->Features;
207 return FEATURE_NONE;
208}
209
210void AMDGPU::fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values) {
211 // XXX: Should this only report unique canonical names?
212 for (const auto &C : AMDGCNGPUs)
213 Values.push_back(Elt: C.Name);
214}
215
216void AMDGPU::fillValidArchListR600(SmallVectorImpl<StringRef> &Values) {
217 for (const auto &C : R600GPUs)
218 Values.push_back(Elt: C.Name);
219}
220
221AMDGPU::IsaVersion AMDGPU::getIsaVersion(StringRef GPU) {
222 AMDGPU::GPUKind AK = parseArchAMDGCN(CPU: GPU);
223 if (AK == AMDGPU::GPUKind::GK_NONE) {
224 if (GPU == "generic-hsa")
225 return {.Major: 7, .Minor: 0, .Stepping: 0};
226 if (GPU == "generic")
227 return {.Major: 6, .Minor: 0, .Stepping: 0};
228 return {.Major: 0, .Minor: 0, .Stepping: 0};
229 }
230
231 // clang-format off
232 switch (AK) {
233 case GK_GFX600: return {.Major: 6, .Minor: 0, .Stepping: 0};
234 case GK_GFX601: return {.Major: 6, .Minor: 0, .Stepping: 1};
235 case GK_GFX602: return {.Major: 6, .Minor: 0, .Stepping: 2};
236 case GK_GFX700: return {.Major: 7, .Minor: 0, .Stepping: 0};
237 case GK_GFX701: return {.Major: 7, .Minor: 0, .Stepping: 1};
238 case GK_GFX702: return {.Major: 7, .Minor: 0, .Stepping: 2};
239 case GK_GFX703: return {.Major: 7, .Minor: 0, .Stepping: 3};
240 case GK_GFX704: return {.Major: 7, .Minor: 0, .Stepping: 4};
241 case GK_GFX705: return {.Major: 7, .Minor: 0, .Stepping: 5};
242 case GK_GFX801: return {.Major: 8, .Minor: 0, .Stepping: 1};
243 case GK_GFX802: return {.Major: 8, .Minor: 0, .Stepping: 2};
244 case GK_GFX803: return {.Major: 8, .Minor: 0, .Stepping: 3};
245 case GK_GFX805: return {.Major: 8, .Minor: 0, .Stepping: 5};
246 case GK_GFX810: return {.Major: 8, .Minor: 1, .Stepping: 0};
247 case GK_GFX900: return {.Major: 9, .Minor: 0, .Stepping: 0};
248 case GK_GFX902: return {.Major: 9, .Minor: 0, .Stepping: 2};
249 case GK_GFX904: return {.Major: 9, .Minor: 0, .Stepping: 4};
250 case GK_GFX906: return {.Major: 9, .Minor: 0, .Stepping: 6};
251 case GK_GFX908: return {.Major: 9, .Minor: 0, .Stepping: 8};
252 case GK_GFX909: return {.Major: 9, .Minor: 0, .Stepping: 9};
253 case GK_GFX90A: return {.Major: 9, .Minor: 0, .Stepping: 10};
254 case GK_GFX90C: return {.Major: 9, .Minor: 0, .Stepping: 12};
255 case GK_GFX940: return {.Major: 9, .Minor: 4, .Stepping: 0};
256 case GK_GFX941: return {.Major: 9, .Minor: 4, .Stepping: 1};
257 case GK_GFX942: return {.Major: 9, .Minor: 4, .Stepping: 2};
258 case GK_GFX1010: return {.Major: 10, .Minor: 1, .Stepping: 0};
259 case GK_GFX1011: return {.Major: 10, .Minor: 1, .Stepping: 1};
260 case GK_GFX1012: return {.Major: 10, .Minor: 1, .Stepping: 2};
261 case GK_GFX1013: return {.Major: 10, .Minor: 1, .Stepping: 3};
262 case GK_GFX1030: return {.Major: 10, .Minor: 3, .Stepping: 0};
263 case GK_GFX1031: return {.Major: 10, .Minor: 3, .Stepping: 1};
264 case GK_GFX1032: return {.Major: 10, .Minor: 3, .Stepping: 2};
265 case GK_GFX1033: return {.Major: 10, .Minor: 3, .Stepping: 3};
266 case GK_GFX1034: return {.Major: 10, .Minor: 3, .Stepping: 4};
267 case GK_GFX1035: return {.Major: 10, .Minor: 3, .Stepping: 5};
268 case GK_GFX1036: return {.Major: 10, .Minor: 3, .Stepping: 6};
269 case GK_GFX1100: return {.Major: 11, .Minor: 0, .Stepping: 0};
270 case GK_GFX1101: return {.Major: 11, .Minor: 0, .Stepping: 1};
271 case GK_GFX1102: return {.Major: 11, .Minor: 0, .Stepping: 2};
272 case GK_GFX1103: return {.Major: 11, .Minor: 0, .Stepping: 3};
273 case GK_GFX1150: return {.Major: 11, .Minor: 5, .Stepping: 0};
274 case GK_GFX1151: return {.Major: 11, .Minor: 5, .Stepping: 1};
275 case GK_GFX1200: return {.Major: 12, .Minor: 0, .Stepping: 0};
276 case GK_GFX1201: return {.Major: 12, .Minor: 0, .Stepping: 1};
277
278 // Generic targets return the lowest common denominator
279 // within their family. That is, the ISA that is the most
280 // restricted in terms of features.
281 //
282 // gfx9-generic is tricky because there is no lowest
283 // common denominator, so we return gfx900 which has mad-mix
284 // but this family doesn't have it.
285 //
286 // This API should never be used to check for a particular
287 // feature anyway.
288 //
289 // TODO: Split up this API depending on its caller so
290 // generic target handling is more obvious and less risky.
291 case GK_GFX9_GENERIC: return {.Major: 9, .Minor: 0, .Stepping: 0};
292 case GK_GFX10_1_GENERIC: return {.Major: 10, .Minor: 1, .Stepping: 0};
293 case GK_GFX10_3_GENERIC: return {.Major: 10, .Minor: 3, .Stepping: 0};
294 case GK_GFX11_GENERIC: return {.Major: 11, .Minor: 0, .Stepping: 3};
295 default: return {.Major: 0, .Minor: 0, .Stepping: 0};
296 }
297 // clang-format on
298}
299
300StringRef AMDGPU::getCanonicalArchName(const Triple &T, StringRef Arch) {
301 assert(T.isAMDGPU());
302 auto ProcKind = T.isAMDGCN() ? parseArchAMDGCN(CPU: Arch) : parseArchR600(CPU: Arch);
303 if (ProcKind == GK_NONE)
304 return StringRef();
305
306 return T.isAMDGCN() ? getArchNameAMDGCN(AK: ProcKind) : getArchNameR600(AK: ProcKind);
307}
308
309void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
310 StringMap<bool> &Features) {
311 // XXX - What does the member GPU mean if device name string passed here?
312 if (T.isAMDGCN()) {
313 switch (parseArchAMDGCN(CPU: GPU)) {
314 case GK_GFX1201:
315 case GK_GFX1200:
316 Features["ci-insts"] = true;
317 Features["dot7-insts"] = true;
318 Features["dot8-insts"] = true;
319 Features["dot9-insts"] = true;
320 Features["dot10-insts"] = true;
321 Features["dot11-insts"] = true;
322 Features["dl-insts"] = true;
323 Features["atomic-ds-pk-add-16-insts"] = true;
324 Features["atomic-flat-pk-add-16-insts"] = true;
325 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
326 Features["atomic-global-pk-add-bf16-inst"] = true;
327 Features["16-bit-insts"] = true;
328 Features["dpp"] = true;
329 Features["gfx8-insts"] = true;
330 Features["gfx9-insts"] = true;
331 Features["gfx10-insts"] = true;
332 Features["gfx10-3-insts"] = true;
333 Features["gfx11-insts"] = true;
334 Features["gfx12-insts"] = true;
335 Features["atomic-fadd-rtn-insts"] = true;
336 Features["image-insts"] = true;
337 Features["fp8-conversion-insts"] = true;
338 break;
339 case GK_GFX1151:
340 case GK_GFX1150:
341 case GK_GFX1103:
342 case GK_GFX1102:
343 case GK_GFX1101:
344 case GK_GFX1100:
345 case GK_GFX11_GENERIC:
346 Features["ci-insts"] = true;
347 Features["dot5-insts"] = true;
348 Features["dot7-insts"] = true;
349 Features["dot8-insts"] = true;
350 Features["dot9-insts"] = true;
351 Features["dot10-insts"] = true;
352 Features["dl-insts"] = true;
353 Features["16-bit-insts"] = true;
354 Features["dpp"] = true;
355 Features["gfx8-insts"] = true;
356 Features["gfx9-insts"] = true;
357 Features["gfx10-insts"] = true;
358 Features["gfx10-3-insts"] = true;
359 Features["gfx11-insts"] = true;
360 Features["atomic-fadd-rtn-insts"] = true;
361 Features["image-insts"] = true;
362 Features["gws"] = true;
363 break;
364 case GK_GFX1036:
365 case GK_GFX1035:
366 case GK_GFX1034:
367 case GK_GFX1033:
368 case GK_GFX1032:
369 case GK_GFX1031:
370 case GK_GFX1030:
371 case GK_GFX10_3_GENERIC:
372 Features["ci-insts"] = true;
373 Features["dot1-insts"] = true;
374 Features["dot2-insts"] = true;
375 Features["dot5-insts"] = true;
376 Features["dot6-insts"] = true;
377 Features["dot7-insts"] = true;
378 Features["dot10-insts"] = true;
379 Features["dl-insts"] = true;
380 Features["16-bit-insts"] = true;
381 Features["dpp"] = true;
382 Features["gfx8-insts"] = true;
383 Features["gfx9-insts"] = true;
384 Features["gfx10-insts"] = true;
385 Features["gfx10-3-insts"] = true;
386 Features["image-insts"] = true;
387 Features["s-memrealtime"] = true;
388 Features["s-memtime-inst"] = true;
389 Features["gws"] = true;
390 break;
391 case GK_GFX1012:
392 case GK_GFX1011:
393 Features["dot1-insts"] = true;
394 Features["dot2-insts"] = true;
395 Features["dot5-insts"] = true;
396 Features["dot6-insts"] = true;
397 Features["dot7-insts"] = true;
398 Features["dot10-insts"] = true;
399 [[fallthrough]];
400 case GK_GFX1013:
401 case GK_GFX1010:
402 case GK_GFX10_1_GENERIC:
403 Features["dl-insts"] = true;
404 Features["ci-insts"] = true;
405 Features["16-bit-insts"] = true;
406 Features["dpp"] = true;
407 Features["gfx8-insts"] = true;
408 Features["gfx9-insts"] = true;
409 Features["gfx10-insts"] = true;
410 Features["image-insts"] = true;
411 Features["s-memrealtime"] = true;
412 Features["s-memtime-inst"] = true;
413 Features["gws"] = true;
414 break;
415 case GK_GFX942:
416 case GK_GFX941:
417 case GK_GFX940:
418 Features["gfx940-insts"] = true;
419 Features["fp8-insts"] = true;
420 Features["fp8-conversion-insts"] = true;
421 Features["atomic-ds-pk-add-16-insts"] = true;
422 Features["atomic-flat-pk-add-16-insts"] = true;
423 Features["atomic-global-pk-add-bf16-inst"] = true;
424 Features["gfx90a-insts"] = true;
425 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
426 Features["atomic-fadd-rtn-insts"] = true;
427 Features["dot3-insts"] = true;
428 Features["dot4-insts"] = true;
429 Features["dot5-insts"] = true;
430 Features["dot6-insts"] = true;
431 Features["mai-insts"] = true;
432 Features["dl-insts"] = true;
433 Features["dot1-insts"] = true;
434 Features["dot2-insts"] = true;
435 Features["dot7-insts"] = true;
436 Features["dot10-insts"] = true;
437 Features["gfx9-insts"] = true;
438 Features["gfx8-insts"] = true;
439 Features["16-bit-insts"] = true;
440 Features["dpp"] = true;
441 Features["s-memrealtime"] = true;
442 Features["ci-insts"] = true;
443 Features["s-memtime-inst"] = true;
444 Features["gws"] = true;
445 break;
446 case GK_GFX90A:
447 Features["gfx90a-insts"] = true;
448 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
449 Features["atomic-fadd-rtn-insts"] = true;
450 [[fallthrough]];
451 case GK_GFX908:
452 Features["dot3-insts"] = true;
453 Features["dot4-insts"] = true;
454 Features["dot5-insts"] = true;
455 Features["dot6-insts"] = true;
456 Features["mai-insts"] = true;
457 [[fallthrough]];
458 case GK_GFX906:
459 Features["dl-insts"] = true;
460 Features["dot1-insts"] = true;
461 Features["dot2-insts"] = true;
462 Features["dot7-insts"] = true;
463 Features["dot10-insts"] = true;
464 [[fallthrough]];
465 case GK_GFX90C:
466 case GK_GFX909:
467 case GK_GFX904:
468 case GK_GFX902:
469 case GK_GFX900:
470 case GK_GFX9_GENERIC:
471 Features["gfx9-insts"] = true;
472 [[fallthrough]];
473 case GK_GFX810:
474 case GK_GFX805:
475 case GK_GFX803:
476 case GK_GFX802:
477 case GK_GFX801:
478 Features["gfx8-insts"] = true;
479 Features["16-bit-insts"] = true;
480 Features["dpp"] = true;
481 Features["s-memrealtime"] = true;
482 [[fallthrough]];
483 case GK_GFX705:
484 case GK_GFX704:
485 case GK_GFX703:
486 case GK_GFX702:
487 case GK_GFX701:
488 case GK_GFX700:
489 Features["ci-insts"] = true;
490 [[fallthrough]];
491 case GK_GFX602:
492 case GK_GFX601:
493 case GK_GFX600:
494 Features["image-insts"] = true;
495 Features["s-memtime-inst"] = true;
496 Features["gws"] = true;
497 break;
498 case GK_NONE:
499 break;
500 default:
501 llvm_unreachable("Unhandled GPU!");
502 }
503 } else {
504 if (GPU.empty())
505 GPU = "r600";
506
507 switch (llvm::AMDGPU::parseArchR600(CPU: GPU)) {
508 case GK_CAYMAN:
509 case GK_CYPRESS:
510 case GK_RV770:
511 case GK_RV670:
512 // TODO: Add fp64 when implemented.
513 break;
514 case GK_TURKS:
515 case GK_CAICOS:
516 case GK_BARTS:
517 case GK_SUMO:
518 case GK_REDWOOD:
519 case GK_JUNIPER:
520 case GK_CEDAR:
521 case GK_RV730:
522 case GK_RV710:
523 case GK_RS880:
524 case GK_R630:
525 case GK_R600:
526 break;
527 default:
528 llvm_unreachable("Unhandled GPU!");
529 }
530 }
531}
532
533static bool isWave32Capable(StringRef GPU, const Triple &T) {
534 bool IsWave32Capable = false;
535 // XXX - What does the member GPU mean if device name string passed here?
536 if (T.isAMDGCN()) {
537 switch (parseArchAMDGCN(CPU: GPU)) {
538 case GK_GFX1201:
539 case GK_GFX1200:
540 case GK_GFX1151:
541 case GK_GFX1150:
542 case GK_GFX1103:
543 case GK_GFX1102:
544 case GK_GFX1101:
545 case GK_GFX1100:
546 case GK_GFX1036:
547 case GK_GFX1035:
548 case GK_GFX1034:
549 case GK_GFX1033:
550 case GK_GFX1032:
551 case GK_GFX1031:
552 case GK_GFX1030:
553 case GK_GFX1012:
554 case GK_GFX1011:
555 case GK_GFX1013:
556 case GK_GFX1010:
557 case GK_GFX11_GENERIC:
558 case GK_GFX10_3_GENERIC:
559 case GK_GFX10_1_GENERIC:
560 IsWave32Capable = true;
561 break;
562 default:
563 break;
564 }
565 }
566 return IsWave32Capable;
567}
568
569bool AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
570 StringMap<bool> &Features,
571 std::string &ErrorMsg) {
572 bool IsWave32Capable = isWave32Capable(GPU, T);
573 const bool IsNullGPU = GPU.empty();
574 // FIXME: Not diagnosing wavefrontsize32 on wave64 only targets.
575 const bool HaveWave32 =
576 (IsWave32Capable || IsNullGPU) && Features.count(Key: "wavefrontsize32");
577 const bool HaveWave64 = Features.count(Key: "wavefrontsize64");
578 if (HaveWave32 && HaveWave64) {
579 ErrorMsg = "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive";
580 return false;
581 }
582 // Don't assume any wavesize with an unknown subtarget.
583 if (!IsNullGPU) {
584 // Default to wave32 if available, or wave64 if not
585 if (!HaveWave32 && !HaveWave64) {
586 StringRef DefaultWaveSizeFeature =
587 IsWave32Capable ? "wavefrontsize32" : "wavefrontsize64";
588 Features.insert(KV: std::make_pair(x&: DefaultWaveSizeFeature, y: true));
589 }
590 }
591 return true;
592}
593

source code of llvm/lib/TargetParser/TargetParser.cpp