LLVM  15.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 
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/ADT/Triple.h"
17 #include <cctype>
18 
19 using namespace llvm;
20 
21 static unsigned checkArchVersion(llvm::StringRef Arch) {
22  if (Arch.size() >= 2 && Arch[0] == 'v' && std::isdigit(Arch[1]))
23  return (Arch[1] - 48);
24  return 0;
25 }
26 
28  if (CPU == "generic")
29  return AArch64ARCHNames[static_cast<unsigned>(AK)].DefaultFPU;
30 
31  return StringSwitch<unsigned>(CPU)
32 #define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
33  .Case(NAME, ARM::DEFAULT_FPU)
34 #include "../../include/llvm/Support/AArch64TargetParser.def"
36 }
37 
39  if (CPU == "generic")
40  return AArch64ARCHNames[static_cast<unsigned>(AK)].ArchBaseExtensions;
41 
42  return StringSwitch<uint64_t>(CPU)
43 #define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
44  .Case(NAME, AArch64ARCHNames[static_cast<unsigned>(ArchKind::ID)] \
45  .ArchBaseExtensions | \
46  DEFAULT_EXT)
47 #include "../../include/llvm/Support/AArch64TargetParser.def"
49 }
50 
52  if (CPU == "generic")
53  return ArchKind::ARMV8A;
54 
56 #define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
57  .Case(NAME, ArchKind::ID)
58 #include "../../include/llvm/Support/AArch64TargetParser.def"
59  .Default(ArchKind::INVALID);
60 }
61 
63  std::vector<StringRef> &Features) {
64  if (Extensions == AArch64::AEK_INVALID)
65  return false;
66 
67 #define AARCH64_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
68  if (Extensions & ID) { \
69  const char *feature = FEATURE; \
70  /* INVALID and NONE have no feature name. */ \
71  if (feature) \
72  Features.push_back(feature); \
73  }
74 #include "../../include/llvm/Support/AArch64TargetParser.def"
75 
76  return true;
77 }
78 
80  std::vector<StringRef> &Features) {
81  if (AK == ArchKind::ARMV8A)
82  Features.push_back("+v8a");
83  if (AK == ArchKind::ARMV8_1A)
84  Features.push_back("+v8.1a");
85  if (AK == ArchKind::ARMV8_2A)
86  Features.push_back("+v8.2a");
87  if (AK == ArchKind::ARMV8_3A)
88  Features.push_back("+v8.3a");
89  if (AK == ArchKind::ARMV8_4A)
90  Features.push_back("+v8.4a");
91  if (AK == ArchKind::ARMV8_5A)
92  Features.push_back("+v8.5a");
93  if (AK == AArch64::ArchKind::ARMV8_6A)
94  Features.push_back("+v8.6a");
95  if (AK == AArch64::ArchKind::ARMV8_7A)
96  Features.push_back("+v8.7a");
97  if (AK == AArch64::ArchKind::ARMV8_8A)
98  Features.push_back("+v8.8a");
99  if (AK == AArch64::ArchKind::ARMV9A)
100  Features.push_back("+v9a");
101  if (AK == AArch64::ArchKind::ARMV9_1A)
102  Features.push_back("+v9.1a");
103  if (AK == AArch64::ArchKind::ARMV9_2A)
104  Features.push_back("+v9.2a");
105  if (AK == AArch64::ArchKind::ARMV9_3A)
106  Features.push_back("+v9.3a");
107  if(AK == AArch64::ArchKind::ARMV8R)
108  Features.push_back("+v8r");
109 
110  return AK != ArchKind::INVALID;
111 }
112 
114  return AArch64ARCHNames[static_cast<unsigned>(AK)].getName();
115 }
116 
118  return AArch64ARCHNames[static_cast<unsigned>(AK)].getCPUAttr();
119 }
120 
122  return AArch64ARCHNames[static_cast<unsigned>(AK)].getSubArch();
123 }
124 
126  return AArch64ARCHNames[static_cast<unsigned>(AK)].ArchAttr;
127 }
128 
130  for (const auto &AE : AArch64ARCHExtNames)
131  if (ArchExtKind == AE.ID)
132  return AE.getName();
133  return StringRef();
134 }
135 
137  if (ArchExt.startswith("no")) {
138  StringRef ArchExtBase(ArchExt.substr(2));
139  for (const auto &AE : AArch64ARCHExtNames) {
140  if (AE.NegFeature && ArchExtBase == AE.getName())
141  return StringRef(AE.NegFeature);
142  }
143  }
144 
145  for (const auto &AE : AArch64ARCHExtNames)
146  if (AE.Feature && ArchExt == AE.getName())
147  return StringRef(AE.Feature);
148  return StringRef();
149 }
150 
152  ArchKind AK = parseArch(Arch);
153  if (AK == ArchKind::INVALID)
154  return StringRef();
155 
156  // Look for multiple AKs to find the default for pair AK+Name.
157  for (const auto &CPU : AArch64CPUNames)
158  if (CPU.ArchID == AK && CPU.Default)
159  return CPU.getName();
160 
161  // If we can't find a default then target the architecture instead
162  return "generic";
163 }
164 
166  for (const auto &Arch : AArch64CPUNames) {
167  if (Arch.ArchID != ArchKind::INVALID)
168  Values.push_back(Arch.getName());
169  }
170 }
171 
173  return TT.isAndroid() || TT.isOSDarwin() || TT.isOSFuchsia() ||
174  TT.isOSWindows();
175 }
176 
177 // Allows partial match, ex. "v8a" matches "armv8a".
179  Arch = ARM::getCanonicalArchName(Arch);
180  if (checkArchVersion(Arch) < 8)
181  return ArchKind::INVALID;
182 
183  StringRef Syn = ARM::getArchSynonym(Arch);
184  for (const auto &A : AArch64ARCHNames) {
185  if (A.getName().endswith(Syn))
186  return A.ID;
187  }
188  return ArchKind::INVALID;
189 }
190 
192  for (const auto &A : AArch64ARCHExtNames) {
193  if (ArchExt == A.getName())
194  return static_cast<ArchExtKind>(A.ID);
195  }
196  return AArch64::AEK_INVALID;
197 }
198 
200  for (const auto &C : AArch64CPUNames) {
201  if (CPU == C.getName())
202  return C.ArchID;
203  }
204  return ArchKind::INVALID;
205 }
llvm::AArch64::getArchFeatures
bool getArchFeatures(ArchKind AK, std::vector< StringRef > &Features)
Definition: AArch64TargetParser.cpp:79
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:286
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:42
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::AArch64::ArchExtKind
ArchExtKind
Definition: AArch64TargetParser.h:29
llvm::ARM::getCanonicalArchName
StringRef getCanonicalArchName(StringRef Arch)
Definition: ARMTargetParser.cpp:295
AArch64TargetParser.h
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:183
llvm::AArch64::getExtensionFeatures
bool getExtensionFeatures(uint64_t Extensions, std::vector< StringRef > &Features)
Definition: AArch64TargetParser.cpp:62
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::ARM::getArchSynonym
StringRef getArchSynonym(StringRef Arch)
Definition: ARMTargetParser.cpp:151
llvm::AArch64::getCPUAttr
StringRef getCPUAttr(ArchKind AK)
Definition: AArch64TargetParser.cpp:117
llvm::AArch64::parseArchExt
ArchExtKind parseArchExt(StringRef ArchExt)
Definition: AArch64TargetParser.cpp:191
llvm::AArch64::getArchExtName
StringRef getArchExtName(unsigned ArchExtKind)
Definition: AArch64TargetParser.cpp:129
llvm::AArch64::getDefaultExtensions
uint64_t getDefaultExtensions(StringRef CPU, ArchKind AK)
Definition: AArch64TargetParser.cpp:38
llvm::AArch64::getDefaultCPU
StringRef getDefaultCPU(StringRef Arch)
Definition: AArch64TargetParser.cpp:151
llvm::AArch64::getArchAttr
unsigned getArchAttr(ArchKind AK)
Definition: AArch64TargetParser.cpp:125
llvm::AArch64::getArchExtFeature
StringRef getArchExtFeature(StringRef ArchExt)
Definition: AArch64TargetParser.cpp:136
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:611
llvm::AArch64::AArch64CPUNames
const ARM::CpuNames< ArchKind > AArch64CPUNames[]
Definition: AArch64TargetParser.h:103
llvm::AArch64::AEK_INVALID
@ AEK_INVALID
Definition: AArch64TargetParser.h:30
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::AArch64::isX18ReservedByDefault
bool isX18ReservedByDefault(const Triple &TT)
Definition: AArch64TargetParser.cpp:172
llvm::AArch64::getDefaultFPU
unsigned getDefaultFPU(StringRef CPU, ArchKind AK)
Definition: AArch64TargetParser.cpp:27
checkArchVersion
static unsigned checkArchVersion(llvm::StringRef Arch)
Definition: AArch64TargetParser.cpp:21
parseArch
static Triple::ArchType parseArch(StringRef ArchName)
Definition: Triple.cpp:442
uint64_t
llvm::AArch64::getArchName
StringRef getArchName(ArchKind AK)
Definition: AArch64TargetParser.cpp:113
llvm::AArch64::AArch64ARCHNames
const ARM::ArchNames< ArchKind > AArch64ARCHNames[]
Definition: AArch64TargetParser.h:81
llvm::AArch64::fillValidCPUArchList
void fillValidCPUArchList(SmallVectorImpl< StringRef > &Values)
Definition: AArch64TargetParser.cpp:165
llvm::AArch64::parseCPUArch
ArchKind parseCPUArch(StringRef CPU)
Definition: AArch64TargetParser.cpp:199
Triple.h
llvm::AArch64::parseArch
ArchKind parseArch(StringRef Arch)
Definition: AArch64TargetParser.cpp:178
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AArch64::AArch64ARCHExtNames
const ARM::ExtName AArch64ARCHExtNames[]
Definition: AArch64TargetParser.h:97
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
llvm::RISCV::FK_INVALID
@ FK_INVALID
Definition: TargetParser.h:166
llvm::AArch64::getSubArch
StringRef getSubArch(ArchKind AK)
Definition: AArch64TargetParser.cpp:121
StringSwitch.h
llvm::AArch64::getCPUArchKind
ArchKind getCPUArchKind(StringRef CPU)
Definition: AArch64TargetParser.cpp:51
llvm::AArch64::ArchKind
ArchKind
Definition: AArch64TargetParser.h:76
llvm::SmallVectorImpl< StringRef >
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44