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