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