LLVM 20.0.0git
AArch64TargetParser.h
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
14#ifndef LLVM_TARGETPARSER_AARCH64TARGETPARSER_H
15#define LLVM_TARGETPARSER_AARCH64TARGETPARSER_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/Bitset.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/StringRef.h"
25#include <array>
26#include <set>
27#include <vector>
28
29namespace llvm {
30
31class Triple;
32
33namespace AArch64 {
34
35struct ArchInfo;
36struct CpuInfo;
37
39
40static_assert(FEAT_MAX < 62,
41 "Number of features in CPUFeatures are limited to 62 entries");
42
43// Each ArchExtKind correponds directly to a possible -target-feature.
44#define EMIT_ARCHEXTKIND_ENUM
45#include "llvm/TargetParser/AArch64TargetParserDef.inc"
46
48
49// Represents an extension that can be enabled with -march=<arch>+<extension>.
50// Typically these correspond to Arm Architecture extensions, unlike
51// SubtargetFeature which may represent either an actual extension or some
52// internal LLVM property.
54 StringRef UserVisibleName; // Human readable name used in -march, -cpu
55 // and target func attribute, e.g. "profile".
56 std::optional<StringRef> Alias; // An alias for this extension, if one exists.
57 ArchExtKind ID; // Corresponding to the ArchExtKind, this
58 // extensions representation in the bitfield.
59 StringRef ArchFeatureName; // The feature name defined by the
60 // Architecture, e.g. FEAT_AdvSIMD.
61 StringRef Description; // The textual description of the extension.
62 StringRef PosTargetFeature; // -target-feature/-mattr enable string,
63 // e.g. "+spe".
64 StringRef NegTargetFeature; // -target-feature/-mattr disable string,
65 // e.g. "-spe".
66};
67
68#define EMIT_EXTENSIONS
69#include "llvm/TargetParser/AArch64TargetParserDef.inc"
70
71struct FMVInfo {
72 StringRef Name; // The target_version/target_clones spelling.
73 CPUFeatures Bit; // Index of the bit in the FMV feature bitset.
74 std::optional<ArchExtKind> ID; // The architecture extension to enable.
75 unsigned Priority; // FMV priority.
76 FMVInfo(StringRef Name, CPUFeatures Bit, std::optional<ArchExtKind> ID,
77 unsigned Priority)
78 : Name(Name), Bit(Bit), ID(ID), Priority(Priority) {};
79};
80
81const std::vector<FMVInfo> &getFMVInfo();
82
83// Represents a dependency between two architecture extensions. Later is the
84// feature which was added to the architecture after Earlier, and expands the
85// functionality provided by it. If Later is enabled, then Earlier will also be
86// enabled. If Earlier is disabled, then Later will also be disabled.
88 ArchExtKind Earlier;
89 ArchExtKind Later;
90};
91
92#define EMIT_EXTENSION_DEPENDENCIES
93#include "llvm/TargetParser/AArch64TargetParserDef.inc"
94
95enum ArchProfile { AProfile = 'A', RProfile = 'R', InvalidProfile = '?' };
96
97// Information about a specific architecture, e.g. V8.1-A
98struct ArchInfo {
99 VersionTuple Version; // Architecture version, major + minor.
100 ArchProfile Profile; // Architecuture profile
101 StringRef Name; // Name as supplied to -march e.g. "armv8.1-a"
102 StringRef ArchFeature; // Name as supplied to -target-feature, e.g. "+v8a"
104 DefaultExts; // bitfield of default extensions ArchExtKind
105
106 bool operator==(const ArchInfo &Other) const {
107 return this->Name == Other.Name;
108 }
109 bool operator!=(const ArchInfo &Other) const {
110 return this->Name != Other.Name;
111 }
112
113 // Defines the following partial order, indicating when an architecture is
114 // a superset of another:
115 //
116 // v9.6a > v9.5a > v9.4a > v9.3a > v9.2a > v9.1a > v9a;
117 // v v v v v
118 // v8.9a > v8.8a > v8.7a > v8.6a > v8.5a > v8.4a > ... > v8a;
119 //
120 // v8r has no relation to anything. This is used to determine which
121 // features to enable for a given architecture. See
122 // AArch64TargetInfo::setFeatureEnabled.
123 bool implies(const ArchInfo &Other) const {
124 if (this->Profile != Other.Profile)
125 return false; // ARMV8R
126 if (this->Version.getMajor() == Other.Version.getMajor()) {
127 return this->Version > Other.Version;
128 }
129 if (this->Version.getMajor() == 9 && Other.Version.getMajor() == 8) {
130 assert(this->Version.getMinor() && Other.Version.getMinor() &&
131 "AArch64::ArchInfo should have a minor version.");
132 return this->Version.getMinor().value_or(0) + 5 >=
133 Other.Version.getMinor().value_or(0);
134 }
135 return false;
136 }
137
138 // True if this architecture is a superset of Other (including being equal to
139 // it).
140 bool is_superset(const ArchInfo &Other) const {
141 return (*this == Other) || implies(Other);
142 }
143
144 // Return ArchFeature without the leading "+".
145 StringRef getSubArch() const { return ArchFeature.substr(1); }
146
147 // Search for ArchInfo by SubArch name
148 static std::optional<ArchInfo> findBySubArch(StringRef SubArch);
149};
150
151#define EMIT_ARCHITECTURES
152#include "llvm/TargetParser/AArch64TargetParserDef.inc"
153
154// Details of a specific CPU.
155struct CpuInfo {
156 StringRef Name; // Name, as written for -mcpu.
159 DefaultExtensions; // Default extensions for this CPU.
160
162 return DefaultExtensions;
163 }
164};
165
166#define EMIT_CPU_INFO
167#include "llvm/TargetParser/AArch64TargetParserDef.inc"
168
170 // Set of extensions which are currently enabled.
172 // Set of extensions which have been enabled or disabled at any point. Used
173 // to avoid cluttering the cc1 command-line with lots of unneeded features.
175 // Base architecture version, which we need to know because some feature
176 // dependencies change depending on this.
178
179 ExtensionSet() : Enabled(), Touched(), BaseArch(nullptr) {}
180
181 // Enable the given architecture extension, and any other extensions it
182 // depends on. Does not change the base architecture, or follow dependencies
183 // between features which are only related by required arcitecture versions.
184 void enable(ArchExtKind E);
185
186 // Disable the given architecture extension, and any other extensions which
187 // depend on it. Does not change the base architecture, or follow
188 // dependencies between features which are only related by required
189 // arcitecture versions.
190 void disable(ArchExtKind E);
191
192 // Add default extensions for the given CPU. Records the base architecture,
193 // to later resolve dependencies which depend on it.
194 void addCPUDefaults(const CpuInfo &CPU);
195
196 // Add default extensions for the given architecture version. Records the
197 // base architecture, to later resolve dependencies which depend on it.
198 void addArchDefaults(const ArchInfo &Arch);
199
200 // Add or remove a feature based on a modifier string. The string must be of
201 // the form "<name>" to enable a feature or "no<name>" to disable it. This
202 // will also enable or disable any features as required by the dependencies
203 // between them.
204 bool parseModifier(StringRef Modifier, const bool AllowNoDashForm = false);
205
206 // Constructs a new ExtensionSet by toggling the corresponding bits for every
207 // feature in the \p Features list without expanding their dependencies. Used
208 // for reconstructing an ExtensionSet from the output of toLLVMFeatures().
209 // Features that are not recognized are pushed back to \p NonExtensions.
210 void reconstructFromParsedFeatures(const std::vector<std::string> &Features,
211 std::vector<std::string> &NonExtensions);
212
213 // Convert the set of enabled extension to an LLVM feature list, appending
214 // them to Features.
215 template <typename T> void toLLVMFeatureList(std::vector<T> &Features) const {
217 Features.emplace_back(T(BaseArch->ArchFeature));
218
219 for (const auto &E : Extensions) {
220 if (E.PosTargetFeature.empty() || !Touched.test(E.ID))
221 continue;
222 if (Enabled.test(E.ID))
223 Features.emplace_back(T(E.PosTargetFeature));
224 else
225 Features.emplace_back(T(E.NegTargetFeature));
226 }
227 }
228
229 void dump() const;
230};
231
232// Name alias.
233struct Alias {
236};
237
238#define EMIT_CPU_ALIAS
239#include "llvm/TargetParser/AArch64TargetParserDef.inc"
240
241const ExtensionInfo &getExtensionByID(ArchExtKind(ExtID));
242
245 std::vector<StringRef> &Features);
246
249
250// Information by Name
252
253// Parser
254const ArchInfo *parseArch(StringRef Arch);
255
256// Return the extension which has the given -target-feature name.
257std::optional<ExtensionInfo> targetFeatureToExtension(StringRef TargetFeature);
258
259// Parse a name as defined by the Extension class in tablegen.
260std::optional<ExtensionInfo> parseArchExtension(StringRef Extension);
261
262// Parse a name as defined by the FMVInfo class in tablegen.
263std::optional<FMVInfo> parseFMVExtension(StringRef Extension);
264
265// Given the name of a CPU or alias, return the correponding CpuInfo.
266std::optional<CpuInfo> parseCpu(StringRef Name);
267// Used by target parser tests
269
270bool isX18ReservedByDefault(const Triple &TT);
271
272// Return the priority for a given set of FMV features.
273unsigned getFMVPriority(ArrayRef<StringRef> Features);
274
275// For given feature names, return a bitmask corresponding to the entries of
276// AArch64::CPUFeatures. The values in CPUFeatures are not bitmasks themselves,
277// they are sequential (0, 1, 2, 3, ...). The resulting bitmask is used at
278// runtime to test whether a certain FMV feature is available on the host.
280
282
283void printEnabledExtensions(const std::set<StringRef> &EnabledFeatureNames);
284
285} // namespace AArch64
286} // namespace llvm
287
288#endif
This file defines the StringMap class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::string Name
#define T
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static cl::opt< std::set< SPIRV::Extension::Extension >, false, SPIRVExtensionsParser > Extensions("spirv-ext", cl::desc("Specify list of enabled SPIR-V extensions"))
This file contains some functions that are useful when dealing with strings.
Defines the llvm::VersionTuple class, which represents a version in the form major[....
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
constexpr bool test(unsigned I) const
Definition: Bitset.h:77
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:571
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
unsigned getMajor() const
Retrieve the major version number.
Definition: VersionTuple.h:71
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
Definition: VersionTuple.h:74
bool isX18ReservedByDefault(const Triple &TT)
StringRef getArchExtFeature(StringRef ArchExt)
std::optional< ExtensionInfo > parseArchExtension(StringRef Extension)
std::optional< CpuInfo > parseCpu(StringRef Name)
const ArchInfo * parseArch(StringRef Arch)
const ArchInfo * getArchForCpu(StringRef CPU)
void fillValidCPUArchList(SmallVectorImpl< StringRef > &Values)
const ExtensionInfo & getExtensionByID(ArchExtKind(ExtID))
void printEnabledExtensions(const std::set< StringRef > &EnabledFeatureNames)
std::optional< FMVInfo > parseFMVExtension(StringRef Extension)
const std::vector< FMVInfo > & getFMVInfo()
std::optional< ExtensionInfo > targetFeatureToExtension(StringRef TargetFeature)
StringRef resolveCPUAlias(StringRef CPU)
bool getExtensionFeatures(const AArch64::ExtensionBitset &Extensions, std::vector< StringRef > &Features)
unsigned getFMVPriority(ArrayRef< StringRef > Features)
uint64_t getCpuSupportsMask(ArrayRef< StringRef > Features)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Other
Any other memory.
bool is_superset(const ArchInfo &Other) const
StringRef getSubArch() const
bool implies(const ArchInfo &Other) const
AArch64::ExtensionBitset DefaultExts
static std::optional< ArchInfo > findBySubArch(StringRef SubArch)
bool operator==(const ArchInfo &Other) const
bool operator!=(const ArchInfo &Other) const
AArch64::ExtensionBitset getImpliedExtensions() const
AArch64::ExtensionBitset DefaultExtensions
std::optional< StringRef > Alias
bool parseModifier(StringRef Modifier, const bool AllowNoDashForm=false)
void addCPUDefaults(const CpuInfo &CPU)
void toLLVMFeatureList(std::vector< T > &Features) const
void addArchDefaults(const ArchInfo &Arch)
void reconstructFromParsedFeatures(const std::vector< std::string > &Features, std::vector< std::string > &NonExtensions)
std::optional< ArchExtKind > ID
FMVInfo(StringRef Name, CPUFeatures Bit, std::optional< ArchExtKind > ID, unsigned Priority)