LLVM 19.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"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
24#include <array>
25#include <set>
26#include <vector>
27
28namespace llvm {
29
30class Triple;
31
32namespace AArch64 {
33
34struct ArchInfo;
35struct CpuInfo;
36
37// Function Multi Versioning CPU features. They must be kept in sync with
38// compiler-rt enum CPUFeatures in lib/builtins/cpu_model/aarch64.c with
39// FEAT_MAX as sentinel.
105
106static_assert(FEAT_MAX < 62,
107 "Number of features in CPUFeatures are limited to 62 entries");
108
109// Each ArchExtKind correponds directly to a possible -target-feature.
110#define EMIT_ARCHEXTKIND_ENUM
111#include "llvm/TargetParser/AArch64TargetParserDef.inc"
112
114
115// Represents an extension that can be enabled with -march=<arch>+<extension>.
116// Typically these correspond to Arm Architecture extensions, unlike
117// SubtargetFeature which may represent either an actual extension or some
118// internal LLVM property.
120 StringRef UserVisibleName; // Human readable name used in -march, -cpu
121 // and target func attribute, e.g. "profile".
122 std::optional<StringRef> Alias; // An alias for this extension, if one exists.
123 ArchExtKind ID; // Corresponding to the ArchExtKind, this
124 // extensions representation in the bitfield.
125 StringRef ArchFeatureName; // The feature name defined by the
126 // Architecture, e.g. FEAT_AdvSIMD.
127 StringRef Description; // The textual description of the extension.
128 StringRef PosTargetFeature; // -target-feature/-mattr enable string,
129 // e.g. "+spe".
130 StringRef NegTargetFeature; // -target-feature/-mattr disable string,
131 // e.g. "-spe".
132};
133
134#define EMIT_EXTENSIONS
135#include "llvm/TargetParser/AArch64TargetParserDef.inc"
136
137struct FMVInfo {
138 StringRef Name; // The target_version/target_clones spelling.
139 CPUFeatures Bit; // Index of the bit in the FMV feature bitset.
140 StringRef Features; // List of SubtargetFeatures to enable.
141 unsigned Priority; // FMV priority.
143 unsigned Priority)
145
148 Features.split(Feats, ',', -1, false); // discard empty strings
149 return Feats;
150 }
151};
152
153const std::vector<FMVInfo> &getFMVInfo();
154
155// Represents a dependency between two architecture extensions. Later is the
156// feature which was added to the architecture after Earlier, and expands the
157// functionality provided by it. If Later is enabled, then Earlier will also be
158// enabled. If Earlier is disabled, then Later will also be disabled.
160 ArchExtKind Earlier;
161 ArchExtKind Later;
162};
163
164#define EMIT_EXTENSION_DEPENDENCIES
165#include "llvm/TargetParser/AArch64TargetParserDef.inc"
166
167enum ArchProfile { AProfile = 'A', RProfile = 'R', InvalidProfile = '?' };
168
169// Information about a specific architecture, e.g. V8.1-A
170struct ArchInfo {
171 VersionTuple Version; // Architecture version, major + minor.
172 ArchProfile Profile; // Architecuture profile
173 StringRef Name; // Name as supplied to -march e.g. "armv8.1-a"
174 StringRef ArchFeature; // Name as supplied to -target-feature, e.g. "+v8a"
176 DefaultExts; // bitfield of default extensions ArchExtKind
177
178 bool operator==(const ArchInfo &Other) const {
179 return this->Name == Other.Name;
180 }
181 bool operator!=(const ArchInfo &Other) const {
182 return this->Name != Other.Name;
183 }
184
185 // Defines the following partial order, indicating when an architecture is
186 // a superset of another:
187 //
188 // v9.5a > v9.4a > v9.3a > v9.2a > v9.1a > v9a;
189 // v v v v v
190 // v8.9a > v8.8a > v8.7a > v8.6a > v8.5a > v8.4a > ... > v8a;
191 //
192 // v8r has no relation to anything. This is used to determine which
193 // features to enable for a given architecture. See
194 // AArch64TargetInfo::setFeatureEnabled.
195 bool implies(const ArchInfo &Other) const {
196 if (this->Profile != Other.Profile)
197 return false; // ARMV8R
198 if (this->Version.getMajor() == Other.Version.getMajor()) {
199 return this->Version > Other.Version;
200 }
201 if (this->Version.getMajor() == 9 && Other.Version.getMajor() == 8) {
202 assert(this->Version.getMinor() && Other.Version.getMinor() &&
203 "AArch64::ArchInfo should have a minor version.");
204 return this->Version.getMinor().value_or(0) + 5 >=
205 Other.Version.getMinor().value_or(0);
206 }
207 return false;
208 }
209
210 // True if this architecture is a superset of Other (including being equal to
211 // it).
212 bool is_superset(const ArchInfo &Other) const {
213 return (*this == Other) || implies(Other);
214 }
215
216 // Return ArchFeature without the leading "+".
217 StringRef getSubArch() const { return ArchFeature.substr(1); }
218
219 // Search for ArchInfo by SubArch name
220 static std::optional<ArchInfo> findBySubArch(StringRef SubArch);
221};
222
223#define EMIT_ARCHITECTURES
224#include "llvm/TargetParser/AArch64TargetParserDef.inc"
225
226// Details of a specific CPU.
227struct CpuInfo {
228 StringRef Name; // Name, as written for -mcpu.
231 DefaultExtensions; // Default extensions for this CPU. These will be
232 // ORd with the architecture defaults.
233
235 AArch64::ExtensionBitset ImpliedExts;
236 ImpliedExts |= DefaultExtensions;
237 ImpliedExts |= Arch.DefaultExts;
238 return ImpliedExts;
239 }
240};
241
242#define EMIT_CPU_INFO
243#include "llvm/TargetParser/AArch64TargetParserDef.inc"
244
246 // Set of extensions which are currently enabled.
248 // Set of extensions which have been enabled or disabled at any point. Used
249 // to avoid cluttering the cc1 command-line with lots of unneeded features.
251 // Base architecture version, which we need to know because some feature
252 // dependencies change depending on this.
254
255 ExtensionSet() : Enabled(), Touched(), BaseArch(nullptr) {}
256
257 // Enable the given architecture extension, and any other extensions it
258 // depends on. Does not change the base architecture, or follow dependencies
259 // between features which are only related by required arcitecture versions.
260 void enable(ArchExtKind E);
261
262 // Disable the given architecture extension, and any other extensions which
263 // depend on it. Does not change the base architecture, or follow
264 // dependencies between features which are only related by required
265 // arcitecture versions.
266 void disable(ArchExtKind E);
267
268 // Add default extensions for the given CPU. Records the base architecture,
269 // to later resolve dependencies which depend on it.
270 void addCPUDefaults(const CpuInfo &CPU);
271
272 // Add default extensions for the given architecture version. Records the
273 // base architecture, to later resolve dependencies which depend on it.
274 void addArchDefaults(const ArchInfo &Arch);
275
276 // Add or remove a feature based on a modifier string. The string must be of
277 // the form "<name>" to enable a feature or "no<name>" to disable it. This
278 // will also enable or disable any features as required by the dependencies
279 // between them.
280 bool parseModifier(StringRef Modifier, const bool AllowNoDashForm = false);
281
282 // Constructs a new ExtensionSet by toggling the corresponding bits for every
283 // feature in the \p Features list without expanding their dependencies. Used
284 // for reconstructing an ExtensionSet from the output of toLLVMFeatures().
285 // Features that are not recognized are pushed back to \p NonExtensions.
286 void reconstructFromParsedFeatures(const std::vector<std::string> &Features,
287 std::vector<std::string> &NonExtensions);
288
289 // Convert the set of enabled extension to an LLVM feature list, appending
290 // them to Features.
291 template <typename T> void toLLVMFeatureList(std::vector<T> &Features) const {
293 Features.emplace_back(T(BaseArch->ArchFeature));
294
295 for (const auto &E : Extensions) {
296 if (E.PosTargetFeature.empty() || !Touched.test(E.ID))
297 continue;
298 if (Enabled.test(E.ID))
299 Features.emplace_back(T(E.PosTargetFeature));
300 else
301 Features.emplace_back(T(E.NegTargetFeature));
302 }
303 }
304
305 void dump() const;
306};
307
308// Name alias.
309struct Alias {
312};
313
314#define EMIT_CPU_ALIAS
315#include "llvm/TargetParser/AArch64TargetParserDef.inc"
316
317const ExtensionInfo &getExtensionByID(ArchExtKind(ExtID));
318
321 std::vector<StringRef> &Features);
322
325
326// Information by Name
328
329// Parser
330const ArchInfo *parseArch(StringRef Arch);
331
332// Return the extension which has the given -target-feature name.
333std::optional<ExtensionInfo> targetFeatureToExtension(StringRef TargetFeature);
334
335// Parse a name as defined by the Extension class in tablegen.
336std::optional<ExtensionInfo> parseArchExtension(StringRef Extension);
337
338// Parse a name as defined by the FMVInfo class in tablegen.
339std::optional<FMVInfo> parseFMVExtension(StringRef Extension);
340
341// Given the name of a CPU or alias, return the correponding CpuInfo.
342std::optional<CpuInfo> parseCpu(StringRef Name);
343// Used by target parser tests
345
346bool isX18ReservedByDefault(const Triple &TT);
347
348// For given feature names, return a bitmask corresponding to the entries of
349// AArch64::CPUFeatures. The values in CPUFeatures are not bitmasks
350// themselves, they are sequential (0, 1, 2, 3, ...).
352
354
355void printEnabledExtensions(const std::set<StringRef> &EnabledFeatureNames);
356
357} // namespace AArch64
358} // namespace llvm
359
360#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"))
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:586
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:693
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:564
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
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)
uint64_t getCpuSupportsMask(ArrayRef< StringRef > FeatureStrs)
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)
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)
FMVInfo(StringRef Name, CPUFeatures Bit, StringRef Features, unsigned Priority)
SmallVector< StringRef, 8 > getImpliedFeatures()