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