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