LLVM 24.0.0git
AMDGPUTargetParser.cpp
Go to the documentation of this file.
1//===-- AMDGPUTargetParser - Parser for AMDGPU 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 AMDGPU hardware features.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/Twine.h"
21
22using namespace llvm;
23using namespace AMDGPU;
24
26 StringRef ArchName = getArchNameAMDGCN(AK);
28 ArchName.ends_with("-generic") &&
29 "Generic AMDGCN arch not classified correctly!");
31 // Return the part before the first '-', e.g. "gfx9-4-generic" -> "gfx9".
32 return ArchName.take_front(ArchName.find('-'));
33 }
34 return ArchName.empty() ? "" : ArchName.drop_back(2);
35}
36
38 switch (AK) {
39#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) \
40 case ENUM: \
41 return SUBARCH;
42#include "llvm/TargetParser/AMDGPUTargetParser.def"
43 default:
45 }
46}
47
50 switch (SubArch) {
51#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) \
52 case SUBARCH: \
53 return ENUM;
54#include "llvm/TargetParser/AMDGPUTargetParser.def"
55 default:
56 return GK_NONE;
57 }
58}
59
60static const Triple::SubArchType
62 1] = {
65
70
74
76
81
83
86
90
95
101
104
107
110
112
118
120 if (A == B || A == Triple::NoSubArch || B == Triple::NoSubArch)
121 return true;
122
125
126 // One side is the major-family subarch covering the other's family.
127 if (A == MajorA)
128 return MajorA == MajorB;
129 if (B == MajorB)
130 return MajorA == MajorB;
131
132 return false;
133}
134
136 // An unrecognized GPU is never valid.
137 if (AK == GK_NONE)
138 return false;
139 // A legacy triple without a subarch accepts any known GPU.
140 if (SubArch == Triple::NoSubArch)
141 return true;
142 return isSubArchCompatible(getSubArch(AK), SubArch);
143}
144
148
150 // Tolerate subarch mismatch if one entry is none. This is a hack for bitcode
151 // libraries.
152 // There's a missing enum entry for an unknown subarch. Make sure the
153 // subarch is really empty.
154 if (A.getSubArch() == Triple::NoSubArch)
155 return A.getArchName().size() == 6;
156
157 if (B.getSubArch() == Triple::NoSubArch)
158 return B.getArchName().size() == 6;
159
160 return isSubArchCompatible(A.getSubArch(), B.getSubArch());
161}
162
163std::string AMDGPU::mergeSubArch(const Triple &A, const Triple &B) {
164 if (A.getSubArch() == Triple::NoSubArch)
165 return B.str();
166 if (B.getSubArch() == Triple::NoSubArch)
167 return A.str();
168
169 Triple::SubArchType MajorA = AMDGPU::getMajorSubArch(A.getSubArch());
170 Triple::SubArchType MajorB = AMDGPU::getMajorSubArch(B.getSubArch());
171
172 // With a compatible major arch, return the specific subarch.
173 if (A.getSubArch() == MajorA) {
174 if (MajorA == MajorB)
175 return B.str();
176 }
177
178 if (B.getSubArch() == MajorB) {
179 if (MajorA == MajorB)
180 return A.str();
181 }
182
183 // Invalid case.
184 return B.str();
185}
186
188 switch (AK) {
189#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) \
190 case ENUM: \
191 return NAME;
192#include "llvm/TargetParser/AMDGPUTargetParser.def"
193 default:
194 return "";
195 }
196}
197
198// Canonical GPU name for each AMDGPU subarch, indexed by SubArch -
199// Triple::FirstAMDGPUSubArch.
202 {"gfx600", // AMDGPUSubArch6 (no generic target)
203 "gfx600", "gfx601", "gfx602",
204
205 "gfx700", // AMDGPUSubArch7 (no generic target)
206 "gfx700", "gfx701", "gfx702", "gfx703", "gfx704",
207 "gfx705",
208
209 "gfx801", // AMDGPUSubArch8 (no generic target)
210 "gfx801", "gfx802", "gfx803", "gfx805",
211
212 "gfx810",
213
214 "gfx9-generic", "gfx900", "gfx902", "gfx904", "gfx906",
215 "gfx909", "gfx90c",
216
217 "gfx908", "gfx90a",
218
219 "gfx9-4-generic", "gfx942", "gfx950",
220
221 "gfx10-1-generic", "gfx1010", "gfx1011", "gfx1012", "gfx1013",
222
223 "gfx10-3-generic", "gfx1030", "gfx1031", "gfx1032", "gfx1033",
224 "gfx1034", "gfx1035", "gfx1036",
225
226 "gfx11-generic", "gfx1100", "gfx1101", "gfx1102", "gfx1103",
227 "gfx1150", "gfx1151", "gfx1152", "gfx1153", "gfx1154",
228
229 "gfx11-7-generic", "gfx1170", "gfx1171", "gfx1172",
230
231 "gfx12-generic", "gfx1200", "gfx1201", "gfx12-5-generic", "gfx1250",
232 "gfx1251",
233
234 "gfx13-generic", "gfx1310"};
235
242
244 switch (AK) {
245#define R600_GPU(NAME, ENUM, FEATURES) \
246 case ENUM: \
247 return NAME;
248#include "llvm/TargetParser/AMDGPUTargetParser.def"
249 default:
250 return "";
251 }
252}
253
256#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) .Case(NAME, ENUM)
257#define AMDGCN_GPU_ALIAS(NAME, ENUM) .Case(NAME, ENUM)
258#include "llvm/TargetParser/AMDGPUTargetParser.def"
259 .Case("generic", AMDGPU::GPUKind::GK_GFX600)
260 .Case("generic-hsa", AMDGPU::GPUKind::GK_GFX700)
262}
263
266#define R600_GPU(NAME, ENUM, FEATURES) .Case(NAME, ENUM)
267#define R600_GPU_ALIAS(NAME, ENUM) .Case(NAME, ENUM)
268#include "llvm/TargetParser/AMDGPUTargetParser.def"
270}
271
273 switch (AK) {
274#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) \
275 case ENUM: \
276 return FEATURES;
277#include "llvm/TargetParser/AMDGPUTargetParser.def"
278 default:
279 return FEATURE_NONE;
280 }
281}
282
284 switch (SubArch) {
285#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) \
286 case SUBARCH: \
287 return FEATURES;
288#include "llvm/TargetParser/AMDGPUTargetParser.def"
289 default:
290 return FEATURE_NONE;
291 }
292}
293
295 switch (AK) {
296#define R600_GPU(NAME, ENUM, FEATURES) \
297 case ENUM: \
298 return FEATURES;
299#include "llvm/TargetParser/AMDGPUTargetParser.def"
300 default:
301 return FEATURE_NONE;
302 }
303}
304
306 Triple::SubArchType SubArch) {
307 // XXX: Should this only report unique canonical names?
308 // An alias shares its GPU's GPUKind, so it is filtered alongside it.
309#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) \
310 if (isCPUValidForSubArch(SubArch, ENUM)) \
311 Values.push_back(NAME);
312#define AMDGCN_GPU_ALIAS(NAME, ENUM) \
313 if (isCPUValidForSubArch(SubArch, ENUM)) \
314 Values.push_back(NAME);
315#include "llvm/TargetParser/AMDGPUTargetParser.def"
316}
317
319 Values.append({
320#define R600_GPU(NAME, ENUM, FEATURES) NAME,
321#define R600_GPU_ALIAS(NAME, ENUM) NAME,
322#include "llvm/TargetParser/AMDGPUTargetParser.def"
323 });
324}
325
328 if (AK == AMDGPU::GPUKind::GK_NONE) {
329 if (GPU == "generic-hsa")
330 return {7, 0, 0};
331 if (GPU == "generic")
332 return {6, 0, 0};
333 return {0, 0, 0};
334 }
335
336 switch (AK) {
337#define MAKE_ISAVERSION(A, B, C) {A, B, C}
338#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) \
339 case ENUM: \
340 return MAKE_ISAVERSION ISAVERSION;
341#include "llvm/TargetParser/AMDGPUTargetParser.def"
342#undef MAKE_ISAVERSION
343 default:
344 return {0, 0, 0};
345 }
346}
347
349 switch (SubArch) {
350#define MAKE_ISAVERSION(A, B, C) {A, B, C}
351#define AMDGCN_GPU(NAME, ENUM, SUBARCH, ISAVERSION, FEATURES) \
352 case SUBARCH: \
353 return MAKE_ISAVERSION ISAVERSION;
354#include "llvm/TargetParser/AMDGPUTargetParser.def"
355#undef MAKE_ISAVERSION
356 default:
357 return {0, 0, 0};
358 }
359}
360
362 assert(T.isAMDGPU());
363 auto ProcKind = T.isAMDGCN() ? parseArchAMDGCN(Arch) : parseArchR600(Arch);
364 if (ProcKind == GK_NONE)
365 return StringRef();
366
367 return T.isAMDGCN() ? getArchNameAMDGCN(ProcKind) : getArchNameR600(ProcKind);
368}
369
370static std::pair<FeatureError, StringRef>
372 const StringMap<bool> &DefaultFeatures,
373 StringMap<bool> &Features) {
374 const bool IsNullGPU = GPU.empty();
375 const bool TargetHasWave32 = DefaultFeatures.count("wavefrontsize32");
376 const bool TargetHasWave64 = DefaultFeatures.count("wavefrontsize64");
377
378 auto Wave32Itr = Features.find("wavefrontsize32");
379 auto Wave64Itr = Features.find("wavefrontsize64");
380 const bool EnableWave32 =
381 Wave32Itr != Features.end() && Wave32Itr->getValue();
382 const bool EnableWave64 =
383 Wave64Itr != Features.end() && Wave64Itr->getValue();
384 const bool DisableWave32 =
385 Wave32Itr != Features.end() && !Wave32Itr->getValue();
386 const bool DisableWave64 =
387 Wave64Itr != Features.end() && !Wave64Itr->getValue();
388
389 if (EnableWave32 && EnableWave64)
391 "'+wavefrontsize32' and '+wavefrontsize64' are mutually exclusive"};
392 if (DisableWave32 && DisableWave64)
394 "'-wavefrontsize32' and '-wavefrontsize64' are mutually exclusive"};
395
396 if (!IsNullGPU) {
397 if (TargetHasWave64) {
398 if (EnableWave32)
399 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "+wavefrontsize32"};
400 if (DisableWave64)
401 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "-wavefrontsize64"};
402 }
403
404 if (TargetHasWave32) {
405 if (EnableWave64)
406 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "+wavefrontsize64"};
407 if (DisableWave32)
408 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "-wavefrontsize32"};
409 }
410 }
411
412 // Don't assume any wavesize with an unknown subtarget.
413 // Default to wave32 if target supports both.
414 if (!IsNullGPU && !EnableWave32 && !EnableWave64 && !TargetHasWave32 &&
415 !TargetHasWave64)
416 Features.insert(std::make_pair("wavefrontsize32", true));
417
418 for (const auto &Entry : DefaultFeatures) {
419 if (!Features.count(Entry.getKey()))
420 Features[Entry.getKey()] = Entry.getValue();
421 }
422
423 return {NO_ERROR, StringRef()};
424}
425
426/// Fills Features map with default values for given target GPU.
427/// \p Features contains overriding target features and this function returns
428/// default target features with entries overridden by \p Features.
429static void fillAMDGCNFeatureMap(StringRef GPU, const Triple &T,
430 StringMap<bool> &Features) {
432 switch (Kind) {
433 case GK_GFX1251:
434 Features["gfx1251-gemm-insts"] = true;
435 [[fallthrough]];
436 case GK_GFX1250:
437 Features["swmmac-gfx1200-insts"] = true;
438 Features["swmmac-gfx1250-insts"] = true;
439 [[fallthrough]];
440 case GK_GFX1310:
441 case GK_GFX13_GENERIC:
442 Features["cube-insts"] = true;
443 Features["cvt-pknorm-vop2-insts"] = true;
444 Features["lerp-inst"] = true;
445 Features["qsad-insts"] = true;
446 Features["sad-insts"] = true;
447 Features["msad-insts"] = true;
448 Features["mqsad-pk-insts"] = true;
449 Features["mqsad-insts"] = true;
450 [[fallthrough]];
451 case GK_GFX12_5_GENERIC:
452 Features["ci-insts"] = true;
453 Features["dot7-insts"] = true;
454 Features["dot8-insts"] = true;
455 Features["dl-insts"] = true;
456 Features["16-bit-insts"] = true;
457 Features["dpp"] = true;
458 Features["gfx8-insts"] = true;
459 Features["gfx9-insts"] = true;
460 Features["flat-global-insts"] = true;
461 Features["gfx10-insts"] = true;
462 Features["gfx10-3-insts"] = true;
463 Features["gfx11-insts"] = true;
464 Features["gfx12-insts"] = true;
465 Features["gfx1250-insts"] = true;
466 Features["bitop3-insts"] = true;
467 Features["prng-inst"] = true;
468 Features["tanh-insts"] = true;
469 Features["tensor-cvt-lut-insts"] = true;
470 Features["transpose-load-f4f6-insts"] = true;
471 Features["bf16-trans-insts"] = true;
472 Features["bf16-cvt-insts"] = true;
473 Features["bf16-pk-insts"] = true;
474 Features["fp8-conversion-insts"] = true;
475 Features["fp8e5m3-insts"] = true;
476 Features["permlane16-swap"] = true;
477 Features["ashr-pk-insts"] = true;
478 Features["add-min-max-insts"] = true;
479 Features["pk-add-min-max-insts"] = true;
480 Features["atomic-buffer-pk-add-bf16-inst"] = true;
481 Features["vmem-pref-insts"] = true;
482 Features["atomic-fadd-rtn-insts"] = true;
483 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
484 Features["atomic-flat-pk-add-16-insts"] = true;
485 Features["atomic-global-pk-add-bf16-inst"] = true;
486 Features["atomic-ds-pk-add-16-insts"] = true;
487 Features["setprio-inc-wg-inst"] = true;
488 Features["s-wakeup-barrier-inst"] = true;
489 Features["atomic-fmin-fmax-global-f32"] = true;
490 Features["atomic-fmin-fmax-global-f64"] = true;
491 Features["wavefrontsize32"] = true;
492 Features["clusters"] = true;
493 Features["mcast-load-insts"] = true;
494 Features["asynccnt"] = true;
495 break;
496 case GK_GFX1201:
497 case GK_GFX1200:
498 case GK_GFX12_GENERIC:
499 Features["ci-insts"] = true;
500 Features["dot7-insts"] = true;
501 Features["dot8-insts"] = true;
502 Features["dot9-insts"] = true;
503 Features["dot10-insts"] = true;
504 Features["dot11-insts"] = true;
505 Features["dot12-insts"] = true;
506 Features["dl-insts"] = true;
507 Features["atomic-ds-pk-add-16-insts"] = true;
508 Features["atomic-flat-pk-add-16-insts"] = true;
509 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
510 Features["atomic-buffer-pk-add-bf16-inst"] = true;
511 Features["atomic-global-pk-add-bf16-inst"] = true;
512 Features["16-bit-insts"] = true;
513 Features["dpp"] = true;
514 Features["gfx8-insts"] = true;
515 Features["gfx9-insts"] = true;
516 Features["flat-global-insts"] = true;
517 Features["gfx10-insts"] = true;
518 Features["gfx10-3-insts"] = true;
519 Features["gfx11-insts"] = true;
520 Features["gfx12-insts"] = true;
521 Features["atomic-fadd-rtn-insts"] = true;
522 Features["image-insts"] = true;
523 Features["cube-insts"] = true;
524 Features["lerp-inst"] = true;
525 Features["sad-insts"] = true;
526 Features["qsad-insts"] = true;
527 Features["msad-insts"] = true;
528 Features["mqsad-pk-insts"] = true;
529 Features["mqsad-insts"] = true;
530 Features["cvt-pknorm-vop2-insts"] = true;
531 Features["fp8-conversion-insts"] = true;
532 Features["wmma-128b-insts"] = true;
533 Features["swmmac-gfx1200-insts"] = true;
534 Features["atomic-fmin-fmax-global-f32"] = true;
535 break;
536 case GK_GFX1170:
537 case GK_GFX1171:
538 case GK_GFX1172:
539 case GK_GFX11_7_GENERIC:
540 Features["ci-insts"] = true;
541 Features["dot7-insts"] = true;
542 Features["dot8-insts"] = true;
543 Features["dot9-insts"] = true;
544 Features["dot10-insts"] = true;
545 Features["dot12-insts"] = true;
546 Features["dl-insts"] = true;
547 Features["16-bit-insts"] = true;
548 Features["dpp"] = true;
549 Features["gfx8-insts"] = true;
550 Features["gfx9-insts"] = true;
551 Features["flat-global-insts"] = true;
552 Features["gfx10-insts"] = true;
553 Features["gfx10-3-insts"] = true;
554 Features["gfx11-insts"] = true;
555 Features["atomic-fadd-rtn-insts"] = true;
556 Features["image-insts"] = true;
557 Features["cube-insts"] = true;
558 Features["lerp-inst"] = true;
559 Features["sad-insts"] = true;
560 Features["qsad-insts"] = true;
561 Features["msad-insts"] = true;
562 Features["mqsad-pk-insts"] = true;
563 Features["mqsad-insts"] = true;
564 Features["cvt-pknorm-vop2-insts"] = true;
565 Features["gws"] = true;
566 Features["dot11-insts"] = true;
567 Features["fp8-conversion-insts"] = true;
568 Features["wmma-128b-insts"] = true;
569 Features["swmmac-gfx1200-insts"] = true;
570 Features["atomic-fmin-fmax-global-f32"] = true;
571 break;
572 case GK_GFX1154:
573 case GK_GFX1153:
574 case GK_GFX1152:
575 case GK_GFX1151:
576 case GK_GFX1150:
577 case GK_GFX1103:
578 case GK_GFX1102:
579 case GK_GFX1101:
580 case GK_GFX1100:
581 case GK_GFX11_GENERIC:
582 Features["ci-insts"] = true;
583 Features["dot5-insts"] = true;
584 Features["dot7-insts"] = true;
585 Features["dot8-insts"] = true;
586 Features["dot9-insts"] = true;
587 Features["dot10-insts"] = true;
588 Features["dot12-insts"] = true;
589 Features["dl-insts"] = true;
590 Features["16-bit-insts"] = true;
591 Features["dpp"] = true;
592 Features["gfx8-insts"] = true;
593 Features["gfx9-insts"] = true;
594 Features["flat-global-insts"] = true;
595 Features["gfx10-insts"] = true;
596 Features["gfx10-3-insts"] = true;
597 Features["gfx11-insts"] = true;
598 Features["atomic-fadd-rtn-insts"] = true;
599 Features["image-insts"] = true;
600 Features["cube-insts"] = true;
601 Features["lerp-inst"] = true;
602 Features["sad-insts"] = true;
603 Features["qsad-insts"] = true;
604 Features["msad-insts"] = true;
605 Features["mqsad-pk-insts"] = true;
606 Features["mqsad-insts"] = true;
607 Features["cvt-pknorm-vop2-insts"] = true;
608 Features["gws"] = true;
609 Features["wmma-256b-insts"] = true;
610 Features["atomic-fmin-fmax-global-f32"] = true;
611 break;
612 case GK_GFX1036:
613 case GK_GFX1035:
614 case GK_GFX1034:
615 case GK_GFX1033:
616 case GK_GFX1032:
617 case GK_GFX1031:
618 case GK_GFX1030:
619 case GK_GFX10_3_GENERIC:
620 Features["ci-insts"] = true;
621 Features["dot1-insts"] = true;
622 Features["dot2-insts"] = true;
623 Features["dot5-insts"] = true;
624 Features["dot6-insts"] = true;
625 Features["dot7-insts"] = true;
626 Features["dot10-insts"] = true;
627 Features["dl-insts"] = true;
628 Features["16-bit-insts"] = true;
629 Features["dpp"] = true;
630 Features["gfx8-insts"] = true;
631 Features["gfx9-insts"] = true;
632 Features["flat-global-insts"] = true;
633 Features["gfx10-insts"] = true;
634 Features["gfx10-3-insts"] = true;
635 Features["image-insts"] = true;
636 Features["s-memrealtime"] = true;
637 Features["s-memtime-inst"] = true;
638 Features["gws"] = true;
639 Features["vmem-to-lds-load-insts"] = true;
640 Features["atomic-fmin-fmax-global-f32"] = true;
641 Features["atomic-fmin-fmax-global-f64"] = true;
642 Features["cube-insts"] = true;
643 Features["lerp-inst"] = true;
644 Features["sad-insts"] = true;
645 Features["qsad-insts"] = true;
646 Features["msad-insts"] = true;
647 Features["mqsad-pk-insts"] = true;
648 Features["mqsad-insts"] = true;
649 Features["cvt-pknorm-vop2-insts"] = true;
650 break;
651 case GK_GFX1012:
652 case GK_GFX1011:
653 Features["dot1-insts"] = true;
654 Features["dot2-insts"] = true;
655 Features["dot5-insts"] = true;
656 Features["dot6-insts"] = true;
657 Features["dot7-insts"] = true;
658 Features["dot10-insts"] = true;
659 [[fallthrough]];
660 case GK_GFX1013:
661 case GK_GFX1010:
662 case GK_GFX10_1_GENERIC:
663 Features["dl-insts"] = true;
664 Features["ci-insts"] = true;
665 Features["16-bit-insts"] = true;
666 Features["dpp"] = true;
667 Features["gfx8-insts"] = true;
668 Features["gfx9-insts"] = true;
669 Features["flat-global-insts"] = true;
670 Features["gfx10-insts"] = true;
671 Features["image-insts"] = true;
672 Features["s-memrealtime"] = true;
673 Features["s-memtime-inst"] = true;
674 Features["gws"] = true;
675 Features["vmem-to-lds-load-insts"] = true;
676 Features["atomic-fmin-fmax-global-f32"] = true;
677 Features["atomic-fmin-fmax-global-f64"] = true;
678 Features["cube-insts"] = true;
679 Features["lerp-inst"] = true;
680 Features["sad-insts"] = true;
681 Features["qsad-insts"] = true;
682 Features["msad-insts"] = true;
683 Features["mqsad-pk-insts"] = true;
684 Features["mqsad-insts"] = true;
685 Features["cvt-pknorm-vop2-insts"] = true;
686 break;
687 case GK_GFX950:
688 Features["bitop3-insts"] = true;
689 Features["fp6bf6-cvt-scale-insts"] = true;
690 Features["fp4-cvt-scale-insts"] = true;
691 Features["bf8-cvt-scale-insts"] = true;
692 Features["fp8-cvt-scale-insts"] = true;
693 Features["f16bf16-to-fp6bf6-cvt-scale-insts"] = true;
694 Features["f32-to-f16bf16-cvt-sr-insts"] = true;
695 Features["prng-inst"] = true;
696 Features["permlane16-swap"] = true;
697 Features["permlane32-swap"] = true;
698 Features["ashr-pk-insts"] = true;
699 Features["dot12-insts"] = true;
700 Features["dot13-insts"] = true;
701 Features["atomic-buffer-pk-add-bf16-inst"] = true;
702 Features["gfx950-insts"] = true;
703 [[fallthrough]];
704 case GK_GFX942:
705 Features["fp8-insts"] = true;
706 Features["fp8-conversion-insts"] = true;
707 if (Kind != GK_GFX950)
708 Features["xf32-insts"] = true;
709 [[fallthrough]];
710 case GK_GFX9_4_GENERIC:
711 Features["gfx940-insts"] = true;
712 Features["atomic-ds-pk-add-16-insts"] = true;
713 Features["atomic-flat-pk-add-16-insts"] = true;
714 Features["atomic-global-pk-add-bf16-inst"] = true;
715 Features["gfx90a-insts"] = true;
716 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
717 Features["atomic-fadd-rtn-insts"] = true;
718 Features["dot3-insts"] = true;
719 Features["dot4-insts"] = true;
720 Features["dot5-insts"] = true;
721 Features["dot6-insts"] = true;
722 Features["mai-insts"] = true;
723 Features["dl-insts"] = true;
724 Features["dot1-insts"] = true;
725 Features["dot2-insts"] = true;
726 Features["dot7-insts"] = true;
727 Features["dot10-insts"] = true;
728 Features["gfx9-insts"] = true;
729 Features["flat-global-insts"] = true;
730 Features["gfx8-insts"] = true;
731 Features["16-bit-insts"] = true;
732 Features["dpp"] = true;
733 Features["s-memrealtime"] = true;
734 Features["ci-insts"] = true;
735 Features["s-memtime-inst"] = true;
736 Features["gws"] = true;
737 Features["vmem-to-lds-load-insts"] = true;
738 Features["atomic-fmin-fmax-global-f64"] = true;
739 Features["wavefrontsize64"] = true;
740 Features["cube-insts"] = true;
741 Features["lerp-inst"] = true;
742 Features["sad-insts"] = true;
743 Features["qsad-insts"] = true;
744 Features["msad-insts"] = true;
745 Features["mqsad-pk-insts"] = true;
746 Features["mqsad-insts"] = true;
747 Features["cvt-pknorm-vop2-insts"] = true;
748 break;
749 case GK_GFX90A:
750 Features["gfx90a-insts"] = true;
751 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
752 Features["atomic-fadd-rtn-insts"] = true;
753 Features["atomic-fmin-fmax-global-f64"] = true;
754 [[fallthrough]];
755 case GK_GFX908:
756 Features["dot3-insts"] = true;
757 Features["dot4-insts"] = true;
758 Features["dot5-insts"] = true;
759 Features["dot6-insts"] = true;
760 Features["mai-insts"] = true;
761 [[fallthrough]];
762 case GK_GFX906:
763 Features["dl-insts"] = true;
764 Features["dot1-insts"] = true;
765 Features["dot2-insts"] = true;
766 Features["dot7-insts"] = true;
767 Features["dot10-insts"] = true;
768 [[fallthrough]];
769 case GK_GFX90C:
770 case GK_GFX909:
771 case GK_GFX904:
772 case GK_GFX902:
773 case GK_GFX900:
774 case GK_GFX9_GENERIC:
775 Features["gfx9-insts"] = true;
776 Features["flat-global-insts"] = true;
777 Features["vmem-to-lds-load-insts"] = true;
778 [[fallthrough]];
779 case GK_GFX810:
780 case GK_GFX805:
781 case GK_GFX803:
782 case GK_GFX802:
783 case GK_GFX801:
784 Features["gfx8-insts"] = true;
785 Features["16-bit-insts"] = true;
786 Features["dpp"] = true;
787 Features["s-memrealtime"] = true;
788 Features["ci-insts"] = true;
789 Features["image-insts"] = true;
790 Features["s-memtime-inst"] = true;
791 Features["gws"] = true;
792 Features["wavefrontsize64"] = true;
793 Features["cube-insts"] = true;
794 Features["lerp-inst"] = true;
795 Features["sad-insts"] = true;
796 Features["qsad-insts"] = true;
797 Features["msad-insts"] = true;
798 Features["mqsad-pk-insts"] = true;
799 Features["mqsad-insts"] = true;
800 Features["cvt-pknorm-vop2-insts"] = true;
801 break;
802 case GK_GFX705:
803 case GK_GFX704:
804 case GK_GFX703:
805 case GK_GFX702:
806 case GK_GFX701:
807 case GK_GFX700:
808 Features["ci-insts"] = true;
809 Features["cube-insts"] = true;
810 Features["lerp-inst"] = true;
811 Features["sad-insts"] = true;
812 Features["qsad-insts"] = true;
813 Features["msad-insts"] = true;
814 Features["mqsad-pk-insts"] = true;
815 Features["mqsad-insts"] = true;
816 Features["cvt-pknorm-vop2-insts"] = true;
817 Features["image-insts"] = true;
818 Features["s-memtime-inst"] = true;
819 Features["gws"] = true;
820 Features["atomic-fmin-fmax-global-f32"] = true;
821 Features["atomic-fmin-fmax-global-f64"] = true;
822 Features["wavefrontsize64"] = true;
823 break;
824 case GK_GFX602:
825 case GK_GFX601:
826 case GK_GFX600:
827 Features["image-insts"] = true;
828 Features["s-memtime-inst"] = true;
829 Features["gws"] = true;
830 Features["atomic-fmin-fmax-global-f32"] = true;
831 Features["atomic-fmin-fmax-global-f64"] = true;
832 Features["wavefrontsize64"] = true;
833 Features["cube-insts"] = true;
834 Features["lerp-inst"] = true;
835 Features["sad-insts"] = true;
836 Features["msad-insts"] = true;
837 Features["mqsad-pk-insts"] = true;
838 Features["cvt-pknorm-vop2-insts"] = true;
839 break;
840 case GK_NONE:
841 break;
842 default:
843 llvm_unreachable("Unhandled GPU!");
844 }
845}
846
847/// Fills Features map with default values for given target GPU.
848/// \p Features contains overriding target features and this function returns
849/// default target features with entries overridden by \p Features.
850std::pair<FeatureError, StringRef>
852 StringMap<bool> &Features) {
853 // XXX - What does the member GPU mean if device name string passed here?
854 if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) {
855 // AMDGCN SPIRV must support the union of all AMDGCN features.
858
859 static const Triple AMDGCN("amdgcn-amd-amdhsa");
860 StringMap<bool> Tmp;
861 for (auto &&GPU : GPUs) {
862 fillAMDGCNFeatureMap(GPU, AMDGCN, Tmp);
863 for (auto &&[F, B] : Tmp)
864 Features[F] = B;
865 }
866 Features["wavefrontsize32"] = true;
867 Features["wavefrontsize64"] = true;
868 } else if (T.isAMDGCN()) {
869 StringMap<bool> DefaultFeatures;
870 fillAMDGCNFeatureMap(GPU, T, DefaultFeatures);
871 return insertWaveSizeFeature(GPU, T, DefaultFeatures, Features);
872 } else {
873 if (GPU.empty())
874 GPU = "r600";
875
876 switch (llvm::AMDGPU::parseArchR600(GPU)) {
877 case GK_CAYMAN:
878 case GK_CYPRESS:
879 case GK_RV770:
880 case GK_RV670:
881 // TODO: Add fp64 when implemented.
882 break;
883 case GK_TURKS:
884 case GK_CAICOS:
885 case GK_BARTS:
886 case GK_SUMO:
887 case GK_REDWOOD:
888 case GK_JUNIPER:
889 case GK_CEDAR:
890 case GK_RV730:
891 case GK_RV710:
892 case GK_RS880:
893 case GK_R630:
894 case GK_R600:
895 break;
896 default:
897 llvm_unreachable("Unhandled GPU!");
898 }
899 }
900 return {NO_ERROR, StringRef()};
901}
902
903TargetID::TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting,
904 TargetIDSetting SramEccSetting)
905 : Arch(Arch),
906 TargetTripleString(TT.normalize(Triple::CanonicalForm::FOUR_IDENT)),
907 XnackSetting(XnackSetting), SramEccSetting(SramEccSetting),
908 IsAMDHSA(TT.getOS() == Triple::AMDHSA) {}
909
910static TargetIDSetting
912 if (FeatureString.ends_with("-"))
913 return TargetIDSetting::Off;
914 if (FeatureString.ends_with("+"))
915 return TargetIDSetting::On;
916
917 llvm_unreachable("Malformed feature string");
918}
919
921 SmallVector<StringRef, 3> TargetIDSplit;
922 TargetID.split(TargetIDSplit, ':');
923
924 for (const auto &FeatureString : TargetIDSplit) {
925 if (FeatureString.starts_with("xnack"))
926 XnackSetting = getTargetIDSettingFromFeatureString(FeatureString);
927 if (FeatureString.starts_with("sramecc"))
928 SramEccSetting = getTargetIDSettingFromFeatureString(FeatureString);
929 }
930}
931
932std::optional<TargetID>
934 // Split on '-' to get arch-vendor-os-environment-processor:features
935 // There is a single dash separator after the 4-component triple
937 TargetIDDirective.split(Parts, '-', /*MaxSplit=*/4);
938 if (Parts.size() < 4)
939 return std::nullopt;
940
941 Triple TT(Parts[0], Parts[1], Parts[2], Parts[3]);
942 if (!TT.isAMDGCN())
943 return std::nullopt;
944
945 SmallVector<StringRef, 3> FeatureSplit;
946 Parts[4].split(FeatureSplit, ':');
947 if (FeatureSplit.empty())
948 return std::nullopt;
949
950 StringRef CPUName = FeatureSplit[0];
951
952 // Prefer the explicitly named processor so the parsed target id reflects it
953 // (e.g. for validation against the triple subarch). The processor field may
954 // be empty when the ISA is already encoded in the triple's subarch
955 // (e.g. "amdgpu12.50-amd-amdhsa-unknown-"), in which case derive the arch
956 // from the subarch.
957 GPUKind Arch = CPUName.empty() ? getGPUKindFromSubArch(TT.getSubArch())
958 : parseArchAMDGCN(CPUName);
959
960 unsigned ArchAttr = getArchAttrAMDGCN(Arch);
961
962 // Determine xnack/sramecc support based on the architecture attributes.
963 TargetIDSetting XnackSetting = (ArchAttr & FEATURE_XNACK)
964 ? TargetIDSetting::Any
965 : TargetIDSetting::Unsupported;
966 TargetIDSetting SramEccSetting = (ArchAttr & FEATURE_SRAMECC)
967 ? TargetIDSetting::Any
968 : TargetIDSetting::Unsupported;
969
970 for (StringRef FeatureString :
971 ArrayRef<StringRef>(FeatureSplit).drop_front(1)) {
972 if (FeatureString.starts_with("xnack"))
973 XnackSetting = getTargetIDSettingFromFeatureString(FeatureString);
974 else if (FeatureString.starts_with("sramecc"))
975 SramEccSetting = getTargetIDSettingFromFeatureString(FeatureString);
976 }
977
978 return TargetID(Arch, TT, XnackSetting, SramEccSetting);
979}
980
981void TargetID::print(raw_ostream &StreamRep) const {
982 StreamRep << TargetTripleString << '-' << getArchNameAMDGCN(Arch);
983
984 if (IsAMDHSA) {
985 // sramecc.
986 if (getSramEccSetting() == TargetIDSetting::Off)
987 StreamRep << ":sramecc-";
988 else if (getSramEccSetting() == TargetIDSetting::On)
989 StreamRep << ":sramecc+";
990
991 // xnack.
992 if (getXnackSetting() == TargetIDSetting::Off)
993 StreamRep << ":xnack-";
994 else if (getXnackSetting() == TargetIDSetting::On)
995 StreamRep << ":xnack+";
996 }
997}
998
999std::string TargetID::toString() const {
1000 std::string Str;
1001 raw_string_ostream OS(Str);
1002 OS << *this;
1003 return Str;
1004}
1005
1007 return Arch == Other.Arch && XnackSetting == Other.XnackSetting &&
1008 SramEccSetting == Other.SramEccSetting && IsAMDHSA == Other.IsAMDHSA &&
1009 TargetTripleString == Other.TargetTripleString;
1010}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void fillAMDGCNFeatureMap(StringRef GPU, const Triple &T, StringMap< bool > &Features)
Fills Features map with default values for given target GPU.
static const StringLiteral AMDGPUSubArchNames[Triple::LastAMDGPUSubArch - Triple::FirstAMDGPUSubArch+1]
static TargetIDSetting getTargetIDSettingFromFeatureString(StringRef FeatureString)
static const Triple::SubArchType AMDGPUMajorFamilies[Triple::LastAMDGPUSubArch - Triple::FirstAMDGPUSubArch+1]
static std::pair< FeatureError, StringRef > insertWaveSizeFeature(StringRef GPU, const Triple &T, const StringMap< bool > &DefaultFeatures, StringMap< bool > &Features)
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
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 T
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static std::optional< TargetID > parseTargetIDString(StringRef TargetIDDirective)
void print(raw_ostream &OS) const
TargetIDSetting getXnackSetting() const
void setTargetIDFromTargetIDStream(StringRef TargetID)
bool operator==(const TargetID &Other) const
TargetID(GPUKind Arch, const Triple &TT, TargetIDSetting XnackSetting, TargetIDSetting SramEccSetting)
std::string toString() const
TargetIDSetting getSramEccSetting() const
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:888
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:128
iterator end()
Definition StringMap.h:213
iterator find(StringRef Key)
Definition StringMap.h:226
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition StringMap.h:274
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition StringMap.h:310
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
Definition StringRef.h:606
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition StringRef.h:290
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition StringRef.h:270
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Definition StringRef.h:642
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
@ FirstAMDGPUSubArch
Definition Triple.h:275
@ AMDGPUSubArch9
Definition Triple.h:217
@ AMDGPUSubArch9_4
Definition Triple.h:230
@ AMDGPUSubArch6
Definition Triple.h:195
@ AMDGPUSubArch10_3
Definition Triple.h:240
@ AMDGPUSubArch90A
Definition Triple.h:228
@ AMDGPUSubArch810
Definition Triple.h:215
@ AMDGPUSubArch11
Definition Triple.h:249
@ AMDGPUSubArch7
Definition Triple.h:200
@ LastAMDGPUSubArch
Definition Triple.h:276
@ AMDGPUSubArch12_5
Definition Triple.h:269
@ AMDGPUSubArch10_1
Definition Triple.h:234
@ AMDGPUSubArch11_7
Definition Triple.h:260
@ AMDGPUSubArch8
Definition Triple.h:208
@ AMDGPUSubArch13
Definition Triple.h:273
@ AMDGPUSubArch12
Definition Triple.h:265
@ AMDGPUSubArch908
Definition Triple.h:227
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
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)
LLVM_ABI void fillValidArchListAMDGCN(SmallVectorImpl< StringRef > &Values, Triple::SubArchType SubArch=Triple::NoSubArch)
Append the valid AMDGCN GPU names to Values.
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 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 IsaVersion getIsaVersion(StringRef GPU)
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 GPUKind getGPUKindFromSubArch(Triple::SubArchType SubArch)
AMDGPU::TargetID TargetID
LLVM_ABI std::pair< FeatureError, StringRef > fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap< bool > &Features)
Fills Features map with default values for given target GPU.
LLVM_ABI StringRef getArchNameAMDGCN(GPUKind AK)
LLVM_ABI unsigned getArchAttrAMDGCN(GPUKind AK)
LLVM_ABI Triple::SubArchType getMajorSubArch(Triple::SubArchType SubArch)
LLVM_ABI unsigned getArchAttrR600(GPUKind AK)
LLVM_ABI GPUKind parseArchR600(StringRef CPU)
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
Instruction set architecture version.