LLVM 23.0.0git
TargetParser.cpp
Go to the documentation of this file.
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
15#include "llvm/ADT/ArrayRef.h"
17
18using namespace llvm;
19using namespace AMDGPU;
20
21/// Find KV in array using binary search.
22static const BasicSubtargetSubTypeKV *
24 // Binary search the array
25 auto F = llvm::lower_bound(A, S);
26 // If not found then return NULL
27 if (F == A.end() || StringRef(F->Key) != S)
28 return nullptr;
29 // Return the found array item
30 return F;
31}
32
33/// For each feature that is (transitively) implied by this feature, set it.
34static void setImpliedBits(FeatureBitset &Bits, const FeatureBitset &Implies,
36 // OR the Implies bits in outside the loop. This allows the Implies for CPUs
37 // which might imply features not in FeatureTable to use this.
38 Bits |= Implies;
39 for (const auto &FE : FeatureTable)
40 if (Implies.test(FE.Value))
41 setImpliedBits(Bits, FE.Implies.getAsBitset(), FeatureTable);
42}
43
44std::optional<llvm::StringMap<bool>> llvm::getCPUDefaultTargetFeatures(
47 if (CPU.empty())
48 return std::nullopt;
49
50 const BasicSubtargetSubTypeKV *CPUEntry = ::find(CPU, ProcDesc);
51 if (!CPUEntry)
52 return std::nullopt;
53
54 // Set the features implied by this CPU feature if there is a match.
55 FeatureBitset Bits;
56 llvm::StringMap<bool> DefaultFeatures;
57 setImpliedBits(Bits, CPUEntry->Implies.getAsBitset(), ProcFeatures);
58
59 [[maybe_unused]] unsigned BitSize = Bits.size();
60 for (const BasicSubtargetFeatureKV &FE : ProcFeatures) {
61 assert(FE.Value < BitSize && "Target Feature is out of range");
62 if (Bits[FE.Value])
63 DefaultFeatures[FE.Key] = true;
64 }
65 return DefaultFeatures;
66}
67
68namespace {
69
70struct GPUInfo {
71 StringLiteral Name;
72 StringLiteral CanonicalName;
73 AMDGPU::GPUKind Kind;
74 unsigned Features;
75};
76
77constexpr GPUInfo R600GPUs[] = {
78 // Name Canonical Kind Features
79 // Name
80 {{"r600"}, {"r600"}, GK_R600, FEATURE_NONE },
81 {{"rv630"}, {"r600"}, GK_R600, FEATURE_NONE },
82 {{"rv635"}, {"r600"}, GK_R600, FEATURE_NONE },
83 {{"r630"}, {"r630"}, GK_R630, FEATURE_NONE },
84 {{"rs780"}, {"rs880"}, GK_RS880, FEATURE_NONE },
85 {{"rs880"}, {"rs880"}, GK_RS880, FEATURE_NONE },
86 {{"rv610"}, {"rs880"}, GK_RS880, FEATURE_NONE },
87 {{"rv620"}, {"rs880"}, GK_RS880, FEATURE_NONE },
88 {{"rv670"}, {"rv670"}, GK_RV670, FEATURE_NONE },
89 {{"rv710"}, {"rv710"}, GK_RV710, FEATURE_NONE },
90 {{"rv730"}, {"rv730"}, GK_RV730, FEATURE_NONE },
91 {{"rv740"}, {"rv770"}, GK_RV770, FEATURE_NONE },
92 {{"rv770"}, {"rv770"}, GK_RV770, FEATURE_NONE },
93 {{"cedar"}, {"cedar"}, GK_CEDAR, FEATURE_NONE },
94 {{"palm"}, {"cedar"}, GK_CEDAR, FEATURE_NONE },
95 {{"cypress"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA },
96 {{"hemlock"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA },
97 {{"juniper"}, {"juniper"}, GK_JUNIPER, FEATURE_NONE },
98 {{"redwood"}, {"redwood"}, GK_REDWOOD, FEATURE_NONE },
99 {{"sumo"}, {"sumo"}, GK_SUMO, FEATURE_NONE },
100 {{"sumo2"}, {"sumo"}, GK_SUMO, FEATURE_NONE },
101 {{"barts"}, {"barts"}, GK_BARTS, FEATURE_NONE },
102 {{"caicos"}, {"caicos"}, GK_CAICOS, FEATURE_NONE },
103 {{"aruba"}, {"cayman"}, GK_CAYMAN, FEATURE_FMA },
104 {{"cayman"}, {"cayman"}, GK_CAYMAN, FEATURE_FMA },
105 {{"turks"}, {"turks"}, GK_TURKS, FEATURE_NONE }
106};
107
108// This table should be sorted by the value of GPUKind
109// Don't bother listing the implicitly true features
110constexpr GPUInfo AMDGCNGPUs[] = {
111 // clang-format off
112 // Name Canonical Kind Features
113 // Name
114 {{"gfx600"}, {"gfx600"}, GK_GFX600, FEATURE_FAST_FMA_F32},
115 {{"tahiti"}, {"gfx600"}, GK_GFX600, FEATURE_FAST_FMA_F32},
116 {{"gfx601"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
117 {{"pitcairn"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
118 {{"verde"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
119 {{"gfx602"}, {"gfx602"}, GK_GFX602, FEATURE_NONE},
120 {{"hainan"}, {"gfx602"}, GK_GFX602, FEATURE_NONE},
121 {{"oland"}, {"gfx602"}, GK_GFX602, FEATURE_NONE},
122 {{"gfx700"}, {"gfx700"}, GK_GFX700, FEATURE_NONE},
123 {{"kaveri"}, {"gfx700"}, GK_GFX700, FEATURE_NONE},
124 {{"gfx701"}, {"gfx701"}, GK_GFX701, FEATURE_FAST_FMA_F32},
125 {{"hawaii"}, {"gfx701"}, GK_GFX701, FEATURE_FAST_FMA_F32},
126 {{"gfx702"}, {"gfx702"}, GK_GFX702, FEATURE_FAST_FMA_F32},
127 {{"gfx703"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
128 {{"kabini"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
129 {{"mullins"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
130 {{"gfx704"}, {"gfx704"}, GK_GFX704, FEATURE_NONE},
131 {{"bonaire"}, {"gfx704"}, GK_GFX704, FEATURE_NONE},
132 {{"gfx705"}, {"gfx705"}, GK_GFX705, FEATURE_NONE},
135 {{"gfx802"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
136 {{"iceland"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
137 {{"tonga"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
138 {{"gfx803"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
139 {{"fiji"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
140 {{"polaris10"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
141 {{"polaris11"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
142 {{"gfx805"}, {"gfx805"}, GK_GFX805, FEATURE_FAST_DENORMAL_F32},
143 {{"tongapro"}, {"gfx805"}, GK_GFX805, FEATURE_FAST_DENORMAL_F32},
144 {{"gfx810"}, {"gfx810"}, GK_GFX810, FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
145 {{"stoney"}, {"gfx810"}, GK_GFX810, FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
180
187 // clang-format on
188};
189
190const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef<GPUInfo> Table) {
191 GPUInfo Search = { {""}, {""}, AK, AMDGPU::FEATURE_NONE };
192
193 auto I =
194 llvm::lower_bound(Table, Search, [](const GPUInfo &A, const GPUInfo &B) {
195 return A.Kind < B.Kind;
196 });
197
198 if (I == Table.end() || I->Kind != Search.Kind)
199 return nullptr;
200 return I;
201}
202
203} // namespace
204
206 switch (AK) {
209 return "gfx9";
212 return "gfx10";
214 return "gfx11";
216 return "gfx12";
217 default: {
218 StringRef ArchName = getArchNameAMDGCN(AK);
219 return ArchName.empty() ? "" : ArchName.drop_back(2);
220 }
221 }
222}
223
225 if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
226 return Entry->CanonicalName;
227 return "";
228}
229
231 if (const auto *Entry = getArchEntry(AK, R600GPUs))
232 return Entry->CanonicalName;
233 return "";
234}
235
237 for (const auto &C : AMDGCNGPUs) {
238 if (CPU == C.Name)
239 return C.Kind;
240 }
241
243}
244
246 for (const auto &C : R600GPUs) {
247 if (CPU == C.Name)
248 return C.Kind;
249 }
250
252}
253
255 if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
256 return Entry->Features;
257 return FEATURE_NONE;
258}
259
261 if (const auto *Entry = getArchEntry(AK, R600GPUs))
262 return Entry->Features;
263 return FEATURE_NONE;
264}
265
267 // XXX: Should this only report unique canonical names?
268 for (const auto &C : AMDGCNGPUs)
269 Values.push_back(C.Name);
270}
271
273 for (const auto &C : R600GPUs)
274 Values.push_back(C.Name);
275}
276
279 if (AK == AMDGPU::GPUKind::GK_NONE) {
280 if (GPU == "generic-hsa")
281 return {7, 0, 0};
282 if (GPU == "generic")
283 return {6, 0, 0};
284 return {0, 0, 0};
285 }
286
287 // clang-format off
288 switch (AK) {
289 case GK_GFX600: return {6, 0, 0};
290 case GK_GFX601: return {6, 0, 1};
291 case GK_GFX602: return {6, 0, 2};
292 case GK_GFX700: return {7, 0, 0};
293 case GK_GFX701: return {7, 0, 1};
294 case GK_GFX702: return {7, 0, 2};
295 case GK_GFX703: return {7, 0, 3};
296 case GK_GFX704: return {7, 0, 4};
297 case GK_GFX705: return {7, 0, 5};
298 case GK_GFX801: return {8, 0, 1};
299 case GK_GFX802: return {8, 0, 2};
300 case GK_GFX803: return {8, 0, 3};
301 case GK_GFX805: return {8, 0, 5};
302 case GK_GFX810: return {8, 1, 0};
303 case GK_GFX900: return {9, 0, 0};
304 case GK_GFX902: return {9, 0, 2};
305 case GK_GFX904: return {9, 0, 4};
306 case GK_GFX906: return {9, 0, 6};
307 case GK_GFX908: return {9, 0, 8};
308 case GK_GFX909: return {9, 0, 9};
309 case GK_GFX90A: return {9, 0, 10};
310 case GK_GFX90C: return {9, 0, 12};
311 case GK_GFX942: return {9, 4, 2};
312 case GK_GFX950: return {9, 5, 0};
313 case GK_GFX1010: return {10, 1, 0};
314 case GK_GFX1011: return {10, 1, 1};
315 case GK_GFX1012: return {10, 1, 2};
316 case GK_GFX1013: return {10, 1, 3};
317 case GK_GFX1030: return {10, 3, 0};
318 case GK_GFX1031: return {10, 3, 1};
319 case GK_GFX1032: return {10, 3, 2};
320 case GK_GFX1033: return {10, 3, 3};
321 case GK_GFX1034: return {10, 3, 4};
322 case GK_GFX1035: return {10, 3, 5};
323 case GK_GFX1036: return {10, 3, 6};
324 case GK_GFX1100: return {11, 0, 0};
325 case GK_GFX1101: return {11, 0, 1};
326 case GK_GFX1102: return {11, 0, 2};
327 case GK_GFX1103: return {11, 0, 3};
328 case GK_GFX1150: return {11, 5, 0};
329 case GK_GFX1151: return {11, 5, 1};
330 case GK_GFX1152: return {11, 5, 2};
331 case GK_GFX1153: return {11, 5, 3};
332 case GK_GFX1200: return {12, 0, 0};
333 case GK_GFX1201: return {12, 0, 1};
334 case GK_GFX1250: return {12, 5, 0};
335 case GK_GFX1251: return {12, 5, 1};
336 case GK_GFX1310: return {13, 1, 0};
337
338 // Generic targets return the lowest common denominator
339 // within their family. That is, the ISA that is the most
340 // restricted in terms of features.
341 //
342 // gfx9-generic is tricky because there is no lowest
343 // common denominator, so we return gfx900 which has mad-mix
344 // but this family doesn't have it.
345 //
346 // This API should never be used to check for a particular
347 // feature anyway.
348 //
349 // TODO: Split up this API depending on its caller so
350 // generic target handling is more obvious and less risky.
351 case GK_GFX9_GENERIC: return {9, 0, 0};
352 case GK_GFX9_4_GENERIC: return {9, 4, 0};
353 case GK_GFX10_1_GENERIC: return {10, 1, 0};
354 case GK_GFX10_3_GENERIC: return {10, 3, 0};
355 case GK_GFX11_GENERIC: return {11, 0, 3};
356 case GK_GFX12_GENERIC: return {12, 0, 0};
357 default: return {0, 0, 0};
358 }
359 // clang-format on
360}
361
363 assert(T.isAMDGPU());
364 auto ProcKind = T.isAMDGCN() ? parseArchAMDGCN(Arch) : parseArchR600(Arch);
365 if (ProcKind == GK_NONE)
366 return StringRef();
367
368 return T.isAMDGCN() ? getArchNameAMDGCN(ProcKind) : getArchNameR600(ProcKind);
369}
370
371static std::pair<FeatureError, StringRef>
373 const StringMap<bool> &DefaultFeatures,
374 StringMap<bool> &Features) {
375 const bool IsNullGPU = GPU.empty();
376 const bool TargetHasWave32 = DefaultFeatures.count("wavefrontsize32");
377 const bool TargetHasWave64 = DefaultFeatures.count("wavefrontsize64");
378
379 auto Wave32Itr = Features.find("wavefrontsize32");
380 auto Wave64Itr = Features.find("wavefrontsize64");
381 const bool EnableWave32 =
382 Wave32Itr != Features.end() && Wave32Itr->getValue();
383 const bool EnableWave64 =
384 Wave64Itr != Features.end() && Wave64Itr->getValue();
385 const bool DisableWave32 =
386 Wave32Itr != Features.end() && !Wave32Itr->getValue();
387 const bool DisableWave64 =
388 Wave64Itr != Features.end() && !Wave64Itr->getValue();
389
390 if (EnableWave32 && EnableWave64)
392 "'+wavefrontsize32' and '+wavefrontsize64' are mutually exclusive"};
393 if (DisableWave32 && DisableWave64)
395 "'-wavefrontsize32' and '-wavefrontsize64' are mutually exclusive"};
396
397 if (!IsNullGPU) {
398 if (TargetHasWave64) {
399 if (EnableWave32)
400 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "+wavefrontsize32"};
401 if (DisableWave64)
402 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "-wavefrontsize64"};
403 }
404
405 if (TargetHasWave32) {
406 if (EnableWave64)
407 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "+wavefrontsize64"};
408 if (DisableWave32)
409 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "-wavefrontsize32"};
410 }
411 }
412
413 // Don't assume any wavesize with an unknown subtarget.
414 // Default to wave32 if target supports both.
415 if (!IsNullGPU && !EnableWave32 && !EnableWave64 && !TargetHasWave32 &&
416 !TargetHasWave64)
417 Features.insert(std::make_pair("wavefrontsize32", true));
418
419 for (const auto &Entry : DefaultFeatures) {
420 if (!Features.count(Entry.getKey()))
421 Features[Entry.getKey()] = Entry.getValue();
422 }
423
424 return {NO_ERROR, StringRef()};
425}
426
427/// Fills Features map with default values for given target GPU.
428/// \p Features contains overriding target features and this function returns
429/// default target features with entries overridden by \p Features.
430static void fillAMDGCNFeatureMap(StringRef GPU, const Triple &T,
431 StringMap<bool> &Features) {
433 switch (Kind) {
434 case GK_GFX1310:
435 case GK_GFX1251:
436 case GK_GFX1250:
437 Features["ci-insts"] = true;
438 Features["dot7-insts"] = true;
439 Features["dot8-insts"] = true;
440 Features["dl-insts"] = true;
441 Features["16-bit-insts"] = true;
442 Features["dpp"] = true;
443 Features["gfx8-insts"] = true;
444 Features["gfx9-insts"] = true;
445 Features["gfx10-insts"] = true;
446 Features["gfx10-3-insts"] = true;
447 Features["gfx11-insts"] = true;
448 Features["gfx12-insts"] = true;
449 Features["gfx1250-insts"] = true;
450 Features["bitop3-insts"] = true;
451 Features["prng-inst"] = true;
452 Features["tanh-insts"] = true;
453 Features["tensor-cvt-lut-insts"] = true;
454 Features["transpose-load-f4f6-insts"] = true;
455 Features["bf16-trans-insts"] = true;
456 Features["bf16-cvt-insts"] = true;
457 Features["bf16-pk-insts"] = true;
458 Features["fp8-conversion-insts"] = true;
459 Features["fp8e5m3-insts"] = true;
460 Features["permlane16-swap"] = true;
461 Features["ashr-pk-insts"] = true;
462 Features["add-min-max-insts"] = true;
463 Features["pk-add-min-max-insts"] = true;
464 Features["atomic-buffer-pk-add-bf16-inst"] = true;
465 Features["vmem-pref-insts"] = true;
466 Features["atomic-fadd-rtn-insts"] = true;
467 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
468 Features["atomic-flat-pk-add-16-insts"] = true;
469 Features["atomic-global-pk-add-bf16-inst"] = true;
470 Features["atomic-ds-pk-add-16-insts"] = true;
471 Features["setprio-inc-wg-inst"] = true;
472 Features["s-wakeup-barrier-inst"] = true;
473 Features["atomic-fmin-fmax-global-f32"] = true;
474 Features["atomic-fmin-fmax-global-f64"] = true;
475 Features["wavefrontsize32"] = true;
476 Features["clusters"] = true;
477 Features["mcast-load-insts"] = true;
478 Features["cube-insts"] = true;
479 Features["lerp-inst"] = true;
480 Features["sad-insts"] = true;
481 Features["qsad-insts"] = true;
482 Features["cvt-pknorm-vop2-insts"] = true;
483 break;
484 case GK_GFX1201:
485 case GK_GFX1200:
486 case GK_GFX12_GENERIC:
487 Features["ci-insts"] = true;
488 Features["dot7-insts"] = true;
489 Features["dot8-insts"] = true;
490 Features["dot9-insts"] = true;
491 Features["dot10-insts"] = true;
492 Features["dot11-insts"] = true;
493 Features["dot12-insts"] = true;
494 Features["dl-insts"] = true;
495 Features["atomic-ds-pk-add-16-insts"] = true;
496 Features["atomic-flat-pk-add-16-insts"] = true;
497 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
498 Features["atomic-buffer-pk-add-bf16-inst"] = true;
499 Features["atomic-global-pk-add-bf16-inst"] = true;
500 Features["16-bit-insts"] = true;
501 Features["dpp"] = true;
502 Features["gfx8-insts"] = true;
503 Features["gfx9-insts"] = true;
504 Features["gfx10-insts"] = true;
505 Features["gfx10-3-insts"] = true;
506 Features["gfx11-insts"] = true;
507 Features["gfx12-insts"] = true;
508 Features["atomic-fadd-rtn-insts"] = true;
509 Features["image-insts"] = true;
510 Features["cube-insts"] = true;
511 Features["lerp-inst"] = true;
512 Features["sad-insts"] = true;
513 Features["qsad-insts"] = true;
514 Features["cvt-pknorm-vop2-insts"] = true;
515 Features["fp8-conversion-insts"] = true;
516 Features["atomic-fmin-fmax-global-f32"] = true;
517 break;
518 case GK_GFX1153:
519 case GK_GFX1152:
520 case GK_GFX1151:
521 case GK_GFX1150:
522 case GK_GFX1103:
523 case GK_GFX1102:
524 case GK_GFX1101:
525 case GK_GFX1100:
526 case GK_GFX11_GENERIC:
527 Features["ci-insts"] = true;
528 Features["dot5-insts"] = true;
529 Features["dot7-insts"] = true;
530 Features["dot8-insts"] = true;
531 Features["dot9-insts"] = true;
532 Features["dot10-insts"] = true;
533 Features["dot12-insts"] = true;
534 Features["dl-insts"] = true;
535 Features["16-bit-insts"] = true;
536 Features["dpp"] = true;
537 Features["gfx8-insts"] = true;
538 Features["gfx9-insts"] = true;
539 Features["gfx10-insts"] = true;
540 Features["gfx10-3-insts"] = true;
541 Features["gfx11-insts"] = true;
542 Features["atomic-fadd-rtn-insts"] = true;
543 Features["image-insts"] = true;
544 Features["cube-insts"] = true;
545 Features["lerp-inst"] = true;
546 Features["sad-insts"] = true;
547 Features["qsad-insts"] = true;
548 Features["cvt-pknorm-vop2-insts"] = true;
549 Features["gws"] = true;
550 Features["atomic-fmin-fmax-global-f32"] = true;
551 break;
552 case GK_GFX1036:
553 case GK_GFX1035:
554 case GK_GFX1034:
555 case GK_GFX1033:
556 case GK_GFX1032:
557 case GK_GFX1031:
558 case GK_GFX1030:
560 Features["ci-insts"] = true;
561 Features["dot1-insts"] = true;
562 Features["dot2-insts"] = true;
563 Features["dot5-insts"] = true;
564 Features["dot6-insts"] = true;
565 Features["dot7-insts"] = true;
566 Features["dot10-insts"] = true;
567 Features["dl-insts"] = true;
568 Features["16-bit-insts"] = true;
569 Features["dpp"] = true;
570 Features["gfx8-insts"] = true;
571 Features["gfx9-insts"] = true;
572 Features["gfx10-insts"] = true;
573 Features["gfx10-3-insts"] = true;
574 Features["image-insts"] = true;
575 Features["s-memrealtime"] = true;
576 Features["s-memtime-inst"] = true;
577 Features["gws"] = true;
578 Features["vmem-to-lds-load-insts"] = true;
579 Features["atomic-fmin-fmax-global-f32"] = true;
580 Features["atomic-fmin-fmax-global-f64"] = true;
581 Features["cube-insts"] = true;
582 Features["lerp-inst"] = true;
583 Features["sad-insts"] = true;
584 Features["qsad-insts"] = true;
585 Features["cvt-pknorm-vop2-insts"] = true;
586 break;
587 case GK_GFX1012:
588 case GK_GFX1011:
589 Features["dot1-insts"] = true;
590 Features["dot2-insts"] = true;
591 Features["dot5-insts"] = true;
592 Features["dot6-insts"] = true;
593 Features["dot7-insts"] = true;
594 Features["dot10-insts"] = true;
595 [[fallthrough]];
596 case GK_GFX1013:
597 case GK_GFX1010:
599 Features["dl-insts"] = true;
600 Features["ci-insts"] = true;
601 Features["16-bit-insts"] = true;
602 Features["dpp"] = true;
603 Features["gfx8-insts"] = true;
604 Features["gfx9-insts"] = true;
605 Features["gfx10-insts"] = true;
606 Features["image-insts"] = true;
607 Features["s-memrealtime"] = true;
608 Features["s-memtime-inst"] = true;
609 Features["gws"] = true;
610 Features["vmem-to-lds-load-insts"] = true;
611 Features["atomic-fmin-fmax-global-f32"] = true;
612 Features["atomic-fmin-fmax-global-f64"] = true;
613 Features["cube-insts"] = true;
614 Features["lerp-inst"] = true;
615 Features["sad-insts"] = true;
616 Features["qsad-insts"] = true;
617 Features["cvt-pknorm-vop2-insts"] = true;
618 break;
619 case GK_GFX950:
620 Features["bitop3-insts"] = true;
621 Features["fp6bf6-cvt-scale-insts"] = true;
622 Features["fp4-cvt-scale-insts"] = true;
623 Features["bf8-cvt-scale-insts"] = true;
624 Features["fp8-cvt-scale-insts"] = true;
625 Features["f16bf16-to-fp6bf6-cvt-scale-insts"] = true;
626 Features["f32-to-f16bf16-cvt-sr-insts"] = true;
627 Features["prng-inst"] = true;
628 Features["permlane16-swap"] = true;
629 Features["permlane32-swap"] = true;
630 Features["ashr-pk-insts"] = true;
631 Features["dot12-insts"] = true;
632 Features["dot13-insts"] = true;
633 Features["atomic-buffer-pk-add-bf16-inst"] = true;
634 Features["gfx950-insts"] = true;
635 [[fallthrough]];
636 case GK_GFX942:
637 Features["fp8-insts"] = true;
638 Features["fp8-conversion-insts"] = true;
639 if (Kind != GK_GFX950)
640 Features["xf32-insts"] = true;
641 [[fallthrough]];
643 Features["gfx940-insts"] = true;
644 Features["atomic-ds-pk-add-16-insts"] = true;
645 Features["atomic-flat-pk-add-16-insts"] = true;
646 Features["atomic-global-pk-add-bf16-inst"] = true;
647 Features["gfx90a-insts"] = true;
648 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
649 Features["atomic-fadd-rtn-insts"] = true;
650 Features["dot3-insts"] = true;
651 Features["dot4-insts"] = true;
652 Features["dot5-insts"] = true;
653 Features["dot6-insts"] = true;
654 Features["mai-insts"] = true;
655 Features["dl-insts"] = true;
656 Features["dot1-insts"] = true;
657 Features["dot2-insts"] = true;
658 Features["dot7-insts"] = true;
659 Features["dot10-insts"] = true;
660 Features["gfx9-insts"] = true;
661 Features["gfx8-insts"] = true;
662 Features["16-bit-insts"] = true;
663 Features["dpp"] = true;
664 Features["s-memrealtime"] = true;
665 Features["ci-insts"] = true;
666 Features["s-memtime-inst"] = true;
667 Features["gws"] = true;
668 Features["vmem-to-lds-load-insts"] = true;
669 Features["atomic-fmin-fmax-global-f64"] = true;
670 Features["wavefrontsize64"] = true;
671 Features["cube-insts"] = true;
672 Features["lerp-inst"] = true;
673 Features["sad-insts"] = true;
674 Features["qsad-insts"] = true;
675 Features["cvt-pknorm-vop2-insts"] = true;
676 break;
677 case GK_GFX90A:
678 Features["gfx90a-insts"] = true;
679 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
680 Features["atomic-fadd-rtn-insts"] = true;
681 Features["atomic-fmin-fmax-global-f64"] = true;
682 [[fallthrough]];
683 case GK_GFX908:
684 Features["dot3-insts"] = true;
685 Features["dot4-insts"] = true;
686 Features["dot5-insts"] = true;
687 Features["dot6-insts"] = true;
688 Features["mai-insts"] = true;
689 [[fallthrough]];
690 case GK_GFX906:
691 Features["dl-insts"] = true;
692 Features["dot1-insts"] = true;
693 Features["dot2-insts"] = true;
694 Features["dot7-insts"] = true;
695 Features["dot10-insts"] = true;
696 [[fallthrough]];
697 case GK_GFX90C:
698 case GK_GFX909:
699 case GK_GFX904:
700 case GK_GFX902:
701 case GK_GFX900:
702 case GK_GFX9_GENERIC:
703 Features["gfx9-insts"] = true;
704 Features["vmem-to-lds-load-insts"] = true;
705 [[fallthrough]];
706 case GK_GFX810:
707 case GK_GFX805:
708 case GK_GFX803:
709 case GK_GFX802:
710 case GK_GFX801:
711 Features["gfx8-insts"] = true;
712 Features["16-bit-insts"] = true;
713 Features["dpp"] = true;
714 Features["s-memrealtime"] = true;
715 Features["ci-insts"] = true;
716 Features["image-insts"] = true;
717 Features["s-memtime-inst"] = true;
718 Features["gws"] = true;
719 Features["wavefrontsize64"] = true;
720 Features["cube-insts"] = true;
721 Features["lerp-inst"] = true;
722 Features["sad-insts"] = true;
723 Features["qsad-insts"] = true;
724 Features["cvt-pknorm-vop2-insts"] = true;
725 break;
726 case GK_GFX705:
727 case GK_GFX704:
728 case GK_GFX703:
729 case GK_GFX702:
730 case GK_GFX701:
731 case GK_GFX700:
732 Features["ci-insts"] = true;
733 Features["cube-insts"] = true;
734 Features["lerp-inst"] = true;
735 Features["sad-insts"] = true;
736 Features["qsad-insts"] = true;
737 Features["cvt-pknorm-vop2-insts"] = true;
738 Features["image-insts"] = true;
739 Features["s-memtime-inst"] = true;
740 Features["gws"] = true;
741 Features["atomic-fmin-fmax-global-f32"] = true;
742 Features["atomic-fmin-fmax-global-f64"] = true;
743 Features["wavefrontsize64"] = true;
744 break;
745 case GK_GFX602:
746 case GK_GFX601:
747 case GK_GFX600:
748 Features["image-insts"] = true;
749 Features["s-memtime-inst"] = true;
750 Features["gws"] = true;
751 Features["atomic-fmin-fmax-global-f32"] = true;
752 Features["atomic-fmin-fmax-global-f64"] = true;
753 Features["wavefrontsize64"] = true;
754 Features["cube-insts"] = true;
755 Features["lerp-inst"] = true;
756 Features["sad-insts"] = true;
757 Features["cvt-pknorm-vop2-insts"] = true;
758 break;
759 case GK_NONE:
760 break;
761 default:
762 llvm_unreachable("Unhandled GPU!");
763 }
764}
765
766/// Fills Features map with default values for given target GPU.
767/// \p Features contains overriding target features and this function returns
768/// default target features with entries overridden by \p Features.
769std::pair<FeatureError, StringRef>
771 StringMap<bool> &Features) {
772 // XXX - What does the member GPU mean if device name string passed here?
773 if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) {
774 // AMDGCN SPIRV must support the union of all AMDGCN features. This list
775 // should be kept in sorted order and updated whenever new features are
776 // added.
777 Features["16-bit-insts"] = true;
778 Features["ashr-pk-insts"] = true;
779 Features["atomic-buffer-pk-add-bf16-inst"] = true;
780 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
781 Features["atomic-ds-pk-add-16-insts"] = true;
782 Features["atomic-fadd-rtn-insts"] = true;
783 Features["atomic-flat-pk-add-16-insts"] = true;
784 Features["atomic-global-pk-add-bf16-inst"] = true;
785 Features["bf16-trans-insts"] = true;
786 Features["bf16-cvt-insts"] = true;
787 Features["bf8-cvt-scale-insts"] = true;
788 Features["bitop3-insts"] = true;
789 Features["ci-insts"] = true;
790 Features["dl-insts"] = true;
791 Features["dot1-insts"] = true;
792 Features["dot2-insts"] = true;
793 Features["dot3-insts"] = true;
794 Features["dot4-insts"] = true;
795 Features["dot5-insts"] = true;
796 Features["dot6-insts"] = true;
797 Features["dot7-insts"] = true;
798 Features["dot8-insts"] = true;
799 Features["dot9-insts"] = true;
800 Features["dot10-insts"] = true;
801 Features["dot11-insts"] = true;
802 Features["dot12-insts"] = true;
803 Features["dot13-insts"] = true;
804 Features["dpp"] = true;
805 Features["f16bf16-to-fp6bf6-cvt-scale-insts"] = true;
806 Features["f32-to-f16bf16-cvt-sr-insts"] = true;
807 Features["fp4-cvt-scale-insts"] = true;
808 Features["fp6bf6-cvt-scale-insts"] = true;
809 Features["fp8e5m3-insts"] = true;
810 Features["fp8-conversion-insts"] = true;
811 Features["fp8-cvt-scale-insts"] = true;
812 Features["fp8-insts"] = true;
813 Features["gfx8-insts"] = true;
814 Features["gfx9-insts"] = true;
815 Features["gfx90a-insts"] = true;
816 Features["gfx940-insts"] = true;
817 Features["gfx950-insts"] = true;
818 Features["gfx10-insts"] = true;
819 Features["gfx10-3-insts"] = true;
820 Features["gfx11-insts"] = true;
821 Features["gfx12-insts"] = true;
822 Features["gfx1250-insts"] = true;
823 Features["gws"] = true;
824 Features["image-insts"] = true;
825 Features["mai-insts"] = true;
826 Features["permlane16-swap"] = true;
827 Features["permlane32-swap"] = true;
828 Features["prng-inst"] = true;
829 Features["setprio-inc-wg-inst"] = true;
830 Features["s-memrealtime"] = true;
831 Features["s-memtime-inst"] = true;
832 Features["tanh-insts"] = true;
833 Features["tensor-cvt-lut-insts"] = true;
834 Features["transpose-load-f4f6-insts"] = true;
835 Features["vmem-pref-insts"] = true;
836 Features["vmem-to-lds-load-insts"] = true;
837 Features["wavefrontsize32"] = true;
838 Features["wavefrontsize64"] = true;
839 } else if (T.isAMDGCN()) {
840 StringMap<bool> DefaultFeatures;
841 fillAMDGCNFeatureMap(GPU, T, DefaultFeatures);
842 return insertWaveSizeFeature(GPU, T, DefaultFeatures, Features);
843 } else {
844 if (GPU.empty())
845 GPU = "r600";
846
847 switch (llvm::AMDGPU::parseArchR600(GPU)) {
848 case GK_CAYMAN:
849 case GK_CYPRESS:
850 case GK_RV770:
851 case GK_RV670:
852 // TODO: Add fp64 when implemented.
853 break;
854 case GK_TURKS:
855 case GK_CAICOS:
856 case GK_BARTS:
857 case GK_SUMO:
858 case GK_REDWOOD:
859 case GK_JUNIPER:
860 case GK_CEDAR:
861 case GK_RV730:
862 case GK_RV710:
863 case GK_RS880:
864 case GK_R630:
865 case GK_R600:
866 break;
867 default:
868 llvm_unreachable("Unhandled GPU!");
869 }
870 }
871 return {NO_ERROR, StringRef()};
872}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
static void fillAMDGCNFeatureMap(StringRef GPU, const Triple &T, StringMap< bool > &Features)
Fills Features map with default values for given target GPU.
static void setImpliedBits(FeatureBitset &Bits, const FeatureBitset &Implies, ArrayRef< BasicSubtargetFeatureKV > FeatureTable)
For each feature that is (transitively) implied by this feature, set it.
static std::pair< FeatureError, StringRef > insertWaveSizeFeature(StringRef GPU, const Triple &T, const StringMap< bool > &DefaultFeatures, StringMap< bool > &Features)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:131
const FeatureBitset & getAsBitset() const
Container class for subtarget features.
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)
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:864
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
iterator end()
Definition StringMap.h:224
iterator find(StringRef Key)
Definition StringMap.h:237
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition StringMap.h:285
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition StringMap.h:321
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Definition StringRef.h:618
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI StringRef getArchNameR600(GPUKind AK)
GPUKind
GPU kinds supported by the AMDGPU target.
LLVM_ABI StringRef getCanonicalArchName(const Triple &T, StringRef Arch)
LLVM_ABI void fillValidArchListR600(SmallVectorImpl< StringRef > &Values)
LLVM_ABI StringRef getArchFamilyNameAMDGCN(GPUKind AK)
LLVM_ABI IsaVersion getIsaVersion(StringRef GPU)
LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl< StringRef > &Values)
LLVM_ABI GPUKind parseArchAMDGCN(StringRef CPU)
@ UNSUPPORTED_TARGET_FEATURE
@ INVALID_FEATURE_COMBINATION
@ FEATURE_FAST_DENORMAL_F32
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 unsigned getArchAttrR600(GPUKind AK)
LLVM_ABI GPUKind parseArchR600(StringRef CPU)
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1763
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2042
LLVM_ABI std::optional< llvm::StringMap< bool > > getCPUDefaultTargetFeatures(StringRef CPU, ArrayRef< BasicSubtargetSubTypeKV > ProcDesc, ArrayRef< BasicSubtargetFeatureKV > ProcFeatures)
Instruction set architecture version.
Used to provide key value pairs for feature and CPU bit flags.
FeatureBitArray Implies
K-V bit mask.