Debian Codegraph @

clang/lib/Basic/Targets/AArch64.h

raw
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"
17 #include "clang/Basic/TargetBuiltins.h"
18 #include "llvm/TargetParser/AArch64TargetParser.h"
19 #include <optional>
20
21 namespace clang {
22 namespace targets {
23
24 enum AArch64AddrSpace { ptr32_sptr = 270, ptr32_uptr = 271, ptr64 = 272 };
25
26 static const unsigned ARM64AddrSpaceMap[] = {
27 0, // Default
28 0, // opencl_global
29 0, // opencl_local
30 0, // opencl_constant
31 0, // opencl_private
32 0, // opencl_generic
33 0, // opencl_global_device
34 0, // opencl_global_host
35 0, // cuda_device
36 0, // cuda_constant
37 0, // cuda_shared
38 0, // sycl_global
39 0, // sycl_global_device
40 0, // sycl_global_host
41 0, // sycl_local
42 0, // sycl_private
43 static_cast<unsigned>(AArch64AddrSpace::ptr32_sptr),
44 static_cast<unsigned>(AArch64AddrSpace::ptr32_uptr),
45 static_cast<unsigned>(AArch64AddrSpace::ptr64),
46 0, // hlsl_groupshared
47 0, // hlsl_constant
48 0, // hlsl_private
49 0, // hlsl_device
50 0, // hlsl_input
51 0, // hlsl_push_constant
52 // Wasm address space values for this target are dummy values,
53 // as it is only enabled for Wasm targets.
54 20, // wasm_funcref
55 };
56
57 class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
58 static const TargetInfo::GCCRegAlias GCCRegAliases[];
59 static const char *const GCCRegNames[];
60
61 enum FPUModeEnum {
62 FPUMode = (1 << 0),
63 NeonMode = (1 << 1),
64 SveMode = (1 << 2),
65 };
66
67 unsigned FPU = FPUMode;
68 bool HasCRC = false;
69 bool HasCSSC = false;
70 bool HasAES = false;
71 bool HasSHA2 = false;
72 bool HasSHA3 = false;
73 bool HasSM4 = false;
74 bool HasFullFP16 = false;
75 bool HasDotProd = false;
76 bool HasFP16FML = false;
77 bool HasMTE = false;
78 bool HasPAuth = false;
79 bool HasLS64 = false;
80 bool HasRandGen = false;
81 bool HasMatMul = false;
82 bool HasBFloat16 = false;
83 bool HasSVE2 = false;
84 bool HasSVE2p1 = false;
85 bool HasSVEAES = false;
86 bool HasSVE2SHA3 = false;
87 bool HasSVE2SM4 = false;
88 bool HasSVEB16B16 = false;
89 bool HasSVEBitPerm = false;
90 bool HasMatmulFP64 = false;
91 bool HasMatmulFP32 = false;
92 bool HasLSE = false;
93 bool HasFlagM = false;
94 bool HasAlternativeNZCV = false;
95 bool HasMOPS = false;
96 bool HasD128 = false;
97 bool HasRCPC = false;
98 bool HasRDM = false;
99 bool HasDIT = false;
100 bool HasCCPP = false;
101 bool HasCCDP = false;
102 bool HasFRInt3264 = false;
103 bool HasSME = false;
104 bool HasSME2 = false;
105 bool HasSMEF64F64 = false;
106 bool HasSMEI16I64 = false;
107 bool HasSMEF16F16 = false;
108 bool HasSMEB16B16 = false;
109 bool HasSME2p1 = false;
110 bool HasFP8 = false;
111 bool HasFP8FMA = false;
112 bool HasFP8DOT2 = false;
113 bool HasFP8DOT4 = false;
114 bool HasSSVE_FP8DOT2 = false;
115 bool HasSSVE_FP8DOT4 = false;
116 bool HasSSVE_FP8FMA = false;
117 bool HasSME_F8F32 = false;
118 bool HasSME_F8F16 = false;
119 bool HasSB = false;
120 bool HasPredRes = false;
121 bool HasSSBS = false;
122 bool HasBTI = false;
123 bool HasWFxT = false;
124 bool HasJSCVT = false;
125 bool HasFCMA = false;
126 bool HasNoFP = false;
127 bool HasNoNeon = false;
128 bool HasNoSVE = false;
129 bool HasFMV = true;
130 bool HasGCS = false;
131 bool HasRCPC3 = false;
132 bool HasSMEFA64 = false;
133 bool HasPAuthLR = false;
134 bool HasFPRCVT = false;
135 bool HasF8F16MM = false;
136 bool HasF8F32MM = false;
137 bool HasSVE_F16F32MM = false;
138 bool HasSVE_BFSCALE = false;
139 bool HasSVE_AES2 = false;
140 bool HasSSVE_AES = false;
141 bool HasSVE2p2 = false;
142 bool HasSME2p2 = false;
143
144 const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
145
146 protected:
147 std::string ABI;
148
149 public:
150 AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
151
152 StringRef getABI() const override;
153 bool setABI(const std::string &Name) override;
154
155 bool validateBranchProtection(StringRef Spec, StringRef Arch,
156 BranchProtectionInfo &BPI,
157 const LangOptions &LO,
158 StringRef &Err) const override;
159
160 bool isValidCPUName(StringRef Name) const override;
161 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
162 bool setCPU(const std::string &Name) override;
163
164 llvm::APInt getFMVPriority(ArrayRef<StringRef> Features) const override;
165
166 bool useFP16ConversionIntrinsics() const override {
167 return false;
168 }
169
170 void getTargetDefinesARMV81A(const LangOptions &Opts,
171 MacroBuilder &Builder) const;
172 void getTargetDefinesARMV82A(const LangOptions &Opts,
173 MacroBuilder &Builder) const;
174 void getTargetDefinesARMV83A(const LangOptions &Opts,
175 MacroBuilder &Builder) const;
176 void getTargetDefinesARMV84A(const LangOptions &Opts,
177 MacroBuilder &Builder) const;
178 void getTargetDefinesARMV85A(const LangOptions &Opts,
179 MacroBuilder &Builder) const;
180 void getTargetDefinesARMV86A(const LangOptions &Opts,
181 MacroBuilder &Builder) const;
182 void getTargetDefinesARMV87A(const LangOptions &Opts,
183 MacroBuilder &Builder) const;
184 void getTargetDefinesARMV88A(const LangOptions &Opts,
185 MacroBuilder &Builder) const;
186 void getTargetDefinesARMV89A(const LangOptions &Opts,
187 MacroBuilder &Builder) const;
188 void getTargetDefinesARMV9A(const LangOptions &Opts,
189 MacroBuilder &Builder) const;
190 void getTargetDefinesARMV91A(const LangOptions &Opts,
191 MacroBuilder &Builder) const;
192 void getTargetDefinesARMV92A(const LangOptions &Opts,
193 MacroBuilder &Builder) const;
194 void getTargetDefinesARMV93A(const LangOptions &Opts,
195 MacroBuilder &Builder) const;
196 void getTargetDefinesARMV94A(const LangOptions &Opts,
197 MacroBuilder &Builder) const;
198 void getTargetDefinesARMV95A(const LangOptions &Opts,
199 MacroBuilder &Builder) const;
200 void getTargetDefinesARMV96A(const LangOptions &Opts,
201 MacroBuilder &Builder) const;
202 void getTargetDefinesARMV97A(const LangOptions &Opts,
203 MacroBuilder &Builder) const;
204 void getTargetDefines(const LangOptions &Opts,
205 MacroBuilder &Builder) const override;
206
207 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
208
209 std::optional<std::pair<unsigned, unsigned>>
210 getVScaleRange(const LangOptions &LangOpts, ArmStreamingKind Mode,
211 llvm::StringMap<bool> *FeatureMap = nullptr) const override;
212 bool doesFeatureAffectCodeGen(StringRef Name) const override;
213 bool validateCpuSupports(StringRef FeatureStr) const override;
214 bool hasFeature(StringRef Feature) const override;
215 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
216 bool Enabled) const override;
217 bool handleTargetFeatures(std::vector<std::string> &Features,
218 DiagnosticsEngine &Diags) override;
219 ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
220 bool supportsTargetAttributeTune() const override { return true; }
221 bool supportsCpuSupports() const override { return true; }
222 bool checkArithmeticFenceSupported() const override { return true; }
223
224 bool hasBFloat16Type() const override;
225
226 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
227
228 bool isCLZForZeroUndef() const override;
229
230 BuiltinVaListKind getBuiltinVaListKind() const override;
231
232 ArrayRef<const char *> getGCCRegNames() const override;
233 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
234
235 std::string convertConstraint(const char *&Constraint) const override;
236
237 bool validateAsmConstraint(const char *&Name,
238 TargetInfo::ConstraintInfo &Info) const override;
239 bool
240 validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size,
241 std::string &SuggestedModifier) const override;
242 std::string_view getClobbers() const override;
243
244 StringRef getConstraintRegister(StringRef Constraint,
245 StringRef Expression) const override {
246 return Expression;
247 }
248
249 int getEHDataRegisterNumber(unsigned RegNo) const override;
250
251 bool validatePointerAuthKey(const llvm::APSInt &value) const override;
252
253 const char *getBFloat16Mangling() const override { return "u6__bf16"; };
254
255 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
256 return std::make_pair(256, 64);
257 }
258
259 bool hasInt128Type() const override;
260
261 bool hasBitIntType() const override { return true; }
262
263 bool validateTarget(DiagnosticsEngine &Diags) const override;
264
265 bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
266 bool &HasSizeMismatch) const override;
267
268 uint64_t getPointerWidthV(LangAS AddrSpace) const override {
269 if (AddrSpace == LangAS::ptr32_sptr || AddrSpace == LangAS::ptr32_uptr)
270 return 32;
271 if (AddrSpace == LangAS::ptr64)
272 return 64;
273 return PointerWidth;
274 }
275
276 uint64_t getPointerAlignV(LangAS AddrSpace) const override {
277 return getPointerWidthV(AddrSpace);
278 }
279 };
280
281 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
282 public:
283 AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
284
285 void getTargetDefines(const LangOptions &Opts,
286 MacroBuilder &Builder) const override;
287 };
288
289 template <>
290 inline bool
291 LinuxTargetInfo<AArch64leTargetInfo>::setABI(const std::string &Name) {
292 if (Name == "pauthtest") {
293 ABI = Name;
294 return true;
295 }
296 return AArch64leTargetInfo::setABI(Name);
297 }
298
299 class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo
300 : public WindowsTargetInfo<AArch64leTargetInfo> {
301 const llvm::Triple Triple;
302
303 public:
304 WindowsARM64TargetInfo(const llvm::Triple &Triple,
305 const TargetOptions &Opts);
306
307 BuiltinVaListKind getBuiltinVaListKind() const override;
308
309 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
310 };
311
312 // Windows ARM, MS (C++) ABI
313 class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo
314 : public WindowsARM64TargetInfo {
315 public:
316 MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
317 const TargetOptions &Opts);
318
319 void getTargetDefines(const LangOptions &Opts,
320 MacroBuilder &Builder) const override;
321 TargetInfo::CallingConvKind
322 getCallingConvKind(bool ClangABICompat4) const override;
323
324 unsigned getMinGlobalAlign(uint64_t TypeSize,
325 bool HasNonWeakDef) const override;
326 };
327
328 // ARM64 MinGW target
329 class LLVM_LIBRARY_VISIBILITY MinGWARM64TargetInfo
330 : public WindowsARM64TargetInfo {
331 public:
332 MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
333 };
334
335 class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {
336 public:
337 AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
338 void getTargetDefines(const LangOptions &Opts,
339 MacroBuilder &Builder) const override;
340 };
341
342 void getAppleMachOAArch64Defines(MacroBuilder &Builder, const LangOptions &Opts,
343 const llvm::Triple &Triple);
344
345 class LLVM_LIBRARY_VISIBILITY AppleMachOAArch64TargetInfo
346 : public AppleMachOTargetInfo<AArch64leTargetInfo> {
347 public:
348 AppleMachOAArch64TargetInfo(const llvm::Triple &Triple,
349 const TargetOptions &Opts);
350
351 protected:
352 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
353 MacroBuilder &Builder) const override;
354 };
355
356 class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo
357 : public DarwinTargetInfo<AArch64leTargetInfo> {
358 public:
359 DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
360
361 BuiltinVaListKind getBuiltinVaListKind() const override;
362
363 protected:
364 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
365 MacroBuilder &Builder) const override;
366 };
367
368 } // namespace targets
369 } // namespace clang
370
371 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H