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 | |
14 | #include "llvm/TargetParser/TargetParser.h" |
15 | #include "llvm/ADT/ArrayRef.h" |
16 | #include "llvm/TargetParser/Triple.h" |
17 | |
18 | using namespace llvm; |
19 | using namespace AMDGPU; |
20 | |
21 | namespace { |
22 | |
23 | struct GPUInfo { |
24 | StringLiteral Name; |
25 | StringLiteral CanonicalName; |
26 | AMDGPU::GPUKind Kind; |
27 | unsigned Features; |
28 | }; |
29 | |
30 | constexpr GPUInfo R600GPUs[] = { |
31 | // Name Canonical Kind Features |
32 | // Name |
33 | {.Name: {"r600" }, .CanonicalName: {"r600" }, .Kind: GK_R600, .Features: FEATURE_NONE }, |
34 | {.Name: {"rv630" }, .CanonicalName: {"r600" }, .Kind: GK_R600, .Features: FEATURE_NONE }, |
35 | {.Name: {"rv635" }, .CanonicalName: {"r600" }, .Kind: GK_R600, .Features: FEATURE_NONE }, |
36 | {.Name: {"r630" }, .CanonicalName: {"r630" }, .Kind: GK_R630, .Features: FEATURE_NONE }, |
37 | {.Name: {"rs780" }, .CanonicalName: {"rs880" }, .Kind: GK_RS880, .Features: FEATURE_NONE }, |
38 | {.Name: {"rs880" }, .CanonicalName: {"rs880" }, .Kind: GK_RS880, .Features: FEATURE_NONE }, |
39 | {.Name: {"rv610" }, .CanonicalName: {"rs880" }, .Kind: GK_RS880, .Features: FEATURE_NONE }, |
40 | {.Name: {"rv620" }, .CanonicalName: {"rs880" }, .Kind: GK_RS880, .Features: FEATURE_NONE }, |
41 | {.Name: {"rv670" }, .CanonicalName: {"rv670" }, .Kind: GK_RV670, .Features: FEATURE_NONE }, |
42 | {.Name: {"rv710" }, .CanonicalName: {"rv710" }, .Kind: GK_RV710, .Features: FEATURE_NONE }, |
43 | {.Name: {"rv730" }, .CanonicalName: {"rv730" }, .Kind: GK_RV730, .Features: FEATURE_NONE }, |
44 | {.Name: {"rv740" }, .CanonicalName: {"rv770" }, .Kind: GK_RV770, .Features: FEATURE_NONE }, |
45 | {.Name: {"rv770" }, .CanonicalName: {"rv770" }, .Kind: GK_RV770, .Features: FEATURE_NONE }, |
46 | {.Name: {"cedar" }, .CanonicalName: {"cedar" }, .Kind: GK_CEDAR, .Features: FEATURE_NONE }, |
47 | {.Name: {"palm" }, .CanonicalName: {"cedar" }, .Kind: GK_CEDAR, .Features: FEATURE_NONE }, |
48 | {.Name: {"cypress" }, .CanonicalName: {"cypress" }, .Kind: GK_CYPRESS, .Features: FEATURE_FMA }, |
49 | {.Name: {"hemlock" }, .CanonicalName: {"cypress" }, .Kind: GK_CYPRESS, .Features: FEATURE_FMA }, |
50 | {.Name: {"juniper" }, .CanonicalName: {"juniper" }, .Kind: GK_JUNIPER, .Features: FEATURE_NONE }, |
51 | {.Name: {"redwood" }, .CanonicalName: {"redwood" }, .Kind: GK_REDWOOD, .Features: FEATURE_NONE }, |
52 | {.Name: {"sumo" }, .CanonicalName: {"sumo" }, .Kind: GK_SUMO, .Features: FEATURE_NONE }, |
53 | {.Name: {"sumo2" }, .CanonicalName: {"sumo" }, .Kind: GK_SUMO, .Features: FEATURE_NONE }, |
54 | {.Name: {"barts" }, .CanonicalName: {"barts" }, .Kind: GK_BARTS, .Features: FEATURE_NONE }, |
55 | {.Name: {"caicos" }, .CanonicalName: {"caicos" }, .Kind: GK_CAICOS, .Features: FEATURE_NONE }, |
56 | {.Name: {"aruba" }, .CanonicalName: {"cayman" }, .Kind: GK_CAYMAN, .Features: FEATURE_FMA }, |
57 | {.Name: {"cayman" }, .CanonicalName: {"cayman" }, .Kind: GK_CAYMAN, .Features: FEATURE_FMA }, |
58 | {.Name: {"turks" }, .CanonicalName: {"turks" }, .Kind: GK_TURKS, .Features: FEATURE_NONE } |
59 | }; |
60 | |
61 | // This table should be sorted by the value of GPUKind |
62 | // Don't bother listing the implicitly true features |
63 | constexpr GPUInfo AMDGCNGPUs[] = { |
64 | // clang-format off |
65 | // Name Canonical Kind Features |
66 | // Name |
67 | {.Name: {"gfx600" }, .CanonicalName: {"gfx600" }, .Kind: GK_GFX600, .Features: FEATURE_FAST_FMA_F32}, |
68 | {.Name: {"tahiti" }, .CanonicalName: {"gfx600" }, .Kind: GK_GFX600, .Features: FEATURE_FAST_FMA_F32}, |
69 | {.Name: {"gfx601" }, .CanonicalName: {"gfx601" }, .Kind: GK_GFX601, .Features: FEATURE_NONE}, |
70 | {.Name: {"pitcairn" }, .CanonicalName: {"gfx601" }, .Kind: GK_GFX601, .Features: FEATURE_NONE}, |
71 | {.Name: {"verde" }, .CanonicalName: {"gfx601" }, .Kind: GK_GFX601, .Features: FEATURE_NONE}, |
72 | {.Name: {"gfx602" }, .CanonicalName: {"gfx602" }, .Kind: GK_GFX602, .Features: FEATURE_NONE}, |
73 | {.Name: {"hainan" }, .CanonicalName: {"gfx602" }, .Kind: GK_GFX602, .Features: FEATURE_NONE}, |
74 | {.Name: {"oland" }, .CanonicalName: {"gfx602" }, .Kind: GK_GFX602, .Features: FEATURE_NONE}, |
75 | {.Name: {"gfx700" }, .CanonicalName: {"gfx700" }, .Kind: GK_GFX700, .Features: FEATURE_NONE}, |
76 | {.Name: {"kaveri" }, .CanonicalName: {"gfx700" }, .Kind: GK_GFX700, .Features: FEATURE_NONE}, |
77 | {.Name: {"gfx701" }, .CanonicalName: {"gfx701" }, .Kind: GK_GFX701, .Features: FEATURE_FAST_FMA_F32}, |
78 | {.Name: {"hawaii" }, .CanonicalName: {"gfx701" }, .Kind: GK_GFX701, .Features: FEATURE_FAST_FMA_F32}, |
79 | {.Name: {"gfx702" }, .CanonicalName: {"gfx702" }, .Kind: GK_GFX702, .Features: FEATURE_FAST_FMA_F32}, |
80 | {.Name: {"gfx703" }, .CanonicalName: {"gfx703" }, .Kind: GK_GFX703, .Features: FEATURE_NONE}, |
81 | {.Name: {"kabini" }, .CanonicalName: {"gfx703" }, .Kind: GK_GFX703, .Features: FEATURE_NONE}, |
82 | {.Name: {"mullins" }, .CanonicalName: {"gfx703" }, .Kind: GK_GFX703, .Features: FEATURE_NONE}, |
83 | {.Name: {"gfx704" }, .CanonicalName: {"gfx704" }, .Kind: GK_GFX704, .Features: FEATURE_NONE}, |
84 | {.Name: {"bonaire" }, .CanonicalName: {"gfx704" }, .Kind: GK_GFX704, .Features: FEATURE_NONE}, |
85 | {.Name: {"gfx705" }, .CanonicalName: {"gfx705" }, .Kind: GK_GFX705, .Features: FEATURE_NONE}, |
86 | {.Name: {"gfx801" }, .CanonicalName: {"gfx801" }, .Kind: GK_GFX801, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
87 | {.Name: {"carrizo" }, .CanonicalName: {"gfx801" }, .Kind: GK_GFX801, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
88 | {.Name: {"gfx802" }, .CanonicalName: {"gfx802" }, .Kind: GK_GFX802, .Features: FEATURE_FAST_DENORMAL_F32}, |
89 | {.Name: {"iceland" }, .CanonicalName: {"gfx802" }, .Kind: GK_GFX802, .Features: FEATURE_FAST_DENORMAL_F32}, |
90 | {.Name: {"tonga" }, .CanonicalName: {"gfx802" }, .Kind: GK_GFX802, .Features: FEATURE_FAST_DENORMAL_F32}, |
91 | {.Name: {"gfx803" }, .CanonicalName: {"gfx803" }, .Kind: GK_GFX803, .Features: FEATURE_FAST_DENORMAL_F32}, |
92 | {.Name: {"fiji" }, .CanonicalName: {"gfx803" }, .Kind: GK_GFX803, .Features: FEATURE_FAST_DENORMAL_F32}, |
93 | {.Name: {"polaris10" }, .CanonicalName: {"gfx803" }, .Kind: GK_GFX803, .Features: FEATURE_FAST_DENORMAL_F32}, |
94 | {.Name: {"polaris11" }, .CanonicalName: {"gfx803" }, .Kind: GK_GFX803, .Features: FEATURE_FAST_DENORMAL_F32}, |
95 | {.Name: {"gfx805" }, .CanonicalName: {"gfx805" }, .Kind: GK_GFX805, .Features: FEATURE_FAST_DENORMAL_F32}, |
96 | {.Name: {"tongapro" }, .CanonicalName: {"gfx805" }, .Kind: GK_GFX805, .Features: FEATURE_FAST_DENORMAL_F32}, |
97 | {.Name: {"gfx810" }, .CanonicalName: {"gfx810" }, .Kind: GK_GFX810, .Features: FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
98 | {.Name: {"stoney" }, .CanonicalName: {"gfx810" }, .Kind: GK_GFX810, .Features: FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
99 | {.Name: {"gfx900" }, .CanonicalName: {"gfx900" }, .Kind: GK_GFX900, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
100 | {.Name: {"gfx902" }, .CanonicalName: {"gfx902" }, .Kind: GK_GFX902, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
101 | {.Name: {"gfx904" }, .CanonicalName: {"gfx904" }, .Kind: GK_GFX904, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
102 | {.Name: {"gfx906" }, .CanonicalName: {"gfx906" }, .Kind: GK_GFX906, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, |
103 | {.Name: {"gfx908" }, .CanonicalName: {"gfx908" }, .Kind: GK_GFX908, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, |
104 | {.Name: {"gfx909" }, .CanonicalName: {"gfx909" }, .Kind: GK_GFX909, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
105 | {.Name: {"gfx90a" }, .CanonicalName: {"gfx90a" }, .Kind: GK_GFX90A, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, |
106 | {.Name: {"gfx90c" }, .CanonicalName: {"gfx90c" }, .Kind: GK_GFX90C, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
107 | {.Name: {"gfx940" }, .CanonicalName: {"gfx940" }, .Kind: GK_GFX940, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, |
108 | {.Name: {"gfx941" }, .CanonicalName: {"gfx941" }, .Kind: GK_GFX941, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, |
109 | {.Name: {"gfx942" }, .CanonicalName: {"gfx942" }, .Kind: GK_GFX942, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC}, |
110 | {.Name: {"gfx1010" }, .CanonicalName: {"gfx1010" }, .Kind: GK_GFX1010, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, |
111 | {.Name: {"gfx1011" }, .CanonicalName: {"gfx1011" }, .Kind: GK_GFX1011, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, |
112 | {.Name: {"gfx1012" }, .CanonicalName: {"gfx1012" }, .Kind: GK_GFX1012, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, |
113 | {.Name: {"gfx1013" }, .CanonicalName: {"gfx1013" }, .Kind: GK_GFX1013, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, |
114 | {.Name: {"gfx1030" }, .CanonicalName: {"gfx1030" }, .Kind: GK_GFX1030, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
115 | {.Name: {"gfx1031" }, .CanonicalName: {"gfx1031" }, .Kind: GK_GFX1031, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
116 | {.Name: {"gfx1032" }, .CanonicalName: {"gfx1032" }, .Kind: GK_GFX1032, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
117 | {.Name: {"gfx1033" }, .CanonicalName: {"gfx1033" }, .Kind: GK_GFX1033, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
118 | {.Name: {"gfx1034" }, .CanonicalName: {"gfx1034" }, .Kind: GK_GFX1034, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
119 | {.Name: {"gfx1035" }, .CanonicalName: {"gfx1035" }, .Kind: GK_GFX1035, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
120 | {.Name: {"gfx1036" }, .CanonicalName: {"gfx1036" }, .Kind: GK_GFX1036, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
121 | {.Name: {"gfx1100" }, .CanonicalName: {"gfx1100" }, .Kind: GK_GFX1100, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
122 | {.Name: {"gfx1101" }, .CanonicalName: {"gfx1101" }, .Kind: GK_GFX1101, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
123 | {.Name: {"gfx1102" }, .CanonicalName: {"gfx1102" }, .Kind: GK_GFX1102, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
124 | {.Name: {"gfx1103" }, .CanonicalName: {"gfx1103" }, .Kind: GK_GFX1103, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
125 | {.Name: {"gfx1150" }, .CanonicalName: {"gfx1150" }, .Kind: GK_GFX1150, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
126 | {.Name: {"gfx1151" }, .CanonicalName: {"gfx1151" }, .Kind: GK_GFX1151, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
127 | {.Name: {"gfx1152" }, .CanonicalName: {"gfx1152" }, .Kind: GK_GFX1152, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
128 | {.Name: {"gfx1200" }, .CanonicalName: {"gfx1200" }, .Kind: GK_GFX1200, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
129 | {.Name: {"gfx1201" }, .CanonicalName: {"gfx1201" }, .Kind: GK_GFX1201, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
130 | |
131 | {.Name: {"gfx9-generic" }, .CanonicalName: {"gfx9-generic" }, .Kind: GK_GFX9_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK}, |
132 | {.Name: {"gfx10-1-generic" }, .CanonicalName: {"gfx10-1-generic" }, .Kind: GK_GFX10_1_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP}, |
133 | {.Name: {"gfx10-3-generic" }, .CanonicalName: {"gfx10-3-generic" }, .Kind: GK_GFX10_3_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
134 | {.Name: {"gfx11-generic" }, .CanonicalName: {"gfx11-generic" }, .Kind: GK_GFX11_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
135 | {.Name: {"gfx12-generic" }, .CanonicalName: {"gfx12-generic" }, .Kind: GK_GFX12_GENERIC, .Features: FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP}, |
136 | // clang-format on |
137 | }; |
138 | |
139 | const GPUInfo *getArchEntry(AMDGPU::GPUKind AK, ArrayRef<GPUInfo> Table) { |
140 | GPUInfo Search = { .Name: {"" }, .CanonicalName: {"" }, .Kind: AK, .Features: AMDGPU::FEATURE_NONE }; |
141 | |
142 | auto I = |
143 | llvm::lower_bound(Range&: Table, Value&: Search, C: [](const GPUInfo &A, const GPUInfo &B) { |
144 | return A.Kind < B.Kind; |
145 | }); |
146 | |
147 | if (I == Table.end() || I->Kind != Search.Kind) |
148 | return nullptr; |
149 | return I; |
150 | } |
151 | |
152 | } // namespace |
153 | |
154 | StringRef llvm::AMDGPU::getArchFamilyNameAMDGCN(GPUKind AK) { |
155 | switch (AK) { |
156 | case AMDGPU::GK_GFX9_GENERIC: |
157 | return "gfx9" ; |
158 | case AMDGPU::GK_GFX10_1_GENERIC: |
159 | case AMDGPU::GK_GFX10_3_GENERIC: |
160 | return "gfx10" ; |
161 | case AMDGPU::GK_GFX11_GENERIC: |
162 | return "gfx11" ; |
163 | case AMDGPU::GK_GFX12_GENERIC: |
164 | return "gfx12" ; |
165 | default: { |
166 | StringRef ArchName = getArchNameAMDGCN(AK); |
167 | return ArchName.empty() ? "" : ArchName.drop_back(N: 2); |
168 | } |
169 | } |
170 | } |
171 | |
172 | StringRef llvm::AMDGPU::getArchNameAMDGCN(GPUKind AK) { |
173 | if (const auto *Entry = getArchEntry(AK, Table: AMDGCNGPUs)) |
174 | return Entry->CanonicalName; |
175 | return "" ; |
176 | } |
177 | |
178 | StringRef llvm::AMDGPU::getArchNameR600(GPUKind AK) { |
179 | if (const auto *Entry = getArchEntry(AK, Table: R600GPUs)) |
180 | return Entry->CanonicalName; |
181 | return "" ; |
182 | } |
183 | |
184 | AMDGPU::GPUKind llvm::AMDGPU::parseArchAMDGCN(StringRef CPU) { |
185 | for (const auto &C : AMDGCNGPUs) { |
186 | if (CPU == C.Name) |
187 | return C.Kind; |
188 | } |
189 | |
190 | return AMDGPU::GPUKind::GK_NONE; |
191 | } |
192 | |
193 | AMDGPU::GPUKind llvm::AMDGPU::parseArchR600(StringRef CPU) { |
194 | for (const auto &C : R600GPUs) { |
195 | if (CPU == C.Name) |
196 | return C.Kind; |
197 | } |
198 | |
199 | return AMDGPU::GPUKind::GK_NONE; |
200 | } |
201 | |
202 | unsigned AMDGPU::getArchAttrAMDGCN(GPUKind AK) { |
203 | if (const auto *Entry = getArchEntry(AK, Table: AMDGCNGPUs)) |
204 | return Entry->Features; |
205 | return FEATURE_NONE; |
206 | } |
207 | |
208 | unsigned AMDGPU::getArchAttrR600(GPUKind AK) { |
209 | if (const auto *Entry = getArchEntry(AK, Table: R600GPUs)) |
210 | return Entry->Features; |
211 | return FEATURE_NONE; |
212 | } |
213 | |
214 | void AMDGPU::fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values) { |
215 | // XXX: Should this only report unique canonical names? |
216 | for (const auto &C : AMDGCNGPUs) |
217 | Values.push_back(Elt: C.Name); |
218 | } |
219 | |
220 | void AMDGPU::fillValidArchListR600(SmallVectorImpl<StringRef> &Values) { |
221 | for (const auto &C : R600GPUs) |
222 | Values.push_back(Elt: C.Name); |
223 | } |
224 | |
225 | AMDGPU::IsaVersion AMDGPU::getIsaVersion(StringRef GPU) { |
226 | AMDGPU::GPUKind AK = parseArchAMDGCN(CPU: GPU); |
227 | if (AK == AMDGPU::GPUKind::GK_NONE) { |
228 | if (GPU == "generic-hsa" ) |
229 | return {.Major: 7, .Minor: 0, .Stepping: 0}; |
230 | if (GPU == "generic" ) |
231 | return {.Major: 6, .Minor: 0, .Stepping: 0}; |
232 | return {.Major: 0, .Minor: 0, .Stepping: 0}; |
233 | } |
234 | |
235 | // clang-format off |
236 | switch (AK) { |
237 | case GK_GFX600: return {.Major: 6, .Minor: 0, .Stepping: 0}; |
238 | case GK_GFX601: return {.Major: 6, .Minor: 0, .Stepping: 1}; |
239 | case GK_GFX602: return {.Major: 6, .Minor: 0, .Stepping: 2}; |
240 | case GK_GFX700: return {.Major: 7, .Minor: 0, .Stepping: 0}; |
241 | case GK_GFX701: return {.Major: 7, .Minor: 0, .Stepping: 1}; |
242 | case GK_GFX702: return {.Major: 7, .Minor: 0, .Stepping: 2}; |
243 | case GK_GFX703: return {.Major: 7, .Minor: 0, .Stepping: 3}; |
244 | case GK_GFX704: return {.Major: 7, .Minor: 0, .Stepping: 4}; |
245 | case GK_GFX705: return {.Major: 7, .Minor: 0, .Stepping: 5}; |
246 | case GK_GFX801: return {.Major: 8, .Minor: 0, .Stepping: 1}; |
247 | case GK_GFX802: return {.Major: 8, .Minor: 0, .Stepping: 2}; |
248 | case GK_GFX803: return {.Major: 8, .Minor: 0, .Stepping: 3}; |
249 | case GK_GFX805: return {.Major: 8, .Minor: 0, .Stepping: 5}; |
250 | case GK_GFX810: return {.Major: 8, .Minor: 1, .Stepping: 0}; |
251 | case GK_GFX900: return {.Major: 9, .Minor: 0, .Stepping: 0}; |
252 | case GK_GFX902: return {.Major: 9, .Minor: 0, .Stepping: 2}; |
253 | case GK_GFX904: return {.Major: 9, .Minor: 0, .Stepping: 4}; |
254 | case GK_GFX906: return {.Major: 9, .Minor: 0, .Stepping: 6}; |
255 | case GK_GFX908: return {.Major: 9, .Minor: 0, .Stepping: 8}; |
256 | case GK_GFX909: return {.Major: 9, .Minor: 0, .Stepping: 9}; |
257 | case GK_GFX90A: return {.Major: 9, .Minor: 0, .Stepping: 10}; |
258 | case GK_GFX90C: return {.Major: 9, .Minor: 0, .Stepping: 12}; |
259 | case GK_GFX940: return {.Major: 9, .Minor: 4, .Stepping: 0}; |
260 | case GK_GFX941: return {.Major: 9, .Minor: 4, .Stepping: 1}; |
261 | case GK_GFX942: return {.Major: 9, .Minor: 4, .Stepping: 2}; |
262 | case GK_GFX1010: return {.Major: 10, .Minor: 1, .Stepping: 0}; |
263 | case GK_GFX1011: return {.Major: 10, .Minor: 1, .Stepping: 1}; |
264 | case GK_GFX1012: return {.Major: 10, .Minor: 1, .Stepping: 2}; |
265 | case GK_GFX1013: return {.Major: 10, .Minor: 1, .Stepping: 3}; |
266 | case GK_GFX1030: return {.Major: 10, .Minor: 3, .Stepping: 0}; |
267 | case GK_GFX1031: return {.Major: 10, .Minor: 3, .Stepping: 1}; |
268 | case GK_GFX1032: return {.Major: 10, .Minor: 3, .Stepping: 2}; |
269 | case GK_GFX1033: return {.Major: 10, .Minor: 3, .Stepping: 3}; |
270 | case GK_GFX1034: return {.Major: 10, .Minor: 3, .Stepping: 4}; |
271 | case GK_GFX1035: return {.Major: 10, .Minor: 3, .Stepping: 5}; |
272 | case GK_GFX1036: return {.Major: 10, .Minor: 3, .Stepping: 6}; |
273 | case GK_GFX1100: return {.Major: 11, .Minor: 0, .Stepping: 0}; |
274 | case GK_GFX1101: return {.Major: 11, .Minor: 0, .Stepping: 1}; |
275 | case GK_GFX1102: return {.Major: 11, .Minor: 0, .Stepping: 2}; |
276 | case GK_GFX1103: return {.Major: 11, .Minor: 0, .Stepping: 3}; |
277 | case GK_GFX1150: return {.Major: 11, .Minor: 5, .Stepping: 0}; |
278 | case GK_GFX1151: return {.Major: 11, .Minor: 5, .Stepping: 1}; |
279 | case GK_GFX1152: return {.Major: 11, .Minor: 5, .Stepping: 2}; |
280 | case GK_GFX1200: return {.Major: 12, .Minor: 0, .Stepping: 0}; |
281 | case GK_GFX1201: return {.Major: 12, .Minor: 0, .Stepping: 1}; |
282 | |
283 | // Generic targets return the lowest common denominator |
284 | // within their family. That is, the ISA that is the most |
285 | // restricted in terms of features. |
286 | // |
287 | // gfx9-generic is tricky because there is no lowest |
288 | // common denominator, so we return gfx900 which has mad-mix |
289 | // but this family doesn't have it. |
290 | // |
291 | // This API should never be used to check for a particular |
292 | // feature anyway. |
293 | // |
294 | // TODO: Split up this API depending on its caller so |
295 | // generic target handling is more obvious and less risky. |
296 | case GK_GFX9_GENERIC: return {.Major: 9, .Minor: 0, .Stepping: 0}; |
297 | case GK_GFX10_1_GENERIC: return {.Major: 10, .Minor: 1, .Stepping: 0}; |
298 | case GK_GFX10_3_GENERIC: return {.Major: 10, .Minor: 3, .Stepping: 0}; |
299 | case GK_GFX11_GENERIC: return {.Major: 11, .Minor: 0, .Stepping: 3}; |
300 | case GK_GFX12_GENERIC: return {.Major: 12, .Minor: 0, .Stepping: 0}; |
301 | default: return {.Major: 0, .Minor: 0, .Stepping: 0}; |
302 | } |
303 | // clang-format on |
304 | } |
305 | |
306 | StringRef AMDGPU::getCanonicalArchName(const Triple &T, StringRef Arch) { |
307 | assert(T.isAMDGPU()); |
308 | auto ProcKind = T.isAMDGCN() ? parseArchAMDGCN(CPU: Arch) : parseArchR600(CPU: Arch); |
309 | if (ProcKind == GK_NONE) |
310 | return StringRef(); |
311 | |
312 | return T.isAMDGCN() ? getArchNameAMDGCN(AK: ProcKind) : getArchNameR600(AK: ProcKind); |
313 | } |
314 | |
315 | void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T, |
316 | StringMap<bool> &Features) { |
317 | // XXX - What does the member GPU mean if device name string passed here? |
318 | if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) { |
319 | // AMDGCN SPIRV must support the union of all AMDGCN features. |
320 | Features["atomic-ds-pk-add-16-insts" ] = true; |
321 | Features["atomic-flat-pk-add-16-insts" ] = true; |
322 | Features["atomic-buffer-global-pk-add-f16-insts" ] = true; |
323 | Features["atomic-global-pk-add-bf16-inst" ] = true; |
324 | Features["atomic-fadd-rtn-insts" ] = true; |
325 | Features["ci-insts" ] = true; |
326 | Features["dot1-insts" ] = true; |
327 | Features["dot2-insts" ] = true; |
328 | Features["dot3-insts" ] = true; |
329 | Features["dot4-insts" ] = true; |
330 | Features["dot5-insts" ] = true; |
331 | Features["dot7-insts" ] = true; |
332 | Features["dot8-insts" ] = true; |
333 | Features["dot9-insts" ] = true; |
334 | Features["dot10-insts" ] = true; |
335 | Features["dot11-insts" ] = true; |
336 | Features["dl-insts" ] = true; |
337 | Features["16-bit-insts" ] = true; |
338 | Features["dpp" ] = true; |
339 | Features["gfx8-insts" ] = true; |
340 | Features["gfx9-insts" ] = true; |
341 | Features["gfx90a-insts" ] = true; |
342 | Features["gfx940-insts" ] = true; |
343 | Features["gfx10-insts" ] = true; |
344 | Features["gfx10-3-insts" ] = true; |
345 | Features["gfx11-insts" ] = true; |
346 | Features["gfx12-insts" ] = true; |
347 | Features["image-insts" ] = true; |
348 | Features["fp8-conversion-insts" ] = true; |
349 | Features["s-memrealtime" ] = true; |
350 | Features["s-memtime-inst" ] = true; |
351 | Features["gws" ] = true; |
352 | Features["fp8-insts" ] = true; |
353 | Features["fp8-conversion-insts" ] = true; |
354 | Features["atomic-ds-pk-add-16-insts" ] = true; |
355 | Features["mai-insts" ] = true; |
356 | Features["wavefrontsize32" ] = true; |
357 | Features["wavefrontsize64" ] = true; |
358 | } else if (T.isAMDGCN()) { |
359 | switch (parseArchAMDGCN(CPU: GPU)) { |
360 | case GK_GFX1201: |
361 | case GK_GFX1200: |
362 | case GK_GFX12_GENERIC: |
363 | Features["ci-insts" ] = true; |
364 | Features["dot7-insts" ] = true; |
365 | Features["dot8-insts" ] = true; |
366 | Features["dot9-insts" ] = true; |
367 | Features["dot10-insts" ] = true; |
368 | Features["dot11-insts" ] = true; |
369 | Features["dl-insts" ] = true; |
370 | Features["atomic-ds-pk-add-16-insts" ] = true; |
371 | Features["atomic-flat-pk-add-16-insts" ] = true; |
372 | Features["atomic-buffer-global-pk-add-f16-insts" ] = true; |
373 | Features["atomic-global-pk-add-bf16-inst" ] = true; |
374 | Features["16-bit-insts" ] = true; |
375 | Features["dpp" ] = true; |
376 | Features["gfx8-insts" ] = true; |
377 | Features["gfx9-insts" ] = true; |
378 | Features["gfx10-insts" ] = true; |
379 | Features["gfx10-3-insts" ] = true; |
380 | Features["gfx11-insts" ] = true; |
381 | Features["gfx12-insts" ] = true; |
382 | Features["atomic-fadd-rtn-insts" ] = true; |
383 | Features["image-insts" ] = true; |
384 | Features["fp8-conversion-insts" ] = true; |
385 | break; |
386 | case GK_GFX1152: |
387 | case GK_GFX1151: |
388 | case GK_GFX1150: |
389 | case GK_GFX1103: |
390 | case GK_GFX1102: |
391 | case GK_GFX1101: |
392 | case GK_GFX1100: |
393 | case GK_GFX11_GENERIC: |
394 | Features["ci-insts" ] = true; |
395 | Features["dot5-insts" ] = true; |
396 | Features["dot7-insts" ] = true; |
397 | Features["dot8-insts" ] = true; |
398 | Features["dot9-insts" ] = true; |
399 | Features["dot10-insts" ] = true; |
400 | Features["dl-insts" ] = true; |
401 | Features["16-bit-insts" ] = true; |
402 | Features["dpp" ] = true; |
403 | Features["gfx8-insts" ] = true; |
404 | Features["gfx9-insts" ] = true; |
405 | Features["gfx10-insts" ] = true; |
406 | Features["gfx10-3-insts" ] = true; |
407 | Features["gfx11-insts" ] = true; |
408 | Features["atomic-fadd-rtn-insts" ] = true; |
409 | Features["image-insts" ] = true; |
410 | Features["gws" ] = true; |
411 | break; |
412 | case GK_GFX1036: |
413 | case GK_GFX1035: |
414 | case GK_GFX1034: |
415 | case GK_GFX1033: |
416 | case GK_GFX1032: |
417 | case GK_GFX1031: |
418 | case GK_GFX1030: |
419 | case GK_GFX10_3_GENERIC: |
420 | Features["ci-insts" ] = true; |
421 | Features["dot1-insts" ] = true; |
422 | Features["dot2-insts" ] = true; |
423 | Features["dot5-insts" ] = true; |
424 | Features["dot6-insts" ] = true; |
425 | Features["dot7-insts" ] = true; |
426 | Features["dot10-insts" ] = true; |
427 | Features["dl-insts" ] = true; |
428 | Features["16-bit-insts" ] = true; |
429 | Features["dpp" ] = true; |
430 | Features["gfx8-insts" ] = true; |
431 | Features["gfx9-insts" ] = true; |
432 | Features["gfx10-insts" ] = true; |
433 | Features["gfx10-3-insts" ] = true; |
434 | Features["image-insts" ] = true; |
435 | Features["s-memrealtime" ] = true; |
436 | Features["s-memtime-inst" ] = true; |
437 | Features["gws" ] = true; |
438 | break; |
439 | case GK_GFX1012: |
440 | case GK_GFX1011: |
441 | Features["dot1-insts" ] = true; |
442 | Features["dot2-insts" ] = true; |
443 | Features["dot5-insts" ] = true; |
444 | Features["dot6-insts" ] = true; |
445 | Features["dot7-insts" ] = true; |
446 | Features["dot10-insts" ] = true; |
447 | [[fallthrough]]; |
448 | case GK_GFX1013: |
449 | case GK_GFX1010: |
450 | case GK_GFX10_1_GENERIC: |
451 | Features["dl-insts" ] = true; |
452 | Features["ci-insts" ] = true; |
453 | Features["16-bit-insts" ] = true; |
454 | Features["dpp" ] = true; |
455 | Features["gfx8-insts" ] = true; |
456 | Features["gfx9-insts" ] = true; |
457 | Features["gfx10-insts" ] = true; |
458 | Features["image-insts" ] = true; |
459 | Features["s-memrealtime" ] = true; |
460 | Features["s-memtime-inst" ] = true; |
461 | Features["gws" ] = true; |
462 | break; |
463 | case GK_GFX942: |
464 | case GK_GFX941: |
465 | case GK_GFX940: |
466 | Features["gfx940-insts" ] = true; |
467 | Features["fp8-insts" ] = true; |
468 | Features["fp8-conversion-insts" ] = true; |
469 | Features["atomic-ds-pk-add-16-insts" ] = true; |
470 | Features["atomic-flat-pk-add-16-insts" ] = true; |
471 | Features["atomic-global-pk-add-bf16-inst" ] = true; |
472 | Features["gfx90a-insts" ] = true; |
473 | Features["atomic-buffer-global-pk-add-f16-insts" ] = true; |
474 | Features["atomic-fadd-rtn-insts" ] = true; |
475 | Features["dot3-insts" ] = true; |
476 | Features["dot4-insts" ] = true; |
477 | Features["dot5-insts" ] = true; |
478 | Features["dot6-insts" ] = true; |
479 | Features["mai-insts" ] = true; |
480 | Features["dl-insts" ] = true; |
481 | Features["dot1-insts" ] = true; |
482 | Features["dot2-insts" ] = true; |
483 | Features["dot7-insts" ] = true; |
484 | Features["dot10-insts" ] = true; |
485 | Features["gfx9-insts" ] = true; |
486 | Features["gfx8-insts" ] = true; |
487 | Features["16-bit-insts" ] = true; |
488 | Features["dpp" ] = true; |
489 | Features["s-memrealtime" ] = true; |
490 | Features["ci-insts" ] = true; |
491 | Features["s-memtime-inst" ] = true; |
492 | Features["gws" ] = true; |
493 | break; |
494 | case GK_GFX90A: |
495 | Features["gfx90a-insts" ] = true; |
496 | Features["atomic-buffer-global-pk-add-f16-insts" ] = true; |
497 | Features["atomic-fadd-rtn-insts" ] = true; |
498 | [[fallthrough]]; |
499 | case GK_GFX908: |
500 | Features["dot3-insts" ] = true; |
501 | Features["dot4-insts" ] = true; |
502 | Features["dot5-insts" ] = true; |
503 | Features["dot6-insts" ] = true; |
504 | Features["mai-insts" ] = true; |
505 | [[fallthrough]]; |
506 | case GK_GFX906: |
507 | Features["dl-insts" ] = true; |
508 | Features["dot1-insts" ] = true; |
509 | Features["dot2-insts" ] = true; |
510 | Features["dot7-insts" ] = true; |
511 | Features["dot10-insts" ] = true; |
512 | [[fallthrough]]; |
513 | case GK_GFX90C: |
514 | case GK_GFX909: |
515 | case GK_GFX904: |
516 | case GK_GFX902: |
517 | case GK_GFX900: |
518 | case GK_GFX9_GENERIC: |
519 | Features["gfx9-insts" ] = true; |
520 | [[fallthrough]]; |
521 | case GK_GFX810: |
522 | case GK_GFX805: |
523 | case GK_GFX803: |
524 | case GK_GFX802: |
525 | case GK_GFX801: |
526 | Features["gfx8-insts" ] = true; |
527 | Features["16-bit-insts" ] = true; |
528 | Features["dpp" ] = true; |
529 | Features["s-memrealtime" ] = true; |
530 | [[fallthrough]]; |
531 | case GK_GFX705: |
532 | case GK_GFX704: |
533 | case GK_GFX703: |
534 | case GK_GFX702: |
535 | case GK_GFX701: |
536 | case GK_GFX700: |
537 | Features["ci-insts" ] = true; |
538 | [[fallthrough]]; |
539 | case GK_GFX602: |
540 | case GK_GFX601: |
541 | case GK_GFX600: |
542 | Features["image-insts" ] = true; |
543 | Features["s-memtime-inst" ] = true; |
544 | Features["gws" ] = true; |
545 | break; |
546 | case GK_NONE: |
547 | break; |
548 | default: |
549 | llvm_unreachable("Unhandled GPU!" ); |
550 | } |
551 | } else { |
552 | if (GPU.empty()) |
553 | GPU = "r600" ; |
554 | |
555 | switch (llvm::AMDGPU::parseArchR600(CPU: GPU)) { |
556 | case GK_CAYMAN: |
557 | case GK_CYPRESS: |
558 | case GK_RV770: |
559 | case GK_RV670: |
560 | // TODO: Add fp64 when implemented. |
561 | break; |
562 | case GK_TURKS: |
563 | case GK_CAICOS: |
564 | case GK_BARTS: |
565 | case GK_SUMO: |
566 | case GK_REDWOOD: |
567 | case GK_JUNIPER: |
568 | case GK_CEDAR: |
569 | case GK_RV730: |
570 | case GK_RV710: |
571 | case GK_RS880: |
572 | case GK_R630: |
573 | case GK_R600: |
574 | break; |
575 | default: |
576 | llvm_unreachable("Unhandled GPU!" ); |
577 | } |
578 | } |
579 | } |
580 | |
581 | static bool isWave32Capable(StringRef GPU, const Triple &T) { |
582 | bool IsWave32Capable = false; |
583 | // XXX - What does the member GPU mean if device name string passed here? |
584 | if (T.isAMDGCN()) { |
585 | switch (parseArchAMDGCN(CPU: GPU)) { |
586 | case GK_GFX1201: |
587 | case GK_GFX1200: |
588 | case GK_GFX1152: |
589 | case GK_GFX1151: |
590 | case GK_GFX1150: |
591 | case GK_GFX1103: |
592 | case GK_GFX1102: |
593 | case GK_GFX1101: |
594 | case GK_GFX1100: |
595 | case GK_GFX1036: |
596 | case GK_GFX1035: |
597 | case GK_GFX1034: |
598 | case GK_GFX1033: |
599 | case GK_GFX1032: |
600 | case GK_GFX1031: |
601 | case GK_GFX1030: |
602 | case GK_GFX1012: |
603 | case GK_GFX1011: |
604 | case GK_GFX1013: |
605 | case GK_GFX1010: |
606 | case GK_GFX12_GENERIC: |
607 | case GK_GFX11_GENERIC: |
608 | case GK_GFX10_3_GENERIC: |
609 | case GK_GFX10_1_GENERIC: |
610 | IsWave32Capable = true; |
611 | break; |
612 | default: |
613 | break; |
614 | } |
615 | } |
616 | return IsWave32Capable; |
617 | } |
618 | |
619 | std::pair<FeatureError, StringRef> |
620 | AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T, |
621 | StringMap<bool> &Features) { |
622 | bool IsWave32Capable = isWave32Capable(GPU, T); |
623 | const bool IsNullGPU = GPU.empty(); |
624 | const bool HaveWave32 = Features.count(Key: "wavefrontsize32" ); |
625 | const bool HaveWave64 = Features.count(Key: "wavefrontsize64" ); |
626 | if (HaveWave32 && HaveWave64) { |
627 | return {AMDGPU::INVALID_FEATURE_COMBINATION, |
628 | "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive" }; |
629 | } |
630 | if (HaveWave32 && !IsNullGPU && !IsWave32Capable) { |
631 | return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "wavefrontsize32" }; |
632 | } |
633 | // Don't assume any wavesize with an unknown subtarget. |
634 | if (!IsNullGPU) { |
635 | // Default to wave32 if available, or wave64 if not |
636 | if (!HaveWave32 && !HaveWave64) { |
637 | StringRef DefaultWaveSizeFeature = |
638 | IsWave32Capable ? "wavefrontsize32" : "wavefrontsize64" ; |
639 | Features.insert(KV: std::make_pair(x&: DefaultWaveSizeFeature, y: true)); |
640 | } |
641 | } |
642 | return {NO_ERROR, StringRef()}; |
643 | } |
644 | |