llvm-project
661 строка · 20.0 Кб
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/TargetParser/ARMTargetParser.h"
15#include "llvm/ADT/StringSwitch.h"
16#include "llvm/Support/Format.h"
17#include "llvm/Support/raw_ostream.h"
18#include "llvm/TargetParser/ARMTargetParserCommon.h"
19#include "llvm/TargetParser/Triple.h"
20#include <cctype>
21
22using namespace llvm;
23
24static StringRef getHWDivSynonym(StringRef HWDiv) {
25return StringSwitch<StringRef>(HWDiv)
26.Case("thumb,arm", "arm,thumb")
27.Default(HWDiv);
28}
29
30// Allows partial match, ex. "v7a" matches "armv7a".
31ARM::ArchKind ARM::parseArch(StringRef Arch) {
32Arch = getCanonicalArchName(Arch);
33StringRef Syn = getArchSynonym(Arch);
34for (const auto &A : ARMArchNames) {
35if (A.Name.ends_with(Syn))
36return A.ID;
37}
38return ArchKind::INVALID;
39}
40
41// Version number (ex. v7 = 7).
42unsigned ARM::parseArchVersion(StringRef Arch) {
43Arch = getCanonicalArchName(Arch);
44switch (parseArch(Arch)) {
45case ArchKind::ARMV4:
46case ArchKind::ARMV4T:
47return 4;
48case ArchKind::ARMV5T:
49case ArchKind::ARMV5TE:
50case ArchKind::IWMMXT:
51case ArchKind::IWMMXT2:
52case ArchKind::XSCALE:
53case ArchKind::ARMV5TEJ:
54return 5;
55case ArchKind::ARMV6:
56case ArchKind::ARMV6K:
57case ArchKind::ARMV6T2:
58case ArchKind::ARMV6KZ:
59case ArchKind::ARMV6M:
60return 6;
61case ArchKind::ARMV7A:
62case ArchKind::ARMV7VE:
63case ArchKind::ARMV7R:
64case ArchKind::ARMV7M:
65case ArchKind::ARMV7S:
66case ArchKind::ARMV7EM:
67case ArchKind::ARMV7K:
68return 7;
69case ArchKind::ARMV8A:
70case ArchKind::ARMV8_1A:
71case ArchKind::ARMV8_2A:
72case ArchKind::ARMV8_3A:
73case ArchKind::ARMV8_4A:
74case ArchKind::ARMV8_5A:
75case ArchKind::ARMV8_6A:
76case ArchKind::ARMV8_7A:
77case ArchKind::ARMV8_8A:
78case ArchKind::ARMV8_9A:
79case ArchKind::ARMV8R:
80case ArchKind::ARMV8MBaseline:
81case ArchKind::ARMV8MMainline:
82case ArchKind::ARMV8_1MMainline:
83return 8;
84case ArchKind::ARMV9A:
85case ArchKind::ARMV9_1A:
86case ArchKind::ARMV9_2A:
87case ArchKind::ARMV9_3A:
88case ArchKind::ARMV9_4A:
89case ArchKind::ARMV9_5A:
90return 9;
91case ArchKind::INVALID:
92return 0;
93}
94llvm_unreachable("Unhandled architecture");
95}
96
97static ARM::ProfileKind getProfileKind(ARM::ArchKind AK) {
98switch (AK) {
99case ARM::ArchKind::ARMV6M:
100case ARM::ArchKind::ARMV7M:
101case ARM::ArchKind::ARMV7EM:
102case ARM::ArchKind::ARMV8MMainline:
103case ARM::ArchKind::ARMV8MBaseline:
104case ARM::ArchKind::ARMV8_1MMainline:
105return ARM::ProfileKind::M;
106case ARM::ArchKind::ARMV7R:
107case ARM::ArchKind::ARMV8R:
108return ARM::ProfileKind::R;
109case ARM::ArchKind::ARMV7A:
110case ARM::ArchKind::ARMV7VE:
111case ARM::ArchKind::ARMV7K:
112case ARM::ArchKind::ARMV8A:
113case ARM::ArchKind::ARMV8_1A:
114case ARM::ArchKind::ARMV8_2A:
115case ARM::ArchKind::ARMV8_3A:
116case ARM::ArchKind::ARMV8_4A:
117case ARM::ArchKind::ARMV8_5A:
118case ARM::ArchKind::ARMV8_6A:
119case ARM::ArchKind::ARMV8_7A:
120case ARM::ArchKind::ARMV8_8A:
121case ARM::ArchKind::ARMV8_9A:
122case ARM::ArchKind::ARMV9A:
123case ARM::ArchKind::ARMV9_1A:
124case ARM::ArchKind::ARMV9_2A:
125case ARM::ArchKind::ARMV9_3A:
126case ARM::ArchKind::ARMV9_4A:
127case ARM::ArchKind::ARMV9_5A:
128return ARM::ProfileKind::A;
129case ARM::ArchKind::ARMV4:
130case ARM::ArchKind::ARMV4T:
131case ARM::ArchKind::ARMV5T:
132case ARM::ArchKind::ARMV5TE:
133case ARM::ArchKind::ARMV5TEJ:
134case ARM::ArchKind::ARMV6:
135case ARM::ArchKind::ARMV6K:
136case ARM::ArchKind::ARMV6T2:
137case ARM::ArchKind::ARMV6KZ:
138case ARM::ArchKind::ARMV7S:
139case ARM::ArchKind::IWMMXT:
140case ARM::ArchKind::IWMMXT2:
141case ARM::ArchKind::XSCALE:
142case ARM::ArchKind::INVALID:
143return ARM::ProfileKind::INVALID;
144}
145llvm_unreachable("Unhandled architecture");
146}
147
148// Profile A/R/M
149ARM::ProfileKind ARM::parseArchProfile(StringRef Arch) {
150Arch = getCanonicalArchName(Arch);
151return getProfileKind(parseArch(Arch));
152}
153
154bool ARM::getFPUFeatures(ARM::FPUKind FPUKind,
155std::vector<StringRef> &Features) {
156
157if (FPUKind >= FK_LAST || FPUKind == FK_INVALID)
158return false;
159
160static const struct FPUFeatureNameInfo {
161const char *PlusName, *MinusName;
162FPUVersion MinVersion;
163FPURestriction MaxRestriction;
164} FPUFeatureInfoList[] = {
165// We have to specify the + and - versions of the name in full so
166// that we can return them as static StringRefs.
167//
168// Also, the SubtargetFeatures ending in just "sp" are listed here
169// under FPURestriction::None, which is the only FPURestriction in
170// which they would be valid (since FPURestriction::SP doesn't
171// exist).
172{"+vfp2", "-vfp2", FPUVersion::VFPV2, FPURestriction::D16},
173{"+vfp2sp", "-vfp2sp", FPUVersion::VFPV2, FPURestriction::SP_D16},
174{"+vfp3", "-vfp3", FPUVersion::VFPV3, FPURestriction::None},
175{"+vfp3d16", "-vfp3d16", FPUVersion::VFPV3, FPURestriction::D16},
176{"+vfp3d16sp", "-vfp3d16sp", FPUVersion::VFPV3, FPURestriction::SP_D16},
177{"+vfp3sp", "-vfp3sp", FPUVersion::VFPV3, FPURestriction::None},
178{"+fp16", "-fp16", FPUVersion::VFPV3_FP16, FPURestriction::SP_D16},
179{"+vfp4", "-vfp4", FPUVersion::VFPV4, FPURestriction::None},
180{"+vfp4d16", "-vfp4d16", FPUVersion::VFPV4, FPURestriction::D16},
181{"+vfp4d16sp", "-vfp4d16sp", FPUVersion::VFPV4, FPURestriction::SP_D16},
182{"+vfp4sp", "-vfp4sp", FPUVersion::VFPV4, FPURestriction::None},
183{"+fp-armv8", "-fp-armv8", FPUVersion::VFPV5, FPURestriction::None},
184{"+fp-armv8d16", "-fp-armv8d16", FPUVersion::VFPV5, FPURestriction::D16},
185{"+fp-armv8d16sp", "-fp-armv8d16sp", FPUVersion::VFPV5, FPURestriction::SP_D16},
186{"+fp-armv8sp", "-fp-armv8sp", FPUVersion::VFPV5, FPURestriction::None},
187{"+fullfp16", "-fullfp16", FPUVersion::VFPV5_FULLFP16, FPURestriction::SP_D16},
188{"+fp64", "-fp64", FPUVersion::VFPV2, FPURestriction::D16},
189{"+d32", "-d32", FPUVersion::VFPV3, FPURestriction::None},
190};
191
192for (const auto &Info: FPUFeatureInfoList) {
193if (FPUNames[FPUKind].FPUVer >= Info.MinVersion &&
194FPUNames[FPUKind].Restriction <= Info.MaxRestriction)
195Features.push_back(Info.PlusName);
196else
197Features.push_back(Info.MinusName);
198}
199
200static const struct NeonFeatureNameInfo {
201const char *PlusName, *MinusName;
202NeonSupportLevel MinSupportLevel;
203} NeonFeatureInfoList[] = {
204{"+neon", "-neon", NeonSupportLevel::Neon},
205{"+sha2", "-sha2", NeonSupportLevel::Crypto},
206{"+aes", "-aes", NeonSupportLevel::Crypto},
207};
208
209for (const auto &Info: NeonFeatureInfoList) {
210if (FPUNames[FPUKind].NeonSupport >= Info.MinSupportLevel)
211Features.push_back(Info.PlusName);
212else
213Features.push_back(Info.MinusName);
214}
215
216return true;
217}
218
219ARM::FPUKind ARM::parseFPU(StringRef FPU) {
220StringRef Syn = getFPUSynonym(FPU);
221for (const auto &F : FPUNames) {
222if (Syn == F.Name)
223return F.ID;
224}
225return FK_INVALID;
226}
227
228ARM::NeonSupportLevel ARM::getFPUNeonSupportLevel(ARM::FPUKind FPUKind) {
229if (FPUKind >= FK_LAST)
230return NeonSupportLevel::None;
231return FPUNames[FPUKind].NeonSupport;
232}
233
234StringRef ARM::getFPUSynonym(StringRef FPU) {
235return StringSwitch<StringRef>(FPU)
236.Cases("fpa", "fpe2", "fpe3", "maverick", "invalid") // Unsupported
237.Case("vfp2", "vfpv2")
238.Case("vfp3", "vfpv3")
239.Case("vfp4", "vfpv4")
240.Case("vfp3-d16", "vfpv3-d16")
241.Case("vfp4-d16", "vfpv4-d16")
242.Cases("fp4-sp-d16", "vfpv4-sp-d16", "fpv4-sp-d16")
243.Cases("fp4-dp-d16", "fpv4-dp-d16", "vfpv4-d16")
244.Case("fp5-sp-d16", "fpv5-sp-d16")
245.Cases("fp5-dp-d16", "fpv5-dp-d16", "fpv5-d16")
246// FIXME: Clang uses it, but it's bogus, since neon defaults to vfpv3.
247.Case("neon-vfpv3", "neon")
248.Default(FPU);
249}
250
251StringRef ARM::getFPUName(ARM::FPUKind FPUKind) {
252if (FPUKind >= FK_LAST)
253return StringRef();
254return FPUNames[FPUKind].Name;
255}
256
257ARM::FPUVersion ARM::getFPUVersion(ARM::FPUKind FPUKind) {
258if (FPUKind >= FK_LAST)
259return FPUVersion::NONE;
260return FPUNames[FPUKind].FPUVer;
261}
262
263ARM::FPURestriction ARM::getFPURestriction(ARM::FPUKind FPUKind) {
264if (FPUKind >= FK_LAST)
265return FPURestriction::None;
266return FPUNames[FPUKind].Restriction;
267}
268
269ARM::FPUKind ARM::getDefaultFPU(StringRef CPU, ARM::ArchKind AK) {
270if (CPU == "generic")
271return ARM::ARMArchNames[static_cast<unsigned>(AK)].DefaultFPU;
272
273return StringSwitch<ARM::FPUKind>(CPU)
274#define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
275.Case(NAME, DEFAULT_FPU)
276#include "llvm/TargetParser/ARMTargetParser.def"
277.Default(ARM::FK_INVALID);
278}
279
280uint64_t ARM::getDefaultExtensions(StringRef CPU, ARM::ArchKind AK) {
281if (CPU == "generic")
282return ARM::ARMArchNames[static_cast<unsigned>(AK)].ArchBaseExtensions;
283
284return StringSwitch<uint64_t>(CPU)
285#define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
286.Case(NAME, \
287ARMArchNames[static_cast<unsigned>(ArchKind::ID)].ArchBaseExtensions | \
288DEFAULT_EXT)
289#include "llvm/TargetParser/ARMTargetParser.def"
290.Default(ARM::AEK_INVALID);
291}
292
293bool ARM::getHWDivFeatures(uint64_t HWDivKind,
294std::vector<StringRef> &Features) {
295
296if (HWDivKind == AEK_INVALID)
297return false;
298
299if (HWDivKind & AEK_HWDIVARM)
300Features.push_back("+hwdiv-arm");
301else
302Features.push_back("-hwdiv-arm");
303
304if (HWDivKind & AEK_HWDIVTHUMB)
305Features.push_back("+hwdiv");
306else
307Features.push_back("-hwdiv");
308
309return true;
310}
311
312bool ARM::getExtensionFeatures(uint64_t Extensions,
313std::vector<StringRef> &Features) {
314
315if (Extensions == AEK_INVALID)
316return false;
317
318for (const auto &AE : ARCHExtNames) {
319if ((Extensions & AE.ID) == AE.ID && !AE.Feature.empty())
320Features.push_back(AE.Feature);
321else if (!AE.NegFeature.empty())
322Features.push_back(AE.NegFeature);
323}
324
325return getHWDivFeatures(Extensions, Features);
326}
327
328StringRef ARM::getArchName(ARM::ArchKind AK) {
329return ARMArchNames[static_cast<unsigned>(AK)].Name;
330}
331
332StringRef ARM::getCPUAttr(ARM::ArchKind AK) {
333return ARMArchNames[static_cast<unsigned>(AK)].CPUAttr;
334}
335
336StringRef ARM::getSubArch(ARM::ArchKind AK) {
337return ARMArchNames[static_cast<unsigned>(AK)].getSubArch();
338}
339
340unsigned ARM::getArchAttr(ARM::ArchKind AK) {
341return ARMArchNames[static_cast<unsigned>(AK)].ArchAttr;
342}
343
344StringRef ARM::getArchExtName(uint64_t ArchExtKind) {
345for (const auto &AE : ARCHExtNames) {
346if (ArchExtKind == AE.ID)
347return AE.Name;
348}
349return StringRef();
350}
351
352static bool stripNegationPrefix(StringRef &Name) {
353return Name.consume_front("no");
354}
355
356StringRef ARM::getArchExtFeature(StringRef ArchExt) {
357bool Negated = stripNegationPrefix(ArchExt);
358for (const auto &AE : ARCHExtNames) {
359if (!AE.Feature.empty() && ArchExt == AE.Name)
360return StringRef(Negated ? AE.NegFeature : AE.Feature);
361}
362
363return StringRef();
364}
365
366static ARM::FPUKind findDoublePrecisionFPU(ARM::FPUKind InputFPUKind) {
367if (InputFPUKind == ARM::FK_INVALID || InputFPUKind == ARM::FK_NONE)
368return ARM::FK_INVALID;
369
370const ARM::FPUName &InputFPU = ARM::FPUNames[InputFPUKind];
371
372// If the input FPU already supports double-precision, then there
373// isn't any different FPU we can return here.
374if (ARM::isDoublePrecision(InputFPU.Restriction))
375return InputFPUKind;
376
377// Otherwise, look for an FPU entry with all the same fields, except
378// that it supports double precision.
379for (const ARM::FPUName &CandidateFPU : ARM::FPUNames) {
380if (CandidateFPU.FPUVer == InputFPU.FPUVer &&
381CandidateFPU.NeonSupport == InputFPU.NeonSupport &&
382ARM::has32Regs(CandidateFPU.Restriction) ==
383ARM::has32Regs(InputFPU.Restriction) &&
384ARM::isDoublePrecision(CandidateFPU.Restriction)) {
385return CandidateFPU.ID;
386}
387}
388
389// nothing found
390return ARM::FK_INVALID;
391}
392
393static ARM::FPUKind findSinglePrecisionFPU(ARM::FPUKind InputFPUKind) {
394if (InputFPUKind == ARM::FK_INVALID || InputFPUKind == ARM::FK_NONE)
395return ARM::FK_INVALID;
396
397const ARM::FPUName &InputFPU = ARM::FPUNames[InputFPUKind];
398
399// If the input FPU already is single-precision only, then there
400// isn't any different FPU we can return here.
401if (!ARM::isDoublePrecision(InputFPU.Restriction))
402return InputFPUKind;
403
404// Otherwise, look for an FPU entry with all the same fields, except
405// that it does not support double precision.
406for (const ARM::FPUName &CandidateFPU : ARM::FPUNames) {
407if (CandidateFPU.FPUVer == InputFPU.FPUVer &&
408CandidateFPU.NeonSupport == InputFPU.NeonSupport &&
409ARM::has32Regs(CandidateFPU.Restriction) ==
410ARM::has32Regs(InputFPU.Restriction) &&
411!ARM::isDoublePrecision(CandidateFPU.Restriction)) {
412return CandidateFPU.ID;
413}
414}
415
416// nothing found
417return ARM::FK_INVALID;
418}
419
420bool ARM::appendArchExtFeatures(StringRef CPU, ARM::ArchKind AK,
421StringRef ArchExt,
422std::vector<StringRef> &Features,
423ARM::FPUKind &ArgFPUKind) {
424
425size_t StartingNumFeatures = Features.size();
426const bool Negated = stripNegationPrefix(ArchExt);
427uint64_t ID = parseArchExt(ArchExt);
428
429if (ID == AEK_INVALID)
430return false;
431
432for (const auto &AE : ARCHExtNames) {
433if (Negated) {
434if ((AE.ID & ID) == ID && !AE.NegFeature.empty())
435Features.push_back(AE.NegFeature);
436} else {
437if ((AE.ID & ID) == AE.ID && !AE.Feature.empty())
438Features.push_back(AE.Feature);
439}
440}
441
442if (CPU == "")
443CPU = "generic";
444
445if (ArchExt == "fp" || ArchExt == "fp.dp") {
446const ARM::FPUKind DefaultFPU = getDefaultFPU(CPU, AK);
447ARM::FPUKind FPUKind;
448if (ArchExt == "fp.dp") {
449const bool IsDP = ArgFPUKind != ARM::FK_INVALID &&
450ArgFPUKind != ARM::FK_NONE &&
451isDoublePrecision(getFPURestriction(ArgFPUKind));
452if (Negated) {
453/* If there is no FPU selected yet, we still need to set ArgFPUKind, as
454* leaving it as FK_INVALID, would cause default FPU to be selected
455* later and that could be double precision one. */
456if (ArgFPUKind != ARM::FK_INVALID && !IsDP)
457return true;
458FPUKind = findSinglePrecisionFPU(DefaultFPU);
459if (FPUKind == ARM::FK_INVALID)
460FPUKind = ARM::FK_NONE;
461} else {
462if (IsDP)
463return true;
464FPUKind = findDoublePrecisionFPU(DefaultFPU);
465if (FPUKind == ARM::FK_INVALID)
466return false;
467}
468} else if (Negated) {
469FPUKind = ARM::FK_NONE;
470} else {
471FPUKind = DefaultFPU;
472}
473ArgFPUKind = FPUKind;
474return true;
475}
476return StartingNumFeatures != Features.size();
477}
478
479ARM::ArchKind ARM::convertV9toV8(ARM::ArchKind AK) {
480if (getProfileKind(AK) != ProfileKind::A)
481return ARM::ArchKind::INVALID;
482if (AK < ARM::ArchKind::ARMV9A || AK > ARM::ArchKind::ARMV9_3A)
483return ARM::ArchKind::INVALID;
484unsigned AK_v8 = static_cast<unsigned>(ARM::ArchKind::ARMV8_5A);
485AK_v8 += static_cast<unsigned>(AK) -
486static_cast<unsigned>(ARM::ArchKind::ARMV9A);
487return static_cast<ARM::ArchKind>(AK_v8);
488}
489
490StringRef ARM::getDefaultCPU(StringRef Arch) {
491ArchKind AK = parseArch(Arch);
492if (AK == ArchKind::INVALID)
493return StringRef();
494
495// Look for multiple AKs to find the default for pair AK+Name.
496for (const auto &CPU : CPUNames) {
497if (CPU.ArchID == AK && CPU.Default)
498return CPU.Name;
499}
500
501// If we can't find a default then target the architecture instead
502return "generic";
503}
504
505uint64_t ARM::parseHWDiv(StringRef HWDiv) {
506StringRef Syn = getHWDivSynonym(HWDiv);
507for (const auto &D : HWDivNames) {
508if (Syn == D.Name)
509return D.ID;
510}
511return AEK_INVALID;
512}
513
514uint64_t ARM::parseArchExt(StringRef ArchExt) {
515for (const auto &A : ARCHExtNames) {
516if (ArchExt == A.Name)
517return A.ID;
518}
519return AEK_INVALID;
520}
521
522ARM::ArchKind ARM::parseCPUArch(StringRef CPU) {
523for (const auto &C : CPUNames) {
524if (CPU == C.Name)
525return C.ArchID;
526}
527return ArchKind::INVALID;
528}
529
530void ARM::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values) {
531for (const auto &Arch : CPUNames) {
532if (Arch.ArchID != ArchKind::INVALID)
533Values.push_back(Arch.Name);
534}
535}
536
537StringRef ARM::computeDefaultTargetABI(const Triple &TT, StringRef CPU) {
538StringRef ArchName =
539CPU.empty() ? TT.getArchName() : getArchName(parseCPUArch(CPU));
540
541if (TT.isOSBinFormatMachO()) {
542if (TT.getEnvironment() == Triple::EABI ||
543TT.getOS() == Triple::UnknownOS ||
544parseArchProfile(ArchName) == ProfileKind::M)
545return "aapcs";
546if (TT.isWatchABI())
547return "aapcs16";
548return "apcs-gnu";
549} else if (TT.isOSWindows())
550// FIXME: this is invalid for WindowsCE.
551return "aapcs";
552
553// Select the default based on the platform.
554switch (TT.getEnvironment()) {
555case Triple::Android:
556case Triple::GNUEABI:
557case Triple::GNUEABIHF:
558case Triple::MuslEABI:
559case Triple::MuslEABIHF:
560case Triple::OpenHOS:
561return "aapcs-linux";
562case Triple::EABIHF:
563case Triple::EABI:
564return "aapcs";
565default:
566if (TT.isOSNetBSD())
567return "apcs-gnu";
568if (TT.isOSFreeBSD() || TT.isOSOpenBSD() || TT.isOSHaiku() ||
569TT.isOHOSFamily())
570return "aapcs-linux";
571return "aapcs";
572}
573}
574
575StringRef ARM::getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch) {
576if (MArch.empty())
577MArch = Triple.getArchName();
578MArch = llvm::ARM::getCanonicalArchName(MArch);
579
580// Some defaults are forced.
581switch (Triple.getOS()) {
582case llvm::Triple::FreeBSD:
583case llvm::Triple::NetBSD:
584case llvm::Triple::OpenBSD:
585case llvm::Triple::Haiku:
586if (!MArch.empty() && MArch == "v6")
587return "arm1176jzf-s";
588if (!MArch.empty() && MArch == "v7")
589return "cortex-a8";
590break;
591case llvm::Triple::Win32:
592// FIXME: this is invalid for WindowsCE
593if (llvm::ARM::parseArchVersion(MArch) <= 7)
594return "cortex-a9";
595break;
596case llvm::Triple::IOS:
597case llvm::Triple::MacOSX:
598case llvm::Triple::TvOS:
599case llvm::Triple::WatchOS:
600case llvm::Triple::DriverKit:
601case llvm::Triple::XROS:
602if (MArch == "v7k")
603return "cortex-a7";
604break;
605default:
606break;
607}
608
609if (MArch.empty())
610return StringRef();
611
612StringRef CPU = llvm::ARM::getDefaultCPU(MArch);
613if (!CPU.empty() && CPU != "invalid")
614return CPU;
615
616// If no specific architecture version is requested, return the minimum CPU
617// required by the OS and environment.
618switch (Triple.getOS()) {
619case llvm::Triple::Haiku:
620return "arm1176jzf-s";
621case llvm::Triple::NetBSD:
622switch (Triple.getEnvironment()) {
623case llvm::Triple::EABI:
624case llvm::Triple::EABIHF:
625case llvm::Triple::GNUEABI:
626case llvm::Triple::GNUEABIHF:
627return "arm926ej-s";
628default:
629return "strongarm";
630}
631case llvm::Triple::NaCl:
632case llvm::Triple::OpenBSD:
633return "cortex-a8";
634default:
635switch (Triple.getEnvironment()) {
636case llvm::Triple::EABIHF:
637case llvm::Triple::GNUEABIHF:
638case llvm::Triple::MuslEABIHF:
639return "arm1176jzf-s";
640default:
641return "arm7tdmi";
642}
643}
644
645llvm_unreachable("invalid arch name");
646}
647
648void ARM::PrintSupportedExtensions(StringMap<StringRef> DescMap) {
649outs() << "All available -march extensions for ARM\n\n"
650<< " " << left_justify("Name", 20)
651<< (DescMap.empty() ? "\n" : "Description\n");
652for (const auto &Ext : ARCHExtNames) {
653// Extensions without a feature cannot be used with -march.
654if (!Ext.Feature.empty()) {
655std::string Description = DescMap[Ext.Name].str();
656outs() << " "
657<< format(Description.empty() ? "%s\n" : "%-20s%s\n",
658Ext.Name.str().c_str(), Description.c_str());
659}
660}
661}
662