LLVM 17.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"
18
19using namespace llvm;
20using namespace AMDGPU;
21
22namespace {
23
24struct GPUInfo {
26 StringLiteral CanonicalName;
28 unsigned Features;
29};
30
31constexpr GPUInfo R600GPUs[] = {
32 // Name Canonical Kind Features
33 // Name
34 {{"r600"}, {"r600"}, GK_R600, FEATURE_NONE },
35 {{"rv630"}, {"r600"}, GK_R600, FEATURE_NONE },
36 {{"rv635"}, {"r600"}, GK_R600, FEATURE_NONE },
37 {{"r630"}, {"r630"}, GK_R630, FEATURE_NONE },
38 {{"rs780"}, {"rs880"}, GK_RS880, FEATURE_NONE },
39 {{"rs880"}, {"rs880"}, GK_RS880, FEATURE_NONE },
40 {{"rv610"}, {"rs880"}, GK_RS880, FEATURE_NONE },
41 {{"rv620"}, {"rs880"}, GK_RS880, FEATURE_NONE },
42 {{"rv670"}, {"rv670"}, GK_RV670, FEATURE_NONE },
43 {{"rv710"}, {"rv710"}, GK_RV710, FEATURE_NONE },
44 {{"rv730"}, {"rv730"}, GK_RV730, FEATURE_NONE },
45 {{"rv740"}, {"rv770"}, GK_RV770, FEATURE_NONE },
46 {{"rv770"}, {"rv770"}, GK_RV770, FEATURE_NONE },
47 {{"cedar"}, {"cedar"}, GK_CEDAR, FEATURE_NONE },
48 {{"palm"}, {"cedar"}, GK_CEDAR, FEATURE_NONE },
49 {{"cypress"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA },
50 {{"hemlock"}, {"cypress"}, GK_CYPRESS, FEATURE_FMA },
51 {{"juniper"}, {"juniper"}, GK_JUNIPER, FEATURE_NONE },
52 {{"redwood"}, {"redwood"}, GK_REDWOOD, FEATURE_NONE },
53 {{"sumo"}, {"sumo"}, GK_SUMO, FEATURE_NONE },
54 {{"sumo2"}, {"sumo"}, GK_SUMO, FEATURE_NONE },
55 {{"barts"}, {"barts"}, GK_BARTS, FEATURE_NONE },
56 {{"caicos"}, {"caicos"}, GK_CAICOS, FEATURE_NONE },
57 {{"aruba"}, {"cayman"}, GK_CAYMAN, FEATURE_FMA },
58 {{"cayman"}, {"cayman"}, GK_CAYMAN, FEATURE_FMA },
59 {{"turks"}, {"turks"}, GK_TURKS, FEATURE_NONE }
60};
61
62// This table should be sorted by the value of GPUKind
63// Don't bother listing the implicitly true features
64constexpr GPUInfo AMDGCNGPUs[] = {
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},
123};
124
125const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef<GPUInfo> Table) {
126 GPUInfo Search = { {""}, {""}, AK, AMDGPU::FEATURE_NONE };
127
128 auto I =
129 llvm::lower_bound(Table, Search, [](const GPUInfo &A, const GPUInfo &B) {
130 return A.Kind < B.Kind;
131 });
132
133 if (I == Table.end())
134 return nullptr;
135 return I;
136}
137
138} // namespace
139
141 if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
142 return Entry->CanonicalName;
143 return "";
144}
145
147 if (const auto *Entry = getArchEntry(AK, R600GPUs))
148 return Entry->CanonicalName;
149 return "";
150}
151
153 for (const auto &C : AMDGCNGPUs) {
154 if (CPU == C.Name)
155 return C.Kind;
156 }
157
158 return AMDGPU::GPUKind::GK_NONE;
159}
160
162 for (const auto &C : R600GPUs) {
163 if (CPU == C.Name)
164 return C.Kind;
165 }
166
167 return AMDGPU::GPUKind::GK_NONE;
168}
169
170unsigned AMDGPU::getArchAttrAMDGCN(GPUKind AK) {
171 if (const auto *Entry = getArchEntry(AK, AMDGCNGPUs))
172 return Entry->Features;
173 return FEATURE_NONE;
174}
175
176unsigned AMDGPU::getArchAttrR600(GPUKind AK) {
177 if (const auto *Entry = getArchEntry(AK, R600GPUs))
178 return Entry->Features;
179 return FEATURE_NONE;
180}
181
182void AMDGPU::fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values) {
183 // XXX: Should this only report unique canonical names?
184 for (const auto &C : AMDGCNGPUs)
185 Values.push_back(C.Name);
186}
187
188void AMDGPU::fillValidArchListR600(SmallVectorImpl<StringRef> &Values) {
189 for (const auto &C : R600GPUs)
190 Values.push_back(C.Name);
191}
192
193AMDGPU::IsaVersion AMDGPU::getIsaVersion(StringRef GPU) {
195 if (AK == AMDGPU::GPUKind::GK_NONE) {
196 if (GPU == "generic-hsa")
197 return {7, 0, 0};
198 if (GPU == "generic")
199 return {6, 0, 0};
200 return {0, 0, 0};
201 }
202
203 switch (AK) {
204 case GK_GFX600: return {6, 0, 0};
205 case GK_GFX601: return {6, 0, 1};
206 case GK_GFX602: return {6, 0, 2};
207 case GK_GFX700: return {7, 0, 0};
208 case GK_GFX701: return {7, 0, 1};
209 case GK_GFX702: return {7, 0, 2};
210 case GK_GFX703: return {7, 0, 3};
211 case GK_GFX704: return {7, 0, 4};
212 case GK_GFX705: return {7, 0, 5};
213 case GK_GFX801: return {8, 0, 1};
214 case GK_GFX802: return {8, 0, 2};
215 case GK_GFX803: return {8, 0, 3};
216 case GK_GFX805: return {8, 0, 5};
217 case GK_GFX810: return {8, 1, 0};
218 case GK_GFX900: return {9, 0, 0};
219 case GK_GFX902: return {9, 0, 2};
220 case GK_GFX904: return {9, 0, 4};
221 case GK_GFX906: return {9, 0, 6};
222 case GK_GFX908: return {9, 0, 8};
223 case GK_GFX909: return {9, 0, 9};
224 case GK_GFX90A: return {9, 0, 10};
225 case GK_GFX90C: return {9, 0, 12};
226 case GK_GFX940: return {9, 4, 0};
227 case GK_GFX1010: return {10, 1, 0};
228 case GK_GFX1011: return {10, 1, 1};
229 case GK_GFX1012: return {10, 1, 2};
230 case GK_GFX1013: return {10, 1, 3};
231 case GK_GFX1030: return {10, 3, 0};
232 case GK_GFX1031: return {10, 3, 1};
233 case GK_GFX1032: return {10, 3, 2};
234 case GK_GFX1033: return {10, 3, 3};
235 case GK_GFX1034: return {10, 3, 4};
236 case GK_GFX1035: return {10, 3, 5};
237 case GK_GFX1036: return {10, 3, 6};
238 case GK_GFX1100: return {11, 0, 0};
239 case GK_GFX1101: return {11, 0, 1};
240 case GK_GFX1102: return {11, 0, 2};
241 case GK_GFX1103: return {11, 0, 3};
242 default: return {0, 0, 0};
243 }
244}
245
246StringRef AMDGPU::getCanonicalArchName(const Triple &T, StringRef Arch) {
247 assert(T.isAMDGPU());
248 auto ProcKind = T.isAMDGCN() ? parseArchAMDGCN(Arch) : parseArchR600(Arch);
249 if (ProcKind == GK_NONE)
250 return StringRef();
251
252 return T.isAMDGCN() ? getArchNameAMDGCN(ProcKind) : getArchNameR600(ProcKind);
253}
254
255void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
256 StringMap<bool> &Features) {
257 // XXX - What does the member GPU mean if device name string passed here?
258 if (T.isAMDGCN()) {
259 switch (parseArchAMDGCN(GPU)) {
260 case GK_GFX1103:
261 case GK_GFX1102:
262 case GK_GFX1101:
263 case GK_GFX1100:
264 Features["ci-insts"] = true;
265 Features["dot5-insts"] = true;
266 Features["dot7-insts"] = true;
267 Features["dot8-insts"] = true;
268 Features["dot9-insts"] = true;
269 Features["dot10-insts"] = true;
270 Features["dl-insts"] = true;
271 Features["16-bit-insts"] = true;
272 Features["dpp"] = true;
273 Features["gfx8-insts"] = true;
274 Features["gfx9-insts"] = true;
275 Features["gfx10-insts"] = true;
276 Features["gfx10-3-insts"] = true;
277 Features["gfx11-insts"] = true;
278 Features["atomic-fadd-rtn-insts"] = true;
279 break;
280 case GK_GFX1036:
281 case GK_GFX1035:
282 case GK_GFX1034:
283 case GK_GFX1033:
284 case GK_GFX1032:
285 case GK_GFX1031:
286 case GK_GFX1030:
287 Features["ci-insts"] = true;
288 Features["dot1-insts"] = true;
289 Features["dot2-insts"] = true;
290 Features["dot5-insts"] = true;
291 Features["dot6-insts"] = true;
292 Features["dot7-insts"] = true;
293 Features["dot10-insts"] = true;
294 Features["dl-insts"] = true;
295 Features["16-bit-insts"] = true;
296 Features["dpp"] = true;
297 Features["gfx8-insts"] = true;
298 Features["gfx9-insts"] = true;
299 Features["gfx10-insts"] = true;
300 Features["gfx10-3-insts"] = true;
301 Features["s-memrealtime"] = true;
302 Features["s-memtime-inst"] = true;
303 break;
304 case GK_GFX1012:
305 case GK_GFX1011:
306 Features["dot1-insts"] = true;
307 Features["dot2-insts"] = true;
308 Features["dot5-insts"] = true;
309 Features["dot6-insts"] = true;
310 Features["dot7-insts"] = true;
311 Features["dot10-insts"] = true;
312 [[fallthrough]];
313 case GK_GFX1013:
314 case GK_GFX1010:
315 Features["dl-insts"] = true;
316 Features["ci-insts"] = true;
317 Features["16-bit-insts"] = true;
318 Features["dpp"] = true;
319 Features["gfx8-insts"] = true;
320 Features["gfx9-insts"] = true;
321 Features["gfx10-insts"] = true;
322 Features["s-memrealtime"] = true;
323 Features["s-memtime-inst"] = true;
324 break;
325 case GK_GFX940:
326 Features["gfx940-insts"] = true;
327 Features["fp8-insts"] = true;
328 Features["atomic-ds-pk-add-16-insts"] = true;
329 Features["atomic-flat-pk-add-16-insts"] = true;
330 Features["atomic-global-pk-add-bf16-inst"] = true;
331 [[fallthrough]];
332 case GK_GFX90A:
333 Features["gfx90a-insts"] = true;
334 Features["atomic-buffer-global-pk-add-f16-insts"] = true;
335 Features["atomic-fadd-rtn-insts"] = true;
336 [[fallthrough]];
337 case GK_GFX908:
338 Features["dot3-insts"] = true;
339 Features["dot4-insts"] = true;
340 Features["dot5-insts"] = true;
341 Features["dot6-insts"] = true;
342 Features["mai-insts"] = true;
343 [[fallthrough]];
344 case GK_GFX906:
345 Features["dl-insts"] = true;
346 Features["dot1-insts"] = true;
347 Features["dot2-insts"] = true;
348 Features["dot7-insts"] = true;
349 Features["dot10-insts"] = true;
350 [[fallthrough]];
351 case GK_GFX90C:
352 case GK_GFX909:
353 case GK_GFX904:
354 case GK_GFX902:
355 case GK_GFX900:
356 Features["gfx9-insts"] = true;
357 [[fallthrough]];
358 case GK_GFX810:
359 case GK_GFX805:
360 case GK_GFX803:
361 case GK_GFX802:
362 case GK_GFX801:
363 Features["gfx8-insts"] = true;
364 Features["16-bit-insts"] = true;
365 Features["dpp"] = true;
366 Features["s-memrealtime"] = true;
367 [[fallthrough]];
368 case GK_GFX705:
369 case GK_GFX704:
370 case GK_GFX703:
371 case GK_GFX702:
372 case GK_GFX701:
373 case GK_GFX700:
374 Features["ci-insts"] = true;
375 [[fallthrough]];
376 case GK_GFX602:
377 case GK_GFX601:
378 case GK_GFX600:
379 Features["s-memtime-inst"] = true;
380 break;
381 case GK_NONE:
382 break;
383 default:
384 llvm_unreachable("Unhandled GPU!");
385 }
386 } else {
387 if (GPU.empty())
388 GPU = "r600";
389
390 switch (llvm::AMDGPU::parseArchR600(GPU)) {
391 case GK_CAYMAN:
392 case GK_CYPRESS:
393 case GK_RV770:
394 case GK_RV670:
395 // TODO: Add fp64 when implemented.
396 break;
397 case GK_TURKS:
398 case GK_CAICOS:
399 case GK_BARTS:
400 case GK_SUMO:
401 case GK_REDWOOD:
402 case GK_JUNIPER:
403 case GK_CEDAR:
404 case GK_RV730:
405 case GK_RV710:
406 case GK_RS880:
407 case GK_R630:
408 case GK_R600:
409 break;
410 default:
411 llvm_unreachable("Unhandled GPU!");
412 }
413 }
414}
415
416static bool isWave32Capable(StringRef GPU, const Triple &T) {
417 bool IsWave32Capable = false;
418 // XXX - What does the member GPU mean if device name string passed here?
419 if (T.isAMDGCN()) {
420 switch (parseArchAMDGCN(GPU)) {
421 case GK_GFX1103:
422 case GK_GFX1102:
423 case GK_GFX1101:
424 case GK_GFX1100:
425 case GK_GFX1036:
426 case GK_GFX1035:
427 case GK_GFX1034:
428 case GK_GFX1033:
429 case GK_GFX1032:
430 case GK_GFX1031:
431 case GK_GFX1030:
432 case GK_GFX1012:
433 case GK_GFX1011:
434 case GK_GFX1013:
435 case GK_GFX1010:
436 IsWave32Capable = true;
437 break;
438 default:
439 break;
440 }
441 }
442 return IsWave32Capable;
443}
444
445bool AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
446 StringMap<bool> &Features,
447 std::string &ErrorMsg) {
448 bool IsWave32Capable = isWave32Capable(GPU, T);
449 const bool IsNullGPU = GPU.empty();
450 // FIXME: Not diagnosing wavefrontsize32 on wave64 only targets.
451 const bool HaveWave32 =
452 (IsWave32Capable || IsNullGPU) && Features.count("wavefrontsize32");
453 const bool HaveWave64 = Features.count("wavefrontsize64");
454 if (HaveWave32 && HaveWave64) {
455 ErrorMsg = "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive";
456 return false;
457 }
458 // Don't assume any wavesize with an unknown subtarget.
459 if (!IsNullGPU) {
460 // Default to wave32 if available, or wave64 if not
461 if (!HaveWave32 && !HaveWave64) {
462 StringRef DefaultWaveSizeFeature =
463 IsWave32Capable ? "wavefrontsize32" : "wavefrontsize64";
464 Features.insert(std::make_pair(DefaultWaveSizeFeature, true));
465 }
466 }
467 return true;
468}
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())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
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:152
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:840
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:111
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:256
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:286
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
GPUKind parseArchAMDGCN(StringRef CPU)
@ FEATURE_FAST_DENORMAL_F32
Definition: TargetParser.h:128
StringRef getArchNameAMDGCN(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:2038
Instruction set architecture version.
Definition: TargetParser.h:110