18#include "llvm/ADT/APSInt.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringExtras.h"
21#include "llvm/ADT/StringSwitch.h"
22#include "llvm/TargetParser/AArch64TargetParser.h"
23#include "llvm/TargetParser/ARMTargetParserCommon.h"
30#define BUILTIN(ID, TYPE, ATTRS) \
31 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
32#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
33 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
34#include "clang/Basic/BuiltinsNEON.def"
36#define BUILTIN(ID, TYPE, ATTRS) \
37 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
38#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
39 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
40#include "clang/Basic/BuiltinsSVE.def"
42#define BUILTIN(ID, TYPE, ATTRS) \
43 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
44#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
45 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
46#include "clang/Basic/BuiltinsSME.def"
48#define BUILTIN(ID, TYPE, ATTRS) \
49 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
50#define LANGBUILTIN(ID, TYPE, ATTRS, LANG) \
51 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, LANG},
52#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
53 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
54#define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \
55 {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::HEADER, LANGS},
56#include "clang/Basic/BuiltinsAArch64.def"
60 if (*ArchInfo == llvm::AArch64::ARMV8R) {
70 }
else if (ArchInfo->Version.getMajor() == 8) {
71 if (ArchInfo->Version.getMinor() >= 7u) {
74 if (ArchInfo->Version.getMinor() >= 6u) {
78 if (ArchInfo->Version.getMinor() >= 5u) {
79 HasAlternativeNZCV =
true;
86 if (ArchInfo->Version.getMinor() >= 4u) {
91 if (ArchInfo->Version.getMinor() >= 3u) {
95 if (ArchInfo->Version.getMinor() >= 2u) {
98 if (ArchInfo->Version.getMinor() >= 1u) {
103 }
else if (ArchInfo->Version.getMajor() == 9) {
104 if (ArchInfo->Version.getMinor() >= 2u) {
107 if (ArchInfo->Version.getMinor() >= 1u) {
114 HasAlternativeNZCV =
true;
152 if (Triple.isArch64Bit())
197 if (Triple.getOS() == llvm::Triple::Linux)
199 else if (Triple.getOS() == llvm::Triple::UnknownOS)
201 Opts.
EABIVersion == llvm::EABI::GNU ?
"\01_mcount" :
"mcount";
207 if (Name !=
"aapcs" && Name !=
"aapcs-soft" && Name !=
"darwinpcs" &&
216 if (
hasFeature(
"fp") && ABI ==
"aapcs-soft") {
219 Diags.
Report(diag::err_target_unsupported_abi_with_fpu) << ABI;
222 if (
getTriple().getEnvironment() == llvm::Triple::PAuthTest &&
223 getTriple().getOS() != llvm::Triple::Linux) {
224 Diags.
Report(diag::err_target_unsupported_abi_for_triple)
232 StringRef RegName,
unsigned RegSize,
bool &HasSizeMismatch)
const {
233 if ((RegName ==
"sp") || RegName.starts_with(
"x")) {
234 HasSizeMismatch = RegSize != 64;
236 }
else if (RegName.starts_with(
"w")) {
237 HasSizeMismatch = RegSize != 32;
245 StringRef &Err)
const {
246 llvm::ARM::ParsedBranchProtection PBP;
247 if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err, HasPAuthLR))
251 llvm::StringSwitch<LangOptions::SignReturnAddressScopeKind>(PBP.Scope)
256 if (PBP.Key ==
"a_key")
268 return llvm::AArch64::parseCpu(Name).has_value();
277 llvm::AArch64::fillValidCPUArchList(Values);
282 Builder.defineMacro(
"__ARM_FEATURE_QRDMX",
"1");
293 Builder.defineMacro(
"__ARM_FEATURE_COMPLEX",
"1");
294 Builder.defineMacro(
"__ARM_FEATURE_JCVT",
"1");
307 Builder.defineMacro(
"__ARM_FEATURE_FRINT",
"1");
382 Builder.defineMacro(
"__amd64__");
383 Builder.defineMacro(
"__amd64");
384 Builder.defineMacro(
"__x86_64");
385 Builder.defineMacro(
"__x86_64__");
386 Builder.defineMacro(
"__arm64ec__");
388 Builder.defineMacro(
"__aarch64__");
392 Builder.defineMacro(
"__GCC_ASM_FLAG_OUTPUTS__");
395 if (CodeModel ==
"default")
397 for (
char &
c : CodeModel)
399 Builder.defineMacro(
"__AARCH64_CMODEL_" + CodeModel +
"__");
402 Builder.defineMacro(
"__ARM_ACLE",
"200");
403 Builder.defineMacro(
"__ARM_ARCH",
404 std::to_string(ArchInfo->Version.getMajor()));
405 Builder.defineMacro(
"__ARM_ARCH_PROFILE",
406 std::string(
"'") + (
char)ArchInfo->Profile +
"'");
408 Builder.defineMacro(
"__ARM_64BIT_STATE",
"1");
409 Builder.defineMacro(
"__ARM_PCS_AAPCS64",
"1");
410 Builder.defineMacro(
"__ARM_ARCH_ISA_A64",
"1");
412 Builder.defineMacro(
"__ARM_FEATURE_CLZ",
"1");
413 Builder.defineMacro(
"__ARM_FEATURE_FMA",
"1");
414 Builder.defineMacro(
"__ARM_FEATURE_LDREX",
"0xF");
415 Builder.defineMacro(
"__ARM_FEATURE_IDIV",
"1");
416 Builder.defineMacro(
"__ARM_FEATURE_DIV");
417 Builder.defineMacro(
"__ARM_FEATURE_NUMERIC_MAXMIN",
"1");
418 Builder.defineMacro(
"__ARM_FEATURE_DIRECTED_ROUNDING",
"1");
420 Builder.defineMacro(
"__ARM_ALIGN_MAX_STACK_PWR",
"4");
424 Builder.defineMacro(
"__ARM_STATE_ZA",
"1");
425 Builder.defineMacro(
"__ARM_STATE_ZT0",
"1");
429 Builder.defineMacro(
"__ARM_FP",
"0xE");
433 Builder.defineMacro(
"__ARM_FP16_FORMAT_IEEE",
"1");
434 Builder.defineMacro(
"__ARM_FP16_ARGS",
"1");
436 if (Opts.UnsafeFPMath)
437 Builder.defineMacro(
"__ARM_FP_FAST",
"1");
439 Builder.defineMacro(
"__ARM_SIZEOF_WCHAR_T",
440 Twine(Opts.WCharSize ? Opts.WCharSize : 4));
442 Builder.defineMacro(
"__ARM_SIZEOF_MINIMAL_ENUM", Opts.ShortEnums ?
"1" :
"4");
444 if (FPU & NeonMode) {
445 Builder.defineMacro(
"__ARM_NEON",
"1");
447 Builder.defineMacro(
"__ARM_NEON_FP",
"0xE");
451 Builder.defineMacro(
"__ARM_FEATURE_SVE",
"1");
453 if ((FPU & NeonMode) && (FPU & SveMode))
454 Builder.defineMacro(
"__ARM_NEON_SVE_BRIDGE",
"1");
457 Builder.defineMacro(
"__ARM_FEATURE_SVE2",
"1");
460 Builder.defineMacro(
"__ARM_FEATURE_SVE2p1",
"1");
462 if (HasSVE2 && HasSVE2AES)
463 Builder.defineMacro(
"__ARM_FEATURE_SVE2_AES",
"1");
465 if (HasSVE2 && HasSVE2BitPerm)
466 Builder.defineMacro(
"__ARM_FEATURE_SVE2_BITPERM",
"1");
468 if (HasSVE2 && HasSVE2SHA3)
469 Builder.defineMacro(
"__ARM_FEATURE_SVE2_SHA3",
"1");
471 if (HasSVE2 && HasSVE2SM4)
472 Builder.defineMacro(
"__ARM_FEATURE_SVE2_SM4",
"1");
475 Builder.defineMacro(
"__ARM_FEATURE_SME");
476 Builder.defineMacro(
"__ARM_FEATURE_LOCALLY_STREAMING",
"1");
480 Builder.defineMacro(
"__ARM_FEATURE_SME",
"1");
481 Builder.defineMacro(
"__ARM_FEATURE_SME2",
"1");
482 Builder.defineMacro(
"__ARM_FEATURE_LOCALLY_STREAMING",
"1");
486 Builder.defineMacro(
"__ARM_FEATURE_SME",
"1");
487 Builder.defineMacro(
"__ARM_FEATURE_SME2",
"1");
488 Builder.defineMacro(
"__ARM_FEATURE_SME2p1",
"1");
489 Builder.defineMacro(
"__ARM_FEATURE_LOCALLY_STREAMING",
"1");
493 Builder.defineMacro(
"__ARM_FEATURE_CRC32",
"1");
496 Builder.defineMacro(
"__ARM_FEATURE_RCPC",
"3");
498 Builder.defineMacro(
"__ARM_FEATURE_RCPC",
"1");
501 Builder.defineMacro(
"__HAVE_FUNCTION_MULTI_VERSIONING",
"1");
505 if (HasAES && HasSHA2)
506 Builder.defineMacro(
"__ARM_FEATURE_CRYPTO",
"1");
509 Builder.defineMacro(
"__ARM_FEATURE_AES",
"1");
512 Builder.defineMacro(
"__ARM_FEATURE_SHA2",
"1");
515 Builder.defineMacro(
"__ARM_FEATURE_SHA3",
"1");
516 Builder.defineMacro(
"__ARM_FEATURE_SHA512",
"1");
520 Builder.defineMacro(
"__ARM_FEATURE_SM3",
"1");
521 Builder.defineMacro(
"__ARM_FEATURE_SM4",
"1");
525 Builder.defineMacro(
"__ARM_FEATURE_PAUTH",
"1");
528 Builder.defineMacro(
"__ARM_FEATURE_PAUTH_LR",
"1");
531 Builder.defineMacro(
"__ARM_FEATURE_BTI",
"1");
534 Builder.defineMacro(
"__ARM_FEATURE_UNALIGNED",
"1");
536 if ((FPU & NeonMode) && HasFullFP16)
537 Builder.defineMacro(
"__ARM_FEATURE_FP16_VECTOR_ARITHMETIC",
"1");
539 Builder.defineMacro(
"__ARM_FEATURE_FP16_SCALAR_ARITHMETIC",
"1");
542 Builder.defineMacro(
"__ARM_FEATURE_DOTPROD",
"1");
545 Builder.defineMacro(
"__ARM_FEATURE_MEMORY_TAGGING",
"1");
548 Builder.defineMacro(
"__ARM_FEATURE_TME",
"1");
551 Builder.defineMacro(
"__ARM_FEATURE_MATMUL_INT8",
"1");
554 Builder.defineMacro(
"__ARM_FEATURE_ATOMICS",
"1");
557 Builder.defineMacro(
"__ARM_FEATURE_BF16",
"1");
558 Builder.defineMacro(
"__ARM_FEATURE_BF16_VECTOR_ARITHMETIC",
"1");
559 Builder.defineMacro(
"__ARM_BF16_FORMAT_ALTERNATIVE",
"1");
560 Builder.defineMacro(
"__ARM_FEATURE_BF16_SCALAR_ARITHMETIC",
"1");
563 if ((FPU & SveMode) && HasBFloat16) {
564 Builder.defineMacro(
"__ARM_FEATURE_SVE_BF16",
"1");
567 if ((FPU & SveMode) && HasMatmulFP64)
568 Builder.defineMacro(
"__ARM_FEATURE_SVE_MATMUL_FP64",
"1");
570 if ((FPU & SveMode) && HasMatmulFP32)
571 Builder.defineMacro(
"__ARM_FEATURE_SVE_MATMUL_FP32",
"1");
573 if ((FPU & SveMode) && HasMatMul)
574 Builder.defineMacro(
"__ARM_FEATURE_SVE_MATMUL_INT8",
"1");
576 if ((FPU & NeonMode) && HasFP16FML)
577 Builder.defineMacro(
"__ARM_FEATURE_FP16_FML",
"1");
595 if (Opts.BranchProtectionPAuthLR)
598 Builder.defineMacro(
"__ARM_FEATURE_PAC_DEFAULT", std::to_string(
Value));
601 if (Opts.BranchTargetEnforcement)
602 Builder.defineMacro(
"__ARM_FEATURE_BTI_DEFAULT",
"1");
604 if (Opts.GuardedControlStack)
605 Builder.defineMacro(
"__ARM_FEATURE_GCS_DEFAULT",
"1");
608 Builder.defineMacro(
"__ARM_FEATURE_LS64",
"1");
611 Builder.defineMacro(
"__ARM_FEATURE_RNG",
"1");
614 Builder.defineMacro(
"__ARM_FEATURE_MOPS",
"1");
617 Builder.defineMacro(
"__ARM_FEATURE_SYSREG128",
"1");
620 Builder.defineMacro(
"__ARM_FEATURE_GCS",
"1");
622 if (*ArchInfo == llvm::AArch64::ARMV8_1A)
624 else if (*ArchInfo == llvm::AArch64::ARMV8_2A)
626 else if (*ArchInfo == llvm::AArch64::ARMV8_3A)
628 else if (*ArchInfo == llvm::AArch64::ARMV8_4A)
630 else if (*ArchInfo == llvm::AArch64::ARMV8_5A)
632 else if (*ArchInfo == llvm::AArch64::ARMV8_6A)
634 else if (*ArchInfo == llvm::AArch64::ARMV8_7A)
636 else if (*ArchInfo == llvm::AArch64::ARMV8_8A)
638 else if (*ArchInfo == llvm::AArch64::ARMV8_9A)
640 else if (*ArchInfo == llvm::AArch64::ARMV9A)
642 else if (*ArchInfo == llvm::AArch64::ARMV9_1A)
644 else if (*ArchInfo == llvm::AArch64::ARMV9_2A)
646 else if (*ArchInfo == llvm::AArch64::ARMV9_3A)
648 else if (*ArchInfo == llvm::AArch64::ARMV9_4A)
650 else if (*ArchInfo == llvm::AArch64::ARMV9_5A)
654 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
655 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
656 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
657 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
658 Builder.defineMacro(
"__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
661 Builder.defineMacro(
"__FP_FAST_FMA",
"1");
662 Builder.defineMacro(
"__FP_FAST_FMAF",
"1");
666 Builder.defineMacro(
"__ARM_FEATURE_SVE_VECTOR_OPERATORS",
"2");
668 if (Opts.VScaleMin && Opts.VScaleMin == Opts.VScaleMax) {
669 Builder.defineMacro(
"__ARM_FEATURE_SVE_BITS", Twine(Opts.VScaleMin * 128));
678std::optional<std::pair<unsigned, unsigned>>
680 if (LangOpts.VScaleMin || LangOpts.VScaleMax)
681 return std::pair<unsigned, unsigned>(
682 LangOpts.VScaleMin ? LangOpts.VScaleMin : 1, LangOpts.VScaleMax);
685 return std::pair<unsigned, unsigned>(1, 16);
691 if (Name ==
"default")
693 if (
auto Ext = llvm::AArch64::parseFMVExtension(Name))
694 return Ext->Priority;
700 constexpr unsigned MaxFMVPriority = 1000;
701 return MaxFMVPriority;
706 if (
auto Ext = llvm::AArch64::parseFMVExtension(Name))
707 return !Ext->Features.empty();
714 FeatureStr.split(Features,
"+");
715 for (
auto &Feature : Features)
716 if (!llvm::AArch64::parseFMVExtension(Feature.trim()).has_value())
722 return llvm::StringSwitch<bool>(Feature)
723 .Cases(
"aarch64",
"arm64",
"arm",
true)
725 .Case(
"fp", FPU & FPUMode)
726 .Cases(
"neon",
"simd", FPU & NeonMode)
727 .Case(
"jscvt", HasJSCVT)
728 .Case(
"fcma", HasFCMA)
729 .Case(
"rng", HasRandGen)
730 .Case(
"flagm", HasFlagM)
731 .Case(
"flagm2", HasAlternativeNZCV)
732 .Case(
"fp16fml", HasFP16FML)
733 .Case(
"dotprod", HasDotProd)
738 .Case(
"sha2", HasSHA2)
739 .Case(
"sha3", HasSHA3)
740 .Cases(
"aes",
"pmull", HasAES)
741 .Cases(
"fp16",
"fullfp16", HasFullFP16)
743 .Case(
"dpb", HasCCPP)
744 .Case(
"dpb2", HasCCDP)
745 .Case(
"rcpc", HasRCPC)
746 .Case(
"frintts", HasFRInt3264)
747 .Case(
"i8mm", HasMatMul)
748 .Case(
"bf16", HasBFloat16)
749 .Case(
"sve", FPU & SveMode)
750 .Case(
"sve-bf16", FPU & SveMode && HasBFloat16)
751 .Case(
"sve-i8mm", FPU & SveMode && HasMatMul)
752 .Case(
"f32mm", FPU & SveMode && HasMatmulFP32)
753 .Case(
"f64mm", FPU & SveMode && HasMatmulFP64)
754 .Case(
"sve2", FPU & SveMode && HasSVE2)
755 .Case(
"sve2-pmull128", FPU & SveMode && HasSVE2AES)
756 .Case(
"sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
757 .Case(
"sve2-sha3", FPU & SveMode && HasSVE2SHA3)
758 .Case(
"sve2-sm4", FPU & SveMode && HasSVE2SM4)
759 .Case(
"sve2p1", FPU & SveMode && HasSVE2p1)
761 .Case(
"sme2", HasSME2)
762 .Case(
"sme2p1", HasSME2p1)
763 .Case(
"sme-f64f64", HasSMEF64F64)
764 .Case(
"sme-i16i64", HasSMEI16I64)
765 .Case(
"sme-fa64", HasSMEFA64)
766 .Cases(
"memtag",
"memtag2", HasMTE)
768 .Case(
"predres", HasPredRes)
769 .Cases(
"ssbs",
"ssbs2", HasSSBS)
771 .Cases(
"ls64",
"ls64_v",
"ls64_accdata", HasLS64)
772 .Case(
"wfxt", HasWFxT)
773 .Case(
"rcpc3", HasRCPC3)
778 StringRef Name,
bool Enabled)
const {
779 Features[Name] = Enabled;
782 const std::optional<llvm::AArch64::ArchInfo> ArchInfo =
783 llvm::AArch64::ArchInfo::findBySubArch(Name);
792 for (
const auto *OtherArch : llvm::AArch64::ArchInfos)
793 if (ArchInfo->implies(*OtherArch))
794 Features[OtherArch->getSubArch()] =
true;
797 std::vector<StringRef> CPUFeats;
798 if (llvm::AArch64::getExtensionFeatures(ArchInfo->DefaultExts, CPUFeats)) {
799 for (
auto F : CPUFeats) {
800 assert(F[0] ==
'+' &&
"Expected + in target feature!");
801 Features[F.drop_front(1)] =
true;
808 for (
const auto &Feature : Features) {
809 if (Feature ==
"-fp-armv8")
811 if (Feature ==
"-neon")
813 if (Feature ==
"-sve")
816 if (Feature ==
"+neon" || Feature ==
"+fp-armv8")
818 if (Feature ==
"+jscvt") {
822 if (Feature ==
"+fcma") {
827 if (Feature ==
"+sve") {
832 if (Feature ==
"+sve2") {
838 if (Feature ==
"+sve2p1") {
845 if (Feature ==
"+sve2-aes") {
852 if (Feature ==
"+sve2-sha3") {
859 if (Feature ==
"+sve2-sm4") {
866 if (Feature ==
"+sve2-bitperm") {
871 HasSVE2BitPerm =
true;
873 if (Feature ==
"+f32mm") {
877 HasMatmulFP32 =
true;
879 if (Feature ==
"+f64mm") {
883 HasMatmulFP64 =
true;
885 if (Feature ==
"+sme") {
890 if (Feature ==
"+sme2") {
896 if (Feature ==
"+sme2p1") {
903 if (Feature ==
"+sme-f64f64") {
909 if (Feature ==
"+sme-i16i64") {
915 if (Feature ==
"+sme-fa64") {
922 if (Feature ==
"+sb")
924 if (Feature ==
"+predres")
926 if (Feature ==
"+ssbs")
928 if (Feature ==
"+bti")
930 if (Feature ==
"+wfxt")
932 if (Feature ==
"-fmv")
934 if (Feature ==
"+crc")
936 if (Feature ==
"+rcpc")
938 if (Feature ==
"+aes") {
942 if (Feature ==
"+sha2") {
946 if (Feature ==
"+sha3") {
951 if (Feature ==
"+rdm") {
955 if (Feature ==
"+dit")
957 if (Feature ==
"+cccp")
959 if (Feature ==
"+ccdp") {
963 if (Feature ==
"+fptoint")
965 if (Feature ==
"+sm4") {
969 if (Feature ==
"+strict-align")
973 if (Feature ==
"+v8a" && ArchInfo->Version < llvm::AArch64::ARMV8A.Version)
974 ArchInfo = &llvm::AArch64::ARMV8A;
975 if (Feature ==
"+v8.1a" &&
976 ArchInfo->Version < llvm::AArch64::ARMV8_1A.Version)
977 ArchInfo = &llvm::AArch64::ARMV8_1A;
978 if (Feature ==
"+v8.2a" &&
979 ArchInfo->Version < llvm::AArch64::ARMV8_2A.Version)
980 ArchInfo = &llvm::AArch64::ARMV8_2A;
981 if (Feature ==
"+v8.3a" &&
982 ArchInfo->Version < llvm::AArch64::ARMV8_3A.Version)
983 ArchInfo = &llvm::AArch64::ARMV8_3A;
984 if (Feature ==
"+v8.4a" &&
985 ArchInfo->Version < llvm::AArch64::ARMV8_4A.Version)
986 ArchInfo = &llvm::AArch64::ARMV8_4A;
987 if (Feature ==
"+v8.5a" &&
988 ArchInfo->Version < llvm::AArch64::ARMV8_5A.Version)
989 ArchInfo = &llvm::AArch64::ARMV8_5A;
990 if (Feature ==
"+v8.6a" &&
991 ArchInfo->Version < llvm::AArch64::ARMV8_6A.Version)
992 ArchInfo = &llvm::AArch64::ARMV8_6A;
993 if (Feature ==
"+v8.7a" &&
994 ArchInfo->Version < llvm::AArch64::ARMV8_7A.Version)
995 ArchInfo = &llvm::AArch64::ARMV8_7A;
996 if (Feature ==
"+v8.8a" &&
997 ArchInfo->Version < llvm::AArch64::ARMV8_8A.Version)
998 ArchInfo = &llvm::AArch64::ARMV8_8A;
999 if (Feature ==
"+v8.9a" &&
1000 ArchInfo->Version < llvm::AArch64::ARMV8_9A.Version)
1001 ArchInfo = &llvm::AArch64::ARMV8_9A;
1002 if (Feature ==
"+v9a" && ArchInfo->Version < llvm::AArch64::ARMV9A.Version)
1003 ArchInfo = &llvm::AArch64::ARMV9A;
1004 if (Feature ==
"+v9.1a" &&
1005 ArchInfo->Version < llvm::AArch64::ARMV9_1A.Version)
1006 ArchInfo = &llvm::AArch64::ARMV9_1A;
1007 if (Feature ==
"+v9.2a" &&
1008 ArchInfo->Version < llvm::AArch64::ARMV9_2A.Version)
1009 ArchInfo = &llvm::AArch64::ARMV9_2A;
1010 if (Feature ==
"+v9.3a" &&
1011 ArchInfo->Version < llvm::AArch64::ARMV9_3A.Version)
1012 ArchInfo = &llvm::AArch64::ARMV9_3A;
1013 if (Feature ==
"+v9.4a" &&
1014 ArchInfo->Version < llvm::AArch64::ARMV9_4A.Version)
1015 ArchInfo = &llvm::AArch64::ARMV9_4A;
1016 if (Feature ==
"+v9.5a" &&
1017 ArchInfo->Version < llvm::AArch64::ARMV9_5A.Version)
1018 ArchInfo = &llvm::AArch64::ARMV9_5A;
1019 if (Feature ==
"+v8r")
1020 ArchInfo = &llvm::AArch64::ARMV8R;
1021 if (Feature ==
"+fullfp16") {
1025 if (Feature ==
"+dotprod") {
1029 if (Feature ==
"+fp16fml") {
1034 if (Feature ==
"+mte")
1036 if (Feature ==
"+tme")
1038 if (Feature ==
"+pauth")
1040 if (Feature ==
"+i8mm")
1042 if (Feature ==
"+bf16")
1044 if (Feature ==
"+lse")
1046 if (Feature ==
"+ls64")
1048 if (Feature ==
"+rand")
1050 if (Feature ==
"+flagm")
1052 if (Feature ==
"+altnzcv") {
1054 HasAlternativeNZCV =
true;
1056 if (Feature ==
"+mops")
1058 if (Feature ==
"+d128")
1060 if (Feature ==
"+gcs")
1062 if (Feature ==
"+rcpc3")
1064 if (Feature ==
"+pauth-lr") {
1073 for (
const auto &Feature : Features) {
1074 if (Feature ==
"-d128")
1109 if (Features ==
"default")
1112 Features.split(AttrFeatures,
",");
1113 bool FoundArch =
false;
1115 auto SplitAndAddFeatures = [](StringRef FeatString,
1116 std::vector<std::string> &Features,
1117 llvm::AArch64::ExtensionSet &FeatureBits) {
1119 FeatString.split(SplitFeatures, StringRef(
"+"), -1,
false);
1120 for (StringRef Feature : SplitFeatures) {
1121 if (FeatureBits.parseModifier(Feature))
1129 if (Feature.starts_with(
"no"))
1130 Features.push_back(
"-" + Feature.drop_front(2).str());
1132 Features.push_back(
"+" + Feature.str());
1136 llvm::AArch64::ExtensionSet FeatureBits;
1141 for (
auto &Feature : AttrFeatures) {
1142 Feature = Feature.trim();
1143 if (Feature.starts_with(
"fpmath="))
1146 if (Feature.starts_with(
"branch-protection=")) {
1147 Ret.BranchProtection = Feature.split(
'=').second.trim();
1151 if (Feature.starts_with(
"arch=")) {
1153 Ret.Duplicate =
"arch=";
1155 std::pair<StringRef, StringRef> Split =
1156 Feature.split(
"=").second.trim().split(
"+");
1157 const llvm::AArch64::ArchInfo *AI = llvm::AArch64::parseArch(Split.first);
1163 FeatureBits.addArchDefaults(*AI);
1165 SplitAndAddFeatures(Split.second, Ret.Features, FeatureBits);
1166 }
else if (Feature.starts_with(
"cpu=")) {
1167 if (!Ret.CPU.empty())
1168 Ret.Duplicate =
"cpu=";
1172 std::pair<StringRef, StringRef> Split =
1173 Feature.split(
"=").second.trim().split(
"+");
1174 Ret.CPU = Split.first;
1175 if (
auto CpuInfo = llvm::AArch64::parseCpu(Ret.CPU)) {
1176 FeatureBits.addCPUDefaults(*CpuInfo);
1177 SplitAndAddFeatures(Split.second, Ret.Features, FeatureBits);
1180 }
else if (Feature.starts_with(
"tune=")) {
1181 if (!Ret.Tune.empty())
1182 Ret.Duplicate =
"tune=";
1184 Ret.Tune = Feature.split(
"=").second.trim();
1185 }
else if (Feature.starts_with(
"+")) {
1186 SplitAndAddFeatures(Feature, Ret.Features, FeatureBits);
1188 if (FeatureBits.parseModifier(Feature,
true))
1196 if (Feature.starts_with(
"no-"))
1197 Ret.Features.push_back(
"-" + Feature.drop_front(3).str());
1199 Ret.Features.push_back(
"+" + Feature.str());
1202 FeatureBits.toLLVMFeatureList(Ret.Features);
1235const char *
const AArch64TargetInfo::GCCRegNames[] = {
1239 "w0",
"w1",
"w2",
"w3",
"w4",
"w5",
"w6",
"w7",
"w8",
"w9",
"w10",
"w11",
1240 "w12",
"w13",
"w14",
"w15",
"w16",
"w17",
"w18",
"w19",
"w20",
"w21",
"w22",
1241 "w23",
"w24",
"w25",
"w26",
"w27",
"w28",
"w29",
"w30",
"wsp",
1244 "x0",
"x1",
"x2",
"x3",
"x4",
"x5",
"x6",
"x7",
"x8",
"x9",
"x10",
"x11",
1245 "x12",
"x13",
"x14",
"x15",
"x16",
"x17",
"x18",
"x19",
"x20",
"x21",
"x22",
1246 "x23",
"x24",
"x25",
"x26",
"x27",
"x28",
"fp",
"lr",
"sp",
1249 "s0",
"s1",
"s2",
"s3",
"s4",
"s5",
"s6",
"s7",
"s8",
"s9",
"s10",
"s11",
1250 "s12",
"s13",
"s14",
"s15",
"s16",
"s17",
"s18",
"s19",
"s20",
"s21",
"s22",
1251 "s23",
"s24",
"s25",
"s26",
"s27",
"s28",
"s29",
"s30",
"s31",
1254 "d0",
"d1",
"d2",
"d3",
"d4",
"d5",
"d6",
"d7",
"d8",
"d9",
"d10",
"d11",
1255 "d12",
"d13",
"d14",
"d15",
"d16",
"d17",
"d18",
"d19",
"d20",
"d21",
"d22",
1256 "d23",
"d24",
"d25",
"d26",
"d27",
"d28",
"d29",
"d30",
"d31",
1259 "v0",
"v1",
"v2",
"v3",
"v4",
"v5",
"v6",
"v7",
"v8",
"v9",
"v10",
"v11",
1260 "v12",
"v13",
"v14",
"v15",
"v16",
"v17",
"v18",
"v19",
"v20",
"v21",
"v22",
1261 "v23",
"v24",
"v25",
"v26",
"v27",
"v28",
"v29",
"v30",
"v31",
1264 "z0",
"z1",
"z2",
"z3",
"z4",
"z5",
"z6",
"z7",
"z8",
"z9",
"z10",
1265 "z11",
"z12",
"z13",
"z14",
"z15",
"z16",
"z17",
"z18",
"z19",
"z20",
"z21",
1266 "z22",
"z23",
"z24",
"z25",
"z26",
"z27",
"z28",
"z29",
"z30",
"z31",
1269 "p0",
"p1",
"p2",
"p3",
"p4",
"p5",
"p6",
"p7",
"p8",
"p9",
"p10",
1270 "p11",
"p12",
"p13",
"p14",
"p15",
1273 "pn0",
"pn1",
"pn2",
"pn3",
"pn4",
"pn5",
"pn6",
"pn7",
"pn8",
1274 "pn9",
"pn10",
"pn11",
"pn12",
"pn13",
"pn14",
"pn15",
1319 {{
"r29",
"x29"},
"fp"},
1320 {{
"r30",
"x30"},
"lr"},
1331 constexpr unsigned len = 5;
1332 auto RV = llvm::StringSwitch<unsigned>(Name)
1356 switch (*Constraint) {
1358 R = std::string(
"@3") + std::string(Constraint, 3);
1363 std::string Converted =
"{" + std::string(Constraint, Len) +
"}";
1364 Constraint += Len - 1;
1367 return std::string(1, *Constraint);
1399 if (Name[1] ==
'p' &&
1400 (Name[2] ==
'l' || Name[2] ==
'a' || Name[2] ==
'h')) {
1406 if (Name[1] ==
'c' && (Name[2] ==
'i' || Name[2] ==
'j')) {
1441 StringRef Constraint,
char Modifier,
unsigned Size,
1442 std::string &SuggestedModifier)
const {
1444 Constraint = Constraint.ltrim(
"=+&");
1446 switch (Constraint[0]) {
1466 SuggestedModifier =
"w";
1484 const llvm::APSInt &value)
const {
1485 return 0 <= value && value <= 3;
1494void AArch64leTargetInfo::setDataLayout() {
1497 resetDataLayout(
"e-m:o-p:32:32-i64:64-i128:128-n32:64-S128-Fn32",
"_");
1501 resetDataLayout(
"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32");
1506 Builder.defineMacro(
"__AARCH64EL__");
1516 Builder.defineMacro(
"__AARCH64EB__");
1517 Builder.defineMacro(
"__AARCH_BIG_ENDIAN");
1518 Builder.defineMacro(
"__ARM_BIG_ENDIAN");
1522void AArch64beTargetInfo::setDataLayout() {
1523 assert(!
getTriple().isOSBinFormatMachO());
1524 resetDataLayout(
"E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32");
1533 IntWidth = IntAlign = 32;
1534 LongWidth = LongAlign = 32;
1535 DoubleAlign = LongLongAlign = 64;
1536 LongDoubleWidth = LongDoubleAlign = 64;
1537 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
1538 IntMaxType = SignedLongLong;
1539 Int64Type = SignedLongLong;
1540 SizeType = UnsignedLongLong;
1541 PtrDiffType = SignedLongLong;
1542 IntPtrType = SignedLongLong;
1546 resetDataLayout(Triple.isOSBinFormatMachO()
1547 ?
"e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
1548 :
"e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32",
1549 Triple.isOSBinFormatMachO() ?
"_" :
"");
1561 if (getTriple().isWindowsArm64EC())
1578 return CCCR_Warning;
1585 TheCXXABI.set(TargetCXXABI::Microsoft);
1591 if (getTriple().isWindowsArm64EC()) {
1592 Builder.defineMacro(
"_M_X64",
"100");
1593 Builder.defineMacro(
"_M_AMD64",
"100");
1594 Builder.defineMacro(
"_M_ARM64EC",
"1");
1596 Builder.defineMacro(
"_M_ARM64",
"1");
1602 return CCK_MicrosoftWin64;
1606 bool HasNonWeakDef)
const {
1608 WindowsARM64TargetInfo::getMinGlobalAlign(TypeSize, HasNonWeakDef);
1614 if (TypeSize >= 512) {
1615 Align = std::max(Align, 128u);
1616 }
else if (TypeSize >= 64) {
1617 Align = std::max(Align, 64u);
1618 }
else if (TypeSize >= 16) {
1619 Align = std::max(Align, 32u);
1627 TheCXXABI.set(TargetCXXABI::GenericAArch64);
1633 Int64Type = SignedLongLong;
1634 if (getTriple().isArch32Bit())
1635 IntMaxType = SignedLongLong;
1637 WCharType = SignedInt;
1638 UseSignedCharForObjCBool =
false;
1640 LongDoubleWidth = LongDoubleAlign = SuitableAlign = 64;
1641 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
1643 UseZeroLengthBitfieldAlignment =
false;
1645 if (getTriple().isArch32Bit()) {
1646 UseBitFieldTypeAlignment =
false;
1647 ZeroLengthBitfieldBoundary = 32;
1648 UseZeroLengthBitfieldAlignment =
true;
1649 TheCXXABI.set(TargetCXXABI::WatchOS);
1651 TheCXXABI.set(TargetCXXABI::AppleARM64);
1655 const llvm::Triple &Triple,
1657 Builder.defineMacro(
"__AARCH64_SIMD__");
1658 if (Triple.isArch32Bit())
1659 Builder.defineMacro(
"__ARM64_ARCH_8_32__");
1661 Builder.defineMacro(
"__ARM64_ARCH_8__");
1662 Builder.defineMacro(
"__ARM_NEON__");
1663 Builder.defineMacro(
"__REGISTER_PREFIX__",
"");
1664 Builder.defineMacro(
"__arm64",
"1");
1665 Builder.defineMacro(
"__arm64__",
"1");
1667 if (Triple.isArm64e())
1668 Builder.defineMacro(
"__arm64e__",
"1");
1683 Triple.getEnvironmentName()),
1690 Builder.defineMacro(
"__RENDERSCRIPT__");
Defines the Diagnostic-related interfaces.
static unsigned matchAsmCCConstraint(const char *Name)
static constexpr Builtin::Info BuiltinInfo[]
static constexpr Builtin::Info BuiltinInfo[]
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.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
@ None
No signing for any function.
@ 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
bool BranchProtectionPAuthLR
bool BranchTargetEnforcement
Exposes information about the current target.
TargetOptions & getTargetOpts() const
Retrieve the target options.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
unsigned HasAArch64SVETypes
void resetDataLayout(StringRef DL, const char *UserLabelPrefix="")
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
@ AArch64ABIBuiltinVaList
__builtin_va_list as defined by the AArch64 ABI http://infocenter.arm.com/help/topic/com....
@ CharPtrBuiltinVaList
typedef char* __builtin_va_list;
unsigned IsRenderScriptTarget
unsigned HasUnalignedAccess
unsigned char MaxAtomicPromoteWidth
virtual std::string convertConstraint(const char *&Constraint) const
unsigned char MaxAtomicInlineWidth
unsigned HasBuiltinMSVaList
Options for controlling the target.
llvm::EABI EABIVersion
The EABI version to use.
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line.
void getTargetDefinesARMV95A(const LangOptions &Opts, MacroBuilder &Builder) const
unsigned multiVersionSortPriority(StringRef Name) const override
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
std::string convertConstraint(const char *&Constraint) const override
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
bool hasBFloat16Type() const override
Determine whether the _BFloat16 type is supported on this target.
ParsedTargetAttr parseTargetAttr(StringRef Str) const override
AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
unsigned multiVersionFeatureCost() const override
ArrayRef< const char * > getGCCRegNames() const override
bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const override
Validate register name used for global register variables.
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
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.
void getTargetDefinesARMV89A(const LangOptions &Opts, MacroBuilder &Builder) const
void getTargetDefinesARMV92A(const LangOptions &Opts, MacroBuilder &Builder) const
bool validateTarget(DiagnosticsEngine &Diags) const override
Check the target is valid after it is fully initialized.
void getTargetDefinesARMV93A(const LangOptions &Opts, MacroBuilder &Builder) const
bool setABI(const std::string &Name) override
Use the specified ABI.
void getTargetDefinesARMV84A(const LangOptions &Opts, MacroBuilder &Builder) const
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
StringRef getABI() const override
Get the ABI currently in use.
bool hasInt128Type() const override
Determine whether the __int128 type is supported on this target.
void getTargetDefinesARMV88A(const LangOptions &Opts, MacroBuilder &Builder) const
bool validateBranchProtection(StringRef Spec, StringRef Arch, BranchProtectionInfo &BPI, StringRef &Err) const override
Determine if this TargetInfo supports the given branch protection specification.
void getTargetDefinesARMV87A(const LangOptions &Opts, MacroBuilder &Builder) const
void getTargetDefinesARMV9A(const LangOptions &Opts, MacroBuilder &Builder) const
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
void getTargetDefinesARMV91A(const LangOptions &Opts, MacroBuilder &Builder) const
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
void getTargetDefinesARMV81A(const LangOptions &Opts, MacroBuilder &Builder) const
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
void getTargetDefinesARMV86A(const LangOptions &Opts, MacroBuilder &Builder) const
bool setCPU(const std::string &Name) override
Target the specified CPU.
std::optional< std::pair< unsigned, unsigned > > getVScaleRange(const LangOptions &LangOpts) const override
Returns target-specific min and max values VScale_Range.
void getTargetDefinesARMV94A(const LangOptions &Opts, MacroBuilder &Builder) const
bool validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size, std::string &SuggestedModifier) const override
bool isCLZForZeroUndef() const override
The __builtin_clz* and __builtin_ctz* built-in functions are specified to have undefined results for ...
void getTargetDefinesARMV82A(const LangOptions &Opts, MacroBuilder &Builder) const
void getTargetDefinesARMV83A(const LangOptions &Opts, MacroBuilder &Builder) const
bool validateCpuSupports(StringRef FeatureStr) const override
bool validatePointerAuthKey(const llvm::APSInt &value) const override
Determine whether the given pointer-authentication key is valid.
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
bool doesFeatureAffectCodeGen(StringRef Name) const override
Returns true if feature has an impact on target code generation.
void getTargetDefinesARMV85A(const LangOptions &Opts, MacroBuilder &Builder) const
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
BuiltinVaListKind getBuiltinVaListKind() const override
unsigned getMinGlobalAlign(uint64_t TypeSize, bool HasNonWeakDef) const override
MicrosoftARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
TargetInfo::CallingConvKind getCallingConvKind(bool ClangABICompat4) const override
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
RenderScript64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
BuiltinVaListKind getBuiltinVaListKind() const override
WindowsARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
void setDataLayout() override
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Defines the clang::TargetInfo interface.
void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple, StringRef &PlatformName, VersionTuple &PlatformMinVersion)
The JSON file list parser is used to communicate input to InstallAPI.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Diagnostic wrappers for TextAPI types for error reporting.
Contains information gathered from parsing the contents of TargetAttr.
unsigned UseZeroLengthBitfieldAlignment
Whether zero length bitfields (e.g., int : 0;) force alignment of the next bitfield.
unsigned short SuitableAlign
unsigned char PointerWidth
const llvm::fltSemantics * LongDoubleFormat
std::optional< unsigned > BitIntMaxAlign
unsigned UseBitFieldTypeAlignment
Control whether the alignment of bit-field types is respected when laying out structures.
unsigned char PointerAlign
unsigned char BFloat16Width
unsigned char LongDoubleAlign
unsigned char LongDoubleWidth
unsigned char BFloat16Align
const llvm::fltSemantics * BFloat16Format