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