LLVM 17.0.0git
AArch64TargetParser.cpp
Go to the documentation of this file.
1//===-- AArch64TargetParser - Parser for AArch64 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 AArch64 hardware features
10// such as FPU/CPU/ARCH and extension names.
11//
12//===----------------------------------------------------------------------===//
13
18#include <cctype>
19
20using namespace llvm;
21
22static unsigned checkArchVersion(llvm::StringRef Arch) {
23 if (Arch.size() >= 2 && Arch[0] == 'v' && std::isdigit(Arch[1]))
24 return (Arch[1] - 48);
25 return 0;
26}
27
28std::optional<AArch64::ArchInfo> AArch64::getArchForCpu(StringRef CPU) {
29 if (CPU == "generic")
30 return ARMV8A;
31
32 // Note: this now takes cpu aliases into account
33 std::optional<CpuInfo> Cpu = parseCpu(CPU);
34 if (!Cpu)
35 return {};
36 return Cpu->Arch;
37}
38
39std::optional<AArch64::ArchInfo> AArch64::ArchInfo::findBySubArch(StringRef SubArch) {
40 for (const auto *A : AArch64::ArchInfos)
41 if (A->getSubArch() == SubArch)
42 return *A;
43 return {};
44}
45
47 uint64_t FeaturesMask = 0;
48 for (const StringRef &FeatureStr : FeatureStrs) {
49 for (const auto &E : llvm::AArch64::Extensions)
50 if (FeatureStr == E.Name) {
51 FeaturesMask |= (1ULL << E.CPUFeature);
52 break;
53 }
54 }
55 return FeaturesMask;
56}
57
59 std::vector<StringRef> &Features) {
60 for (const auto &E : Extensions)
61 /* INVALID and NONE have no feature name. */
62 if ((InputExts & E.ID) && !E.Feature.empty())
63 Features.push_back(E.Feature);
64
65 return true;
66}
67
69 for (const auto &A : CpuAliases)
70 if (A.Alias == Name)
71 return A.Name;
72 return Name;
73}
74
76 if (ArchExt.startswith("no")) {
77 StringRef ArchExtBase(ArchExt.substr(2));
78 for (const auto &AE : Extensions) {
79 if (!AE.NegFeature.empty() && ArchExtBase == AE.Name)
80 return AE.NegFeature;
81 }
82 }
83
84 for (const auto &AE : Extensions)
85 if (!AE.Feature.empty() && ArchExt == AE.Name)
86 return AE.Feature;
87 return StringRef();
88}
89
91 for (const auto &C : CpuInfos)
92 Values.push_back(C.Name);
93
94 for (const auto &Alias : CpuAliases)
95 Values.push_back(Alias.Alias);
96}
97
99 return TT.isAndroid() || TT.isOSDarwin() || TT.isOSFuchsia() ||
100 TT.isOSWindows();
101}
102
103// Allows partial match, ex. "v8a" matches "armv8a".
104std::optional<AArch64::ArchInfo> AArch64::parseArch(StringRef Arch) {
106 if (checkArchVersion(Arch) < 8)
107 return {};
108
110 for (const auto *A : ArchInfos) {
111 if (A->Name.endswith(Syn))
112 return *A;
113 }
114 return {};
115}
116
117std::optional<AArch64::ExtensionInfo> AArch64::parseArchExtension(StringRef ArchExt) {
118 for (const auto &A : Extensions) {
119 if (ArchExt == A.Name)
120 return A;
121 }
122 return {};
123}
124
125std::optional<AArch64::CpuInfo> AArch64::parseCpu(StringRef Name) {
126 // Resolve aliases first.
128
129 // Then find the CPU name.
130 for (const auto &C : CpuInfos)
131 if (Name == C.Name)
132 return C;
133
134 return {};
135}
static unsigned checkArchVersion(llvm::StringRef Arch)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::string Name
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
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
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:559
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
bool startswith(StringRef Prefix) const
Definition: StringRef.h:261
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
static constexpr std::array< const ArchInfo *, 16 > ArchInfos
bool getExtensionFeatures(uint64_t Extensions, std::vector< StringRef > &Features)
bool isX18ReservedByDefault(const Triple &TT)
StringRef getArchExtFeature(StringRef ArchExt)
std::optional< ExtensionInfo > parseArchExtension(StringRef Extension)
constexpr CpuInfo CpuInfos[]
std::optional< CpuInfo > parseCpu(StringRef Name)
uint64_t getCpuSupportsMask(ArrayRef< StringRef > FeatureStrs)
constexpr ArchInfo ARMV8A
void fillValidCPUArchList(SmallVectorImpl< StringRef > &Values)
std::optional< ArchInfo > parseArch(StringRef Arch)
constexpr CpuAlias CpuAliases[]
std::optional< ArchInfo > getArchForCpu(StringRef CPU)
StringRef resolveCPUAlias(StringRef CPU)
constexpr ExtensionInfo Extensions[]
StringRef getCanonicalArchName(StringRef Arch)
MArch is expected to be of the form (arm|thumb)?(eb)?(v.
StringRef getArchSynonym(StringRef Arch)
Converts e.g. "armv8" -> "armv8-a".
@ 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
static std::optional< ArchInfo > findBySubArch(StringRef SubArch)