clang 22.0.0git
AArch64.cpp
Go to the documentation of this file.
1//===--- AArch64.cpp - Implement AArch64 target feature support -----------===//
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 AArch64 TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#include "AArch64.h"
18#include "llvm/ADT/APSInt.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringSwitch.h"
21#include "llvm/TargetParser/AArch64TargetParser.h"
22#include "llvm/TargetParser/ARMTargetParserCommon.h"
23#include <optional>
24
25using namespace clang;
26using namespace clang::targets;
27
28static constexpr int NumNeonBuiltins =
30static constexpr int NumFp16Builtins =
32static constexpr int NumSVEBuiltins =
34static constexpr int NumSVENeonBridgeBuiltins =
37static constexpr int NumAArch64Builtins =
39static constexpr int NumBuiltins =
41static_assert(NumBuiltins ==
44
45namespace clang {
46namespace NEON {
47#define GET_NEON_BUILTIN_STR_TABLE
48#include "clang/Basic/arm_neon.inc"
49#undef GET_NEON_BUILTIN_STR_TABLE
50
51static constexpr std::array<Builtin::Info, NumNeonBuiltins> BuiltinInfos = {
52#define GET_NEON_BUILTIN_INFOS
53#include "clang/Basic/arm_neon.inc"
54#undef GET_NEON_BUILTIN_INFOS
55};
56
57namespace FP16 {
58#define GET_NEON_BUILTIN_STR_TABLE
59#include "clang/Basic/arm_fp16.inc"
60#undef GET_NEON_BUILTIN_STR_TABLE
61
62static constexpr std::array<Builtin::Info, NumFp16Builtins> BuiltinInfos = {
63#define GET_NEON_BUILTIN_INFOS
64#include "clang/Basic/arm_fp16.inc"
65#undef GET_NEON_BUILTIN_INFOS
66};
67} // namespace FP16
68} // namespace NEON
69
70namespace SVE {
71#define GET_SVE_BUILTIN_STR_TABLE
72#include "clang/Basic/arm_sve_builtins.inc"
73#undef GET_SVE_BUILTIN_STR_TABLE
74
75static constexpr std::array<Builtin::Info, NumSVEBuiltins> BuiltinInfos = {
76#define GET_SVE_BUILTIN_INFOS
77#include "clang/Basic/arm_sve_builtins.inc"
78#undef GET_SVE_BUILTIN_INFOS
79};
80} // namespace SVE
81
82namespace SME {
83#define GET_SME_BUILTIN_STR_TABLE
84#include "clang/Basic/arm_sme_builtins.inc"
85#undef GET_SME_BUILTIN_STR_TABLE
86
87static constexpr std::array<Builtin::Info, NumSMEBuiltins> BuiltinInfos = {
88#define GET_SME_BUILTIN_INFOS
89#include "clang/Basic/arm_sme_builtins.inc"
90#undef GET_SME_BUILTIN_INFOS
91};
92} // namespace SME
93} // namespace clang
94
95static constexpr llvm::StringTable BuiltinSVENeonBridgeStrings =
97#define TARGET_BUILTIN CLANG_TARGET_BUILTIN_STR_TABLE
98#define GET_SVE_BUILTINS
99#include "clang/Basic/BuiltinsAArch64NeonSVEBridge.def"
100#undef GET_SVE_BUILTINS
101#undef TARGET_BUILTIN
102 ;
103static constexpr llvm::StringTable BuiltinAArch64Strings =
105#define BUILTIN CLANG_BUILTIN_STR_TABLE
106#define TARGET_BUILTIN CLANG_TARGET_BUILTIN_STR_TABLE
107#define TARGET_HEADER_BUILTIN CLANG_TARGET_HEADER_BUILTIN_STR_TABLE
108#include "clang/Basic/BuiltinsAArch64.def"
109 ;
110
111static constexpr auto BuiltinSVENeonBridgeInfos =
113#define TARGET_BUILTIN CLANG_TARGET_BUILTIN_ENTRY
114#define GET_SVE_BUILTINS
115#include "clang/Basic/BuiltinsAArch64NeonSVEBridge.def"
116#undef GET_SVE_BUILTINS
117#undef TARGET_BUILTIN
118 });
119static constexpr auto BuiltinAArch64Infos =
121#define BUILTIN CLANG_BUILTIN_ENTRY
122#define TARGET_BUILTIN CLANG_TARGET_BUILTIN_ENTRY
123#define LANGBUILTIN CLANG_LANGBUILTIN_ENTRY
124#define TARGET_HEADER_BUILTIN CLANG_TARGET_HEADER_BUILTIN_ENTRY
125#include "clang/Basic/BuiltinsAArch64.def"
126 });
127
128AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
129 const TargetOptions &Opts)
130 : TargetInfo(Triple), ABI("aapcs") {
131 if (getTriple().isOSOpenBSD()) {
134 } else {
135 if (!getTriple().isOSDarwin() && !getTriple().isOSNetBSD())
137
140 }
141
143
144 // All AArch64 implementations support ARMv8 FP, which makes half a legal type.
145 HasFastHalfType = true;
146 HalfArgsAndReturns = true;
147 HasFloat16 = true;
148 HasStrictFP = true;
149
150 if (Triple.isArch64Bit())
152 else
154
155 BitIntMaxAlign = 128;
156 MaxVectorAlign = 128;
159
161 LongDoubleFormat = &llvm::APFloat::IEEEquad();
162
164 BFloat16Format = &llvm::APFloat::BFloat();
165
166 // Make __builtin_ms_va_list available.
167 HasBuiltinMSVaList = true;
168
169 // Make the Neon ACLE and SVE types available. Note that this deliberately
170 // doesn't depend on SveMode, since in principle it should be possible to turn
171 // SVE on and off within a translation unit. It should also be possible
172 // to compile the global declaration:
173 //
174 // __SVInt8_t *ptr;
175 //
176 // even without SVE.
177 HasAArch64ACLETypes = true;
178
179 // {} in inline assembly are neon specifiers, not assembly variant
180 // specifiers.
181 NoAsmVariants = true;
182
183 // AAPCS gives rules for bitfields. 7.1.7 says: "The container type
184 // contributes to the alignment of the containing aggregate in the same way
185 // a plain (non bit-field) member of that type would, without exception for
186 // zero-sized or anonymous bit-fields."
187 assert(UseBitFieldTypeAlignment && "bitfields affect type alignment");
189
190 // AAPCS64 allows any "fundamental integer data type" to be used for
191 // over-sized bitfields, which includes 128-bit integers.
193
194 HasUnalignedAccess = true;
195
196 // AArch64 targets default to using the ARM C++ ABI.
197 TheCXXABI.set(TargetCXXABI::GenericAArch64);
198
199 if (Triple.getOS() == llvm::Triple::Linux)
200 this->MCountName = "\01_mcount";
201 else if (Triple.getOS() == llvm::Triple::UnknownOS)
202 this->MCountName =
203 Opts.EABIVersion == llvm::EABI::GNU ? "\01_mcount" : "mcount";
204}
205
206StringRef AArch64TargetInfo::getABI() const { return ABI; }
207
208bool AArch64TargetInfo::setABI(const std::string &Name) {
209 if (Name != "aapcs" && Name != "aapcs-soft" && Name != "darwinpcs")
210 return false;
211
212 ABI = Name;
213 return true;
214}
215
217 if (hasFeature("fp") && ABI == "aapcs-soft") {
218 // aapcs-soft is not allowed for targets with an FPU, to avoid there being
219 // two incomatible ABIs.
220 Diags.Report(diag::err_target_unsupported_abi_with_fpu) << ABI;
221 return false;
222 }
223 return true;
224}
225
227 StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const {
228 if (RegName == "sp") {
229 HasSizeMismatch = RegSize != 64;
230 return true;
231 }
232 if (RegName.starts_with("w"))
233 HasSizeMismatch = RegSize != 32;
234 else if (RegName.starts_with("x"))
235 HasSizeMismatch = RegSize != 64;
236 else
237 return false;
238 StringRef RegNum = RegName.drop_front();
239 // Check if the register is reserved. See also
240 // AArch64TargetLowering::getRegisterByName().
241 return RegNum == "0" ||
242 (RegNum == "18" &&
243 llvm::AArch64::isX18ReservedByDefault(getTriple())) ||
244 getTargetOpts().FeatureMap.lookup(("reserve-x" + RegNum).str());
245}
246
247bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
249 const LangOptions &LO,
250 StringRef &Err) const {
251 llvm::ARM::ParsedBranchProtection PBP;
252 if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err, HasPAuthLR))
253 return false;
254
255 // GCS is currently untested with ptrauth-returns, but enabling this could be
256 // allowed in future after testing with a suitable system.
257 if (LO.PointerAuthReturns &&
258 (PBP.Scope != "none" || PBP.BranchProtectionPAuthLR ||
259 PBP.GuardedControlStack))
260 return false;
261
262 BPI.SignReturnAddr =
263 llvm::StringSwitch<LangOptions::SignReturnAddressScopeKind>(PBP.Scope)
267
268 if (PBP.Key == "a_key")
270 else
272
273 BPI.BranchTargetEnforcement = PBP.BranchTargetEnforcement;
274 BPI.BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
275 BPI.GuardedControlStack = PBP.GuardedControlStack;
276 return true;
277}
278
279bool AArch64TargetInfo::isValidCPUName(StringRef Name) const {
280 return llvm::AArch64::parseCpu(Name).has_value();
281}
282
283bool AArch64TargetInfo::setCPU(const std::string &Name) {
284 return isValidCPUName(Name);
285}
286
288 SmallVectorImpl<StringRef> &Values) const {
289 llvm::AArch64::fillValidCPUArchList(Values);
290}
291
293 MacroBuilder &Builder) const {
294 Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
295}
296
298 MacroBuilder &Builder) const {
299 // Also include the ARMv8.1 defines
300 getTargetDefinesARMV81A(Opts, Builder);
301}
302
304 MacroBuilder &Builder) const {
305 Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
306 Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
307 // Also include the Armv8.2 defines
308 getTargetDefinesARMV82A(Opts, Builder);
309}
310
312 MacroBuilder &Builder) const {
313 // Also include the Armv8.3 defines
314 getTargetDefinesARMV83A(Opts, Builder);
315}
316
318 MacroBuilder &Builder) const {
319 Builder.defineMacro("__ARM_FEATURE_FRINT", "1");
320 // Also include the Armv8.4 defines
321 getTargetDefinesARMV84A(Opts, Builder);
322}
323
325 MacroBuilder &Builder) const {
326 // Also include the Armv8.5 defines
327 // FIXME: Armv8.6 makes the following extensions mandatory:
328 // - __ARM_FEATURE_BF16
329 // - __ARM_FEATURE_MATMUL_INT8
330 // Handle them here.
331 getTargetDefinesARMV85A(Opts, Builder);
332}
333
335 MacroBuilder &Builder) const {
336 // Also include the Armv8.6 defines
337 getTargetDefinesARMV86A(Opts, Builder);
338}
339
341 MacroBuilder &Builder) const {
342 // Also include the Armv8.7 defines
343 getTargetDefinesARMV87A(Opts, Builder);
344}
345
347 MacroBuilder &Builder) const {
348 // Also include the Armv8.8 defines
349 getTargetDefinesARMV88A(Opts, Builder);
350}
351
353 MacroBuilder &Builder) const {
354 // Armv9-A maps to Armv8.5-A
355 getTargetDefinesARMV85A(Opts, Builder);
356}
357
359 MacroBuilder &Builder) const {
360 // Armv9.1-A maps to Armv8.6-A
361 getTargetDefinesARMV86A(Opts, Builder);
362}
363
365 MacroBuilder &Builder) const {
366 // Armv9.2-A maps to Armv8.7-A
367 getTargetDefinesARMV87A(Opts, Builder);
368}
369
371 MacroBuilder &Builder) const {
372 // Armv9.3-A maps to Armv8.8-A
373 getTargetDefinesARMV88A(Opts, Builder);
374}
375
377 MacroBuilder &Builder) const {
378 // Armv9.4-A maps to Armv8.9-A
379 getTargetDefinesARMV89A(Opts, Builder);
380}
381
383 MacroBuilder &Builder) const {
384 // Armv9.5-A does not have a v8.* equivalent, but is a superset of v9.4-A.
385 getTargetDefinesARMV94A(Opts, Builder);
386}
387
389 MacroBuilder &Builder) const {
390 // Armv9.6-A does not have a v8.* equivalent, but is a superset of v9.5-A.
391 getTargetDefinesARMV95A(Opts, Builder);
392}
393
395 MacroBuilder &Builder) const {
396 // Armv9.7-A does not have a v8.* equivalent, but is a superset of v9.6-A.
397 getTargetDefinesARMV96A(Opts, Builder);
398}
399
401 MacroBuilder &Builder) const {
402 // Target identification.
403 if (getTriple().isWindowsArm64EC()) {
404 // Define the same set of macros as would be defined on x86_64 to ensure that
405 // ARM64EC datatype layouts match those of x86_64 compiled code
406 Builder.defineMacro("__amd64__");
407 Builder.defineMacro("__amd64");
408 Builder.defineMacro("__x86_64");
409 Builder.defineMacro("__x86_64__");
410 Builder.defineMacro("__arm64ec__");
411 } else {
412 Builder.defineMacro("__aarch64__");
413 }
414
415 // Inline assembly supports AArch64 flag outputs.
416 Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
417
418 std::string CodeModel = getTargetOpts().CodeModel;
419 if (CodeModel == "default")
420 CodeModel = "small";
421 for (char &c : CodeModel)
422 c = toupper(c);
423 Builder.defineMacro("__AARCH64_CMODEL_" + CodeModel + "__");
424
425 // ACLE predefines. Many can only have one possible value on v8 AArch64.
426 Builder.defineMacro("__ARM_ACLE_VERSION(year, quarter, patch)",
427 "(100 * (year) + 10 * (quarter) + (patch))");
428#define ARM_ACLE_VERSION(Y, Q, P) (100 * (Y) + 10 * (Q) + (P))
429 Builder.defineMacro("__ARM_ACLE", Twine(ARM_ACLE_VERSION(2024, 2, 0)));
430 Builder.defineMacro("__FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL",
431 Twine(ARM_ACLE_VERSION(2024, 3, 0)));
432#undef ARM_ACLE_VERSION
433 Builder.defineMacro("__ARM_ARCH",
434 std::to_string(ArchInfo->Version.getMajor()));
435 Builder.defineMacro("__ARM_ARCH_PROFILE",
436 std::string("'") + (char)ArchInfo->Profile + "'");
437
438 Builder.defineMacro("__ARM_64BIT_STATE", "1");
439 Builder.defineMacro("__ARM_PCS_AAPCS64", "1");
440 Builder.defineMacro("__ARM_ARCH_ISA_A64", "1");
441
442 Builder.defineMacro("__ARM_FEATURE_CLZ", "1");
443 Builder.defineMacro("__ARM_FEATURE_FMA", "1");
444 Builder.defineMacro("__ARM_FEATURE_LDREX", "0xF");
445 Builder.defineMacro("__ARM_FEATURE_IDIV", "1"); // As specified in ACLE
446 Builder.defineMacro("__ARM_FEATURE_DIV"); // For backwards compatibility
447 Builder.defineMacro("__ARM_FEATURE_NUMERIC_MAXMIN", "1");
448 Builder.defineMacro("__ARM_FEATURE_DIRECTED_ROUNDING", "1");
449
450 Builder.defineMacro("__ARM_ALIGN_MAX_STACK_PWR", "4");
451
452 // These macros are set when Clang can parse declarations with these
453 // attributes.
454 Builder.defineMacro("__ARM_STATE_ZA", "1");
455 Builder.defineMacro("__ARM_STATE_ZT0", "1");
456
457 // 0xe implies support for half, single and double precision operations.
458 if (FPU & FPUMode)
459 Builder.defineMacro("__ARM_FP", "0xE");
460
461 // PCS specifies this for SysV variants, which is all we support. Other ABIs
462 // may choose __ARM_FP16_FORMAT_ALTERNATIVE.
463 Builder.defineMacro("__ARM_FP16_FORMAT_IEEE", "1");
464 Builder.defineMacro("__ARM_FP16_ARGS", "1");
465
466 // Clang supports arm_neon_sve_bridge.h
467 Builder.defineMacro("__ARM_NEON_SVE_BRIDGE", "1");
468
469 if (Opts.UnsafeFPMath)
470 Builder.defineMacro("__ARM_FP_FAST", "1");
471
472 Builder.defineMacro("__ARM_SIZEOF_WCHAR_T",
473 Twine(Opts.WCharSize ? Opts.WCharSize : 4));
474
475 Builder.defineMacro("__ARM_SIZEOF_MINIMAL_ENUM", Opts.ShortEnums ? "1" : "4");
476
477 if (FPU & NeonMode) {
478 Builder.defineMacro("__ARM_NEON", "1");
479 // 64-bit NEON supports half, single and double precision operations.
480 Builder.defineMacro("__ARM_NEON_FP", "0xE");
481 }
482
483 if (FPU & SveMode)
484 Builder.defineMacro("__ARM_FEATURE_SVE", "1");
485
486 if (HasSVE2)
487 Builder.defineMacro("__ARM_FEATURE_SVE2", "1");
488
489 if (HasSVE2p1)
490 Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
491
492 if (HasSVE2 && HasSVEAES)
493 Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
494
495 if (HasSVE2 && HasSVEBitPerm)
496 Builder.defineMacro("__ARM_FEATURE_SVE2_BITPERM", "1");
497
498 if (HasSVE2 && HasSVE2SHA3)
499 Builder.defineMacro("__ARM_FEATURE_SVE2_SHA3", "1");
500
501 if (HasSVE2 && HasSVE2SM4)
502 Builder.defineMacro("__ARM_FEATURE_SVE2_SM4", "1");
503
504 if (HasSVEB16B16)
505 Builder.defineMacro("__ARM_FEATURE_SVE_B16B16", "1");
506
507 if (HasSME) {
508 Builder.defineMacro("__ARM_FEATURE_SME");
509 Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
510 }
511
512 if (HasSME2)
513 Builder.defineMacro("__ARM_FEATURE_SME2", "1");
514
515 if (HasSME2p1)
516 Builder.defineMacro("__ARM_FEATURE_SME2p1", "1");
517
518 if (HasSMEF16F16)
519 Builder.defineMacro("__ARM_FEATURE_SME_F16F16", "1");
520
521 if (HasSMEB16B16)
522 Builder.defineMacro("__ARM_FEATURE_SME_B16B16", "1");
523
524 if (HasFP8)
525 Builder.defineMacro("__ARM_FEATURE_FP8", "1");
526
527 if (HasFP8FMA)
528 Builder.defineMacro("__ARM_FEATURE_FP8FMA", "1");
529
530 if (HasFP8DOT2)
531 Builder.defineMacro("__ARM_FEATURE_FP8DOT2", "1");
532
533 if (HasFP8DOT4)
534 Builder.defineMacro("__ARM_FEATURE_FP8DOT4", "1");
535
536 if (HasSSVE_FP8DOT2)
537 Builder.defineMacro("__ARM_FEATURE_SSVE_FP8DOT2", "1");
538
539 if (HasSSVE_FP8DOT4)
540 Builder.defineMacro("__ARM_FEATURE_SSVE_FP8DOT4", "1");
541
542 if (HasSSVE_FP8FMA)
543 Builder.defineMacro("__ARM_FEATURE_SSVE_FP8FMA", "1");
544
545 if (HasSME_F8F32)
546 Builder.defineMacro("__ARM_FEATURE_SME_F8F32", "1");
547
548 if (HasSME_F8F16)
549 Builder.defineMacro("__ARM_FEATURE_SME_F8F16", "1");
550
551 if (HasCRC)
552 Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
553
554 if (HasCSSC)
555 Builder.defineMacro("__ARM_FEATURE_CSSC", "1");
556
557 if (HasRCPC3)
558 Builder.defineMacro("__ARM_FEATURE_RCPC", "3");
559 else if (HasRCPC)
560 Builder.defineMacro("__ARM_FEATURE_RCPC", "1");
561
562 if (HasFMV)
563 Builder.defineMacro("__HAVE_FUNCTION_MULTI_VERSIONING", "1");
564
565 // The __ARM_FEATURE_CRYPTO is deprecated in favor of finer grained feature
566 // macros for AES, SHA2, SHA3 and SM4
567 if (HasAES && HasSHA2)
568 Builder.defineMacro("__ARM_FEATURE_CRYPTO", "1");
569
570 if (HasAES)
571 Builder.defineMacro("__ARM_FEATURE_AES", "1");
572
573 if (HasSHA2)
574 Builder.defineMacro("__ARM_FEATURE_SHA2", "1");
575
576 if (HasSHA3) {
577 Builder.defineMacro("__ARM_FEATURE_SHA3", "1");
578 Builder.defineMacro("__ARM_FEATURE_SHA512", "1");
579 }
580
581 if (HasSM4) {
582 Builder.defineMacro("__ARM_FEATURE_SM3", "1");
583 Builder.defineMacro("__ARM_FEATURE_SM4", "1");
584 }
585
586 if (HasPAuth)
587 Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
588
589 if (HasPAuthLR)
590 Builder.defineMacro("__ARM_FEATURE_PAUTH_LR", "1");
591
592 if (HasBTI)
593 Builder.defineMacro("__ARM_FEATURE_BTI", "1");
594
596 Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
597
598 if ((FPU & NeonMode) && HasFullFP16)
599 Builder.defineMacro("__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", "1");
600 if (HasFullFP16)
601 Builder.defineMacro("__ARM_FEATURE_FP16_SCALAR_ARITHMETIC", "1");
602
603 if (HasDotProd)
604 Builder.defineMacro("__ARM_FEATURE_DOTPROD", "1");
605
606 if (HasMTE)
607 Builder.defineMacro("__ARM_FEATURE_MEMORY_TAGGING", "1");
608
609 if (HasTME)
610 Builder.defineMacro("__ARM_FEATURE_TME", "1");
611
612 if (HasMatMul)
613 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
614
615 if (HasLSE)
616 Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
617
618 if (HasBFloat16) {
619 Builder.defineMacro("__ARM_FEATURE_BF16", "1");
620 Builder.defineMacro("__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", "1");
621 Builder.defineMacro("__ARM_BF16_FORMAT_ALTERNATIVE", "1");
622 Builder.defineMacro("__ARM_FEATURE_BF16_SCALAR_ARITHMETIC", "1");
623 }
624
625 if ((FPU & SveMode) && HasBFloat16) {
626 Builder.defineMacro("__ARM_FEATURE_SVE_BF16", "1");
627 }
628
629 if ((FPU & SveMode) && HasMatmulFP64)
630 Builder.defineMacro("__ARM_FEATURE_SVE_MATMUL_FP64", "1");
631
632 if ((FPU & SveMode) && HasMatmulFP32)
633 Builder.defineMacro("__ARM_FEATURE_SVE_MATMUL_FP32", "1");
634
635 if ((FPU & SveMode) && HasMatMul)
636 Builder.defineMacro("__ARM_FEATURE_SVE_MATMUL_INT8", "1");
637
638 if ((FPU & NeonMode) && HasFP16FML)
639 Builder.defineMacro("__ARM_FEATURE_FP16_FML", "1");
640
641 if (Opts.hasSignReturnAddress()) {
642 // Bitmask:
643 // 0: Protection using the A key
644 // 1: Protection using the B key
645 // 2: Protection including leaf functions
646 // 3: Protection using PC as a diversifier
647 unsigned Value = 0;
648
650 Value |= (1 << 0);
651 else
652 Value |= (1 << 1);
653
655 Value |= (1 << 2);
656
657 if (Opts.BranchProtectionPAuthLR)
658 Value |= (1 << 3);
659
660 Builder.defineMacro("__ARM_FEATURE_PAC_DEFAULT", std::to_string(Value));
661 }
662
663 if (Opts.BranchTargetEnforcement)
664 Builder.defineMacro("__ARM_FEATURE_BTI_DEFAULT", "1");
665
666 if (Opts.GuardedControlStack)
667 Builder.defineMacro("__ARM_FEATURE_GCS_DEFAULT", "1");
668
669 if (HasLS64)
670 Builder.defineMacro("__ARM_FEATURE_LS64", "1");
671
672 if (HasRandGen)
673 Builder.defineMacro("__ARM_FEATURE_RNG", "1");
674
675 if (HasMOPS)
676 Builder.defineMacro("__ARM_FEATURE_MOPS", "1");
677
678 if (HasD128)
679 Builder.defineMacro("__ARM_FEATURE_SYSREG128", "1");
680
681 if (HasGCS)
682 Builder.defineMacro("__ARM_FEATURE_GCS", "1");
683
684 if (*ArchInfo == llvm::AArch64::ARMV8_1A)
685 getTargetDefinesARMV81A(Opts, Builder);
686 else if (*ArchInfo == llvm::AArch64::ARMV8_2A)
687 getTargetDefinesARMV82A(Opts, Builder);
688 else if (*ArchInfo == llvm::AArch64::ARMV8_3A)
689 getTargetDefinesARMV83A(Opts, Builder);
690 else if (*ArchInfo == llvm::AArch64::ARMV8_4A)
691 getTargetDefinesARMV84A(Opts, Builder);
692 else if (*ArchInfo == llvm::AArch64::ARMV8_5A)
693 getTargetDefinesARMV85A(Opts, Builder);
694 else if (*ArchInfo == llvm::AArch64::ARMV8_6A)
695 getTargetDefinesARMV86A(Opts, Builder);
696 else if (*ArchInfo == llvm::AArch64::ARMV8_7A)
697 getTargetDefinesARMV87A(Opts, Builder);
698 else if (*ArchInfo == llvm::AArch64::ARMV8_8A)
699 getTargetDefinesARMV88A(Opts, Builder);
700 else if (*ArchInfo == llvm::AArch64::ARMV8_9A)
701 getTargetDefinesARMV89A(Opts, Builder);
702 else if (*ArchInfo == llvm::AArch64::ARMV9A)
703 getTargetDefinesARMV9A(Opts, Builder);
704 else if (*ArchInfo == llvm::AArch64::ARMV9_1A)
705 getTargetDefinesARMV91A(Opts, Builder);
706 else if (*ArchInfo == llvm::AArch64::ARMV9_2A)
707 getTargetDefinesARMV92A(Opts, Builder);
708 else if (*ArchInfo == llvm::AArch64::ARMV9_3A)
709 getTargetDefinesARMV93A(Opts, Builder);
710 else if (*ArchInfo == llvm::AArch64::ARMV9_4A)
711 getTargetDefinesARMV94A(Opts, Builder);
712 else if (*ArchInfo == llvm::AArch64::ARMV9_5A)
713 getTargetDefinesARMV95A(Opts, Builder);
714 else if (*ArchInfo == llvm::AArch64::ARMV9_6A)
715 getTargetDefinesARMV96A(Opts, Builder);
716 else if (*ArchInfo == llvm::AArch64::ARMV9_7A)
717 getTargetDefinesARMV97A(Opts, Builder);
718
719 // All of the __sync_(bool|val)_compare_and_swap_(1|2|4|8|16) builtins work.
720 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
721 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
722 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
723 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
724 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
725
726 // Allow detection of fast FMA support.
727 Builder.defineMacro("__FP_FAST_FMA", "1");
728 Builder.defineMacro("__FP_FAST_FMAF", "1");
729
730 // C/C++ operators work on both VLS and VLA SVE types
731 if (FPU & SveMode)
732 Builder.defineMacro("__ARM_FEATURE_SVE_VECTOR_OPERATORS", "2");
733
734 if (Opts.VScaleMin && Opts.VScaleMin == Opts.VScaleMax) {
735 Builder.defineMacro("__ARM_FEATURE_SVE_BITS", Twine(Opts.VScaleMin * 128));
736 }
737}
738
741 return {
742 {&NEON::BuiltinStrings, NEON::BuiltinInfos, "__builtin_neon_"},
743 {&NEON::FP16::BuiltinStrings, NEON::FP16::BuiltinInfos,
744 "__builtin_neon_"},
745 {&SVE::BuiltinStrings, SVE::BuiltinInfos, "__builtin_sve_"},
747 {&SME::BuiltinStrings, SME::BuiltinInfos, "__builtin_sme_"},
749 };
750}
751
752std::optional<std::pair<unsigned, unsigned>>
754 ArmStreamingKind Mode,
755 llvm::StringMap<bool> *FeatureMap) const {
756 if (Mode == ArmStreamingKind::NotStreaming &&
757 (LangOpts.VScaleMin || LangOpts.VScaleMax))
758 return std::pair<unsigned, unsigned>(
759 LangOpts.VScaleMin ? LangOpts.VScaleMin : 1,
760 LangOpts.VScaleMax ? LangOpts.VScaleMax : 16);
761
762 if (Mode == ArmStreamingKind::Streaming &&
763 (LangOpts.VScaleStreamingMin || LangOpts.VScaleStreamingMax))
764 return std::pair<unsigned, unsigned>(
765 LangOpts.VScaleStreamingMin ? LangOpts.VScaleStreamingMin : 1,
766 LangOpts.VScaleStreamingMax ? LangOpts.VScaleStreamingMax : 16);
767
769 ((LangOpts.VScaleMin && LangOpts.VScaleStreamingMin) ||
770 (LangOpts.VScaleMax && LangOpts.VScaleStreamingMax))) {
771 unsigned Min =
772 std::min(LangOpts.VScaleMin ? LangOpts.VScaleMin : 1,
773 LangOpts.VScaleStreamingMin ? LangOpts.VScaleStreamingMin : 1);
774 unsigned Max = std::max(
775 LangOpts.VScaleMax ? LangOpts.VScaleMax : 16,
776 LangOpts.VScaleStreamingMax ? LangOpts.VScaleStreamingMax : 16);
777 return std::pair(Min, Max);
778 }
779
780 if (hasFeature("sve") || (FeatureMap && (FeatureMap->lookup("sve"))))
781 return std::pair<unsigned, unsigned>(1, 16);
782
783 if (Mode == ArmStreamingKind::Streaming &&
784 (hasFeature("sme") || (FeatureMap && (FeatureMap->lookup("sme")))))
785 return std::pair<unsigned, unsigned>(1, 16);
786
787 return std::nullopt;
788}
789
790llvm::APInt
792 return llvm::AArch64::getFMVPriority(Features);
793}
794
796 // FMV extensions which imply no backend features do not affect codegen.
797 if (auto Ext = llvm::AArch64::parseFMVExtension(Name))
798 return Ext->ID.has_value();
799 return false;
800}
801
802bool AArch64TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
803 // CPU features might be separated by '+', extract them and check
805 FeatureStr.split(Features, "+");
806 for (auto &Feature : Features)
807 if (!llvm::AArch64::parseFMVExtension(Feature.trim()).has_value())
808 return false;
809 return true;
810}
811
813 return llvm::StringSwitch<bool>(Feature)
814 .Cases({"aarch64", "arm64", "arm"}, true)
815 .Case("fmv", HasFMV)
816 .Case("fp", FPU & FPUMode)
817 .Cases({"neon", "simd"}, FPU & NeonMode)
818 .Case("jscvt", HasJSCVT)
819 .Case("fcma", HasFCMA)
820 .Case("rng", HasRandGen)
821 .Case("flagm", HasFlagM)
822 .Case("flagm2", HasAlternativeNZCV)
823 .Case("fp16fml", HasFP16FML)
824 .Case("dotprod", HasDotProd)
825 .Case("sm4", HasSM4)
826 .Case("rdm", HasRDM)
827 .Case("lse", HasLSE)
828 .Case("crc", HasCRC)
829 .Case("cssc", HasCSSC)
830 .Case("sha2", HasSHA2)
831 .Case("sha3", HasSHA3)
832 .Cases({"aes", "pmull"}, HasAES)
833 .Cases({"fp16", "fullfp16"}, HasFullFP16)
834 .Case("dit", HasDIT)
835 .Case("dpb", HasCCPP)
836 .Case("dpb2", HasCCDP)
837 .Case("rcpc", HasRCPC)
838 .Case("frintts", HasFRInt3264)
839 .Case("i8mm", HasMatMul)
840 .Case("bf16", HasBFloat16)
841 .Case("sve", FPU & SveMode)
842 .Case("sve-b16b16", HasSVEB16B16)
843 .Case("f32mm", FPU & SveMode && HasMatmulFP32)
844 .Case("f64mm", FPU & SveMode && HasMatmulFP64)
845 .Case("sve2", FPU & SveMode && HasSVE2)
846 .Case("sve-aes", HasSVEAES)
847 .Case("sve-bitperm", FPU & HasSVEBitPerm)
848 .Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
849 .Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
850 .Case("sve2p1", FPU & SveMode && HasSVE2p1)
851 .Case("sme", HasSME)
852 .Case("sme2", HasSME2)
853 .Case("sme2p1", HasSME2p1)
854 .Case("sme-f64f64", HasSMEF64F64)
855 .Case("sme-i16i64", HasSMEI16I64)
856 .Case("sme-fa64", HasSMEFA64)
857 .Case("sme-f16f16", HasSMEF16F16)
858 .Case("sme-b16b16", HasSMEB16B16)
859 .Case("memtag", HasMTE)
860 .Case("sb", HasSB)
861 .Case("predres", HasPredRes)
862 .Cases({"ssbs", "ssbs2"}, HasSSBS)
863 .Case("bti", HasBTI)
864 .Cases({"ls64", "ls64_v", "ls64_accdata"}, HasLS64)
865 .Case("wfxt", HasWFxT)
866 .Case("rcpc3", HasRCPC3)
867 .Case("fp8", HasFP8)
868 .Case("fp8fma", HasFP8FMA)
869 .Case("fp8dot2", HasFP8DOT2)
870 .Case("fp8dot4", HasFP8DOT4)
871 .Case("ssve-fp8dot2", HasSSVE_FP8DOT2)
872 .Case("ssve-fp8dot4", HasSSVE_FP8DOT4)
873 .Case("ssve-fp8fma", HasSSVE_FP8FMA)
874 .Case("sme-f8f32", HasSME_F8F32)
875 .Case("sme-f8f16", HasSME_F8F16)
876 .Default(false);
877}
878
879void AArch64TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
880 StringRef Name, bool Enabled) const {
881 Features[Name] = Enabled;
882 // If the feature is an architecture feature (like v8.2a), add all previous
883 // architecture versions and any dependant target features.
884 const std::optional<llvm::AArch64::ArchInfo> ArchInfo =
885 llvm::AArch64::ArchInfo::findBySubArch(Name);
886
887 if (!ArchInfo)
888 return; // Not an architecture, nothing more to do.
889
890 // Disabling an architecture feature does not affect dependent features
891 if (!Enabled)
892 return;
893
894 for (const auto *OtherArch : llvm::AArch64::ArchInfos)
895 if (ArchInfo->implies(*OtherArch))
896 Features[OtherArch->getSubArch()] = true;
897
898 // Set any features implied by the architecture
899 std::vector<StringRef> CPUFeats;
900 if (llvm::AArch64::getExtensionFeatures(ArchInfo->DefaultExts, CPUFeats)) {
901 for (auto F : CPUFeats) {
902 assert(F[0] == '+' && "Expected + in target feature!");
903 Features[F.drop_front(1)] = true;
904 }
905 }
906}
907
908bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
909 DiagnosticsEngine &Diags) {
910 for (const auto &Feature : Features) {
911 if (Feature == "-fp-armv8")
912 HasNoFP = true;
913 if (Feature == "-neon")
914 HasNoNeon = true;
915 if (Feature == "-sve")
916 HasNoSVE = true;
917
918 if (Feature == "+neon" || Feature == "+fp-armv8")
919 FPU |= NeonMode;
920 if (Feature == "+jscvt") {
921 HasJSCVT = true;
922 FPU |= NeonMode;
923 }
924 if (Feature == "+fcma") {
925 HasFCMA = true;
926 FPU |= NeonMode;
927 }
928
929 if (Feature == "+sve") {
930 FPU |= NeonMode;
931 FPU |= SveMode;
932 HasFullFP16 = true;
933 }
934 if (Feature == "+sve2") {
935 FPU |= NeonMode;
936 FPU |= SveMode;
937 HasFullFP16 = true;
938 HasSVE2 = true;
939 }
940 if (Feature == "+sve2p1") {
941 FPU |= NeonMode;
942 FPU |= SveMode;
943 HasFullFP16 = true;
944 HasSVE2 = true;
945 HasSVE2p1 = true;
946 }
947 if (Feature == "+sve-aes") {
948 FPU |= NeonMode;
949 HasFullFP16 = true;
950 HasSVEAES = true;
951 }
952 if (Feature == "+sve2-sha3") {
953 FPU |= NeonMode;
954 FPU |= SveMode;
955 HasFullFP16 = true;
956 HasSVE2 = true;
957 HasSVE2SHA3 = true;
958 }
959 if (Feature == "+sve2-sm4") {
960 FPU |= NeonMode;
961 FPU |= SveMode;
962 HasFullFP16 = true;
963 HasSVE2 = true;
964 HasSVE2SM4 = true;
965 }
966 if (Feature == "+sve-b16b16")
967 HasSVEB16B16 = true;
968 if (Feature == "+sve-bitperm") {
969 FPU |= NeonMode;
970 HasFullFP16 = true;
971 HasSVEBitPerm = true;
972 }
973 if (Feature == "+f32mm") {
974 FPU |= NeonMode;
975 FPU |= SveMode;
976 HasFullFP16 = true;
977 HasMatmulFP32 = true;
978 }
979 if (Feature == "+f64mm") {
980 FPU |= NeonMode;
981 FPU |= SveMode;
982 HasFullFP16 = true;
983 HasMatmulFP64 = true;
984 }
985 if (Feature == "+sme") {
986 HasSME = true;
987 HasBFloat16 = true;
988 HasFullFP16 = true;
989 }
990 if (Feature == "+sme2") {
991 HasSME = true;
992 HasSME2 = true;
993 HasBFloat16 = true;
994 HasFullFP16 = true;
995 }
996 if (Feature == "+sme2p1") {
997 HasSME = true;
998 HasSME2 = true;
999 HasSME2p1 = true;
1000 HasBFloat16 = true;
1001 HasFullFP16 = true;
1002 }
1003 if (Feature == "+sme-f64f64") {
1004 HasSME = true;
1005 HasSMEF64F64 = true;
1006 HasBFloat16 = true;
1007 HasFullFP16 = true;
1008 }
1009 if (Feature == "+sme-i16i64") {
1010 HasSME = true;
1011 HasSMEI16I64 = true;
1012 HasBFloat16 = true;
1013 HasFullFP16 = true;
1014 }
1015 if (Feature == "+sme-fa64") {
1016 FPU |= NeonMode;
1017 FPU |= SveMode;
1018 HasSME = true;
1019 HasSVE2 = true;
1020 HasSMEFA64 = true;
1021 }
1022 if (Feature == "+sme-f16f16") {
1023 HasSME = true;
1024 HasSME2 = true;
1025 HasBFloat16 = true;
1026 HasFullFP16 = true;
1027 HasSMEF16F16 = true;
1028 }
1029 if (Feature == "+sme-b16b16") {
1030 HasSME = true;
1031 HasSME2 = true;
1032 HasBFloat16 = true;
1033 HasFullFP16 = true;
1034 HasSVEB16B16 = true;
1035 HasSMEB16B16 = true;
1036 }
1037
1038 if (Feature == "+fp8")
1039 HasFP8 = true;
1040 if (Feature == "+fp8fma")
1041 HasFP8FMA = true;
1042 if (Feature == "+fp8dot2")
1043 HasFP8DOT2 = true;
1044 if (Feature == "+fp8dot4")
1045 HasFP8DOT4 = true;
1046 if (Feature == "+ssve-fp8dot2")
1047 HasSSVE_FP8DOT2 = true;
1048 if (Feature == "+ssve-fp8dot4")
1049 HasSSVE_FP8DOT4 = true;
1050 if (Feature == "+ssve-fp8fma")
1051 HasSSVE_FP8FMA = true;
1052 if (Feature == "+sme-f8f32")
1053 HasSME_F8F32 = true;
1054 if (Feature == "+sme-f8f16")
1055 HasSME_F8F16 = true;
1056 if (Feature == "+sb")
1057 HasSB = true;
1058 if (Feature == "+predres")
1059 HasPredRes = true;
1060 if (Feature == "+ssbs")
1061 HasSSBS = true;
1062 if (Feature == "+bti")
1063 HasBTI = true;
1064 if (Feature == "+wfxt")
1065 HasWFxT = true;
1066 if (Feature == "-fmv")
1067 HasFMV = false;
1068 if (Feature == "+crc")
1069 HasCRC = true;
1070 if (Feature == "+rcpc")
1071 HasRCPC = true;
1072 if (Feature == "+aes") {
1073 FPU |= NeonMode;
1074 HasAES = true;
1075 }
1076 if (Feature == "+sha2") {
1077 FPU |= NeonMode;
1078 HasSHA2 = true;
1079 }
1080 if (Feature == "+sha3") {
1081 FPU |= NeonMode;
1082 HasSHA2 = true;
1083 HasSHA3 = true;
1084 }
1085 if (Feature == "+rdm") {
1086 FPU |= NeonMode;
1087 HasRDM = true;
1088 }
1089 if (Feature == "+dit")
1090 HasDIT = true;
1091 if (Feature == "+cccp")
1092 HasCCPP = true;
1093 if (Feature == "+ccdp") {
1094 HasCCPP = true;
1095 HasCCDP = true;
1096 }
1097 if (Feature == "+fptoint")
1098 HasFRInt3264 = true;
1099 if (Feature == "+sm4") {
1100 FPU |= NeonMode;
1101 HasSM4 = true;
1102 }
1103 if (Feature == "+strict-align")
1104 HasUnalignedAccess = false;
1105
1106 // All predecessor archs are added but select the latest one for ArchKind.
1107 if (Feature == "+v8a" && ArchInfo->Version < llvm::AArch64::ARMV8A.Version)
1108 ArchInfo = &llvm::AArch64::ARMV8A;
1109 if (Feature == "+v8.1a" &&
1110 ArchInfo->Version < llvm::AArch64::ARMV8_1A.Version)
1111 ArchInfo = &llvm::AArch64::ARMV8_1A;
1112 if (Feature == "+v8.2a" &&
1113 ArchInfo->Version < llvm::AArch64::ARMV8_2A.Version)
1114 ArchInfo = &llvm::AArch64::ARMV8_2A;
1115 if (Feature == "+v8.3a" &&
1116 ArchInfo->Version < llvm::AArch64::ARMV8_3A.Version)
1117 ArchInfo = &llvm::AArch64::ARMV8_3A;
1118 if (Feature == "+v8.4a" &&
1119 ArchInfo->Version < llvm::AArch64::ARMV8_4A.Version)
1120 ArchInfo = &llvm::AArch64::ARMV8_4A;
1121 if (Feature == "+v8.5a" &&
1122 ArchInfo->Version < llvm::AArch64::ARMV8_5A.Version)
1123 ArchInfo = &llvm::AArch64::ARMV8_5A;
1124 if (Feature == "+v8.6a" &&
1125 ArchInfo->Version < llvm::AArch64::ARMV8_6A.Version)
1126 ArchInfo = &llvm::AArch64::ARMV8_6A;
1127 if (Feature == "+v8.7a" &&
1128 ArchInfo->Version < llvm::AArch64::ARMV8_7A.Version)
1129 ArchInfo = &llvm::AArch64::ARMV8_7A;
1130 if (Feature == "+v8.8a" &&
1131 ArchInfo->Version < llvm::AArch64::ARMV8_8A.Version)
1132 ArchInfo = &llvm::AArch64::ARMV8_8A;
1133 if (Feature == "+v8.9a" &&
1134 ArchInfo->Version < llvm::AArch64::ARMV8_9A.Version)
1135 ArchInfo = &llvm::AArch64::ARMV8_9A;
1136 if (Feature == "+v9a" && ArchInfo->Version < llvm::AArch64::ARMV9A.Version)
1137 ArchInfo = &llvm::AArch64::ARMV9A;
1138 if (Feature == "+v9.1a" &&
1139 ArchInfo->Version < llvm::AArch64::ARMV9_1A.Version)
1140 ArchInfo = &llvm::AArch64::ARMV9_1A;
1141 if (Feature == "+v9.2a" &&
1142 ArchInfo->Version < llvm::AArch64::ARMV9_2A.Version)
1143 ArchInfo = &llvm::AArch64::ARMV9_2A;
1144 if (Feature == "+v9.3a" &&
1145 ArchInfo->Version < llvm::AArch64::ARMV9_3A.Version)
1146 ArchInfo = &llvm::AArch64::ARMV9_3A;
1147 if (Feature == "+v9.4a" &&
1148 ArchInfo->Version < llvm::AArch64::ARMV9_4A.Version)
1149 ArchInfo = &llvm::AArch64::ARMV9_4A;
1150 if (Feature == "+v9.5a" &&
1151 ArchInfo->Version < llvm::AArch64::ARMV9_5A.Version)
1152 ArchInfo = &llvm::AArch64::ARMV9_5A;
1153 if (Feature == "+v9.6a" &&
1154 ArchInfo->Version < llvm::AArch64::ARMV9_6A.Version)
1155 ArchInfo = &llvm::AArch64::ARMV9_6A;
1156 if (Feature == "+v9.7a" &&
1157 ArchInfo->Version < llvm::AArch64::ARMV9_7A.Version)
1158 ArchInfo = &llvm::AArch64::ARMV9_7A;
1159 if (Feature == "+v8r")
1160 ArchInfo = &llvm::AArch64::ARMV8R;
1161 if (Feature == "+fullfp16") {
1162 FPU |= NeonMode;
1163 HasFullFP16 = true;
1164 }
1165 if (Feature == "+dotprod") {
1166 FPU |= NeonMode;
1167 HasDotProd = true;
1168 }
1169 if (Feature == "+fp16fml") {
1170 FPU |= NeonMode;
1171 HasFullFP16 = true;
1172 HasFP16FML = true;
1173 }
1174 if (Feature == "+mte")
1175 HasMTE = true;
1176 if (Feature == "+tme")
1177 HasTME = true;
1178 if (Feature == "+pauth")
1179 HasPAuth = true;
1180 if (Feature == "+i8mm")
1181 HasMatMul = true;
1182 if (Feature == "+bf16")
1183 HasBFloat16 = true;
1184 if (Feature == "+lse")
1185 HasLSE = true;
1186 if (Feature == "+ls64")
1187 HasLS64 = true;
1188 if (Feature == "+rand")
1189 HasRandGen = true;
1190 if (Feature == "+flagm")
1191 HasFlagM = true;
1192 if (Feature == "+altnzcv") {
1193 HasFlagM = true;
1194 HasAlternativeNZCV = true;
1195 }
1196 if (Feature == "+mops")
1197 HasMOPS = true;
1198 if (Feature == "+d128")
1199 HasD128 = true;
1200 if (Feature == "+gcs")
1201 HasGCS = true;
1202 if (Feature == "+rcpc3")
1203 HasRCPC3 = true;
1204 if (Feature == "+pauth-lr") {
1205 HasPAuthLR = true;
1206 HasPAuth = true;
1207 }
1208 if (Feature == "+cssc")
1209 HasCSSC = true;
1210 }
1211
1212 // Check features that are manually disabled by command line options.
1213 // This needs to be checked after architecture-related features are handled,
1214 // making sure they are properly disabled when required.
1215 for (const auto &Feature : Features) {
1216 if (Feature == "-d128")
1217 HasD128 = false;
1218 }
1219
1220 setDataLayout();
1221
1222 if (HasNoFP) {
1223 FPU &= ~FPUMode;
1224 FPU &= ~NeonMode;
1225 FPU &= ~SveMode;
1226 }
1227 if (HasNoNeon) {
1228 FPU &= ~NeonMode;
1229 FPU &= ~SveMode;
1230 }
1231 if (HasNoSVE)
1232 FPU &= ~SveMode;
1233
1234 return true;
1235}
1236
1237// Parse AArch64 Target attributes, which are a comma separated list of:
1238// "arch=<arch>" - parsed to features as per -march=..
1239// "cpu=<cpu>" - parsed to features as per -mcpu=.., with CPU set to <cpu>
1240// "tune=<cpu>" - TuneCPU set to <cpu>
1241// "feature", "no-feature" - Add (or remove) feature.
1242// "+feature", "+nofeature" - Add (or remove) feature.
1243//
1244// A feature may correspond to an Extension (anything with a corresponding
1245// AEK_), in which case an ExtensionSet is used to parse it and expand its
1246// dependencies. If the feature does not yield a successful parse then it
1247// is passed through.
1249 ParsedTargetAttr Ret;
1250 if (Features == "default")
1251 return Ret;
1252 SmallVector<StringRef, 1> AttrFeatures;
1253 Features.split(AttrFeatures, ",");
1254 bool FoundArch = false;
1255
1256 auto SplitAndAddFeatures = [](StringRef FeatString,
1257 std::vector<std::string> &Features,
1258 llvm::AArch64::ExtensionSet &FeatureBits) {
1259 SmallVector<StringRef, 8> SplitFeatures;
1260 FeatString.split(SplitFeatures, StringRef("+"), -1, false);
1261 for (StringRef Feature : SplitFeatures) {
1262 if (FeatureBits.parseModifier(Feature))
1263 continue;
1264 // Pass through anything that failed to parse so that we can emit
1265 // diagnostics, as well as valid internal feature names.
1266 //
1267 // FIXME: We should consider rejecting internal feature names like
1268 // neon, v8a, etc.
1269 // FIXME: We should consider emitting diagnostics here.
1270 if (Feature.starts_with("no"))
1271 Features.push_back("-" + Feature.drop_front(2).str());
1272 else
1273 Features.push_back("+" + Feature.str());
1274 }
1275 };
1276
1277 llvm::AArch64::ExtensionSet FeatureBits;
1278 // Reconstruct the bitset from the command line option features.
1279 FeatureBits.reconstructFromParsedFeatures(getTargetOpts().FeaturesAsWritten,
1280 Ret.Features);
1281
1282 for (auto &Feature : AttrFeatures) {
1283 Feature = Feature.trim();
1284 if (Feature.starts_with("fpmath="))
1285 continue;
1286
1287 if (Feature.starts_with("branch-protection=")) {
1288 Ret.BranchProtection = Feature.split('=').second.trim();
1289 continue;
1290 }
1291
1292 if (Feature.starts_with("arch=")) {
1293 if (FoundArch)
1294 Ret.Duplicate = "arch=";
1295 FoundArch = true;
1296 std::pair<StringRef, StringRef> Split =
1297 Feature.split("=").second.trim().split("+");
1298 const llvm::AArch64::ArchInfo *AI = llvm::AArch64::parseArch(Split.first);
1299
1300 // Parse the architecture version, adding the required features to
1301 // Ret.Features.
1302 if (!AI)
1303 continue;
1304 FeatureBits.addArchDefaults(*AI);
1305 // Add any extra features, after the +
1306 SplitAndAddFeatures(Split.second, Ret.Features, FeatureBits);
1307 } else if (Feature.starts_with("cpu=")) {
1308 if (!Ret.CPU.empty())
1309 Ret.Duplicate = "cpu=";
1310 else {
1311 // Split the cpu string into "cpu=", "cortex-a710" and any remaining
1312 // "+feat" features.
1313 std::pair<StringRef, StringRef> Split =
1314 Feature.split("=").second.trim().split("+");
1315 Ret.CPU = Split.first;
1316 if (auto CpuInfo = llvm::AArch64::parseCpu(Ret.CPU)) {
1317 FeatureBits.addCPUDefaults(*CpuInfo);
1318 SplitAndAddFeatures(Split.second, Ret.Features, FeatureBits);
1319 }
1320 }
1321 } else if (Feature.starts_with("tune=")) {
1322 if (!Ret.Tune.empty())
1323 Ret.Duplicate = "tune=";
1324 else
1325 Ret.Tune = Feature.split("=").second.trim();
1326 } else if (Feature.starts_with("+")) {
1327 SplitAndAddFeatures(Feature, Ret.Features, FeatureBits);
1328 } else {
1329 if (FeatureBits.parseModifier(Feature, /* AllowNoDashForm = */ true))
1330 continue;
1331 // Pass through anything that failed to parse so that we can emit
1332 // diagnostics, as well as valid internal feature names.
1333 //
1334 // FIXME: We should consider rejecting internal feature names like
1335 // neon, v8a, etc.
1336 // FIXME: We should consider emitting diagnostics here.
1337 if (Feature.starts_with("no-"))
1338 Ret.Features.push_back("-" + Feature.drop_front(3).str());
1339 else
1340 Ret.Features.push_back("+" + Feature.str());
1341 }
1342 }
1343 FeatureBits.toLLVMFeatureList(Ret.Features);
1344 return Ret;
1345}
1346
1348 return true;
1349}
1350
1353 switch (CC) {
1354 case CC_C:
1355 case CC_Swift:
1356 case CC_SwiftAsync:
1357 case CC_PreserveMost:
1358 case CC_PreserveAll:
1359 case CC_PreserveNone:
1360 case CC_DeviceKernel:
1362 case CC_AArch64SVEPCS:
1363 case CC_Win64:
1364 return CCCR_OK;
1365 default:
1366 return CCCR_Warning;
1367 }
1368}
1369
1370bool AArch64TargetInfo::isCLZForZeroUndef() const { return false; }
1371
1375
1376const char *const AArch64TargetInfo::GCCRegNames[] = {
1377 // clang-format off
1378
1379 // 32-bit Integer registers
1380 "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
1381 "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", "w22",
1382 "w23", "w24", "w25", "w26", "w27", "w28", "w29", "w30", "wsp",
1383
1384 // 64-bit Integer registers
1385 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11",
1386 "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22",
1387 "x23", "x24", "x25", "x26", "x27", "x28", "fp", "lr", "sp",
1388
1389 // 32-bit floating point regsisters
1390 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11",
1391 "s12", "s13", "s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", "s22",
1392 "s23", "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
1393
1394 // 64-bit floating point regsisters
1395 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10", "d11",
1396 "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19", "d20", "d21", "d22",
1397 "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
1398
1399 // Neon vector registers
1400 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
1401 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22",
1402 "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
1403
1404 // SVE vector registers
1405 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10",
1406 "z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21",
1407 "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
1408
1409 // SVE predicate registers
1410 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10",
1411 "p11", "p12", "p13", "p14", "p15",
1412
1413 // SVE predicate-as-counter registers
1414 "pn0", "pn1", "pn2", "pn3", "pn4", "pn5", "pn6", "pn7", "pn8",
1415 "pn9", "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
1416
1417 // SME registers
1418 "za", "zt0",
1419
1420 // clang-format on
1421};
1422
1426
1427const TargetInfo::GCCRegAlias AArch64TargetInfo::GCCRegAliases[] = {
1428 {{"w31"}, "wsp"},
1429 {{"x31"}, "sp"},
1430 // GCC rN registers are aliases of xN registers.
1431 {{"r0"}, "x0"},
1432 {{"r1"}, "x1"},
1433 {{"r2"}, "x2"},
1434 {{"r3"}, "x3"},
1435 {{"r4"}, "x4"},
1436 {{"r5"}, "x5"},
1437 {{"r6"}, "x6"},
1438 {{"r7"}, "x7"},
1439 {{"r8"}, "x8"},
1440 {{"r9"}, "x9"},
1441 {{"r10"}, "x10"},
1442 {{"r11"}, "x11"},
1443 {{"r12"}, "x12"},
1444 {{"r13"}, "x13"},
1445 {{"r14"}, "x14"},
1446 {{"r15"}, "x15"},
1447 {{"r16"}, "x16"},
1448 {{"r17"}, "x17"},
1449 {{"r18"}, "x18"},
1450 {{"r19"}, "x19"},
1451 {{"r20"}, "x20"},
1452 {{"r21"}, "x21"},
1453 {{"r22"}, "x22"},
1454 {{"r23"}, "x23"},
1455 {{"r24"}, "x24"},
1456 {{"r25"}, "x25"},
1457 {{"r26"}, "x26"},
1458 {{"r27"}, "x27"},
1459 {{"r28"}, "x28"},
1460 {{"r29", "x29"}, "fp"},
1461 {{"r30", "x30"}, "lr"},
1462 // The S/D/Q and W/X registers overlap, but aren't really aliases; we
1463 // don't want to substitute one of these for a different-sized one.
1464};
1465
1469
1470// Returns the length of cc constraint.
1471static unsigned matchAsmCCConstraint(const char *Name) {
1472 constexpr unsigned len = 5;
1473 auto RV = llvm::StringSwitch<unsigned>(Name)
1474 .Case("@cceq", len)
1475 .Case("@ccne", len)
1476 .Case("@cchs", len)
1477 .Case("@cccs", len)
1478 .Case("@cccc", len)
1479 .Case("@cclo", len)
1480 .Case("@ccmi", len)
1481 .Case("@ccpl", len)
1482 .Case("@ccvs", len)
1483 .Case("@ccvc", len)
1484 .Case("@cchi", len)
1485 .Case("@ccls", len)
1486 .Case("@ccge", len)
1487 .Case("@cclt", len)
1488 .Case("@ccgt", len)
1489 .Case("@ccle", len)
1490 .Default(0);
1491 return RV;
1492}
1493
1494std::string
1495AArch64TargetInfo::convertConstraint(const char *&Constraint) const {
1496 std::string R;
1497 switch (*Constraint) {
1498 case 'U': // Three-character constraint; add "@3" hint for later parsing.
1499 R = std::string("@3") + std::string(Constraint, 3);
1500 Constraint += 2;
1501 break;
1502 case '@':
1503 if (const unsigned Len = matchAsmCCConstraint(Constraint)) {
1504 std::string Converted = "{" + std::string(Constraint, Len) + "}";
1505 Constraint += Len - 1;
1506 return Converted;
1507 }
1508 return std::string(1, *Constraint);
1509 default:
1510 R = TargetInfo::convertConstraint(Constraint);
1511 break;
1512 }
1513 return R;
1514}
1515
1517 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
1518 switch (*Name) {
1519 default:
1520 return false;
1521 case 'w': // Floating point and SIMD registers (V0-V31)
1522 Info.setAllowsRegister();
1523 return true;
1524 case 'I': // Constant that can be used with an ADD instruction
1525 case 'J': // Constant that can be used with a SUB instruction
1526 case 'K': // Constant that can be used with a 32-bit logical instruction
1527 case 'L': // Constant that can be used with a 64-bit logical instruction
1528 case 'M': // Constant that can be used as a 32-bit MOV immediate
1529 case 'N': // Constant that can be used as a 64-bit MOV immediate
1530 case 'Y': // Floating point constant zero
1531 case 'Z': // Integer constant zero
1532 return true;
1533 case 'Q': // A memory reference with base register and no offset
1534 Info.setAllowsMemory();
1535 return true;
1536 case 'S': // A symbolic address
1537 Info.setAllowsRegister();
1538 return true;
1539 case 'U':
1540 if (Name[1] == 'p' &&
1541 (Name[2] == 'l' || Name[2] == 'a' || Name[2] == 'h')) {
1542 // SVE predicate registers ("Upa"=P0-15, "Upl"=P0-P7, "Uph"=P8-P15)
1543 Info.setAllowsRegister();
1544 Name += 2;
1545 return true;
1546 }
1547 if (Name[1] == 'c' && (Name[2] == 'i' || Name[2] == 'j')) {
1548 // Gpr registers ("Uci"=w8-11, "Ucj"=w12-15)
1549 Info.setAllowsRegister();
1550 Name += 2;
1551 return true;
1552 }
1553 // Ump: A memory address suitable for ldp/stp in SI, DI, SF and DF modes.
1554 // Utf: A memory address suitable for ldp/stp in TF mode.
1555 // Usa: An absolute symbolic address.
1556 // Ush: The high part (bits 32:12) of a pc-relative symbolic address.
1557
1558 // Better to return an error saying that it's an unrecognised constraint
1559 // even if this is a valid constraint in gcc.
1560 return false;
1561 case 'z': // Zero register, wzr or xzr
1562 Info.setAllowsRegister();
1563 return true;
1564 case 'x': // Floating point and SIMD registers (V0-V15)
1565 Info.setAllowsRegister();
1566 return true;
1567 case 'y': // SVE registers (V0-V7)
1568 Info.setAllowsRegister();
1569 return true;
1570 case '@':
1571 // CC condition
1572 if (const unsigned Len = matchAsmCCConstraint(Name)) {
1573 Name += Len - 1;
1574 Info.setAllowsRegister();
1575 Info.setOutputOperandBounds(0, 2);
1576 return true;
1577 }
1578 }
1579 return false;
1580}
1581
1583 StringRef Constraint, char Modifier, unsigned Size,
1584 std::string &SuggestedModifier) const {
1585 // Strip off constraint modifiers.
1586 Constraint = Constraint.ltrim("=+&");
1587
1588 switch (Constraint[0]) {
1589 default:
1590 return true;
1591 case 'z':
1592 case 'r': {
1593 switch (Modifier) {
1594 case 'x':
1595 case 'w':
1596 // For now assume that the person knows what they're
1597 // doing with the modifier.
1598 return true;
1599 default:
1600 // By default an 'r' constraint will be in the 'x'
1601 // registers.
1602 if (Size == 64)
1603 return true;
1604
1605 if (Size == 512)
1606 return HasLS64;
1607
1608 SuggestedModifier = "w";
1609 return false;
1610 }
1611 }
1612 }
1613}
1614
1615std::string_view AArch64TargetInfo::getClobbers() const { return ""; }
1616
1618 if (RegNo == 0)
1619 return 0;
1620 if (RegNo == 1)
1621 return 1;
1622 return -1;
1623}
1624
1626 const llvm::APSInt &value) const {
1627 return 0 <= value && value <= 3;
1628}
1629
1630bool AArch64TargetInfo::hasInt128Type() const { return true; }
1631
1633 const TargetOptions &Opts)
1634 : AArch64TargetInfo(Triple, Opts) {}
1635
1636void AArch64leTargetInfo::setDataLayout() {
1637 if (getTriple().isOSBinFormatMachO()) {
1638 if(getTriple().isArch32Bit())
1639 resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-"
1640 "i128:128-n32:64-S128-Fn32",
1641 "_");
1642 else
1643 resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-"
1644 "n32:64-S128-Fn32",
1645 "_");
1646 } else
1647 resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-"
1648 "i64:64-i128:128-n32:64-S128-Fn32");
1649}
1650
1652 MacroBuilder &Builder) const {
1653 Builder.defineMacro("__AARCH64EL__");
1655}
1656
1658 const TargetOptions &Opts)
1659 : AArch64TargetInfo(Triple, Opts) {}
1660
1662 MacroBuilder &Builder) const {
1663 Builder.defineMacro("__AARCH64EB__");
1664 Builder.defineMacro("__AARCH_BIG_ENDIAN");
1665 Builder.defineMacro("__ARM_BIG_ENDIAN");
1667}
1668
1669void AArch64beTargetInfo::setDataLayout() {
1670 assert(!getTriple().isOSBinFormatMachO());
1671 resetDataLayout("E-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-"
1672 "i64:64-i128:128-n32:64-S128-Fn32");
1673}
1674
1676 const TargetOptions &Opts)
1677 : WindowsTargetInfo<AArch64leTargetInfo>(Triple, Opts), Triple(Triple) {
1678
1679 // This is an LLP64 platform.
1680 // int:4, long:4, long long:8, long double:8.
1681 IntWidth = IntAlign = 32;
1682 LongWidth = LongAlign = 32;
1685 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
1691}
1692
1694 resetDataLayout(Triple.isOSBinFormatMachO()
1695 ? "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:"
1696 "128-n32:64-S128-Fn32"
1697 : "e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-"
1698 "i64:64-i128:128-n32:64-S128-Fn32",
1699 Triple.isOSBinFormatMachO() ? "_" : "");
1700}
1701
1706
1709 switch (CC) {
1710 case CC_X86VectorCall:
1711 if (getTriple().isWindowsArm64EC())
1712 return CCCR_OK;
1713 return CCCR_Ignore;
1714 case CC_X86StdCall:
1715 case CC_X86ThisCall:
1716 case CC_X86FastCall:
1717 return CCCR_Ignore;
1718 case CC_C:
1719 case CC_DeviceKernel:
1720 case CC_PreserveMost:
1721 case CC_PreserveAll:
1722 case CC_PreserveNone:
1723 case CC_Swift:
1724 case CC_SwiftAsync:
1725 case CC_Win64:
1726 return CCCR_OK;
1727 default:
1728 return CCCR_Warning;
1729 }
1730}
1731
1733 const TargetOptions &Opts)
1734 : WindowsARM64TargetInfo(Triple, Opts) {
1735 TheCXXABI.set(TargetCXXABI::Microsoft);
1736}
1737
1739 MacroBuilder &Builder) const {
1741 if (getTriple().isWindowsArm64EC()) {
1742 Builder.defineMacro("_M_X64", "100");
1743 Builder.defineMacro("_M_AMD64", "100");
1744 Builder.defineMacro("_M_ARM64EC", "1");
1745 } else {
1746 Builder.defineMacro("_M_ARM64", "1");
1747 }
1748}
1749
1752 return CCK_MicrosoftWin64;
1753}
1754
1756 bool HasNonWeakDef) const {
1757 unsigned Align =
1758 WindowsARM64TargetInfo::getMinGlobalAlign(TypeSize, HasNonWeakDef);
1759
1760 // MSVC does size based alignment for arm64 based on alignment section in
1761 // below document, replicate that to keep alignment consistent with object
1762 // files compiled by MSVC.
1763 // https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions
1764 if (TypeSize >= 512) { // TypeSize >= 64 bytes
1765 Align = std::max(Align, 128u); // align type at least 16 bytes
1766 } else if (TypeSize >= 64) { // TypeSize >= 8 bytes
1767 Align = std::max(Align, 64u); // align type at least 8 butes
1768 } else if (TypeSize >= 16) { // TypeSize >= 2 bytes
1769 Align = std::max(Align, 32u); // align type at least 4 bytes
1770 }
1771 return Align;
1772}
1773
1775 const TargetOptions &Opts)
1776 : WindowsARM64TargetInfo(Triple, Opts) {
1777 TheCXXABI.set(TargetCXXABI::GenericAArch64);
1778}
1779
1781 const llvm::Triple &Triple, const TargetOptions &Opts)
1782 : AppleMachOTargetInfo<AArch64leTargetInfo>(Triple, Opts) {}
1783
1785 const TargetOptions &Opts)
1786 : DarwinTargetInfo<AArch64leTargetInfo>(Triple, Opts) {
1788 if (getTriple().isArch32Bit())
1790
1793
1795 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
1796
1798
1799 if (getTriple().isArch32Bit()) {
1803 TheCXXABI.set(TargetCXXABI::WatchOS);
1804 } else
1805 TheCXXABI.set(TargetCXXABI::AppleARM64);
1806}
1807
1809 const LangOptions &Opts,
1810 const llvm::Triple &Triple) {
1811 Builder.defineMacro("__AARCH64_SIMD__");
1812 if (Triple.isArch32Bit())
1813 Builder.defineMacro("__ARM64_ARCH_8_32__");
1814 else
1815 Builder.defineMacro("__ARM64_ARCH_8__");
1816 Builder.defineMacro("__ARM_NEON__");
1817 Builder.defineMacro("__REGISTER_PREFIX__", "");
1818 Builder.defineMacro("__arm64", "1");
1819 Builder.defineMacro("__arm64__", "1");
1820
1821 if (Triple.isArm64e())
1822 Builder.defineMacro("__arm64e__", "1");
1823}
1824
1826 const llvm::Triple &Triple,
1827 MacroBuilder &Builder) const {
1828 getAppleMachOAArch64Defines(Builder, Opts, Triple);
1830 Builder);
1831}
1832
1834 const llvm::Triple &Triple,
1835 MacroBuilder &Builder) const {
1836 getAppleMachOAArch64Defines(Builder, Opts, Triple);
1838}
1839
Defines the Diagnostic-related interfaces.
static unsigned matchAsmCCConstraint(const char *Name)
Definition AArch64.cpp:1471
static constexpr int NumAArch64Builtins
Definition AArch64.cpp:37
#define ARM_ACLE_VERSION(Y, Q, P)
static constexpr int NumSVEBuiltins
Definition AArch64.cpp:32
static constexpr int NumFp16Builtins
Definition AArch64.cpp:30
static constexpr int NumSMEBuiltins
Definition AArch64.cpp:36
static constexpr auto BuiltinAArch64Infos
Definition AArch64.cpp:119
static constexpr llvm::StringTable BuiltinSVENeonBridgeStrings
Definition AArch64.cpp:95
static constexpr int NumSVENeonBridgeBuiltins
Definition AArch64.cpp:34
static constexpr int NumNeonBuiltins
Definition AArch64.cpp:28
static constexpr llvm::StringTable BuiltinAArch64Strings
Definition AArch64.cpp:103
static constexpr auto BuiltinSVENeonBridgeInfos
Definition AArch64.cpp:111
static constexpr unsigned NumBuiltins
Definition Builtins.cpp:32
#define CLANG_BUILTIN_STR_TABLE_START
Definition Builtins.h:158
Defines the clang::LangOptions interface.
Enumerates target-specific builtins in their own namespaces within namespace clang.
__device__ __2f16 float c
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
@ NonLeaf
Sign the return address of functions that spill LR.
@ All
Sign the return address of all functions,.
@ BKey
Return address signing uses APIB key.
@ AKey
Return address signing uses APIA key.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isSignReturnAddressWithAKey() const
Check if return address signing uses AKey.
bool hasSignReturnAddress() const
Check if return address signing is enabled.
bool isSignReturnAddressScopeAll() const
Check if leaf functions are also signed.
LangOptions::SignReturnAddressScopeKind SignReturnAddr
LangOptions::SignReturnAddressKeyKind SignKey
TargetOptions & getTargetOpts() const
Retrieve the target options.
Definition TargetInfo.h:323
TargetInfo(const llvm::Triple &T)
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
const LangASMap * AddrSpaceMap
Definition TargetInfo.h:258
void resetDataLayout(StringRef DL, const char *UserLabelPrefix="")
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition TargetInfo.h:330
@ AArch64ABIBuiltinVaList
__builtin_va_list as defined by the AArch64 ABI http://infocenter.arm.com/help/topic/com....
Definition TargetInfo.h:339
@ CharPtrBuiltinVaList
typedef char* __builtin_va_list;
Definition TargetInfo.h:332
virtual void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const =0
===-— Other target property query methods -----------------------—===//
unsigned HasUnalignedAccess
Definition TargetInfo.h:283
unsigned char MaxAtomicPromoteWidth
Definition TargetInfo.h:251
virtual unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const
getMinGlobalAlign - Return the minimum alignment of a global variable, unless its alignment is explic...
Definition TargetInfo.h:754
unsigned HasAArch64ACLETypes
Definition TargetInfo.h:274
virtual std::string convertConstraint(const char *&Constraint) const
unsigned char MaxAtomicInlineWidth
Definition TargetInfo.h:251
TargetCXXABI TheCXXABI
Definition TargetInfo.h:256
unsigned HasBuiltinMSVaList
Definition TargetInfo.h:271
Options for controlling the target.
llvm::EABI EABIVersion
The EABI version to use.
llvm::StringMap< bool > FeatureMap
The map of which features have been enabled disabled based on the command line.
void getTargetDefinesARMV95A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:382
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition AArch64.cpp:1615
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition AArch64.cpp:812
std::string convertConstraint(const char *&Constraint) const override
Definition AArch64.cpp:1495
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition AArch64.cpp:1466
bool hasBFloat16Type() const override
Determine whether the _BFloat16 type is supported on this target.
Definition AArch64.cpp:1347
ParsedTargetAttr parseTargetAttr(StringRef Str) const override
Definition AArch64.cpp:1248
void getTargetDefinesARMV96A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:388
void getTargetDefinesARMV97A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:394
AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:128
ArrayRef< const char * > getGCCRegNames() const override
Definition AArch64.cpp:1423
bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const override
Validate register name used for global register variables.
Definition AArch64.cpp:226
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition AArch64.cpp:908
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition AArch64.cpp:400
void setFeatureEnabled(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled) const override
Enable or disable a specific target feature; the feature name must be valid.
Definition AArch64.cpp:879
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition AArch64.cpp:740
void getTargetDefinesARMV89A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:346
void getTargetDefinesARMV92A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:364
bool validateTarget(DiagnosticsEngine &Diags) const override
Check the target is valid after it is fully initialized.
Definition AArch64.cpp:216
void getTargetDefinesARMV93A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:370
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition AArch64.cpp:208
void getTargetDefinesARMV84A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:311
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition AArch64.cpp:279
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition AArch64.cpp:287
StringRef getABI() const override
Get the ABI currently in use.
Definition AArch64.cpp:206
bool hasInt128Type() const override
Determine whether the __int128 type is supported on this target.
Definition AArch64.cpp:1630
void getTargetDefinesARMV88A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:340
void getTargetDefinesARMV87A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:334
void getTargetDefinesARMV9A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:352
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition AArch64.cpp:1352
void getTargetDefinesARMV91A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:358
std::optional< std::pair< unsigned, unsigned > > getVScaleRange(const LangOptions &LangOpts, ArmStreamingKind Mode, llvm::StringMap< bool > *FeatureMap=nullptr) const override
Returns target-specific min and max values VScale_Range.
Definition AArch64.cpp:753
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition AArch64.cpp:1372
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition AArch64.cpp:1617
void getTargetDefinesARMV81A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:292
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:247
void getTargetDefinesARMV86A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:324
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition AArch64.cpp:283
void getTargetDefinesARMV94A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:376
llvm::APInt getFMVPriority(ArrayRef< StringRef > Features) const override
Definition AArch64.cpp:791
bool validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size, std::string &SuggestedModifier) const override
Definition AArch64.cpp:1582
bool isCLZForZeroUndef() const override
The __builtin_clz* and __builtin_ctz* built-in functions are specified to have undefined results for ...
Definition AArch64.cpp:1370
void getTargetDefinesARMV82A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:297
void getTargetDefinesARMV83A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:303
bool validateCpuSupports(StringRef FeatureStr) const override
Definition AArch64.cpp:802
bool validatePointerAuthKey(const llvm::APSInt &value) const override
Determine whether the given pointer-authentication key is valid.
Definition AArch64.cpp:1625
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition AArch64.cpp:1516
bool doesFeatureAffectCodeGen(StringRef Name) const override
Returns true if feature has an impact on target code generation.
Definition AArch64.cpp:795
void getTargetDefinesARMV85A(const LangOptions &Opts, MacroBuilder &Builder) const
Definition AArch64.cpp:317
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition AArch64.cpp:1661
AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1657
AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1632
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition AArch64.cpp:1651
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition AArch64.cpp:1825
AppleMachOAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1780
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition OSTargets.h:48
AppleMachOTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition OSTargets.h:54
DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1784
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition AArch64.cpp:1833
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition AArch64.cpp:1841
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition OSTargets.h:71
DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition OSTargets.h:78
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:1755
MicrosoftARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1732
TargetInfo::CallingConvKind getCallingConvKind(bool ClangABICompat4) const override
Definition AArch64.cpp:1751
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition AArch64.cpp:1738
MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1774
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition AArch64.cpp:1703
WindowsARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition AArch64.cpp:1675
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition AArch64.cpp:1708
WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition OSTargets.h:882
Defines the clang::TargetInfo interface.
static constexpr std::array< Info, N > MakeInfos(std::array< Info, N > Infos)
A constexpr function to construct an infos array from X-macros.
Definition Builtins.h:107
static constexpr std::array< Builtin::Info, NumFp16Builtins > BuiltinInfos
Definition AArch64.cpp:62
static constexpr std::array< Builtin::Info, NumNeonBuiltins > BuiltinInfos
Definition AArch64.cpp:51
static constexpr std::array< Builtin::Info, NumSMEBuiltins > BuiltinInfos
Definition AArch64.cpp:87
static constexpr std::array< Builtin::Info, NumSVEBuiltins > BuiltinInfos
Definition AArch64.cpp:75
void getAppleMachOAArch64Defines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple)
Definition AArch64.cpp:1808
static const unsigned ARM64AddrSpaceMap[]
Definition AArch64.h:26
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:278
@ CC_Swift
Definition Specifiers.h:293
@ CC_PreserveMost
Definition Specifiers.h:295
@ CC_Win64
Definition Specifiers.h:285
@ CC_X86ThisCall
Definition Specifiers.h:282
@ CC_AArch64VectorCall
Definition Specifiers.h:297
@ CC_DeviceKernel
Definition Specifiers.h:292
@ CC_PreserveNone
Definition Specifiers.h:300
@ CC_SwiftAsync
Definition Specifiers.h:294
@ CC_X86VectorCall
Definition Specifiers.h:283
@ CC_AArch64SVEPCS
Definition Specifiers.h:298
@ CC_X86StdCall
Definition Specifiers.h:280
@ CC_PreserveAll
Definition Specifiers.h:296
@ CC_X86FastCall
Definition Specifiers.h:281
Contains information gathered from parsing the contents of TargetAttr.
Definition TargetInfo.h:60
void setOutputOperandBounds(unsigned Min, unsigned Max)
unsigned UseZeroLengthBitfieldAlignment
Whether zero length bitfields (e.g., int : 0;) force alignment of the next bitfield.
Definition TargetInfo.h:187
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:143
unsigned ZeroLengthBitfieldBoundary
If non-zero, specifies a fixed alignment value for bitfields that follow zero length bitfield,...
Definition TargetInfo.h:200
std::optional< unsigned > BitIntMaxAlign
Definition TargetInfo.h:106
unsigned LargestOverSizedBitfieldContainer
The largest container size which should be used for an over-sized bitfield, in bits.
Definition TargetInfo.h:204
unsigned UseBitFieldTypeAlignment
Control whether the alignment of bit-field types is respected when laying out structures.
Definition TargetInfo.h:178
unsigned UseSignedCharForObjCBool
Whether Objective-C's built-in boolean type should be signed char.
Definition TargetInfo.h:170
const llvm::fltSemantics * BFloat16Format
Definition TargetInfo.h:142