LLVM 22.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},
179
186 // clang-format on
187};
188
189const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef<GPUInfo> Table) {
190 GPUInfo Search = { {""}, {""}, AK, AMDGPU::FEATURE_NONE };
191
192 auto I =
193 llvm::lower_bound(Table, Search, [](const GPUInfo &A, const GPUInfo &B) {
194 return A.Kind < B.Kind;
195 });
196
197 if (I == Table.end() || I->Kind != Search.Kind)
198 return nullptr;
199 return I;
200}
201
202} // namespace
203
205 switch (AK) {
208 return "gfx9";
211 return "gfx10";
213 return "gfx11";
215 return "gfx12";
216 default: {
217 StringRef ArchName = getArchNameAMDGCN(AK);
218 return ArchName.empty() ? "" : ArchName.drop_back(2);
219 }
220 }
221}
222
224 if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
225 return Entry->CanonicalName;
226 return "";
227}
228
230 if (const auto *Entry = getArchEntry(AK, R600GPUs))
231 return Entry->CanonicalName;
232 return "";
233}
234
236 for (const auto &C : AMDGCNGPUs) {
237 if (CPU == C.Name)
238 return C.Kind;
239 }
240
242}
243
245 for (const auto &C : R600GPUs) {
246 if (CPU == C.Name)
247 return C.Kind;
248 }
249
251}
252
254 if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
255 return Entry->Features;
256 return FEATURE_NONE;
257}
258
260 if (const auto *Entry = getArchEntry(AK, R600GPUs))
261 return Entry->Features;
262 return FEATURE_NONE;
263}
264
266 // XXX: Should this only report unique canonical names?
267 for (const auto &C : AMDGCNGPUs)
268 Values.push_back(C.Name);
269}
270
272 for (const auto &C : R600GPUs)
273 Values.push_back(C.Name);
274}
275
278 if (AK == AMDGPU::GPUKind::GK_NONE) {
279 if (GPU == "generic-hsa")
280 return {7, 0, 0};
281 if (GPU == "generic")
282 return {6, 0, 0};
283 return {0, 0, 0};
284 }
285
286 // clang-format off
287 switch (AK) {
288 case GK_GFX600: return {6, 0, 0};
289 case GK_GFX601: return {6, 0, 1};
290 case GK_GFX602: return {6, 0, 2};
291 case GK_GFX700: return {7, 0, 0};
292 case GK_GFX701: return {7, 0, 1};
293 case GK_GFX702: return {7, 0, 2};
294 case GK_GFX703: return {7, 0, 3};
295 case GK_GFX704: return {7, 0, 4};
296 case GK_GFX705: return {7, 0, 5};
297 case GK_GFX801: return {8, 0, 1};
298 case GK_GFX802: return {8, 0, 2};
299 case GK_GFX803: return {8, 0, 3};
300 case GK_GFX805: return {8, 0, 5};
301 case GK_GFX810: return {8, 1, 0};
302 case GK_GFX900: return {9, 0, 0};
303 case GK_GFX902: return {9, 0, 2};
304 case GK_GFX904: return {9, 0, 4};
305 case GK_GFX906: return {9, 0, 6};
306 case GK_GFX908: return {9, 0, 8};
307 case GK_GFX909: return {9, 0, 9};
308 case GK_GFX90A: return {9, 0, 10};
309 case GK_GFX90C: return {9, 0, 12};
310 case GK_GFX942: return {9, 4, 2};
311 case GK_GFX950: return {9, 5, 0};
312 case GK_GFX1010: return {10, 1, 0};
313 case GK_GFX1011: return {10, 1, 1};
314 case GK_GFX1012: return {10, 1, 2};
315 case GK_GFX1013: return {10, 1, 3};
316 case GK_GFX1030: return {10, 3, 0};
317 case GK_GFX1031: return {10, 3, 1};
318 case GK_GFX1032: return {10, 3, 2};
319 case GK_GFX1033: return {10, 3, 3};
320 case GK_GFX1034: return {10, 3, 4};
321 case GK_GFX1035: return {10, 3, 5};
322 case GK_GFX1036: return {10, 3, 6};
323 case GK_GFX1100: return {11, 0, 0};
324 case GK_GFX1101: return {11, 0, 1};
325 case GK_GFX1102: return {11, 0, 2};
326 case GK_GFX1103: return {11, 0, 3};
327 case GK_GFX1150: return {11, 5, 0};
328 case GK_GFX1151: return {11, 5, 1};
329 case GK_GFX1152: return {11, 5, 2};
330 case GK_GFX1153: return {11, 5, 3};
331 case GK_GFX1200: return {12, 0, 0};
332 case GK_GFX1201: return {12, 0, 1};
333 case GK_GFX1250: return {12, 5, 0};
334 case GK_GFX1251: return {12, 5, 1};
335
336 // Generic targets return the lowest common denominator
337 // within their family. That is, the ISA that is the most
338 // restricted in terms of features.
339 //
340 // gfx9-generic is tricky because there is no lowest
341 // common denominator, so we return gfx900 which has mad-mix
342 // but this family doesn't have it.
343 //
344 // This API should never be used to check for a particular
345 // feature anyway.
346 //
347 // TODO: Split up this API depending on its caller so
348 // generic target handling is more obvious and less risky.
349 case GK_GFX9_GENERIC: return {9, 0, 0};
350 case GK_GFX9_4_GENERIC: return {9, 4, 0};
351 case GK_GFX10_1_GENERIC: return {10, 1, 0};
352 case GK_GFX10_3_GENERIC: return {10, 3, 0};
353 case GK_GFX11_GENERIC: return {11, 0, 3};
354 case GK_GFX12_GENERIC: return {12, 0, 0};
355 default: return {0, 0, 0};
356 }
357 // clang-format on
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 const bool HaveWave32 = Features.count("wavefrontsize32");
377 const bool HaveWave64 = Features.count("wavefrontsize64");
378 if (HaveWave32 && HaveWave64)
380 "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive"};
381
382 if (HaveWave32 && !IsNullGPU && TargetHasWave64)
383 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "wavefrontsize32"};
384
385 if (HaveWave64 && !IsNullGPU && TargetHasWave32)
386 return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "wavefrontsize64"};
387
388 // Don't assume any wavesize with an unknown subtarget.
389 // Default to wave32 if target supports both.
390 if (!IsNullGPU && !HaveWave32 && !HaveWave64 && !TargetHasWave32 &&
391 !TargetHasWave64)
392 Features.insert(std::make_pair("wavefrontsize32", true));
393
394 for (const auto &Entry : DefaultFeatures) {
395 if (!Features.count(Entry.getKey()))
396 Features[Entry.getKey()] = Entry.getValue();
397 }
398
399 return {NO_ERROR, StringRef()};
400}
401
402/// Fills Features map with default values for given target GPU.
403/// \p Features contains overriding target features and this function returns
404/// default target features with entries overridden by \p Features.
405static void fillAMDGCNFeatureMap(StringRef GPU, const Triple &T,
406 StringMap<bool> &Features) {
408 switch (Kind) {
409 case GK_GFX1251:
410 case GK_GFX1250:
411 Features["ci-insts"] = true;
412 Features["dot7-insts"] = true;
413 Features["dot8-insts"] = true;
414 Features["dl-insts"] = true;
415 Features["16-bit-insts"] = true;
416 Features["dpp"] = true;
417 Features["gfx8-insts"] = true;
418 Features["gfx9-insts"] = true;
419 Features["gfx10-insts"] = true;
420 Features["gfx10-3-insts"] = true;
421 Features["gfx11-insts"] = true;
422 Features["gfx12-insts"] = true;
423 Features["gfx1250-insts"] = true;
424 Features["bitop3-insts"] = true;
425 Features["prng-inst"] = true;
426 Features["tanh-insts"] = true;
427 Features["tensor-cvt-lut-insts"] = true;
428 Features["transpose-load-f4f6-insts"] = true;
429 Features["bf16-trans-insts"] = true;
430 Features["bf16-cvt-insts"] = true;
431 Features["bf16-pk-insts"] = true;
432 Features["fp8-conversion-insts"] = true;
433 Features["fp8e5m3-insts"] = true;
434 Features["permlane16-swap"] = true;
435 Features["ashr-pk-insts"] = true;
436 Features["atomic-buffer-pk-add-bf16-inst"] = true;
437 Features["vmem-pref-insts"] = true;
438 Features["atomic-fadd-rtn-insts"] = true;
439 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
440 Features["atomic-flat-pk-add-16-insts"] = true;
441 Features["atomic-global-pk-add-bf16-inst"] = true;
442 Features["atomic-ds-pk-add-16-insts"] = true;
443 Features["setprio-inc-wg-inst"] = true;
444 Features["atomic-fmin-fmax-global-f32"] = true;
445 Features["atomic-fmin-fmax-global-f64"] = true;
446 Features["wavefrontsize32"] = true;
447 break;
448 case GK_GFX1201:
449 case GK_GFX1200:
450 case GK_GFX12_GENERIC:
451 Features["ci-insts"] = true;
452 Features["dot7-insts"] = true;
453 Features["dot8-insts"] = true;
454 Features["dot9-insts"] = true;
455 Features["dot10-insts"] = true;
456 Features["dot11-insts"] = true;
457 Features["dot12-insts"] = true;
458 Features["dl-insts"] = true;
459 Features["atomic-ds-pk-add-16-insts"] = true;
460 Features["atomic-flat-pk-add-16-insts"] = true;
461 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
462 Features["atomic-buffer-pk-add-bf16-inst"] = true;
463 Features["atomic-global-pk-add-bf16-inst"] = true;
464 Features["16-bit-insts"] = true;
465 Features["dpp"] = true;
466 Features["gfx8-insts"] = true;
467 Features["gfx9-insts"] = true;
468 Features["gfx10-insts"] = true;
469 Features["gfx10-3-insts"] = true;
470 Features["gfx11-insts"] = true;
471 Features["gfx12-insts"] = true;
472 Features["atomic-fadd-rtn-insts"] = true;
473 Features["image-insts"] = true;
474 Features["fp8-conversion-insts"] = true;
475 Features["atomic-fmin-fmax-global-f32"] = true;
476 break;
477 case GK_GFX1153:
478 case GK_GFX1152:
479 case GK_GFX1151:
480 case GK_GFX1150:
481 case GK_GFX1103:
482 case GK_GFX1102:
483 case GK_GFX1101:
484 case GK_GFX1100:
485 case GK_GFX11_GENERIC:
486 Features["ci-insts"] = true;
487 Features["dot5-insts"] = true;
488 Features["dot7-insts"] = true;
489 Features["dot8-insts"] = true;
490 Features["dot9-insts"] = true;
491 Features["dot10-insts"] = true;
492 Features["dot12-insts"] = true;
493 Features["dl-insts"] = true;
494 Features["16-bit-insts"] = true;
495 Features["dpp"] = true;
496 Features["gfx8-insts"] = true;
497 Features["gfx9-insts"] = true;
498 Features["gfx10-insts"] = true;
499 Features["gfx10-3-insts"] = true;
500 Features["gfx11-insts"] = true;
501 Features["atomic-fadd-rtn-insts"] = true;
502 Features["image-insts"] = true;
503 Features["gws"] = true;
504 Features["atomic-fmin-fmax-global-f32"] = true;
505 break;
506 case GK_GFX1036:
507 case GK_GFX1035:
508 case GK_GFX1034:
509 case GK_GFX1033:
510 case GK_GFX1032:
511 case GK_GFX1031:
512 case GK_GFX1030:
514 Features["ci-insts"] = true;
515 Features["dot1-insts"] = true;
516 Features["dot2-insts"] = true;
517 Features["dot5-insts"] = true;
518 Features["dot6-insts"] = true;
519 Features["dot7-insts"] = true;
520 Features["dot10-insts"] = true;
521 Features["dl-insts"] = true;
522 Features["16-bit-insts"] = true;
523 Features["dpp"] = true;
524 Features["gfx8-insts"] = true;
525 Features["gfx9-insts"] = true;
526 Features["gfx10-insts"] = true;
527 Features["gfx10-3-insts"] = true;
528 Features["image-insts"] = true;
529 Features["s-memrealtime"] = true;
530 Features["s-memtime-inst"] = true;
531 Features["gws"] = true;
532 Features["vmem-to-lds-load-insts"] = true;
533 Features["atomic-fmin-fmax-global-f32"] = true;
534 Features["atomic-fmin-fmax-global-f64"] = true;
535 break;
536 case GK_GFX1012:
537 case GK_GFX1011:
538 Features["dot1-insts"] = true;
539 Features["dot2-insts"] = true;
540 Features["dot5-insts"] = true;
541 Features["dot6-insts"] = true;
542 Features["dot7-insts"] = true;
543 Features["dot10-insts"] = true;
544 [[fallthrough]];
545 case GK_GFX1013:
546 case GK_GFX1010:
548 Features["dl-insts"] = true;
549 Features["ci-insts"] = true;
550 Features["16-bit-insts"] = true;
551 Features["dpp"] = true;
552 Features["gfx8-insts"] = true;
553 Features["gfx9-insts"] = true;
554 Features["gfx10-insts"] = true;
555 Features["image-insts"] = true;
556 Features["s-memrealtime"] = true;
557 Features["s-memtime-inst"] = true;
558 Features["gws"] = true;
559 Features["vmem-to-lds-load-insts"] = true;
560 Features["atomic-fmin-fmax-global-f32"] = true;
561 Features["atomic-fmin-fmax-global-f64"] = true;
562 break;
563 case GK_GFX950:
564 Features["bitop3-insts"] = true;
565 Features["fp6bf6-cvt-scale-insts"] = true;
566 Features["fp4-cvt-scale-insts"] = true;
567 Features["bf8-cvt-scale-insts"] = true;
568 Features["fp8-cvt-scale-insts"] = true;
569 Features["f16bf16-to-fp6bf6-cvt-scale-insts"] = true;
570 Features["f32-to-f16bf16-cvt-sr-insts"] = true;
571 Features["prng-inst"] = true;
572 Features["permlane16-swap"] = true;
573 Features["permlane32-swap"] = true;
574 Features["ashr-pk-insts"] = true;
575 Features["dot12-insts"] = true;
576 Features["dot13-insts"] = true;
577 Features["atomic-buffer-pk-add-bf16-inst"] = true;
578 Features["gfx950-insts"] = true;
579 [[fallthrough]];
580 case GK_GFX942:
581 Features["fp8-insts"] = true;
582 Features["fp8-conversion-insts"] = true;
583 if (Kind != GK_GFX950)
584 Features["xf32-insts"] = true;
585 [[fallthrough]];
587 Features["gfx940-insts"] = true;
588 Features["atomic-ds-pk-add-16-insts"] = true;
589 Features["atomic-flat-pk-add-16-insts"] = true;
590 Features["atomic-global-pk-add-bf16-inst"] = true;
591 Features["gfx90a-insts"] = true;
592 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
593 Features["atomic-fadd-rtn-insts"] = true;
594 Features["dot3-insts"] = true;
595 Features["dot4-insts"] = true;
596 Features["dot5-insts"] = true;
597 Features["dot6-insts"] = true;
598 Features["mai-insts"] = true;
599 Features["dl-insts"] = true;
600 Features["dot1-insts"] = true;
601 Features["dot2-insts"] = true;
602 Features["dot7-insts"] = true;
603 Features["dot10-insts"] = true;
604 Features["gfx9-insts"] = true;
605 Features["gfx8-insts"] = true;
606 Features["16-bit-insts"] = true;
607 Features["dpp"] = true;
608 Features["s-memrealtime"] = true;
609 Features["ci-insts"] = true;
610 Features["s-memtime-inst"] = true;
611 Features["gws"] = true;
612 Features["vmem-to-lds-load-insts"] = true;
613 Features["atomic-fmin-fmax-global-f64"] = true;
614 Features["wavefrontsize64"] = true;
615 break;
616 case GK_GFX90A:
617 Features["gfx90a-insts"] = true;
618 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
619 Features["atomic-fadd-rtn-insts"] = true;
620 Features["atomic-fmin-fmax-global-f64"] = true;
621 [[fallthrough]];
622 case GK_GFX908:
623 Features["dot3-insts"] = true;
624 Features["dot4-insts"] = true;
625 Features["dot5-insts"] = true;
626 Features["dot6-insts"] = true;
627 Features["mai-insts"] = true;
628 [[fallthrough]];
629 case GK_GFX906:
630 Features["dl-insts"] = true;
631 Features["dot1-insts"] = true;
632 Features["dot2-insts"] = true;
633 Features["dot7-insts"] = true;
634 Features["dot10-insts"] = true;
635 [[fallthrough]];
636 case GK_GFX90C:
637 case GK_GFX909:
638 case GK_GFX904:
639 case GK_GFX902:
640 case GK_GFX900:
641 case GK_GFX9_GENERIC:
642 Features["gfx9-insts"] = true;
643 Features["vmem-to-lds-load-insts"] = true;
644 [[fallthrough]];
645 case GK_GFX810:
646 case GK_GFX805:
647 case GK_GFX803:
648 case GK_GFX802:
649 case GK_GFX801:
650 Features["gfx8-insts"] = true;
651 Features["16-bit-insts"] = true;
652 Features["dpp"] = true;
653 Features["s-memrealtime"] = true;
654 Features["ci-insts"] = true;
655 Features["image-insts"] = true;
656 Features["s-memtime-inst"] = true;
657 Features["gws"] = true;
658 Features["wavefrontsize64"] = true;
659 break;
660 case GK_GFX705:
661 case GK_GFX704:
662 case GK_GFX703:
663 case GK_GFX702:
664 case GK_GFX701:
665 case GK_GFX700:
666 Features["ci-insts"] = true;
667 [[fallthrough]];
668 case GK_GFX602:
669 case GK_GFX601:
670 case GK_GFX600:
671 Features["image-insts"] = true;
672 Features["s-memtime-inst"] = true;
673 Features["gws"] = true;
674 Features["atomic-fmin-fmax-global-f32"] = true;
675 Features["atomic-fmin-fmax-global-f64"] = true;
676 Features["wavefrontsize64"] = true;
677 break;
678 case GK_NONE:
679 break;
680 default:
681 llvm_unreachable("Unhandled GPU!");
682 }
683}
684
685/// Fills Features map with default values for given target GPU.
686/// \p Features contains overriding target features and this function returns
687/// default target features with entries overridden by \p Features.
688std::pair<FeatureError, StringRef>
690 StringMap<bool> &Features) {
691 // XXX - What does the member GPU mean if device name string passed here?
692 if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) {
693 // AMDGCN SPIRV must support the union of all AMDGCN features. This list
694 // should be kept in sorted order and updated whenever new features are
695 // added.
696 Features["16-bit-insts"] = true;
697 Features["ashr-pk-insts"] = true;
698 Features["atomic-buffer-pk-add-bf16-inst"] = true;
699 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
700 Features["atomic-ds-pk-add-16-insts"] = true;
701 Features["atomic-fadd-rtn-insts"] = true;
702 Features["atomic-flat-pk-add-16-insts"] = true;
703 Features["atomic-global-pk-add-bf16-inst"] = true;
704 Features["bf16-trans-insts"] = true;
705 Features["bf16-cvt-insts"] = true;
706 Features["bf8-cvt-scale-insts"] = true;
707 Features["bitop3-insts"] = true;
708 Features["ci-insts"] = true;
709 Features["dl-insts"] = true;
710 Features["dot1-insts"] = true;
711 Features["dot2-insts"] = true;
712 Features["dot3-insts"] = true;
713 Features["dot4-insts"] = true;
714 Features["dot5-insts"] = true;
715 Features["dot6-insts"] = true;
716 Features["dot7-insts"] = true;
717 Features["dot8-insts"] = true;
718 Features["dot9-insts"] = true;
719 Features["dot10-insts"] = true;
720 Features["dot11-insts"] = true;
721 Features["dot12-insts"] = true;
722 Features["dot13-insts"] = true;
723 Features["dpp"] = true;
724 Features["f16bf16-to-fp6bf6-cvt-scale-insts"] = true;
725 Features["f32-to-f16bf16-cvt-sr-insts"] = true;
726 Features["fp4-cvt-scale-insts"] = true;
727 Features["fp6bf6-cvt-scale-insts"] = true;
728 Features["fp8e5m3-insts"] = true;
729 Features["fp8-conversion-insts"] = true;
730 Features["fp8-cvt-scale-insts"] = true;
731 Features["fp8-insts"] = true;
732 Features["gfx8-insts"] = true;
733 Features["gfx9-insts"] = true;
734 Features["gfx90a-insts"] = true;
735 Features["gfx940-insts"] = true;
736 Features["gfx950-insts"] = true;
737 Features["gfx10-insts"] = true;
738 Features["gfx10-3-insts"] = true;
739 Features["gfx11-insts"] = true;
740 Features["gfx12-insts"] = true;
741 Features["gfx1250-insts"] = true;
742 Features["gws"] = true;
743 Features["image-insts"] = true;
744 Features["mai-insts"] = true;
745 Features["permlane16-swap"] = true;
746 Features["permlane32-swap"] = true;
747 Features["prng-inst"] = true;
748 Features["setprio-inc-wg-inst"] = true;
749 Features["s-memrealtime"] = true;
750 Features["s-memtime-inst"] = true;
751 Features["tanh-insts"] = true;
752 Features["tensor-cvt-lut-insts"] = true;
753 Features["transpose-load-f4f6-insts"] = true;
754 Features["vmem-pref-insts"] = true;
755 Features["vmem-to-lds-load-insts"] = true;
756 Features["wavefrontsize32"] = true;
757 Features["wavefrontsize64"] = true;
758 } else if (T.isAMDGCN()) {
759 StringMap<bool> DefaultFeatures;
760 fillAMDGCNFeatureMap(GPU, T, DefaultFeatures);
761 return insertWaveSizeFeature(GPU, T, DefaultFeatures, Features);
762 } else {
763 if (GPU.empty())
764 GPU = "r600";
765
766 switch (llvm::AMDGPU::parseArchR600(GPU)) {
767 case GK_CAYMAN:
768 case GK_CYPRESS:
769 case GK_RV770:
770 case GK_RV670:
771 // TODO: Add fp64 when implemented.
772 break;
773 case GK_TURKS:
774 case GK_CAICOS:
775 case GK_BARTS:
776 case GK_SUMO:
777 case GK_REDWOOD:
778 case GK_JUNIPER:
779 case GK_CEDAR:
780 case GK_RV730:
781 case GK_RV710:
782 case GK_RS880:
783 case GK_R630:
784 case GK_R600:
785 break;
786 default:
787 llvm_unreachable("Unhandled GPU!");
788 }
789 }
790 return {NO_ERROR, StringRef()};
791}
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:55
#define I(x, y, z)
Definition MD5.cpp:58
#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:41
iterator end() const
Definition ArrayRef.h:136
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:862
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition StringMap.h:278
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition StringMap.h:310
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:151
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Definition StringRef.h:626
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.
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:1731
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:1974
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.