LLVM 18.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
21namespace {
22
23struct GPUInfo {
25 StringLiteral CanonicalName;
27 unsigned Features;
28};
29
30constexpr GPUInfo R600GPUs[] = {
31 // Name Canonical Kind Features
32 // Name
33 {{"r600"}, {"r600"}, GK_R600, FEATURE_NONE },
34 {{"rv630"}, {"r600"}, GK_R600, FEATURE_NONE },
35 {{"rv635"}, {"r600"}, GK_R600, FEATURE_NONE },
36 {{"r630"}, {"r630"}, GK_R630, FEATURE_NONE },
37 {{"rs780"}, {"rs880"}, GK_RS880, FEATURE_NONE },
38 {{"rs880"}, {"rs880"}, GK_RS880, FEATURE_NONE },
39 {{"rv610"}, {"rs880"}, GK_RS880, FEATURE_NONE },
40 {{"rv620"}, {"rs880"}, GK_RS880, FEATURE_NONE },
41 {{"rv670"}, {"rv670"}, GK_RV670, FEATURE_NONE },
42 {{"rv710"}, {"rv710"}, GK_RV710, FEATURE_NONE },
43 {{"rv730"}, {"rv730"}, GK_RV730, FEATURE_NONE },
44 {{"rv740"}, {"rv770"}, GK_RV770, FEATURE_NONE },
45 {{"rv770"}, {"rv770"}, GK_RV770, FEATURE_NONE },
46 {{"cedar"}, {"cedar"}, GK_CEDAR, FEATURE_NONE },
47 {{"palm"}, {"cedar"}, GK_CEDAR, FEATURE_NONE },
48 {{"cypress"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA },
49 {{"hemlock"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA },
50 {{"juniper"}, {"juniper"}, GK_JUNIPER, FEATURE_NONE },
51 {{"redwood"}, {"redwood"}, GK_REDWOOD, FEATURE_NONE },
52 {{"sumo"}, {"sumo"}, GK_SUMO, FEATURE_NONE },
53 {{"sumo2"}, {"sumo"}, GK_SUMO, FEATURE_NONE },
54 {{"barts"}, {"barts"}, GK_BARTS, FEATURE_NONE },
55 {{"caicos"}, {"caicos"}, GK_CAICOS, FEATURE_NONE },
56 {{"aruba"}, {"cayman"}, GK_CAYMAN, FEATURE_FMA },
57 {{"cayman"}, {"cayman"}, GK_CAYMAN, FEATURE_FMA },
58 {{"turks"}, {"turks"}, GK_TURKS, FEATURE_NONE }
59};
60
61// This table should be sorted by the value of GPUKind
62// Don't bother listing the implicitly true features
63constexpr GPUInfo AMDGCNGPUs[] = {
64 // clang-format off
65 // Name Canonical Kind Features
66 // Name
67 {{"gfx600"}, {"gfx600"}, GK_GFX600, FEATURE_FAST_FMA_F32},
68 {{"tahiti"}, {"gfx600"}, GK_GFX600, FEATURE_FAST_FMA_F32},
69 {{"gfx601"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
70 {{"pitcairn"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
71 {{"verde"}, {"gfx601"}, GK_GFX601, FEATURE_NONE},
72 {{"gfx602"}, {"gfx602"}, GK_GFX602, FEATURE_NONE},
73 {{"hainan"}, {"gfx602"}, GK_GFX602, FEATURE_NONE},
74 {{"oland"}, {"gfx602"}, GK_GFX602, FEATURE_NONE},
75 {{"gfx700"}, {"gfx700"}, GK_GFX700, FEATURE_NONE},
76 {{"kaveri"}, {"gfx700"}, GK_GFX700, FEATURE_NONE},
77 {{"gfx701"}, {"gfx701"}, GK_GFX701, FEATURE_FAST_FMA_F32},
78 {{"hawaii"}, {"gfx701"}, GK_GFX701, FEATURE_FAST_FMA_F32},
79 {{"gfx702"}, {"gfx702"}, GK_GFX702, FEATURE_FAST_FMA_F32},
80 {{"gfx703"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
81 {{"kabini"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
82 {{"mullins"}, {"gfx703"}, GK_GFX703, FEATURE_NONE},
83 {{"gfx704"}, {"gfx704"}, GK_GFX704, FEATURE_NONE},
84 {{"bonaire"}, {"gfx704"}, GK_GFX704, FEATURE_NONE},
85 {{"gfx705"}, {"gfx705"}, GK_GFX705, FEATURE_NONE},
88 {{"gfx802"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
89 {{"iceland"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
90 {{"tonga"}, {"gfx802"}, GK_GFX802, FEATURE_FAST_DENORMAL_F32},
91 {{"gfx803"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
92 {{"fiji"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
93 {{"polaris10"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
94 {{"polaris11"}, {"gfx803"}, GK_GFX803, FEATURE_FAST_DENORMAL_F32},
95 {{"gfx805"}, {"gfx805"}, GK_GFX805, FEATURE_FAST_DENORMAL_F32},
96 {{"tongapro"}, {"gfx805"}, GK_GFX805, FEATURE_FAST_DENORMAL_F32},
97 {{"gfx810"}, {"gfx810"}, GK_GFX810, FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
98 {{"stoney"}, {"gfx810"}, GK_GFX810, FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK},
129 // clang-format on
130};
131
132const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef<GPUInfo> Table) {
133 GPUInfo Search = { {""}, {""}, AK, AMDGPU::FEATURE_NONE };
134
135 auto I =
136 llvm::lower_bound(Table, Search, [](const GPUInfo &A, const GPUInfo &B) {
137 return A.Kind < B.Kind;
138 });
139
140 if (I == Table.end() || I->Kind != Search.Kind)
141 return nullptr;
142 return I;
143}
144
145} // namespace
146
148 if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
149 return Entry->CanonicalName;
150 return "";
151}
152
154 if (const auto *Entry = getArchEntry(AK, R600GPUs))
155 return Entry->CanonicalName;
156 return "";
157}
158
160 for (const auto &C : AMDGCNGPUs) {
161 if (CPU == C.Name)
162 return C.Kind;
163 }
164
165 return AMDGPU::GPUKind::GK_NONE;
166}
167
169 for (const auto &C : R600GPUs) {
170 if (CPU == C.Name)
171 return C.Kind;
172 }
173
174 return AMDGPU::GPUKind::GK_NONE;
175}
176
178 if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
179 return Entry->Features;
180 return FEATURE_NONE;
181}
182
184 if (const auto *Entry = getArchEntry(AK, R600GPUs))
185 return Entry->Features;
186 return FEATURE_NONE;
187}
188
190 // XXX: Should this only report unique canonical names?
191 for (const auto &C : AMDGCNGPUs)
192 Values.push_back(C.Name);
193}
194
196 for (const auto &C : R600GPUs)
197 Values.push_back(C.Name);
198}
199
202 if (AK == AMDGPU::GPUKind::GK_NONE) {
203 if (GPU == "generic-hsa")
204 return {7, 0, 0};
205 if (GPU == "generic")
206 return {6, 0, 0};
207 return {0, 0, 0};
208 }
209
210 // clang-format off
211 switch (AK) {
212 case GK_GFX600: return {6, 0, 0};
213 case GK_GFX601: return {6, 0, 1};
214 case GK_GFX602: return {6, 0, 2};
215 case GK_GFX700: return {7, 0, 0};
216 case GK_GFX701: return {7, 0, 1};
217 case GK_GFX702: return {7, 0, 2};
218 case GK_GFX703: return {7, 0, 3};
219 case GK_GFX704: return {7, 0, 4};
220 case GK_GFX705: return {7, 0, 5};
221 case GK_GFX801: return {8, 0, 1};
222 case GK_GFX802: return {8, 0, 2};
223 case GK_GFX803: return {8, 0, 3};
224 case GK_GFX805: return {8, 0, 5};
225 case GK_GFX810: return {8, 1, 0};
226 case GK_GFX900: return {9, 0, 0};
227 case GK_GFX902: return {9, 0, 2};
228 case GK_GFX904: return {9, 0, 4};
229 case GK_GFX906: return {9, 0, 6};
230 case GK_GFX908: return {9, 0, 8};
231 case GK_GFX909: return {9, 0, 9};
232 case GK_GFX90A: return {9, 0, 10};
233 case GK_GFX90C: return {9, 0, 12};
234 case GK_GFX940: return {9, 4, 0};
235 case GK_GFX941: return {9, 4, 1};
236 case GK_GFX942: return {9, 4, 2};
237 case GK_GFX1010: return {10, 1, 0};
238 case GK_GFX1011: return {10, 1, 1};
239 case GK_GFX1012: return {10, 1, 2};
240 case GK_GFX1013: return {10, 1, 3};
241 case GK_GFX1030: return {10, 3, 0};
242 case GK_GFX1031: return {10, 3, 1};
243 case GK_GFX1032: return {10, 3, 2};
244 case GK_GFX1033: return {10, 3, 3};
245 case GK_GFX1034: return {10, 3, 4};
246 case GK_GFX1035: return {10, 3, 5};
247 case GK_GFX1036: return {10, 3, 6};
248 case GK_GFX1100: return {11, 0, 0};
249 case GK_GFX1101: return {11, 0, 1};
250 case GK_GFX1102: return {11, 0, 2};
251 case GK_GFX1103: return {11, 0, 3};
252 case GK_GFX1150: return {11, 5, 0};
253 case GK_GFX1151: return {11, 5, 1};
254 case GK_GFX1200: return {12, 0, 0};
255 case GK_GFX1201: return {12, 0, 1};
256 default: return {0, 0, 0};
257 }
258 // clang-format on
259}
260
262 assert(T.isAMDGPU());
263 auto ProcKind = T.isAMDGCN() ? parseArchAMDGCN(Arch) : parseArchR600(Arch);
264 if (ProcKind == GK_NONE)
265 return StringRef();
266
267 return T.isAMDGCN() ? getArchNameAMDGCN(ProcKind) : getArchNameR600(ProcKind);
268}
269
271 StringMap<bool> &Features) {
272 // XXX - What does the member GPU mean if device name string passed here?
273 if (T.isAMDGCN()) {
274 switch (parseArchAMDGCN(GPU)) {
275 case GK_GFX1201:
276 case GK_GFX1200:
277 Features["ci-insts"] = true;
278 Features["dot5-insts"] = true;
279 Features["dot7-insts"] = true;
280 Features["dot8-insts"] = true;
281 Features["dot9-insts"] = true;
282 Features["dot10-insts"] = true;
283 Features["dl-insts"] = true;
284 Features["16-bit-insts"] = true;
285 Features["dpp"] = true;
286 Features["gfx8-insts"] = true;
287 Features["gfx9-insts"] = true;
288 Features["gfx10-insts"] = true;
289 Features["gfx10-3-insts"] = true;
290 Features["gfx11-insts"] = true;
291 Features["gfx12-insts"] = true;
292 Features["atomic-fadd-rtn-insts"] = true;
293 Features["image-insts"] = true;
294 Features["gws"] = true;
295 break;
296 case GK_GFX1151:
297 case GK_GFX1150:
298 case GK_GFX1103:
299 case GK_GFX1102:
300 case GK_GFX1101:
301 case GK_GFX1100:
302 Features["ci-insts"] = true;
303 Features["dot5-insts"] = true;
304 Features["dot7-insts"] = true;
305 Features["dot8-insts"] = true;
306 Features["dot9-insts"] = true;
307 Features["dot10-insts"] = true;
308 Features["dl-insts"] = true;
309 Features["16-bit-insts"] = true;
310 Features["dpp"] = true;
311 Features["gfx8-insts"] = true;
312 Features["gfx9-insts"] = true;
313 Features["gfx10-insts"] = true;
314 Features["gfx10-3-insts"] = true;
315 Features["gfx11-insts"] = true;
316 Features["atomic-fadd-rtn-insts"] = true;
317 Features["image-insts"] = true;
318 Features["gws"] = true;
319 break;
320 case GK_GFX1036:
321 case GK_GFX1035:
322 case GK_GFX1034:
323 case GK_GFX1033:
324 case GK_GFX1032:
325 case GK_GFX1031:
326 case GK_GFX1030:
327 Features["ci-insts"] = true;
328 Features["dot1-insts"] = true;
329 Features["dot2-insts"] = true;
330 Features["dot5-insts"] = true;
331 Features["dot6-insts"] = true;
332 Features["dot7-insts"] = true;
333 Features["dot10-insts"] = true;
334 Features["dl-insts"] = true;
335 Features["16-bit-insts"] = true;
336 Features["dpp"] = true;
337 Features["gfx8-insts"] = true;
338 Features["gfx9-insts"] = true;
339 Features["gfx10-insts"] = true;
340 Features["gfx10-3-insts"] = true;
341 Features["image-insts"] = true;
342 Features["s-memrealtime"] = true;
343 Features["s-memtime-inst"] = true;
344 Features["gws"] = true;
345 break;
346 case GK_GFX1012:
347 case GK_GFX1011:
348 Features["dot1-insts"] = true;
349 Features["dot2-insts"] = true;
350 Features["dot5-insts"] = true;
351 Features["dot6-insts"] = true;
352 Features["dot7-insts"] = true;
353 Features["dot10-insts"] = true;
354 [[fallthrough]];
355 case GK_GFX1013:
356 case GK_GFX1010:
357 Features["dl-insts"] = true;
358 Features["ci-insts"] = true;
359 Features["16-bit-insts"] = true;
360 Features["dpp"] = true;
361 Features["gfx8-insts"] = true;
362 Features["gfx9-insts"] = true;
363 Features["gfx10-insts"] = true;
364 Features["image-insts"] = true;
365 Features["s-memrealtime"] = true;
366 Features["s-memtime-inst"] = true;
367 Features["gws"] = true;
368 break;
369 case GK_GFX942:
370 case GK_GFX941:
371 case GK_GFX940:
372 Features["gfx940-insts"] = true;
373 Features["fp8-insts"] = true;
374 Features["atomic-ds-pk-add-16-insts"] = true;
375 Features["atomic-flat-pk-add-16-insts"] = true;
376 Features["atomic-global-pk-add-bf16-inst"] = true;
377 Features["gfx90a-insts"] = true;
378 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
379 Features["atomic-fadd-rtn-insts"] = true;
380 Features["dot3-insts"] = true;
381 Features["dot4-insts"] = true;
382 Features["dot5-insts"] = true;
383 Features["dot6-insts"] = true;
384 Features["mai-insts"] = true;
385 Features["dl-insts"] = true;
386 Features["dot1-insts"] = true;
387 Features["dot2-insts"] = true;
388 Features["dot7-insts"] = true;
389 Features["dot10-insts"] = true;
390 Features["gfx9-insts"] = true;
391 Features["gfx8-insts"] = true;
392 Features["16-bit-insts"] = true;
393 Features["dpp"] = true;
394 Features["s-memrealtime"] = true;
395 Features["ci-insts"] = true;
396 Features["s-memtime-inst"] = true;
397 Features["gws"] = true;
398 break;
399 case GK_GFX90A:
400 Features["gfx90a-insts"] = true;
401 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
402 Features["atomic-fadd-rtn-insts"] = true;
403 [[fallthrough]];
404 case GK_GFX908:
405 Features["dot3-insts"] = true;
406 Features["dot4-insts"] = true;
407 Features["dot5-insts"] = true;
408 Features["dot6-insts"] = true;
409 Features["mai-insts"] = true;
410 [[fallthrough]];
411 case GK_GFX906:
412 Features["dl-insts"] = true;
413 Features["dot1-insts"] = true;
414 Features["dot2-insts"] = true;
415 Features["dot7-insts"] = true;
416 Features["dot10-insts"] = true;
417 [[fallthrough]];
418 case GK_GFX90C:
419 case GK_GFX909:
420 case GK_GFX904:
421 case GK_GFX902:
422 case GK_GFX900:
423 Features["gfx9-insts"] = true;
424 [[fallthrough]];
425 case GK_GFX810:
426 case GK_GFX805:
427 case GK_GFX803:
428 case GK_GFX802:
429 case GK_GFX801:
430 Features["gfx8-insts"] = true;
431 Features["16-bit-insts"] = true;
432 Features["dpp"] = true;
433 Features["s-memrealtime"] = true;
434 [[fallthrough]];
435 case GK_GFX705:
436 case GK_GFX704:
437 case GK_GFX703:
438 case GK_GFX702:
439 case GK_GFX701:
440 case GK_GFX700:
441 Features["ci-insts"] = true;
442 [[fallthrough]];
443 case GK_GFX602:
444 case GK_GFX601:
445 case GK_GFX600:
446 Features["image-insts"] = true;
447 Features["s-memtime-inst"] = true;
448 Features["gws"] = true;
449 break;
450 case GK_NONE:
451 break;
452 default:
453 llvm_unreachable("Unhandled GPU!");
454 }
455 } else {
456 if (GPU.empty())
457 GPU = "r600";
458
459 switch (llvm::AMDGPU::parseArchR600(GPU)) {
460 case GK_CAYMAN:
461 case GK_CYPRESS:
462 case GK_RV770:
463 case GK_RV670:
464 // TODO: Add fp64 when implemented.
465 break;
466 case GK_TURKS:
467 case GK_CAICOS:
468 case GK_BARTS:
469 case GK_SUMO:
470 case GK_REDWOOD:
471 case GK_JUNIPER:
472 case GK_CEDAR:
473 case GK_RV730:
474 case GK_RV710:
475 case GK_RS880:
476 case GK_R630:
477 case GK_R600:
478 break;
479 default:
480 llvm_unreachable("Unhandled GPU!");
481 }
482 }
483}
484
485static bool isWave32Capable(StringRef GPU, const Triple &T) {
486 bool IsWave32Capable = false;
487 // XXX - What does the member GPU mean if device name string passed here?
488 if (T.isAMDGCN()) {
489 switch (parseArchAMDGCN(GPU)) {
490 case GK_GFX1201:
491 case GK_GFX1200:
492 case GK_GFX1151:
493 case GK_GFX1150:
494 case GK_GFX1103:
495 case GK_GFX1102:
496 case GK_GFX1101:
497 case GK_GFX1100:
498 case GK_GFX1036:
499 case GK_GFX1035:
500 case GK_GFX1034:
501 case GK_GFX1033:
502 case GK_GFX1032:
503 case GK_GFX1031:
504 case GK_GFX1030:
505 case GK_GFX1012:
506 case GK_GFX1011:
507 case GK_GFX1013:
508 case GK_GFX1010:
509 IsWave32Capable = true;
510 break;
511 default:
512 break;
513 }
514 }
515 return IsWave32Capable;
516}
517
519 StringMap<bool> &Features,
520 std::string &ErrorMsg) {
521 bool IsWave32Capable = isWave32Capable(GPU, T);
522 const bool IsNullGPU = GPU.empty();
523 // FIXME: Not diagnosing wavefrontsize32 on wave64 only targets.
524 const bool HaveWave32 =
525 (IsWave32Capable || IsNullGPU) && Features.count("wavefrontsize32");
526 const bool HaveWave64 = Features.count("wavefrontsize64");
527 if (HaveWave32 && HaveWave64) {
528 ErrorMsg = "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive";
529 return false;
530 }
531 // Don't assume any wavesize with an unknown subtarget.
532 if (!IsNullGPU) {
533 // Default to wave32 if available, or wave64 if not
534 if (!HaveWave32 && !HaveWave64) {
535 StringRef DefaultWaveSizeFeature =
536 IsWave32Capable ? "wavefrontsize32" : "wavefrontsize64";
537 Features.insert(std::make_pair(DefaultWaveSizeFeature, true));
538 }
539 }
540 return true;
541}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isWave32Capable(StringRef GPU, const Triple &T)
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:154
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void push_back(const T &Elt)
Definition: SmallVector.h:416
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:857
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:112
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:257
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:287
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef getArchNameR600(GPUKind AK)
GPUKind
GPU kinds supported by the AMDGPU target.
Definition: TargetParser.h:35
StringRef getCanonicalArchName(const Triple &T, StringRef Arch)
void fillValidArchListR600(SmallVectorImpl< StringRef > &Values)
IsaVersion getIsaVersion(StringRef GPU)
void fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, StringMap< bool > &Features)
Fills Features map with default values for given target GPU.
void fillValidArchListAMDGCN(SmallVectorImpl< StringRef > &Values)
GPUKind parseArchAMDGCN(StringRef CPU)
bool insertWaveSizeFeature(StringRef GPU, const Triple &T, StringMap< bool > &Features, std::string &ErrorMsg)
Inserts wave size feature for given GPU into features map.
@ FEATURE_FAST_DENORMAL_F32
Definition: TargetParser.h:135
StringRef getArchNameAMDGCN(GPUKind AK)
unsigned getArchAttrAMDGCN(GPUKind AK)
unsigned getArchAttrR600(GPUKind AK)
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:1945
Instruction set architecture version.
Definition: TargetParser.h:117