LLVM  16.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"
18 #include <cctype>
19 
20 using namespace llvm;
21 
22 static 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 
29  if (CPU == "generic")
30  return AArch64ARCHNames[static_cast<unsigned>(AK)].ArchBaseExtensions;
31 
32  return StringSwitch<uint64_t>(CPU)
33 #define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
34  .Case(NAME, AArch64ARCHNames[static_cast<unsigned>(ArchKind::ID)] \
35  .ArchBaseExtensions | \
36  DEFAULT_EXT)
37 #include "../../include/llvm/Support/AArch64TargetParser.def"
39 }
40 
42  if (CPU == "generic")
43  return ArchKind::ARMV8A;
44 
46 #define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
47  .Case(NAME, ArchKind::ID)
48 #include "../../include/llvm/Support/AArch64TargetParser.def"
49  .Default(ArchKind::INVALID);
50 }
51 
53  for (const auto &A : AArch64ARCHNames)
54  if (A.getSubArch() == SubArch)
55  return A.ID;
56  return ArchKind::INVALID;
57 }
58 
60  std::vector<StringRef> &Features) {
61  if (Extensions == AArch64::AEK_INVALID)
62  return false;
63 
64 #define AARCH64_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
65  if (Extensions & ID) { \
66  const char *feature = FEATURE; \
67  /* INVALID and NONE have no feature name. */ \
68  if (feature) \
69  Features.push_back(feature); \
70  }
71 #include "../../include/llvm/Support/AArch64TargetParser.def"
72 
73  return true;
74 }
75 
77  return StringSwitch<StringRef>(CPU)
78 #define AARCH64_CPU_ALIAS(ALIAS,NAME) \
79  .Case(ALIAS, NAME)
80 #include "../../include/llvm/Support/AArch64TargetParser.def"
81  .Default(CPU);
82 }
83 
85  std::vector<StringRef> &Features) {
86  if (AK == ArchKind::INVALID)
87  return false;
88  Features.push_back(AArch64ARCHNames[static_cast<unsigned>(AK)].ArchFeature);
89  return true;
90 }
91 
93  return AArch64ARCHNames[static_cast<unsigned>(AK)].Name;
94 }
95 
97  return AArch64ARCHNames[static_cast<unsigned>(AK)].getSubArch();
98 }
99 
101  if (ArchExt.startswith("no")) {
102  StringRef ArchExtBase(ArchExt.substr(2));
103  for (const auto &AE : AArch64ARCHExtNames) {
104  if (!AE.NegFeature.empty() && ArchExtBase == AE.Name)
105  return AE.NegFeature;
106  }
107  }
108 
109  for (const auto &AE : AArch64ARCHExtNames)
110  if (!AE.Feature.empty() && ArchExt == AE.Name)
111  return AE.Feature;
112  return StringRef();
113 }
114 
116  if (AK == AArch64::ArchKind::INVALID)
117  return AK;
118  if (AK < AArch64::ArchKind::ARMV9A)
119  return AK;
120  if (AK >= AArch64::ArchKind::ARMV8R)
121  return AArch64::ArchKind::INVALID;
122  unsigned AK_v8 = static_cast<unsigned>(AArch64::ArchKind::ARMV8_5A);
123  AK_v8 += static_cast<unsigned>(AK) -
124  static_cast<unsigned>(AArch64::ArchKind::ARMV9A);
125  return static_cast<AArch64::ArchKind>(AK_v8);
126 }
127 
129  for (const auto &Arch : AArch64CPUNames) {
130  if (Arch.ArchID != ArchKind::INVALID)
131  Values.push_back(Arch.Name);
132  }
133 
134  for (const auto &Alias: AArch64CPUAliases)
135  Values.push_back(Alias.Alias);
136 }
137 
139  return TT.isAndroid() || TT.isOSDarwin() || TT.isOSFuchsia() ||
140  TT.isOSWindows();
141 }
142 
143 // Allows partial match, ex. "v8a" matches "armv8a".
145  Arch = llvm::ARM::getCanonicalArchName(Arch);
146  if (checkArchVersion(Arch) < 8)
147  return ArchKind::INVALID;
148 
150  for (const auto &A : AArch64ARCHNames) {
151  if (A.Name.endswith(Syn))
152  return A.ID;
153  }
154  return ArchKind::INVALID;
155 }
156 
158  for (const auto &A : AArch64ARCHExtNames) {
159  if (ArchExt == A.Name)
160  return static_cast<ArchExtKind>(A.ID);
161  }
162  return AArch64::AEK_INVALID;
163 }
164 
166  // Resolve aliases first.
167  for (const auto &Alias : AArch64CPUAliases) {
168  if (CPU == Alias.Alias) {
169  CPU = Alias.Name;
170  break;
171  }
172  }
173  // Then find the CPU name.
174  for (const auto &C : AArch64CPUNames)
175  if (CPU == C.Name)
176  return C.ArchID;
177 
178  return ArchKind::INVALID;
179 }
llvm::AArch64::getArchFeatures
bool getArchFeatures(ArchKind AK, std::vector< StringRef > &Features)
Definition: AArch64TargetParser.cpp:84
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::AArch64::ArchExtKind
ArchExtKind
Definition: AArch64TargetParser.h:29
llvm::ARM::getCanonicalArchName
StringRef getCanonicalArchName(StringRef Arch)
MArch is expected to be of the form (arm|thumb)?(eb)?(v.
Definition: ARMTargetParserCommon.cpp:53
AArch64TargetParser.h
llvm::AArch64::getExtensionFeatures
bool getExtensionFeatures(uint64_t Extensions, std::vector< StringRef > &Features)
Definition: AArch64TargetParser.cpp:59
ARMTargetParserCommon.h
llvm::AArch64::AArch64ARCHExtNames
const ExtName AArch64ARCHExtNames[]
Definition: AArch64TargetParser.h:112
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::ARM::getArchSynonym
StringRef getArchSynonym(StringRef Arch)
Converts e.g. "armv8" -> "armv8-a".
Definition: ARMTargetParserCommon.cpp:19
llvm::AArch64::parseArchExt
ArchExtKind parseArchExt(StringRef ArchExt)
Definition: AArch64TargetParser.cpp:157
llvm::StringRef::substr
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:564
llvm::AArch64::getDefaultExtensions
uint64_t getDefaultExtensions(StringRef CPU, ArchKind AK)
Definition: AArch64TargetParser.cpp:28
llvm::AArch64::getArchExtFeature
StringRef getArchExtFeature(StringRef ArchExt)
Definition: AArch64TargetParser.cpp:100
llvm::StringRef::startswith
bool startswith(StringRef Prefix) const
Definition: StringRef.h:260
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::getSubArchArchKind
ArchKind getSubArchArchKind(StringRef SubArch)
Definition: AArch64TargetParser.cpp:52
llvm::AArch64::isX18ReservedByDefault
bool isX18ReservedByDefault(const Triple &TT)
Definition: AArch64TargetParser.cpp:138
checkArchVersion
static unsigned checkArchVersion(llvm::StringRef Arch)
Definition: AArch64TargetParser.cpp:22
llvm::AArch64::convertV9toV8
ArchKind convertV9toV8(ArchKind AK)
Definition: AArch64TargetParser.cpp:115
uint64_t
llvm::AArch64::getArchName
StringRef getArchName(ArchKind AK)
Definition: AArch64TargetParser.cpp:92
llvm::AArch64::fillValidCPUArchList
void fillValidCPUArchList(SmallVectorImpl< StringRef > &Values)
Definition: AArch64TargetParser.cpp:128
llvm::AArch64::parseCPUArch
ArchKind parseCPUArch(StringRef CPU)
Definition: AArch64TargetParser.cpp:165
Triple.h
llvm::AArch64::parseArch
ArchKind parseArch(StringRef Arch)
Definition: AArch64TargetParser.cpp:144
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
llvm::AArch64::Alias
StringRef Alias
Definition: AArch64TargetParser.h:136
llvm::AArch64::AArch64CPUNames
const CpuNames AArch64CPUNames[]
Definition: AArch64TargetParser.h:129
llvm::AArch64::AArch64CPUAliases
const struct llvm::AArch64::@359 AArch64CPUAliases[]
llvm::AArch64::getSubArch
StringRef getSubArch(ArchKind AK)
Definition: AArch64TargetParser.cpp:96
StringSwitch.h
llvm::AArch64::getCPUArchKind
ArchKind getCPUArchKind(StringRef CPU)
Definition: AArch64TargetParser.cpp:41
llvm::AArch64::ArchKind
ArchKind
Definition: AArch64TargetParser.h:83
llvm::SmallVectorImpl< StringRef >
llvm::AArch64::resolveCPUAlias
StringRef resolveCPUAlias(StringRef CPU)
Definition: AArch64TargetParser.cpp:76
llvm::StringSwitch::Default
R Default(T Value)
Definition: StringSwitch.h:183
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:45
llvm::AArch64::AArch64ARCHNames
const ArchNames AArch64ARCHNames[]
Definition: AArch64TargetParser.h:98