clang 23.0.0git
AArch64.h
Go to the documentation of this file.
1//===--- AArch64.h - Declare AArch64 target feature support -----*- 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 declares AArch64 TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H
15
16#include "OSTargets.h"
18#include "llvm/ADT/DenseSet.h"
19#include "llvm/TargetParser/AArch64TargetParser.h"
20#include <optional>
21
22namespace clang {
23namespace targets {
24
25enum AArch64AddrSpace { ptr32_sptr = 270, ptr32_uptr = 271, ptr64 = 272 };
26
27static const unsigned ARM64AddrSpaceMap[] = {
28 0, // Default
29 0, // opencl_global
30 0, // opencl_local
31 0, // opencl_constant
32 0, // opencl_private
33 0, // opencl_generic
34 0, // opencl_global_device
35 0, // opencl_global_host
36 0, // cuda_device
37 0, // cuda_constant
38 0, // cuda_shared
39 0, // sycl_global
40 0, // sycl_global_device
41 0, // sycl_global_host
42 0, // sycl_local
43 0, // sycl_private
44 static_cast<unsigned>(AArch64AddrSpace::ptr32_sptr),
45 static_cast<unsigned>(AArch64AddrSpace::ptr32_uptr),
46 static_cast<unsigned>(AArch64AddrSpace::ptr64),
47 0, // hlsl_groupshared
48 0, // hlsl_constant
49 0, // hlsl_private
50 0, // hlsl_device
51 0, // hlsl_input
52 0, // hlsl_output
53 0, // hlsl_push_constant
54 // Wasm address space values for this target are dummy values,
55 // as it is only enabled for Wasm targets.
56 20, // wasm_funcref
57};
58
59using AArch64FeatureSet = llvm::SmallDenseSet<StringRef, 32>;
60
61class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
62 static const TargetInfo::GCCRegAlias GCCRegAliases[];
63 static const char *const GCCRegNames[];
64
65 enum FPUModeEnum {
66 FPUMode = (1 << 0),
67 NeonMode = (1 << 1),
68 SveMode = (1 << 2),
69 };
70
71 unsigned FPU = FPUMode;
72 bool HasCRC = false;
73 bool HasCSSC = false;
74 bool HasAES = false;
75 bool HasSHA2 = false;
76 bool HasSHA3 = false;
77 bool HasSM4 = false;
78 bool HasFullFP16 = false;
79 bool HasDotProd = false;
80 bool HasFP16FML = false;
81 bool HasMTE = false;
82 bool HasPAuth = false;
83 bool HasLS64 = false;
84 bool HasRandGen = false;
85 bool HasMatMul = false;
86 bool HasBFloat16 = false;
87 bool HasSVE2 = false;
88 bool HasSVE2p1 = false;
89 bool HasSVEAES = false;
90 bool HasSVE2SHA3 = false;
91 bool HasSVE2SM4 = false;
92 bool HasSVEB16B16 = false;
93 bool HasSVEBitPerm = false;
94 bool HasMatmulFP64 = false;
95 bool HasMatmulFP32 = false;
96 bool HasLSE = false;
97 bool HasFlagM = false;
98 bool HasAlternativeNZCV = false;
99 bool HasMOPS = false;
100 bool HasD128 = false;
101 bool HasRCPC = false;
102 bool HasRDM = false;
103 bool HasDIT = false;
104 bool HasCCPP = false;
105 bool HasCCDP = false;
106 bool HasFRInt3264 = false;
107 bool HasSME = false;
108 bool HasSME2 = false;
109 bool HasSMEF64F64 = false;
110 bool HasSMEI16I64 = false;
111 bool HasSMEF16F16 = false;
112 bool HasSMEB16B16 = false;
113 bool HasSME2p1 = false;
114 bool HasFP8 = false;
115 bool HasFP8FMA = false;
116 bool HasFP8DOT2 = false;
117 bool HasFP8DOT4 = false;
118 bool HasSSVE_FP8DOT2 = false;
119 bool HasSSVE_FP8DOT4 = false;
120 bool HasSSVE_FP8FMA = false;
121 bool HasSME_F8F32 = false;
122 bool HasSME_F8F16 = false;
123 bool HasSB = false;
124 bool HasPredRes = false;
125 bool HasSSBS = false;
126 bool HasBTI = false;
127 bool HasWFxT = false;
128 bool HasJSCVT = false;
129 bool HasFCMA = false;
130 bool HasNoFP = false;
131 bool HasNoNeon = false;
132 bool HasNoSVE = false;
133 bool HasFMV = true;
134 bool HasGCS = false;
135 bool HasRCPC3 = false;
136 bool HasSMEFA64 = false;
137 bool HasPAuthLR = false;
138 bool HasFPRCVT = false;
139 bool HasF8F16MM = false;
140 bool HasF8F32MM = false;
141 bool HasSVE_F16F32MM = false;
142 bool HasSVE_BFSCALE = false;
143 bool HasSVE_AES2 = false;
144 bool HasSSVE_AES = false;
145 bool HasSVE2p2 = false;
146 bool HasSME2p2 = false;
147
148 const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
149
150 AArch64FeatureSet HasFeatureLookup;
151
152 void computeFeatureLookup();
153
154protected:
155 std::string ABI;
156
157public:
158 AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
159
160 StringRef getABI() const override;
161 bool setABI(const std::string &Name) override;
162
163 bool validateBranchProtection(StringRef Spec, StringRef Arch,
165 const LangOptions &LO,
166 StringRef &Err) const override;
167
168 bool isValidCPUName(StringRef Name) const override;
169 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
170 bool setCPU(const std::string &Name) override;
171
172 llvm::APInt getFMVPriority(ArrayRef<StringRef> Features) const override;
173
174 bool useFP16ConversionIntrinsics() const override {
175 return false;
176 }
177
178 void getTargetDefinesARMV81A(const LangOptions &Opts,
179 MacroBuilder &Builder) const;
180 void getTargetDefinesARMV82A(const LangOptions &Opts,
181 MacroBuilder &Builder) const;
182 void getTargetDefinesARMV83A(const LangOptions &Opts,
183 MacroBuilder &Builder) const;
184 void getTargetDefinesARMV84A(const LangOptions &Opts,
185 MacroBuilder &Builder) const;
186 void getTargetDefinesARMV85A(const LangOptions &Opts,
187 MacroBuilder &Builder) const;
188 void getTargetDefinesARMV86A(const LangOptions &Opts,
189 MacroBuilder &Builder) const;
190 void getTargetDefinesARMV87A(const LangOptions &Opts,
191 MacroBuilder &Builder) const;
192 void getTargetDefinesARMV88A(const LangOptions &Opts,
193 MacroBuilder &Builder) const;
194 void getTargetDefinesARMV89A(const LangOptions &Opts,
195 MacroBuilder &Builder) const;
196 void getTargetDefinesARMV9A(const LangOptions &Opts,
197 MacroBuilder &Builder) const;
198 void getTargetDefinesARMV91A(const LangOptions &Opts,
199 MacroBuilder &Builder) const;
200 void getTargetDefinesARMV92A(const LangOptions &Opts,
201 MacroBuilder &Builder) const;
202 void getTargetDefinesARMV93A(const LangOptions &Opts,
203 MacroBuilder &Builder) const;
204 void getTargetDefinesARMV94A(const LangOptions &Opts,
205 MacroBuilder &Builder) const;
206 void getTargetDefinesARMV95A(const LangOptions &Opts,
207 MacroBuilder &Builder) const;
208 void getTargetDefinesARMV96A(const LangOptions &Opts,
209 MacroBuilder &Builder) const;
210 void getTargetDefinesARMV97A(const LangOptions &Opts,
211 MacroBuilder &Builder) const;
212 void getTargetDefines(const LangOptions &Opts,
213 MacroBuilder &Builder) const override;
214
215 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
216
217 std::optional<std::pair<unsigned, unsigned>>
218 getVScaleRange(const LangOptions &LangOpts, ArmStreamingKind Mode,
219 llvm::StringMap<bool> *FeatureMap = nullptr) const override;
220 bool doesFeatureAffectCodeGen(StringRef Name) const override;
221 bool validateCpuSupports(StringRef FeatureStr) const override;
222 bool hasFeature(StringRef Feature) const override;
223 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
224 bool Enabled) const override;
225 bool handleTargetFeatures(std::vector<std::string> &Features,
226 DiagnosticsEngine &Diags) override;
227 ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
228 bool supportsTargetAttributeTune() const override { return true; }
229 bool supportsCpuSupports() const override { return true; }
230 bool checkArithmeticFenceSupported() const override { return true; }
231
232 bool hasBFloat16Type() const override;
233
234 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
235
236 bool isCLZForZeroUndef() const override;
237
238 BuiltinVaListKind getBuiltinVaListKind() const override;
239
240 ArrayRef<const char *> getGCCRegNames() const override;
241 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
242
243 std::string convertConstraint(const char *&Constraint) const override;
244
245 bool validateAsmConstraint(const char *&Name,
246 TargetInfo::ConstraintInfo &Info) const override;
247 bool
248 validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size,
249 std::string &SuggestedModifier) const override;
250 std::string_view getClobbers() const override;
251
252 StringRef getConstraintRegister(StringRef Constraint,
253 StringRef Expression) const override {
254 return Expression;
255 }
256
257 int getEHDataRegisterNumber(unsigned RegNo) const override;
258
259 bool validatePointerAuthKey(const llvm::APSInt &value) const override;
260
261 const char *getBFloat16Mangling() const override { return "u6__bf16"; };
262
263 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
264 return std::make_pair(256, 64);
265 }
266
267 bool hasInt128Type() const override;
268
269 bool hasBitIntType() const override { return true; }
270
271 bool validateTarget(DiagnosticsEngine &Diags) const override;
272
273 bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
274 bool &HasSizeMismatch) const override;
275
276 uint64_t getPointerWidthV(LangAS AddrSpace) const override {
277 if (AddrSpace == LangAS::ptr32_sptr || AddrSpace == LangAS::ptr32_uptr)
278 return 32;
279 if (AddrSpace == LangAS::ptr64)
280 return 64;
281 return PointerWidth;
282 }
283
284 uint64_t getPointerAlignV(LangAS AddrSpace) const override {
285 return getPointerWidthV(AddrSpace);
286 }
287};
288
289class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
290public:
291 AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
292
293 void getTargetDefines(const LangOptions &Opts,
294 MacroBuilder &Builder) const override;
295};
296
297template <>
298inline bool
300 if (Name == "pauthtest") {
301 ABI = Name;
302 return true;
303 }
304 return AArch64leTargetInfo::setABI(Name);
305}
306
307class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo
308 : public WindowsTargetInfo<AArch64leTargetInfo> {
309 const llvm::Triple Triple;
310
311public:
312 WindowsARM64TargetInfo(const llvm::Triple &Triple,
313 const TargetOptions &Opts);
314
316
318};
319
320// Windows ARM, MS (C++) ABI
321class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo
322 : public WindowsARM64TargetInfo {
323public:
324 MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
325 const TargetOptions &Opts);
326
327 void getTargetDefines(const LangOptions &Opts,
328 MacroBuilder &Builder) const override;
330 getCallingConvKind(bool ClangABICompat4) const override;
331
332 unsigned getMinGlobalAlign(uint64_t TypeSize,
333 bool HasNonWeakDef) const override;
334};
335
336// ARM64 MinGW target
337class LLVM_LIBRARY_VISIBILITY MinGWARM64TargetInfo
338 : public WindowsARM64TargetInfo {
339public:
340 MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
341};
342
343class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {
344public:
345 AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
346 void getTargetDefines(const LangOptions &Opts,
347 MacroBuilder &Builder) const override;
348};
349
350void getAppleMachOAArch64Defines(MacroBuilder &Builder, const LangOptions &Opts,
351 const llvm::Triple &Triple);
352
353class LLVM_LIBRARY_VISIBILITY AppleMachOAArch64TargetInfo
354 : public AppleMachOTargetInfo<AArch64leTargetInfo> {
355public:
356 AppleMachOAArch64TargetInfo(const llvm::Triple &Triple,
357 const TargetOptions &Opts);
358
359protected:
360 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
361 MacroBuilder &Builder) const override;
362};
363
364class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo
365 : public DarwinTargetInfo<AArch64leTargetInfo> {
366public:
367 DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
368
370
371 protected:
372 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
373 MacroBuilder &Builder) const override;
374};
375
376} // namespace targets
377} // namespace clang
378
379#endif // LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H
static llvm::APInt getFMVPriority(const TargetInfo &TI, const CodeGenFunction::FMVResolverOption &RO)
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition Module.cpp:114
Enumerates target-specific builtins in their own namespaces within namespace clang.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TargetInfo(const llvm::Triple &T)
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition TargetInfo.h:334
virtual bool setABI(const std::string &Name)
Use the specified ABI.
Options for controlling the target.
StringRef getConstraintRegister(StringRef Constraint, StringRef Expression) const override
Extracts a register from the passed constraint (if it is a single-register constraint) and the asm la...
Definition AArch64.h:252
bool useFP16ConversionIntrinsics() const override
Check whether conversions to and from __fp16 should go through an integer bitcast with i16.
Definition AArch64.h:174
std::pair< unsigned, unsigned > hardwareInterferenceSizes() const override
The first value in the pair is the minimum offset between two objects to avoid false sharing (destruc...
Definition AArch64.h:263
uint64_t getPointerWidthV(LangAS AddrSpace) const override
Definition AArch64.h:276
bool supportsTargetAttributeTune() const override
Determine whether this TargetInfo supports tune in target attribute.
Definition AArch64.h:228
AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:133
const char * getBFloat16Mangling() const override
Return the mangled code of bfloat.
Definition AArch64.h:261
bool checkArithmeticFenceSupported() const override
Controls if __arithmetic_fence is supported in the targeted backend.
Definition AArch64.h:230
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition AArch64.cpp:213
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition AArch64.cpp:284
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition AArch64.cpp:292
StringRef getABI() const override
Get the ABI currently in use.
Definition AArch64.cpp:211
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition AArch64.h:269
bool supportsCpuSupports() const override
Definition AArch64.h:229
bool validateBranchProtection(StringRef Spec, StringRef Arch, BranchProtectionInfo &BPI, const LangOptions &LO, StringRef &Err) const override
Determine if this TargetInfo supports the given branch protection specification.
Definition AArch64.cpp:252
uint64_t getPointerAlignV(LangAS AddrSpace) const override
Definition AArch64.h:284
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition AArch64.cpp:288
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition AArch64.cpp:1734
AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1730
AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1720
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition AArch64.cpp:1724
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition AArch64.cpp:1885
AppleMachOAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1838
AppleMachOTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition OSTargets.h:54
DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1842
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition AArch64.cpp:1893
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition AArch64.cpp:1901
DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition OSTargets.h:78
bool setABI(const std::string &Name) override
Definition OSTargets.h:415
unsigned getMinGlobalAlign(uint64_t TypeSize, bool HasNonWeakDef) const override
getMinGlobalAlign - Return the minimum alignment of a global variable, unless its alignment is explic...
Definition AArch64.cpp:1813
MicrosoftARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1790
TargetInfo::CallingConvKind getCallingConvKind(bool ClangABICompat4) const override
Definition AArch64.cpp:1809
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition AArch64.cpp:1796
MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1832
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition AArch64.cpp:1761
WindowsARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1742
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition AArch64.cpp:1766
WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition OSTargets.h:884
void getAppleMachOAArch64Defines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple)
Definition AArch64.cpp:1866
llvm::SmallDenseSet< StringRef, 32 > AArch64FeatureSet
Definition AArch64.h:59
static const unsigned ARM64AddrSpaceMap[]
Definition AArch64.h:27
The JSON file list parser is used to communicate input to InstallAPI.
LangAS
Defines the address space values used by the address space qualifier of QualType.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:278
Contains information gathered from parsing the contents of TargetAttr.
Definition TargetInfo.h:60