LLVM 22.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"
26#include <set>
27#include <vector>
29namespace llvm {
31class Triple;
33namespace AArch64 {
35struct ArchInfo;
36struct CpuInfo;
41static_assert(FEAT_MAX < 62,
42 "Number of features in CPUFeatures are limited to 62 entries");
44static_assert(PRIOR_MAX < 120, "FeatPriorities is limited to 120 entries");
46// Each ArchExtKind correponds directly to a possible -target-feature.
47#define EMIT_ARCHEXTKIND_ENUM
48#include "llvm/TargetParser/AArch64TargetParserDef.inc"
52// Represents an extension that can be enabled with -march=<arch>+<extension>.
53// Typically these correspond to Arm Architecture extensions, unlike
54// SubtargetFeature which may represent either an actual extension or some
55// internal LLVM property.
57 StringRef UserVisibleName; // Human readable name used in -march, -cpu
58 // and target func attribute, e.g. "profile".
59 std::optional<StringRef> Alias; // An alias for this extension, if one exists.
60 ArchExtKind ID; // Corresponding to the ArchExtKind, this
61 // extensions representation in the bitfield.
62 StringRef ArchFeatureName; // The feature name defined by the
63 // Architecture, e.g. FEAT_AdvSIMD.
64 StringRef Description; // The textual description of the extension.
65 StringRef PosTargetFeature; // -target-feature/-mattr enable string,
66 // e.g. "+spe".
67 StringRef NegTargetFeature; // -target-feature/-mattr disable string,
68 // e.g. "-spe".
69};
71#define EMIT_EXTENSIONS
72#include "llvm/TargetParser/AArch64TargetParserDef.inc"
74struct FMVInfo {
75 StringRef Name; // The target_version/target_clones spelling.
76 std::optional<CPUFeatures>
77 FeatureBit; // Index of the bit in the FMV feature bitset.
78 FeatPriorities PriorityBit; // Index of the bit in the FMV priority bitset.
79 std::optional<ArchExtKind> ID; // The architecture extension to enable.
80 FMVInfo(StringRef Name, std::optional<CPUFeatures> FeatureBit,
81 FeatPriorities PriorityBit, std::optional<ArchExtKind> ID)
83};
85LLVM_ABI const std::vector<FMVInfo> &getFMVInfo();
87// Represents a dependency between two architecture extensions. Later is the
88// feature which was added to the architecture after Earlier, and expands the
89// functionality provided by it. If Later is enabled, then Earlier will also be
90// enabled. If Earlier is disabled, then Later will also be disabled.
92 ArchExtKind Earlier;
93 ArchExtKind Later;
94};
95
96#define EMIT_EXTENSION_DEPENDENCIES
97#include "llvm/TargetParser/AArch64TargetParserDef.inc"
98
99enum ArchProfile { AProfile = 'A', RProfile = 'R', InvalidProfile = '?' };
100
101// Information about a specific architecture, e.g. V8.1-A
102struct ArchInfo {
103 VersionTuple Version; // Architecture version, major + minor.
104 ArchProfile Profile; // Architecuture profile
105 StringRef Name; // Name as supplied to -march e.g. "armv8.1-a"
106 StringRef ArchFeature; // Name as supplied to -target-feature, e.g. "+v8a"
108 DefaultExts; // bitfield of default extensions ArchExtKind
109
110 bool operator==(const ArchInfo &Other) const {
111 return this->Name == Other.Name;
112 }
113 bool operator!=(const ArchInfo &Other) const {
114 return this->Name != Other.Name;
115 }
116
117 // Defines the following partial order, indicating when an architecture is
118 // a superset of another:
119 //
120 // v9.7a > v9.6a > v9.5a > v9.4a > v9.3a > v9.2a > v9.1a > v9a;
121 // v v v v v
122 // v8.9a > v8.8a > v8.7a > v8.6a > v8.5a > ... > v8a;
123 //
124 // v8r has no relation to anything. This is used to determine which
125 // features to enable for a given architecture. See
126 // AArch64TargetInfo::setFeatureEnabled.
127 bool implies(const ArchInfo &Other) const {
128 if (this->Profile != Other.Profile)
129 return false; // ARMV8R
130 if (this->Version.getMajor() == Other.Version.getMajor()) {
131 return this->Version > Other.Version;
132 }
133 if (this->Version.getMajor() == 9 && Other.Version.getMajor() == 8) {
134 assert(this->Version.getMinor() && Other.Version.getMinor() &&
135 "AArch64::ArchInfo should have a minor version.");
136 return this->Version.getMinor().value_or(0) + 5 >=
137 Other.Version.getMinor().value_or(0);
138 }
139 return false;
140 }
141
142 // True if this architecture is a superset of Other (including being equal to
143 // it).
144 bool is_superset(const ArchInfo &Other) const {
145 return (*this == Other) || implies(Other);
146 }
147
148 // Return ArchFeature without the leading "+".
149 StringRef getSubArch() const { return ArchFeature.substr(1); }
150
151 // Search for ArchInfo by SubArch name
152 LLVM_ABI static std::optional<ArchInfo> findBySubArch(StringRef SubArch);
153};
154
155#define EMIT_ARCHITECTURES
156#include "llvm/TargetParser/AArch64TargetParserDef.inc"
157
158// Details of a specific CPU.
159struct CpuInfo {
160 StringRef Name; // Name, as written for -mcpu.
163 DefaultExtensions; // Default extensions for this CPU.
164
168};
169
170#define EMIT_CPU_INFO
171#include "llvm/TargetParser/AArch64TargetParserDef.inc"
172
174 // Set of extensions which are currently enabled.
176 // Set of extensions which have been enabled or disabled at any point. Used
177 // to avoid cluttering the cc1 command-line with lots of unneeded features.
179 // Base architecture version, which we need to know because some feature
180 // dependencies change depending on this.
182
183 ExtensionSet() : Enabled(), Touched(), BaseArch(nullptr) {}
184
185 // Enable the given architecture extension, and any other extensions it
186 // depends on. Does not change the base architecture, or follow dependencies
187 // between features which are only related by required arcitecture versions.
188 LLVM_ABI void enable(ArchExtKind E);
189
190 // Disable the given architecture extension, and any other extensions which
191 // depend on it. Does not change the base architecture, or follow
192 // dependencies between features which are only related by required
193 // arcitecture versions.
194 LLVM_ABI void disable(ArchExtKind E);
195
196 // Add default extensions for the given CPU. Records the base architecture,
197 // to later resolve dependencies which depend on it.
198 LLVM_ABI void addCPUDefaults(const CpuInfo &CPU);
199
200 // Add default extensions for the given architecture version. Records the
201 // base architecture, to later resolve dependencies which depend on it.
202 LLVM_ABI void addArchDefaults(const ArchInfo &Arch);
203
204 // Add or remove a feature based on a modifier string. The string must be of
205 // the form "<name>" to enable a feature or "no<name>" to disable it. This
206 // will also enable or disable any features as required by the dependencies
207 // between them.
208 LLVM_ABI bool parseModifier(StringRef Modifier,
209 const bool AllowNoDashForm = false);
210
211 // Constructs a new ExtensionSet by toggling the corresponding bits for every
212 // feature in the \p Features list without expanding their dependencies. Used
213 // for reconstructing an ExtensionSet from the output of toLLVMFeatures().
214 // Features that are not recognized are pushed back to \p NonExtensions.
215 LLVM_ABI void
216 reconstructFromParsedFeatures(const std::vector<std::string> &Features,
217 std::vector<std::string> &NonExtensions);
218
219 // Convert the set of enabled extension to an LLVM feature list, appending
220 // them to Features.
221 template <typename T> void toLLVMFeatureList(std::vector<T> &Features) const {
222 if (BaseArch && !BaseArch->ArchFeature.empty())
223 Features.emplace_back(T(BaseArch->ArchFeature));
224
225 for (const auto &E : Extensions) {
226 if (E.PosTargetFeature.empty() || !Touched.test(E.ID))
227 continue;
228 if (Enabled.test(E.ID))
229 Features.emplace_back(T(E.PosTargetFeature));
230 else
231 Features.emplace_back(T(E.NegTargetFeature));
232 }
233 }
234
235 LLVM_ABI void dump() const;
236};
237
238// Name alias.
243
244#define EMIT_CPU_ALIAS
245#include "llvm/TargetParser/AArch64TargetParserDef.inc"
246
247LLVM_ABI const ExtensionInfo &getExtensionByID(ArchExtKind(ExtID));
248
250 std::vector<StringRef> &Features);
251
254
255// Information by Name
257
258// Parser
260
261// Return the extension which has the given -target-feature name.
262LLVM_ABI std::optional<ExtensionInfo>
264
265// Parse a name as defined by the Extension class in tablegen.
266LLVM_ABI std::optional<ExtensionInfo> parseArchExtension(StringRef Extension);
267
268// Parse a name as defined by the FMVInfo class in tablegen.
269LLVM_ABI std::optional<FMVInfo> parseFMVExtension(StringRef Extension);
270
271// Given the name of a CPU or alias, return the correponding CpuInfo.
272LLVM_ABI std::optional<CpuInfo> parseCpu(StringRef Name);
273// Used by target parser tests
275
277
278// For a given set of feature names, which can be either target-features, or
279// fmv-features metadata, expand their dependencies and then return a bitmask
280// corresponding to the entries of AArch64::FeatPriorities.
282
283// For a given set of FMV feature names, expand their dependencies and then
284// return a bitmask corresponding to the entries of AArch64::CPUFeatures.
285// The values in CPUFeatures are not bitmasks themselves, they are sequential
286// (0, 1, 2, 3, ...). The resulting bitmask is used at runtime to test whether
287// a certain FMV feature is available on the host.
289
291
292LLVM_ABI void
293printEnabledExtensions(const std::set<StringRef> &EnabledFeatureNames);
294
295} // namespace AArch64
296} // namespace llvm
297
298#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:213
#define T
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[....
Class for arbitrary precision integers.
Definition APInt.h:78
ArrayRef - 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...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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.
@ Other
Any other memory.
Definition ModRef.h:68
bool is_superset(const ArchInfo &Other) const
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 getImpliedExtensions() const
AArch64::ExtensionBitset DefaultExtensions
std::optional< StringRef > Alias
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