/home/arjun/llvm-project/llvm/lib/Support/ARMTargetParser.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- ARMTargetParser - Parser for ARM 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 ARM hardware features |
10 | | // such as FPU/CPU/ARCH/extensions and specific support such as HWDIV. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/Support/ARMTargetParser.h" |
15 | | #include "llvm/ADT/StringSwitch.h" |
16 | | #include "llvm/ADT/Triple.h" |
17 | | #include <cctype> |
18 | | |
19 | | using namespace llvm; |
20 | | |
21 | 0 | static StringRef getHWDivSynonym(StringRef HWDiv) { |
22 | 0 | return StringSwitch<StringRef>(HWDiv) |
23 | 0 | .Case("thumb,arm", "arm,thumb") |
24 | 0 | .Default(HWDiv); |
25 | 0 | } |
26 | | |
27 | | // Allows partial match, ex. "v7a" matches "armv7a". |
28 | 6 | ARM::ArchKind ARM::parseArch(StringRef Arch) { |
29 | 6 | Arch = getCanonicalArchName(Arch); |
30 | 6 | StringRef Syn = getArchSynonym(Arch); |
31 | 216 | for (const auto &A : ARCHNames) { |
32 | 216 | if (A.getName().endswith(Syn)) |
33 | 0 | return A.ID; |
34 | 216 | } |
35 | 6 | return ArchKind::INVALID; |
36 | 6 | } |
37 | | |
38 | | // Version number (ex. v7 = 7). |
39 | 0 | unsigned ARM::parseArchVersion(StringRef Arch) { |
40 | 0 | Arch = getCanonicalArchName(Arch); |
41 | 0 | switch (parseArch(Arch)) { |
42 | 0 | case ArchKind::ARMV2: |
43 | 0 | case ArchKind::ARMV2A: |
44 | 0 | return 2; |
45 | 0 | case ArchKind::ARMV3: |
46 | 0 | case ArchKind::ARMV3M: |
47 | 0 | return 3; |
48 | 0 | case ArchKind::ARMV4: |
49 | 0 | case ArchKind::ARMV4T: |
50 | 0 | return 4; |
51 | 0 | case ArchKind::ARMV5T: |
52 | 0 | case ArchKind::ARMV5TE: |
53 | 0 | case ArchKind::IWMMXT: |
54 | 0 | case ArchKind::IWMMXT2: |
55 | 0 | case ArchKind::XSCALE: |
56 | 0 | case ArchKind::ARMV5TEJ: |
57 | 0 | return 5; |
58 | 0 | case ArchKind::ARMV6: |
59 | 0 | case ArchKind::ARMV6K: |
60 | 0 | case ArchKind::ARMV6T2: |
61 | 0 | case ArchKind::ARMV6KZ: |
62 | 0 | case ArchKind::ARMV6M: |
63 | 0 | return 6; |
64 | 0 | case ArchKind::ARMV7A: |
65 | 0 | case ArchKind::ARMV7VE: |
66 | 0 | case ArchKind::ARMV7R: |
67 | 0 | case ArchKind::ARMV7M: |
68 | 0 | case ArchKind::ARMV7S: |
69 | 0 | case ArchKind::ARMV7EM: |
70 | 0 | case ArchKind::ARMV7K: |
71 | 0 | return 7; |
72 | 0 | case ArchKind::ARMV8A: |
73 | 0 | case ArchKind::ARMV8_1A: |
74 | 0 | case ArchKind::ARMV8_2A: |
75 | 0 | case ArchKind::ARMV8_3A: |
76 | 0 | case ArchKind::ARMV8_4A: |
77 | 0 | case ArchKind::ARMV8_5A: |
78 | 0 | case ArchKind::ARMV8_6A: |
79 | 0 | case ArchKind::ARMV8R: |
80 | 0 | case ArchKind::ARMV8MBaseline: |
81 | 0 | case ArchKind::ARMV8MMainline: |
82 | 0 | case ArchKind::ARMV8_1MMainline: |
83 | 0 | return 8; |
84 | 0 | case ArchKind::INVALID: |
85 | 0 | return 0; |
86 | 0 | } |
87 | 0 | llvm_unreachable("Unhandled architecture"); |
88 | 0 | } |
89 | | |
90 | | // Profile A/R/M |
91 | 0 | ARM::ProfileKind ARM::parseArchProfile(StringRef Arch) { |
92 | 0 | Arch = getCanonicalArchName(Arch); |
93 | 0 | switch (parseArch(Arch)) { |
94 | 0 | case ArchKind::ARMV6M: |
95 | 0 | case ArchKind::ARMV7M: |
96 | 0 | case ArchKind::ARMV7EM: |
97 | 0 | case ArchKind::ARMV8MMainline: |
98 | 0 | case ArchKind::ARMV8MBaseline: |
99 | 0 | case ArchKind::ARMV8_1MMainline: |
100 | 0 | return ProfileKind::M; |
101 | 0 | case ArchKind::ARMV7R: |
102 | 0 | case ArchKind::ARMV8R: |
103 | 0 | return ProfileKind::R; |
104 | 0 | case ArchKind::ARMV7A: |
105 | 0 | case ArchKind::ARMV7VE: |
106 | 0 | case ArchKind::ARMV7K: |
107 | 0 | case ArchKind::ARMV8A: |
108 | 0 | case ArchKind::ARMV8_1A: |
109 | 0 | case ArchKind::ARMV8_2A: |
110 | 0 | case ArchKind::ARMV8_3A: |
111 | 0 | case ArchKind::ARMV8_4A: |
112 | 0 | case ArchKind::ARMV8_5A: |
113 | 0 | case ArchKind::ARMV8_6A: |
114 | 0 | return ProfileKind::A; |
115 | 0 | case ArchKind::ARMV2: |
116 | 0 | case ArchKind::ARMV2A: |
117 | 0 | case ArchKind::ARMV3: |
118 | 0 | case ArchKind::ARMV3M: |
119 | 0 | case ArchKind::ARMV4: |
120 | 0 | case ArchKind::ARMV4T: |
121 | 0 | case ArchKind::ARMV5T: |
122 | 0 | case ArchKind::ARMV5TE: |
123 | 0 | case ArchKind::ARMV5TEJ: |
124 | 0 | case ArchKind::ARMV6: |
125 | 0 | case ArchKind::ARMV6K: |
126 | 0 | case ArchKind::ARMV6T2: |
127 | 0 | case ArchKind::ARMV6KZ: |
128 | 0 | case ArchKind::ARMV7S: |
129 | 0 | case ArchKind::IWMMXT: |
130 | 0 | case ArchKind::IWMMXT2: |
131 | 0 | case ArchKind::XSCALE: |
132 | 0 | case ArchKind::INVALID: |
133 | 0 | return ProfileKind::INVALID; |
134 | 0 | } |
135 | 0 | llvm_unreachable("Unhandled architecture"); |
136 | 0 | } |
137 | | |
138 | 6 | StringRef ARM::getArchSynonym(StringRef Arch) { |
139 | 6 | return StringSwitch<StringRef>(Arch) |
140 | 6 | .Case("v5", "v5t") |
141 | 6 | .Case("v5e", "v5te") |
142 | 6 | .Case("v6j", "v6") |
143 | 6 | .Case("v6hl", "v6k") |
144 | 6 | .Cases("v6m", "v6sm", "v6s-m", "v6-m") |
145 | 6 | .Cases("v6z", "v6zk", "v6kz") |
146 | 6 | .Cases("v7", "v7a", "v7hl", "v7l", "v7-a") |
147 | 6 | .Case("v7r", "v7-r") |
148 | 6 | .Case("v7m", "v7-m") |
149 | 6 | .Case("v7em", "v7e-m") |
150 | 6 | .Cases("v8", "v8a", "v8l", "aarch64", "arm64", "v8-a") |
151 | 6 | .Case("v8.1a", "v8.1-a") |
152 | 6 | .Case("v8.2a", "v8.2-a") |
153 | 6 | .Case("v8.3a", "v8.3-a") |
154 | 6 | .Case("v8.4a", "v8.4-a") |
155 | 6 | .Case("v8.5a", "v8.5-a") |
156 | 6 | .Case("v8.6a", "v8.6-a") |
157 | 6 | .Case("v8r", "v8-r") |
158 | 6 | .Case("v8m.base", "v8-m.base") |
159 | 6 | .Case("v8m.main", "v8-m.main") |
160 | 6 | .Case("v8.1m.main", "v8.1-m.main") |
161 | 6 | .Default(Arch); |
162 | 6 | } |
163 | | |
164 | 0 | bool ARM::getFPUFeatures(unsigned FPUKind, std::vector<StringRef> &Features) { |
165 | 0 |
|
166 | 0 | if (FPUKind >= FK_LAST || FPUKind == FK_INVALID) |
167 | 0 | return false; |
168 | 0 | |
169 | 0 | static const struct FPUFeatureNameInfo { |
170 | 0 | const char *PlusName, *MinusName; |
171 | 0 | FPUVersion MinVersion; |
172 | 0 | FPURestriction MaxRestriction; |
173 | 0 | } FPUFeatureInfoList[] = { |
174 | 0 | // We have to specify the + and - versions of the name in full so |
175 | 0 | // that we can return them as static StringRefs. |
176 | 0 | // |
177 | 0 | // Also, the SubtargetFeatures ending in just "sp" are listed here |
178 | 0 | // under FPURestriction::None, which is the only FPURestriction in |
179 | 0 | // which they would be valid (since FPURestriction::SP doesn't |
180 | 0 | // exist). |
181 | 0 | {"+vfp2", "-vfp2", FPUVersion::VFPV2, FPURestriction::D16}, |
182 | 0 | {"+vfp2sp", "-vfp2sp", FPUVersion::VFPV2, FPURestriction::SP_D16}, |
183 | 0 | {"+vfp3", "-vfp3", FPUVersion::VFPV3, FPURestriction::None}, |
184 | 0 | {"+vfp3d16", "-vfp3d16", FPUVersion::VFPV3, FPURestriction::D16}, |
185 | 0 | {"+vfp3d16sp", "-vfp3d16sp", FPUVersion::VFPV3, FPURestriction::SP_D16}, |
186 | 0 | {"+vfp3sp", "-vfp3sp", FPUVersion::VFPV3, FPURestriction::None}, |
187 | 0 | {"+fp16", "-fp16", FPUVersion::VFPV3_FP16, FPURestriction::SP_D16}, |
188 | 0 | {"+vfp4", "-vfp4", FPUVersion::VFPV4, FPURestriction::None}, |
189 | 0 | {"+vfp4d16", "-vfp4d16", FPUVersion::VFPV4, FPURestriction::D16}, |
190 | 0 | {"+vfp4d16sp", "-vfp4d16sp", FPUVersion::VFPV4, FPURestriction::SP_D16}, |
191 | 0 | {"+vfp4sp", "-vfp4sp", FPUVersion::VFPV4, FPURestriction::None}, |
192 | 0 | {"+fp-armv8", "-fp-armv8", FPUVersion::VFPV5, FPURestriction::None}, |
193 | 0 | {"+fp-armv8d16", "-fp-armv8d16", FPUVersion::VFPV5, FPURestriction::D16}, |
194 | 0 | {"+fp-armv8d16sp", "-fp-armv8d16sp", FPUVersion::VFPV5, FPURestriction::SP_D16}, |
195 | 0 | {"+fp-armv8sp", "-fp-armv8sp", FPUVersion::VFPV5, FPURestriction::None}, |
196 | 0 | {"+fullfp16", "-fullfp16", FPUVersion::VFPV5_FULLFP16, FPURestriction::SP_D16}, |
197 | 0 | {"+fp64", "-fp64", FPUVersion::VFPV2, FPURestriction::D16}, |
198 | 0 | {"+d32", "-d32", FPUVersion::VFPV3, FPURestriction::None}, |
199 | 0 | }; |
200 | 0 |
|
201 | 0 | for (const auto &Info: FPUFeatureInfoList) { |
202 | 0 | if (FPUNames[FPUKind].FPUVer >= Info.MinVersion && |
203 | 0 | FPUNames[FPUKind].Restriction <= Info.MaxRestriction) |
204 | 0 | Features.push_back(Info.PlusName); |
205 | 0 | else |
206 | 0 | Features.push_back(Info.MinusName); |
207 | 0 | } |
208 | 0 |
|
209 | 0 | static const struct NeonFeatureNameInfo { |
210 | 0 | const char *PlusName, *MinusName; |
211 | 0 | NeonSupportLevel MinSupportLevel; |
212 | 0 | } NeonFeatureInfoList[] = { |
213 | 0 | {"+neon", "-neon", NeonSupportLevel::Neon}, |
214 | 0 | {"+crypto", "-crypto", NeonSupportLevel::Crypto}, |
215 | 0 | }; |
216 | 0 |
|
217 | 0 | for (const auto &Info: NeonFeatureInfoList) { |
218 | 0 | if (FPUNames[FPUKind].NeonSupport >= Info.MinSupportLevel) |
219 | 0 | Features.push_back(Info.PlusName); |
220 | 0 | else |
221 | 0 | Features.push_back(Info.MinusName); |
222 | 0 | } |
223 | 0 |
|
224 | 0 | return true; |
225 | 0 | } |
226 | | |
227 | | // Little/Big endian |
228 | 0 | ARM::EndianKind ARM::parseArchEndian(StringRef Arch) { |
229 | 0 | if (Arch.startswith("armeb") || Arch.startswith("thumbeb") || |
230 | 0 | Arch.startswith("aarch64_be")) |
231 | 0 | return EndianKind::BIG; |
232 | 0 | |
233 | 0 | if (Arch.startswith("arm") || Arch.startswith("thumb")) { |
234 | 0 | if (Arch.endswith("eb")) |
235 | 0 | return EndianKind::BIG; |
236 | 0 | else |
237 | 0 | return EndianKind::LITTLE; |
238 | 0 | } |
239 | 0 | |
240 | 0 | if (Arch.startswith("aarch64") || Arch.startswith("aarch64_32")) |
241 | 0 | return EndianKind::LITTLE; |
242 | 0 | |
243 | 0 | return EndianKind::INVALID; |
244 | 0 | } |
245 | | |
246 | | // ARM, Thumb, AArch64 |
247 | 0 | ARM::ISAKind ARM::parseArchISA(StringRef Arch) { |
248 | 0 | return StringSwitch<ISAKind>(Arch) |
249 | 0 | .StartsWith("aarch64", ISAKind::AARCH64) |
250 | 0 | .StartsWith("arm64", ISAKind::AARCH64) |
251 | 0 | .StartsWith("thumb", ISAKind::THUMB) |
252 | 0 | .StartsWith("arm", ISAKind::ARM) |
253 | 0 | .Default(ISAKind::INVALID); |
254 | 0 | } |
255 | | |
256 | 0 | unsigned ARM::parseFPU(StringRef FPU) { |
257 | 0 | StringRef Syn = getFPUSynonym(FPU); |
258 | 0 | for (const auto F : FPUNames) { |
259 | 0 | if (Syn == F.getName()) |
260 | 0 | return F.ID; |
261 | 0 | } |
262 | 0 | return FK_INVALID; |
263 | 0 | } |
264 | | |
265 | 0 | ARM::NeonSupportLevel ARM::getFPUNeonSupportLevel(unsigned FPUKind) { |
266 | 0 | if (FPUKind >= FK_LAST) |
267 | 0 | return NeonSupportLevel::None; |
268 | 0 | return FPUNames[FPUKind].NeonSupport; |
269 | 0 | } |
270 | | |
271 | | // MArch is expected to be of the form (arm|thumb)?(eb)?(v.+)?(eb)?, but |
272 | | // (iwmmxt|xscale)(eb)? is also permitted. If the former, return |
273 | | // "v.+", if the latter, return unmodified string, minus 'eb'. |
274 | | // If invalid, return empty string. |
275 | 12 | StringRef ARM::getCanonicalArchName(StringRef Arch) { |
276 | 12 | size_t offset = StringRef::npos; |
277 | 12 | StringRef A = Arch; |
278 | 12 | StringRef Error = ""; |
279 | 12 | |
280 | 12 | // Begins with "arm" / "thumb", move past it. |
281 | 12 | if (A.startswith("arm64_32")) |
282 | 0 | offset = 8; |
283 | 12 | else if (A.startswith("arm64")) |
284 | 0 | offset = 5; |
285 | 12 | else if (A.startswith("aarch64_32")) |
286 | 0 | offset = 10; |
287 | 12 | else if (A.startswith("arm")) |
288 | 0 | offset = 3; |
289 | 12 | else if (A.startswith("thumb")) |
290 | 0 | offset = 5; |
291 | 12 | else if (A.startswith("aarch64")) { |
292 | 0 | offset = 7; |
293 | 0 | // AArch64 uses "_be", not "eb" suffix. |
294 | 0 | if (A.find("eb") != StringRef::npos) |
295 | 0 | return Error; |
296 | 0 | if (A.substr(offset, 3) == "_be") |
297 | 0 | offset += 3; |
298 | 0 | } |
299 | 12 | |
300 | 12 | // Ex. "armebv7", move past the "eb". |
301 | 12 | if (offset != StringRef::npos && A.substr(offset, 2) == "eb") |
302 | 0 | offset += 2; |
303 | 12 | // Or, if it ends with eb ("armv7eb"), chop it off. |
304 | 12 | else if (A.endswith("eb")) |
305 | 0 | A = A.substr(0, A.size() - 2); |
306 | 12 | // Trim the head |
307 | 12 | if (offset != StringRef::npos) |
308 | 0 | A = A.substr(offset); |
309 | 12 | |
310 | 12 | // Empty string means offset reached the end, which means it's valid. |
311 | 12 | if (A.empty()) |
312 | 0 | return Arch; |
313 | 12 | |
314 | 12 | // Only match non-marketing names |
315 | 12 | if (offset != StringRef::npos) { |
316 | 0 | // Must start with 'vN'. |
317 | 0 | if (A.size() >= 2 && (A[0] != 'v' || !std::isdigit(A[1]))) |
318 | 0 | return Error; |
319 | 0 | // Can't have an extra 'eb'. |
320 | 0 | if (A.find("eb") != StringRef::npos) |
321 | 0 | return Error; |
322 | 12 | } |
323 | 12 | |
324 | 12 | // Arch will either be a 'v' name (v7a) or a marketing name (xscale). |
325 | 12 | return A; |
326 | 12 | } |
327 | | |
328 | 0 | StringRef ARM::getFPUSynonym(StringRef FPU) { |
329 | 0 | return StringSwitch<StringRef>(FPU) |
330 | 0 | .Cases("fpa", "fpe2", "fpe3", "maverick", "invalid") // Unsupported |
331 | 0 | .Case("vfp2", "vfpv2") |
332 | 0 | .Case("vfp3", "vfpv3") |
333 | 0 | .Case("vfp4", "vfpv4") |
334 | 0 | .Case("vfp3-d16", "vfpv3-d16") |
335 | 0 | .Case("vfp4-d16", "vfpv4-d16") |
336 | 0 | .Cases("fp4-sp-d16", "vfpv4-sp-d16", "fpv4-sp-d16") |
337 | 0 | .Cases("fp4-dp-d16", "fpv4-dp-d16", "vfpv4-d16") |
338 | 0 | .Case("fp5-sp-d16", "fpv5-sp-d16") |
339 | 0 | .Cases("fp5-dp-d16", "fpv5-dp-d16", "fpv5-d16") |
340 | 0 | // FIXME: Clang uses it, but it's bogus, since neon defaults to vfpv3. |
341 | 0 | .Case("neon-vfpv3", "neon") |
342 | 0 | .Default(FPU); |
343 | 0 | } |
344 | | |
345 | 0 | StringRef ARM::getFPUName(unsigned FPUKind) { |
346 | 0 | if (FPUKind >= FK_LAST) |
347 | 0 | return StringRef(); |
348 | 0 | return FPUNames[FPUKind].getName(); |
349 | 0 | } |
350 | | |
351 | 0 | ARM::FPUVersion ARM::getFPUVersion(unsigned FPUKind) { |
352 | 0 | if (FPUKind >= FK_LAST) |
353 | 0 | return FPUVersion::NONE; |
354 | 0 | return FPUNames[FPUKind].FPUVer; |
355 | 0 | } |
356 | | |
357 | 0 | ARM::FPURestriction ARM::getFPURestriction(unsigned FPUKind) { |
358 | 0 | if (FPUKind >= FK_LAST) |
359 | 0 | return FPURestriction::None; |
360 | 0 | return FPUNames[FPUKind].Restriction; |
361 | 0 | } |
362 | | |
363 | 0 | unsigned ARM::getDefaultFPU(StringRef CPU, ARM::ArchKind AK) { |
364 | 0 | if (CPU == "generic") |
365 | 0 | return ARM::ARCHNames[static_cast<unsigned>(AK)].DefaultFPU; |
366 | 0 | |
367 | 0 | return StringSwitch<unsigned>(CPU) |
368 | 0 | #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \ |
369 | 0 | .Case(NAME, DEFAULT_FPU) |
370 | 0 | #include "llvm/Support/ARMTargetParser.def" |
371 | 0 | .Default(ARM::FK_INVALID); |
372 | 0 | } |
373 | | |
374 | 0 | uint64_t ARM::getDefaultExtensions(StringRef CPU, ARM::ArchKind AK) { |
375 | 0 | if (CPU == "generic") |
376 | 0 | return ARM::ARCHNames[static_cast<unsigned>(AK)].ArchBaseExtensions; |
377 | 0 | |
378 | 0 | return StringSwitch<uint64_t>(CPU) |
379 | 0 | #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \ |
380 | 0 | .Case(NAME, \ |
381 | 0 | ARCHNames[static_cast<unsigned>(ArchKind::ID)].ArchBaseExtensions | \ |
382 | 0 | DEFAULT_EXT) |
383 | 0 | #include "llvm/Support/ARMTargetParser.def" |
384 | 0 | .Default(ARM::AEK_INVALID); |
385 | 0 | } |
386 | | |
387 | | bool ARM::getHWDivFeatures(uint64_t HWDivKind, |
388 | 0 | std::vector<StringRef> &Features) { |
389 | 0 |
|
390 | 0 | if (HWDivKind == AEK_INVALID) |
391 | 0 | return false; |
392 | 0 | |
393 | 0 | if (HWDivKind & AEK_HWDIVARM) |
394 | 0 | Features.push_back("+hwdiv-arm"); |
395 | 0 | else |
396 | 0 | Features.push_back("-hwdiv-arm"); |
397 | 0 |
|
398 | 0 | if (HWDivKind & AEK_HWDIVTHUMB) |
399 | 0 | Features.push_back("+hwdiv"); |
400 | 0 | else |
401 | 0 | Features.push_back("-hwdiv"); |
402 | 0 |
|
403 | 0 | return true; |
404 | 0 | } |
405 | | |
406 | | bool ARM::getExtensionFeatures(uint64_t Extensions, |
407 | 0 | std::vector<StringRef> &Features) { |
408 | 0 |
|
409 | 0 | if (Extensions == AEK_INVALID) |
410 | 0 | return false; |
411 | 0 | |
412 | 0 | for (const auto AE : ARCHExtNames) { |
413 | 0 | if ((Extensions & AE.ID) == AE.ID && AE.Feature) |
414 | 0 | Features.push_back(AE.Feature); |
415 | 0 | else if (AE.NegFeature) |
416 | 0 | Features.push_back(AE.NegFeature); |
417 | 0 | } |
418 | 0 |
|
419 | 0 | return getHWDivFeatures(Extensions, Features); |
420 | 0 | } |
421 | | |
422 | 0 | StringRef ARM::getArchName(ARM::ArchKind AK) { |
423 | 0 | return ARCHNames[static_cast<unsigned>(AK)].getName(); |
424 | 0 | } |
425 | | |
426 | 0 | StringRef ARM::getCPUAttr(ARM::ArchKind AK) { |
427 | 0 | return ARCHNames[static_cast<unsigned>(AK)].getCPUAttr(); |
428 | 0 | } |
429 | | |
430 | 0 | StringRef ARM::getSubArch(ARM::ArchKind AK) { |
431 | 0 | return ARCHNames[static_cast<unsigned>(AK)].getSubArch(); |
432 | 0 | } |
433 | | |
434 | 0 | unsigned ARM::getArchAttr(ARM::ArchKind AK) { |
435 | 0 | return ARCHNames[static_cast<unsigned>(AK)].ArchAttr; |
436 | 0 | } |
437 | | |
438 | 0 | StringRef ARM::getArchExtName(uint64_t ArchExtKind) { |
439 | 0 | for (const auto AE : ARCHExtNames) { |
440 | 0 | if (ArchExtKind == AE.ID) |
441 | 0 | return AE.getName(); |
442 | 0 | } |
443 | 0 | return StringRef(); |
444 | 0 | } |
445 | | |
446 | 0 | static bool stripNegationPrefix(StringRef &Name) { |
447 | 0 | if (Name.startswith("no")) { |
448 | 0 | Name = Name.substr(2); |
449 | 0 | return true; |
450 | 0 | } |
451 | 0 | return false; |
452 | 0 | } |
453 | | |
454 | 0 | StringRef ARM::getArchExtFeature(StringRef ArchExt) { |
455 | 0 | bool Negated = stripNegationPrefix(ArchExt); |
456 | 0 | for (const auto AE : ARCHExtNames) { |
457 | 0 | if (AE.Feature && ArchExt == AE.getName()) |
458 | 0 | return StringRef(Negated ? AE.NegFeature : AE.Feature); |
459 | 0 | } |
460 | 0 |
|
461 | 0 | return StringRef(); |
462 | 0 | } |
463 | | |
464 | 0 | static unsigned findDoublePrecisionFPU(unsigned InputFPUKind) { |
465 | 0 | const ARM::FPUName &InputFPU = ARM::FPUNames[InputFPUKind]; |
466 | 0 |
|
467 | 0 | // If the input FPU already supports double-precision, then there |
468 | 0 | // isn't any different FPU we can return here. |
469 | 0 | // |
470 | 0 | // The current available FPURestriction values are None (no |
471 | 0 | // restriction), D16 (only 16 d-regs) and SP_D16 (16 d-regs |
472 | 0 | // and single precision only); there's no value representing |
473 | 0 | // SP restriction without D16. So this test just means 'is it |
474 | 0 | // SP only?'. |
475 | 0 | if (InputFPU.Restriction != ARM::FPURestriction::SP_D16) |
476 | 0 | return ARM::FK_INVALID; |
477 | 0 | |
478 | 0 | // Otherwise, look for an FPU entry with all the same fields, except |
479 | 0 | // that SP_D16 has been replaced with just D16, representing adding |
480 | 0 | // double precision and not changing anything else. |
481 | 0 | for (const ARM::FPUName &CandidateFPU : ARM::FPUNames) { |
482 | 0 | if (CandidateFPU.FPUVer == InputFPU.FPUVer && |
483 | 0 | CandidateFPU.NeonSupport == InputFPU.NeonSupport && |
484 | 0 | CandidateFPU.Restriction == ARM::FPURestriction::D16) { |
485 | 0 | return CandidateFPU.ID; |
486 | 0 | } |
487 | 0 | } |
488 | 0 |
|
489 | 0 | // nothing found |
490 | 0 | return ARM::FK_INVALID; |
491 | 0 | } |
492 | | |
493 | | bool ARM::appendArchExtFeatures( |
494 | | StringRef CPU, ARM::ArchKind AK, StringRef ArchExt, |
495 | 0 | std::vector<StringRef> &Features) { |
496 | 0 |
|
497 | 0 | size_t StartingNumFeatures = Features.size(); |
498 | 0 | const bool Negated = stripNegationPrefix(ArchExt); |
499 | 0 | uint64_t ID = parseArchExt(ArchExt); |
500 | 0 |
|
501 | 0 | if (ID == AEK_INVALID) |
502 | 0 | return false; |
503 | 0 | |
504 | 0 | for (const auto AE : ARCHExtNames) { |
505 | 0 | if (Negated) { |
506 | 0 | if ((AE.ID & ID) == ID && AE.NegFeature) |
507 | 0 | Features.push_back(AE.NegFeature); |
508 | 0 | } else { |
509 | 0 | if ((AE.ID & ID) == AE.ID && AE.Feature) |
510 | 0 | Features.push_back(AE.Feature); |
511 | 0 | } |
512 | 0 | } |
513 | 0 |
|
514 | 0 | if (CPU == "") |
515 | 0 | CPU = "generic"; |
516 | 0 |
|
517 | 0 | if (ArchExt == "fp" || ArchExt == "fp.dp") { |
518 | 0 | unsigned FPUKind; |
519 | 0 | if (ArchExt == "fp.dp") { |
520 | 0 | if (Negated) { |
521 | 0 | Features.push_back("-fp64"); |
522 | 0 | return true; |
523 | 0 | } |
524 | 0 | FPUKind = findDoublePrecisionFPU(getDefaultFPU(CPU, AK)); |
525 | 0 | } else if (Negated) { |
526 | 0 | FPUKind = ARM::FK_NONE; |
527 | 0 | } else { |
528 | 0 | FPUKind = getDefaultFPU(CPU, AK); |
529 | 0 | } |
530 | 0 | return ARM::getFPUFeatures(FPUKind, Features); |
531 | 0 | } |
532 | 0 | return StartingNumFeatures != Features.size(); |
533 | 0 | } |
534 | | |
535 | 0 | StringRef ARM::getHWDivName(uint64_t HWDivKind) { |
536 | 0 | for (const auto D : HWDivNames) { |
537 | 0 | if (HWDivKind == D.ID) |
538 | 0 | return D.getName(); |
539 | 0 | } |
540 | 0 | return StringRef(); |
541 | 0 | } |
542 | | |
543 | 0 | StringRef ARM::getDefaultCPU(StringRef Arch) { |
544 | 0 | ArchKind AK = parseArch(Arch); |
545 | 0 | if (AK == ArchKind::INVALID) |
546 | 0 | return StringRef(); |
547 | 0 | |
548 | 0 | // Look for multiple AKs to find the default for pair AK+Name. |
549 | 0 | for (const auto CPU : CPUNames) { |
550 | 0 | if (CPU.ArchID == AK && CPU.Default) |
551 | 0 | return CPU.getName(); |
552 | 0 | } |
553 | 0 |
|
554 | 0 | // If we can't find a default then target the architecture instead |
555 | 0 | return "generic"; |
556 | 0 | } |
557 | | |
558 | 0 | uint64_t ARM::parseHWDiv(StringRef HWDiv) { |
559 | 0 | StringRef Syn = getHWDivSynonym(HWDiv); |
560 | 0 | for (const auto D : HWDivNames) { |
561 | 0 | if (Syn == D.getName()) |
562 | 0 | return D.ID; |
563 | 0 | } |
564 | 0 | return AEK_INVALID; |
565 | 0 | } |
566 | | |
567 | 0 | uint64_t ARM::parseArchExt(StringRef ArchExt) { |
568 | 0 | for (const auto A : ARCHExtNames) { |
569 | 0 | if (ArchExt == A.getName()) |
570 | 0 | return A.ID; |
571 | 0 | } |
572 | 0 | return AEK_INVALID; |
573 | 0 | } |
574 | | |
575 | 0 | ARM::ArchKind ARM::parseCPUArch(StringRef CPU) { |
576 | 0 | for (const auto C : CPUNames) { |
577 | 0 | if (CPU == C.getName()) |
578 | 0 | return C.ArchID; |
579 | 0 | } |
580 | 0 | return ArchKind::INVALID; |
581 | 0 | } |
582 | | |
583 | 0 | void ARM::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values) { |
584 | 0 | for (const CpuNames<ArchKind> &Arch : CPUNames) { |
585 | 0 | if (Arch.ArchID != ArchKind::INVALID) |
586 | 0 | Values.push_back(Arch.getName()); |
587 | 0 | } |
588 | 0 | } |
589 | | |
590 | 0 | StringRef ARM::computeDefaultTargetABI(const Triple &TT, StringRef CPU) { |
591 | 0 | StringRef ArchName = |
592 | 0 | CPU.empty() ? TT.getArchName() : getArchName(parseCPUArch(CPU)); |
593 | 0 |
|
594 | 0 | if (TT.isOSBinFormatMachO()) { |
595 | 0 | if (TT.getEnvironment() == Triple::EABI || |
596 | 0 | TT.getOS() == Triple::UnknownOS || |
597 | 0 | parseArchProfile(ArchName) == ProfileKind::M) |
598 | 0 | return "aapcs"; |
599 | 0 | if (TT.isWatchABI()) |
600 | 0 | return "aapcs16"; |
601 | 0 | return "apcs-gnu"; |
602 | 0 | } else if (TT.isOSWindows()) |
603 | 0 | // FIXME: this is invalid for WindowsCE. |
604 | 0 | return "aapcs"; |
605 | 0 | |
606 | 0 | // Select the default based on the platform. |
607 | 0 | switch (TT.getEnvironment()) { |
608 | 0 | case Triple::Android: |
609 | 0 | case Triple::GNUEABI: |
610 | 0 | case Triple::GNUEABIHF: |
611 | 0 | case Triple::MuslEABI: |
612 | 0 | case Triple::MuslEABIHF: |
613 | 0 | return "aapcs-linux"; |
614 | 0 | case Triple::EABIHF: |
615 | 0 | case Triple::EABI: |
616 | 0 | return "aapcs"; |
617 | 0 | default: |
618 | 0 | if (TT.isOSNetBSD()) |
619 | 0 | return "apcs-gnu"; |
620 | 0 | if (TT.isOSOpenBSD()) |
621 | 0 | return "aapcs-linux"; |
622 | 0 | return "aapcs"; |
623 | 0 | } |
624 | 0 | } |