clang 20.0.0git
TargetInfo.cpp
Go to the documentation of this file.
1//===--- TargetInfo.cpp - Information about Target machine ----------------===//
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 the TargetInfo interface.
10//
11//===----------------------------------------------------------------------===//
12
19#include "llvm/ADT/APFloat.h"
20#include "llvm/ADT/STLExtras.h"
21#include "llvm/Support/ErrorHandling.h"
22#include "llvm/TargetParser/TargetParser.h"
23#include <cstdlib>
24using namespace clang;
25
26static const LangASMap DefaultAddrSpaceMap = {0};
27// The fake address space map must have a distinct entry for each
28// language-specific address space.
30 0, // Default
31 1, // opencl_global
32 3, // opencl_local
33 2, // opencl_constant
34 0, // opencl_private
35 4, // opencl_generic
36 5, // opencl_global_device
37 6, // opencl_global_host
38 7, // cuda_device
39 8, // cuda_constant
40 9, // cuda_shared
41 1, // sycl_global
42 5, // sycl_global_device
43 6, // sycl_global_host
44 3, // sycl_local
45 0, // sycl_private
46 10, // ptr32_sptr
47 11, // ptr32_uptr
48 12, // ptr64
49 13, // hlsl_groupshared
50 20, // wasm_funcref
51};
52
53// TargetInfo Constructor.
54TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
55 // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
56 // SPARC. These should be overridden by concrete targets as needed.
57 BigEndian = !T.isLittleEndian();
58 TLSSupported = true;
59 VLASupported = true;
60 NoAsmVariants = false;
61 HasLegalHalfType = false;
62 HalfArgsAndReturns = false;
63 HasFloat128 = false;
64 HasIbm128 = false;
65 HasFloat16 = false;
66 HasBFloat16 = false;
67 HasFullBFloat16 = false;
68 HasLongDouble = true;
69 HasFPReturn = true;
70 HasStrictFP = false;
72 BoolWidth = BoolAlign = 8;
74 IntWidth = IntAlign = 32;
75 LongWidth = LongAlign = 32;
77 Int128Align = 128;
78
79 // Fixed point default bit widths
86
87 // Fixed point default integral and fractional bit sizes
88 // We give the _Accum 1 fewer fractional bits than their corresponding _Fract
89 // types by default to have the same number of fractional bits between _Accum
90 // and _Fract types.
93 AccumScale = 15;
94 LongAccumScale = 31;
95
96 SuitableAlign = 64;
99 // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
100 // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
101 // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
102 // This alignment guarantee also applies to Windows and Android. On Darwin
103 // and OpenBSD, the alignment is 16 bytes on both 64-bit and 32-bit systems.
104 if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid() ||
105 T.isOHOSFamily())
106 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
107 else if (T.isOSDarwin() || T.isOSOpenBSD())
108 NewAlign = 128;
109 else
110 NewAlign = 0; // Infer from basic type alignment.
111 HalfWidth = 16;
112 HalfAlign = 16;
113 FloatWidth = 32;
114 FloatAlign = 32;
115 DoubleWidth = 64;
116 DoubleAlign = 64;
117 LongDoubleWidth = 64;
118 LongDoubleAlign = 64;
119 Float128Align = 128;
120 Ibm128Align = 128;
122 LargeArrayAlign = 0;
124 MaxVectorAlign = 0;
125 MaxTLSAlign = 0;
145 HalfFormat = &llvm::APFloat::IEEEhalf();
146 FloatFormat = &llvm::APFloat::IEEEsingle();
147 DoubleFormat = &llvm::APFloat::IEEEdouble();
148 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
149 Float128Format = &llvm::APFloat::IEEEquad();
150 Ibm128Format = &llvm::APFloat::PPCDoubleDouble();
151 MCountName = "mcount";
152 UserLabelPrefix = "_";
153 RegParmMax = 0;
154 SSERegParmMax = 0;
155 HasAlignMac68kSupport = false;
156 HasBuiltinMSVaList = false;
157 HasAArch64SVETypes = false;
158 HasRISCVVTypes = false;
160 HasUnalignedAccess = false;
162
163 // Default to no types using fpret.
165
166 // Default to not using fp2ret for __Complex long double
168
169 // Set the C++ ABI based on the triple.
170 TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment()
171 ? TargetCXXABI::Microsoft
172 : TargetCXXABI::GenericItanium);
173
174 // Default to an empty address space map.
177
178 // Default to an unknown platform name.
179 PlatformName = "unknown";
180 PlatformMinVersion = VersionTuple();
181
183
184 MaxBitIntWidth.reset();
185}
186
187// Out of line virtual dtor for TargetInfo.
189
190void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) {
191 DataLayoutString = DL.str();
192 UserLabelPrefix = ULP;
193}
194
195bool
197 Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
198 return false;
199}
200
202 // if this hook is called, the target should override it to return a
203 // non-default scheme
204 llvm::report_fatal_error("not implemented");
205}
206
208 const CFBranchLabelSchemeKind Scheme, DiagnosticsEngine &Diags) const {
210 Diags.Report(diag::err_opt_not_valid_on_target)
211 << (Twine("mcf-branch-label-scheme=") +
213 .str();
214 return false;
215}
216
217bool
219 Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return";
220 return false;
221}
222
223/// getTypeName - Return the user string for the specified integer type enum.
224/// For example, SignedShort -> "short".
226 switch (T) {
227 default: llvm_unreachable("not an integer!");
228 case SignedChar: return "signed char";
229 case UnsignedChar: return "unsigned char";
230 case SignedShort: return "short";
231 case UnsignedShort: return "unsigned short";
232 case SignedInt: return "int";
233 case UnsignedInt: return "unsigned int";
234 case SignedLong: return "long int";
235 case UnsignedLong: return "long unsigned int";
236 case SignedLongLong: return "long long int";
237 case UnsignedLongLong: return "long long unsigned int";
238 }
239}
240
241/// getTypeConstantSuffix - Return the constant suffix for the specified
242/// integer type enum. For example, SignedLong -> "L".
244 switch (T) {
245 default: llvm_unreachable("not an integer!");
246 case SignedChar:
247 case SignedShort:
248 case SignedInt: return "";
249 case SignedLong: return "L";
250 case SignedLongLong: return "LL";
251 case UnsignedChar:
252 if (getCharWidth() < getIntWidth())
253 return "";
254 [[fallthrough]];
255 case UnsignedShort:
256 if (getShortWidth() < getIntWidth())
257 return "";
258 [[fallthrough]];
259 case UnsignedInt: return "U";
260 case UnsignedLong: return "UL";
261 case UnsignedLongLong: return "ULL";
262 }
263}
264
265/// getTypeFormatModifier - Return the printf format modifier for the
266/// specified integer type enum. For example, SignedLong -> "l".
267
269 switch (T) {
270 default: llvm_unreachable("not an integer!");
271 case SignedChar:
272 case UnsignedChar: return "hh";
273 case SignedShort:
274 case UnsignedShort: return "h";
275 case SignedInt:
276 case UnsignedInt: return "";
277 case SignedLong:
278 case UnsignedLong: return "l";
279 case SignedLongLong:
280 case UnsignedLongLong: return "ll";
281 }
282}
283
284/// getTypeWidth - Return the width (in bits) of the specified integer type
285/// enum. For example, SignedInt -> getIntWidth().
287 switch (T) {
288 default: llvm_unreachable("not an integer!");
289 case SignedChar:
290 case UnsignedChar: return getCharWidth();
291 case SignedShort:
292 case UnsignedShort: return getShortWidth();
293 case SignedInt:
294 case UnsignedInt: return getIntWidth();
295 case SignedLong:
296 case UnsignedLong: return getLongWidth();
297 case SignedLongLong:
298 case UnsignedLongLong: return getLongLongWidth();
299 };
300}
301
303 unsigned BitWidth, bool IsSigned) const {
304 if (getCharWidth() == BitWidth)
305 return IsSigned ? SignedChar : UnsignedChar;
306 if (getShortWidth() == BitWidth)
307 return IsSigned ? SignedShort : UnsignedShort;
308 if (getIntWidth() == BitWidth)
309 return IsSigned ? SignedInt : UnsignedInt;
310 if (getLongWidth() == BitWidth)
311 return IsSigned ? SignedLong : UnsignedLong;
312 if (getLongLongWidth() == BitWidth)
313 return IsSigned ? SignedLongLong : UnsignedLongLong;
314 return NoInt;
315}
316
318 bool IsSigned) const {
319 if (getCharWidth() >= BitWidth)
320 return IsSigned ? SignedChar : UnsignedChar;
321 if (getShortWidth() >= BitWidth)
322 return IsSigned ? SignedShort : UnsignedShort;
323 if (getIntWidth() >= BitWidth)
324 return IsSigned ? SignedInt : UnsignedInt;
325 if (getLongWidth() >= BitWidth)
326 return IsSigned ? SignedLong : UnsignedLong;
327 if (getLongLongWidth() >= BitWidth)
328 return IsSigned ? SignedLongLong : UnsignedLongLong;
329 return NoInt;
330}
331
333 FloatModeKind ExplicitType) const {
334 if (getHalfWidth() == BitWidth)
335 return FloatModeKind::Half;
336 if (getFloatWidth() == BitWidth)
338 if (getDoubleWidth() == BitWidth)
340
341 switch (BitWidth) {
342 case 96:
343 if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
345 break;
346 case 128:
347 // The caller explicitly asked for an IEEE compliant type but we still
348 // have to check if the target supports it.
349 if (ExplicitType == FloatModeKind::Float128)
352 if (ExplicitType == FloatModeKind::Ibm128)
355 if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
356 &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
358 if (hasFloat128Type())
360 break;
361 }
362
364}
365
366/// getTypeAlign - Return the alignment (in bits) of the specified integer type
367/// enum. For example, SignedInt -> getIntAlign().
369 switch (T) {
370 default: llvm_unreachable("not an integer!");
371 case SignedChar:
372 case UnsignedChar: return getCharAlign();
373 case SignedShort:
374 case UnsignedShort: return getShortAlign();
375 case SignedInt:
376 case UnsignedInt: return getIntAlign();
377 case SignedLong:
378 case UnsignedLong: return getLongAlign();
379 case SignedLongLong:
380 case UnsignedLongLong: return getLongLongAlign();
381 };
382}
383
384/// isTypeSigned - Return whether an integer types is signed. Returns true if
385/// the type is signed; false otherwise.
387 switch (T) {
388 default: llvm_unreachable("not an integer!");
389 case SignedChar:
390 case SignedShort:
391 case SignedInt:
392 case SignedLong:
393 case SignedLongLong:
394 return true;
395 case UnsignedChar:
396 case UnsignedShort:
397 case UnsignedInt:
398 case UnsignedLong:
399 case UnsignedLongLong:
400 return false;
401 };
402}
403
404/// adjust - Set forced language options.
405/// Apply changes to the target information with respect to certain
406/// language options which change the target configuration and adjust
407/// the language based on the target options where applicable.
409 if (Opts.NoBitFieldTypeAlign)
411
412 switch (Opts.WCharSize) {
413 default: llvm_unreachable("invalid wchar_t width");
414 case 0: break;
415 case 1: WCharType = Opts.WCharIsSigned ? SignedChar : UnsignedChar; break;
416 case 2: WCharType = Opts.WCharIsSigned ? SignedShort : UnsignedShort; break;
417 case 4: WCharType = Opts.WCharIsSigned ? SignedInt : UnsignedInt; break;
418 }
419
420 if (Opts.AlignDouble) {
422 LongDoubleAlign = 64;
423 }
424
425 // HLSL explicitly defines the sizes and formats of some data types, and we
426 // need to conform to those regardless of what architecture you are targeting.
427 if (Opts.HLSL) {
428 BoolWidth = BoolAlign = 32;
429 LongWidth = LongAlign = 64;
430 if (!Opts.NativeHalfType) {
431 HalfFormat = &llvm::APFloat::IEEEsingle();
432 HalfWidth = HalfAlign = 32;
433 }
434 }
435
436 if (Opts.OpenCL) {
437 // OpenCL C requires specific widths for types, irrespective of
438 // what these normally are for the target.
439 // We also define long long and long double here, although the
440 // OpenCL standard only mentions these as "reserved".
441 ShortWidth = ShortAlign = 16;
442 IntWidth = IntAlign = 32;
443 LongWidth = LongAlign = 64;
445 HalfWidth = HalfAlign = 16;
446 FloatWidth = FloatAlign = 32;
447
448 // Embedded 32-bit targets (OpenCL EP) might have double C type
449 // defined as float. Let's not override this as it might lead
450 // to generating illegal code that uses 64bit doubles.
451 if (DoubleWidth != FloatWidth) {
453 DoubleFormat = &llvm::APFloat::IEEEdouble();
454 }
456
457 unsigned MaxPointerWidth = getMaxPointerWidth();
458 assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
459 bool Is32BitArch = MaxPointerWidth == 32;
460 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
461 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
462 IntPtrType = Is32BitArch ? SignedInt : SignedLong;
463
466
467 HalfFormat = &llvm::APFloat::IEEEhalf();
468 FloatFormat = &llvm::APFloat::IEEEsingle();
469 LongDoubleFormat = &llvm::APFloat::IEEEquad();
470
471 // OpenCL C v3.0 s6.7.5 - The generic address space requires support for
472 // OpenCL C 2.0 or OpenCL C 3.0 with the __opencl_c_generic_address_space
473 // feature
474 // OpenCL C v3.0 s6.2.1 - OpenCL pipes require support of OpenCL C 2.0
475 // or later and __opencl_c_pipes feature
476 // FIXME: These language options are also defined in setLangDefaults()
477 // for OpenCL C 2.0 but with no access to target capabilities. Target
478 // should be immutable once created and thus these language options need
479 // to be defined only once.
480 if (Opts.getOpenCLCompatibleVersion() == 300) {
481 const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
482 Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
483 OpenCLFeaturesMap, "__opencl_c_generic_address_space");
484 Opts.OpenCLPipes =
485 hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes");
486 Opts.Blocks =
487 hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_device_enqueue");
488 }
489 }
490
491 if (Opts.DoubleSize) {
492 if (Opts.DoubleSize == 32) {
493 DoubleWidth = 32;
494 LongDoubleWidth = 32;
495 DoubleFormat = &llvm::APFloat::IEEEsingle();
496 LongDoubleFormat = &llvm::APFloat::IEEEsingle();
497 } else if (Opts.DoubleSize == 64) {
498 DoubleWidth = 64;
499 LongDoubleWidth = 64;
500 DoubleFormat = &llvm::APFloat::IEEEdouble();
501 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
502 }
503 }
504
505 if (Opts.LongDoubleSize) {
506 if (Opts.LongDoubleSize == DoubleWidth) {
510 } else if (Opts.LongDoubleSize == 128) {
512 LongDoubleFormat = &llvm::APFloat::IEEEquad();
513 } else if (Opts.LongDoubleSize == 80) {
514 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
515 if (getTriple().isWindowsMSVCEnvironment()) {
516 LongDoubleWidth = 128;
517 LongDoubleAlign = 128;
518 } else { // Linux
519 if (getTriple().getArch() == llvm::Triple::x86) {
520 LongDoubleWidth = 96;
521 LongDoubleAlign = 32;
522 } else {
523 LongDoubleWidth = 128;
524 LongDoubleAlign = 128;
525 }
526 }
527 }
528 }
529
530 if (Opts.NewAlignOverride)
531 NewAlign = Opts.NewAlignOverride * getCharWidth();
532
533 // Each unsigned fixed point type has the same number of fractional bits as
534 // its corresponding signed type.
535 PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
536 CheckFixedPointBits();
537
538 if (Opts.ProtectParens && !checkArithmeticFenceSupported()) {
539 Diags.Report(diag::err_opt_not_valid_on_target) << "-fprotect-parens";
540 Opts.ProtectParens = false;
541 }
542
543 if (Opts.MaxBitIntWidth)
544 MaxBitIntWidth = static_cast<unsigned>(Opts.MaxBitIntWidth);
545
546 if (Opts.FakeAddressSpaceMap)
548}
549
551 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
552 const std::vector<std::string> &FeatureVec) const {
553 for (const auto &F : FeatureVec) {
554 StringRef Name = F;
555 if (Name.empty())
556 continue;
557 // Apply the feature via the target.
558 if (Name[0] != '+' && Name[0] != '-')
559 Diags.Report(diag::warn_fe_backend_invalid_feature_flag) << Name;
560 else
561 setFeatureEnabled(Features, Name.substr(1), Name[0] == '+');
562 }
563 return true;
564}
565
568 if (Features == "default")
569 return Ret;
570 SmallVector<StringRef, 1> AttrFeatures;
571 Features.split(AttrFeatures, ",");
572
573 // Grab the various features and prepend a "+" to turn on the feature to
574 // the backend and add them to our existing set of features.
575 for (auto &Feature : AttrFeatures) {
576 // Go ahead and trim whitespace rather than either erroring or
577 // accepting it weirdly.
578 Feature = Feature.trim();
579
580 // TODO: Support the fpmath option. It will require checking
581 // overall feature validity for the function with the rest of the
582 // attributes on the function.
583 if (Feature.starts_with("fpmath="))
584 continue;
585
586 if (Feature.starts_with("branch-protection=")) {
587 Ret.BranchProtection = Feature.split('=').second.trim();
588 continue;
589 }
590
591 // While we're here iterating check for a different target cpu.
592 if (Feature.starts_with("arch=")) {
593 if (!Ret.CPU.empty())
594 Ret.Duplicate = "arch=";
595 else
596 Ret.CPU = Feature.split("=").second.trim();
597 } else if (Feature.starts_with("tune=")) {
598 if (!Ret.Tune.empty())
599 Ret.Duplicate = "tune=";
600 else
601 Ret.Tune = Feature.split("=").second.trim();
602 } else if (Feature.starts_with("no-"))
603 Ret.Features.push_back("-" + Feature.split("-").second.str());
604 else
605 Ret.Features.push_back("+" + Feature.str());
606 }
607 return Ret;
608}
609
611TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
612 if (getCXXABI() != TargetCXXABI::Microsoft &&
613 (ClangABICompat4 || getTriple().isPS4()))
614 return CCK_ClangABI4OrPS4;
615 return CCK_Default;
616}
617
619 return LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver15;
620}
621
623 switch (TK) {
624 case OCLTK_Image:
625 case OCLTK_Pipe:
627
628 case OCLTK_Sampler:
630
631 default:
632 return LangAS::Default;
633 }
634}
635
636//===----------------------------------------------------------------------===//
637
638
639static StringRef removeGCCRegisterPrefix(StringRef Name) {
640 if (Name[0] == '%' || Name[0] == '#')
641 Name = Name.substr(1);
642
643 return Name;
644}
645
646/// isValidClobber - Returns whether the passed in string is
647/// a valid clobber in an inline asm statement. This is used by
648/// Sema.
649bool TargetInfo::isValidClobber(StringRef Name) const {
650 return (isValidGCCRegisterName(Name) || Name == "memory" || Name == "cc" ||
651 Name == "unwind");
652}
653
654/// isValidGCCRegisterName - Returns whether the passed in string
655/// is a valid register name according to GCC. This is used by Sema for
656/// inline asm statements.
657bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
658 if (Name.empty())
659 return false;
660
661 // Get rid of any register prefix.
662 Name = removeGCCRegisterPrefix(Name);
663 if (Name.empty())
664 return false;
665
667
668 // If we have a number it maps to an entry in the register name array.
669 if (isDigit(Name[0])) {
670 unsigned n;
671 if (!Name.getAsInteger(0, n))
672 return n < Names.size();
673 }
674
675 // Check register names.
676 if (llvm::is_contained(Names, Name))
677 return true;
678
679 // Check any additional names that we have.
680 for (const AddlRegName &ARN : getGCCAddlRegNames())
681 for (const char *AN : ARN.Names) {
682 if (!AN)
683 break;
684 // Make sure the register that the additional name is for is within
685 // the bounds of the register names from above.
686 if (AN == Name && ARN.RegNum < Names.size())
687 return true;
688 }
689
690 // Now check aliases.
691 for (const GCCRegAlias &GRA : getGCCRegAliases())
692 for (const char *A : GRA.Aliases) {
693 if (!A)
694 break;
695 if (A == Name)
696 return true;
697 }
698
699 return false;
700}
701
703 bool ReturnCanonical) const {
704 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
705
706 // Get rid of any register prefix.
707 Name = removeGCCRegisterPrefix(Name);
708
710
711 // First, check if we have a number.
712 if (isDigit(Name[0])) {
713 unsigned n;
714 if (!Name.getAsInteger(0, n)) {
715 assert(n < Names.size() && "Out of bounds register number!");
716 return Names[n];
717 }
718 }
719
720 // Check any additional names that we have.
721 for (const AddlRegName &ARN : getGCCAddlRegNames())
722 for (const char *AN : ARN.Names) {
723 if (!AN)
724 break;
725 // Make sure the register that the additional name is for is within
726 // the bounds of the register names from above.
727 if (AN == Name && ARN.RegNum < Names.size())
728 return ReturnCanonical ? Names[ARN.RegNum] : Name;
729 }
730
731 // Now check aliases.
732 for (const GCCRegAlias &RA : getGCCRegAliases())
733 for (const char *A : RA.Aliases) {
734 if (!A)
735 break;
736 if (A == Name)
737 return RA.Register;
738 }
739
740 return Name;
741}
742
744 const char *Name = Info.getConstraintStr().c_str();
745 // An output constraint must start with '=' or '+'
746 if (*Name != '=' && *Name != '+')
747 return false;
748
749 if (*Name == '+')
750 Info.setIsReadWrite();
751
752 Name++;
753 while (*Name) {
754 switch (*Name) {
755 default:
756 if (!validateAsmConstraint(Name, Info)) {
757 // FIXME: We temporarily return false
758 // so we can add more constraints as we hit it.
759 // Eventually, an unknown constraint should just be treated as 'g'.
760 return false;
761 }
762 break;
763 case '&': // early clobber.
764 Info.setEarlyClobber();
765 break;
766 case '%': // commutative.
767 // FIXME: Check that there is a another register after this one.
768 break;
769 case 'r': // general register.
770 Info.setAllowsRegister();
771 break;
772 case 'm': // memory operand.
773 case 'o': // offsetable memory operand.
774 case 'V': // non-offsetable memory operand.
775 case '<': // autodecrement memory operand.
776 case '>': // autoincrement memory operand.
777 Info.setAllowsMemory();
778 break;
779 case 'g': // general register, memory operand or immediate integer.
780 case 'X': // any operand.
781 Info.setAllowsRegister();
782 Info.setAllowsMemory();
783 break;
784 case ',': // multiple alternative constraint. Pass it.
785 // Handle additional optional '=' or '+' modifiers.
786 if (Name[1] == '=' || Name[1] == '+')
787 Name++;
788 break;
789 case '#': // Ignore as constraint.
790 while (Name[1] && Name[1] != ',')
791 Name++;
792 break;
793 case '?': // Disparage slightly code.
794 case '!': // Disparage severely.
795 case '*': // Ignore for choosing register preferences.
796 case 'i': // Ignore i,n,E,F as output constraints (match from the other
797 // chars)
798 case 'n':
799 case 'E':
800 case 'F':
801 break; // Pass them.
802 }
803
804 Name++;
805 }
806
807 // Early clobber with a read-write constraint which doesn't permit registers
808 // is invalid.
809 if (Info.earlyClobber() && Info.isReadWrite() && !Info.allowsRegister())
810 return false;
811
812 // If a constraint allows neither memory nor register operands it contains
813 // only modifiers. Reject it.
814 return Info.allowsMemory() || Info.allowsRegister();
815}
816
817bool TargetInfo::resolveSymbolicName(const char *&Name,
818 ArrayRef<ConstraintInfo> OutputConstraints,
819 unsigned &Index) const {
820 assert(*Name == '[' && "Symbolic name did not start with '['");
821 Name++;
822 const char *Start = Name;
823 while (*Name && *Name != ']')
824 Name++;
825
826 if (!*Name) {
827 // Missing ']'
828 return false;
829 }
830
831 std::string SymbolicName(Start, Name - Start);
832
833 for (Index = 0; Index != OutputConstraints.size(); ++Index)
834 if (SymbolicName == OutputConstraints[Index].getName())
835 return true;
836
837 return false;
838}
839
841 MutableArrayRef<ConstraintInfo> OutputConstraints,
842 ConstraintInfo &Info) const {
843 const char *Name = Info.ConstraintStr.c_str();
844
845 if (!*Name)
846 return false;
847
848 while (*Name) {
849 switch (*Name) {
850 default:
851 // Check if we have a matching constraint
852 if (*Name >= '0' && *Name <= '9') {
853 const char *DigitStart = Name;
854 while (Name[1] >= '0' && Name[1] <= '9')
855 Name++;
856 const char *DigitEnd = Name;
857 unsigned i;
858 if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
859 .getAsInteger(10, i))
860 return false;
861
862 // Check if matching constraint is out of bounds.
863 if (i >= OutputConstraints.size()) return false;
864
865 // A number must refer to an output only operand.
866 if (OutputConstraints[i].isReadWrite())
867 return false;
868
869 // If the constraint is already tied, it must be tied to the
870 // same operand referenced to by the number.
871 if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
872 return false;
873
874 // The constraint should have the same info as the respective
875 // output constraint.
876 Info.setTiedOperand(i, OutputConstraints[i]);
877 } else if (!validateAsmConstraint(Name, Info)) {
878 // FIXME: This error return is in place temporarily so we can
879 // add more constraints as we hit it. Eventually, an unknown
880 // constraint should just be treated as 'g'.
881 return false;
882 }
883 break;
884 case '[': {
885 unsigned Index = 0;
886 if (!resolveSymbolicName(Name, OutputConstraints, Index))
887 return false;
888
889 // If the constraint is already tied, it must be tied to the
890 // same operand referenced to by the number.
891 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
892 return false;
893
894 // A number must refer to an output only operand.
895 if (OutputConstraints[Index].isReadWrite())
896 return false;
897
898 Info.setTiedOperand(Index, OutputConstraints[Index]);
899 break;
900 }
901 case '%': // commutative
902 // FIXME: Fail if % is used with the last operand.
903 break;
904 case 'i': // immediate integer.
905 break;
906 case 'n': // immediate integer with a known value.
908 break;
909 case 'I': // Various constant constraints with target-specific meanings.
910 case 'J':
911 case 'K':
912 case 'L':
913 case 'M':
914 case 'N':
915 case 'O':
916 case 'P':
917 if (!validateAsmConstraint(Name, Info))
918 return false;
919 break;
920 case 'r': // general register.
921 Info.setAllowsRegister();
922 break;
923 case 'm': // memory operand.
924 case 'o': // offsettable memory operand.
925 case 'V': // non-offsettable memory operand.
926 case '<': // autodecrement memory operand.
927 case '>': // autoincrement memory operand.
928 Info.setAllowsMemory();
929 break;
930 case 'g': // general register, memory operand or immediate integer.
931 case 'X': // any operand.
932 Info.setAllowsRegister();
933 Info.setAllowsMemory();
934 break;
935 case 'E': // immediate floating point.
936 case 'F': // immediate floating point.
937 case 'p': // address operand.
938 break;
939 case ',': // multiple alternative constraint. Ignore comma.
940 break;
941 case '#': // Ignore as constraint.
942 while (Name[1] && Name[1] != ',')
943 Name++;
944 break;
945 case '?': // Disparage slightly code.
946 case '!': // Disparage severely.
947 case '*': // Ignore for choosing register preferences.
948 break; // Pass them.
949 }
950
951 Name++;
952 }
953
954 return true;
955}
956
957bool TargetInfo::validatePointerAuthKey(const llvm::APSInt &value) const {
958 return false;
959}
960
961void TargetInfo::CheckFixedPointBits() const {
962 // Check that the number of fractional and integral bits (and maybe sign) can
963 // fit into the bits given for a fixed point type.
965 assert(AccumScale + getAccumIBits() + 1 <= AccumWidth);
972
973 assert(getShortFractScale() + 1 <= ShortFractWidth);
974 assert(getFractScale() + 1 <= FractWidth);
975 assert(getLongFractScale() + 1 <= LongFractWidth);
979
980 // Each unsigned fract type has either the same number of fractional bits
981 // as, or one more fractional bit than, its corresponding signed fract type.
984 assert(getFractScale() == getUnsignedFractScale() ||
988
989 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
990 // fractional bits is nondecreasing for each of the following sets of
991 // fixed-point types:
992 // - signed fract types
993 // - unsigned fract types
994 // - signed accum types
995 // - unsigned accum types.
996 assert(getLongFractScale() >= getFractScale() &&
1003
1004 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
1005 // integral bits is nondecreasing for each of the following sets of
1006 // fixed-point types:
1007 // - signed accum types
1008 // - unsigned accum types
1009 assert(getLongAccumIBits() >= getAccumIBits() &&
1013
1014 // Each signed accum type has at least as many integral bits as its
1015 // corresponding unsigned accum type.
1017 assert(getAccumIBits() >= getUnsignedAccumIBits());
1019}
1020
1022 auto *Target = static_cast<TransferrableTargetInfo*>(this);
1023 auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
1024 *Target = *Src;
1025}
Provides definitions for the various language-specific address spaces.
Defines the Diagnostic-related interfaces.
static const LangASMap DefaultAddrSpaceMap
Definition: TargetInfo.cpp:26
static StringRef removeGCCRegisterPrefix(StringRef Name)
Definition: TargetInfo.cpp:639
static const LangASMap FakeAddrSpaceMap
Definition: TargetInfo.cpp:29
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Definition: MachO.h:51
static std::string getName(const CallEvent &Call)
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:231
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1493
@ Ver15
Attempt to be ABI-compatible with code generated by Clang 15.0.x.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:499
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
Definition: LangOptions.cpp:63
void set(Kind kind)
Definition: TargetCXXABI.h:76
Exposes information about the current target.
Definition: TargetInfo.h:220
virtual bool validatePointerAuthKey(const llvm::APSInt &value) const
Determine whether the given pointer-authentication key is valid.
Definition: TargetInfo.cpp:957
unsigned getUnsignedLongFractScale() const
getUnsignedLongFractScale - Return the number of fractional bits in a 'unsigned long _Fract' type.
Definition: TargetInfo.h:659
bool validateInputConstraint(MutableArrayRef< ConstraintInfo > OutputConstraints, ConstraintInfo &info) const
Definition: TargetInfo.cpp:840
virtual ~TargetInfo()
Definition: TargetInfo.cpp:188
bool resolveSymbolicName(const char *&Name, ArrayRef< ConstraintInfo > OutputConstraints, unsigned &Index) const
Definition: TargetInfo.cpp:817
void copyAuxTarget(const TargetInfo *Aux)
Copy type and layout related info.
TargetInfo(const llvm::Triple &T)
Definition: TargetInfo.cpp:54
virtual bool checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const
Check if the target supports CFProtection return.
Definition: TargetInfo.cpp:218
unsigned getShortWidth() const
getShortWidth/Align - Return the size of 'signed short' and 'unsigned short' for this target,...
Definition: TargetInfo.h:514
unsigned getUnsignedAccumScale() const
getUnsignedAccumScale/IBits - Return the number of fractional/integral bits in a 'unsigned _Accum' ty...
Definition: TargetInfo.h:613
unsigned getIntAlign() const
Definition: TargetInfo.h:520
virtual ArrayRef< AddlRegName > getGCCAddlRegNames() const
Definition: TargetInfo.h:1868
unsigned getUnsignedAccumIBits() const
Definition: TargetInfo.h:616
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1262
const LangASMap * AddrSpaceMap
Definition: TargetInfo.h:250
const char * UserLabelPrefix
Definition: TargetInfo.h:246
unsigned getUnsignedFractScale() const
getUnsignedFractScale - Return the number of fractional bits in a 'unsigned _Fract' type.
Definition: TargetInfo.h:653
virtual bool checkCFBranchLabelSchemeSupported(const CFBranchLabelSchemeKind Scheme, DiagnosticsEngine &Diags) const
Definition: TargetInfo.cpp:207
unsigned getLongAlign() const
Definition: TargetInfo.h:525
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
Definition: TargetInfo.cpp:317
unsigned getLongLongAlign() const
Definition: TargetInfo.h:530
virtual bool hasFeatureEnabled(const llvm::StringMap< bool > &Features, StringRef Name) const
Check if target has a given feature enabled.
Definition: TargetInfo.h:1385
virtual CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const
Get the target default CFBranchLabelScheme scheme.
Definition: TargetInfo.cpp:201
unsigned HasAArch64SVETypes
Definition: TargetInfo.h:266
void resetDataLayout(StringRef DL, const char *UserLabelPrefix="")
Definition: TargetInfo.cpp:190
unsigned char RegParmMax
Definition: TargetInfo.h:248
virtual ArrayRef< const char * > getGCCRegNames() const =0
unsigned getTypeWidth(IntType T) const
Return the width (in bits) of the specified integer type enum.
Definition: TargetInfo.cpp:286
unsigned getLongFractScale() const
getLongFractScale - Return the number of fractional bits in a 'signed long _Fract' type.
Definition: TargetInfo.h:642
static bool isTypeSigned(IntType T)
Returns true if the type is signed; false otherwise.
Definition: TargetInfo.cpp:386
std::optional< unsigned > MaxBitIntWidth
Definition: TargetInfo.h:281
virtual void setFeatureEnabled(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled) const
Enable or disable a specific target feature; the feature name must be valid.
Definition: TargetInfo.h:1392
unsigned getAccumIBits() const
Definition: TargetInfo.h:591
virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const
Definition: TargetInfo.cpp:611
VersionTuple PlatformMinVersion
Definition: TargetInfo.h:253
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target,...
Definition: TargetInfo.h:519
const char * MCountName
Definition: TargetInfo.h:247
unsigned getShortAccumIBits() const
Definition: TargetInfo.h:584
unsigned getFloatWidth() const
getFloatWidth/Align/Format - Return the size/align/format of 'float'.
Definition: TargetInfo.h:777
virtual ArrayRef< GCCRegAlias > getGCCRegAliases() const =0
StringRef getNormalizedGCCRegisterName(StringRef Name, bool ReturnCanonical=false) const
Returns the "normalized" GCC register name.
Definition: TargetInfo.cpp:702
unsigned getLongAccumIBits() const
Definition: TargetInfo.h:596
FloatModeKind getRealTypeByWidth(unsigned BitWidth, FloatModeKind ExplicitType) const
Return floating point type with specified width.
Definition: TargetInfo.cpp:332
virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return integer type with specified width.
Definition: TargetInfo.cpp:302
unsigned getHalfWidth() const
getHalfWidth/Align/Format - Return the size/align/format of 'half'.
Definition: TargetInfo.h:772
unsigned char SSERegParmMax
Definition: TargetInfo.h:248
unsigned HasUnalignedAccess
Definition: TargetInfo.h:275
unsigned char MaxAtomicPromoteWidth
Definition: TargetInfo.h:244
virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const
Get address space for OpenCL type.
Definition: TargetInfo.cpp:622
static const char * getTypeName(IntType T)
Return the user string for the specified integer type enum.
Definition: TargetInfo.cpp:225
unsigned getCharAlign() const
Definition: TargetInfo.h:510
unsigned RealTypeUsesObjCFPRetMask
Definition: TargetInfo.h:258
unsigned MaxOpenCLWorkGroupSize
Definition: TargetInfo.h:279
unsigned getLongLongWidth() const
getLongLongWidth/Align - Return the size of 'signed long long' and 'unsigned long long' for this targ...
Definition: TargetInfo.h:529
virtual bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const =0
llvm::StringMap< bool > & getSupportedOpenCLOpts()
Get supported OpenCL extensions and optional core features.
Definition: TargetInfo.h:1779
StringRef PlatformName
Definition: TargetInfo.h:252
bool UseAddrSpaceMapMangling
Specify if mangling based on address space map should be used or not for language specific address sp...
Definition: TargetInfo.h:374
unsigned ComplexLongDoubleUsesFP2Ret
Definition: TargetInfo.h:260
virtual bool hasIbm128Type() const
Determine whether the __ibm128 type is supported on this target.
Definition: TargetInfo.h:718
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts)
Set forced language options.
Definition: TargetInfo.cpp:408
unsigned getUnsignedShortAccumIBits() const
Definition: TargetInfo.h:605
std::string DataLayoutString
Definition: TargetInfo.h:245
unsigned getUnsignedLongAccumScale() const
getUnsignedLongAccumScale/IBits - Return the number of fractional/integral bits in a 'unsigned long _...
Definition: TargetInfo.h:623
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
Definition: TargetInfo.h:703
unsigned getUnsignedLongAccumIBits() const
Definition: TargetInfo.h:626
unsigned getUnsignedShortFractScale() const
getUnsignedShortFractScale - Return the number of fractional bits in a 'unsigned short _Fract' type.
Definition: TargetInfo.h:646
unsigned HasAlignMac68kSupport
Definition: TargetInfo.h:256
const llvm::fltSemantics & getLongDoubleFormat() const
Definition: TargetInfo.h:795
bool validateOutputConstraint(ConstraintInfo &Info) const
Definition: TargetInfo.cpp:743
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1333
const char * getTypeConstantSuffix(IntType T) const
Return the constant suffix for the specified integer type enum.
Definition: TargetInfo.cpp:243
unsigned getDoubleWidth() const
getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
Definition: TargetInfo.h:787
virtual bool checkArithmeticFenceSupported() const
Controls if __arithmetic_fence is supported in the targeted backend.
Definition: TargetInfo.h:1679
bool isValidClobber(StringRef Name) const
Returns whether the passed in string is a valid clobber in an inline asm statement.
Definition: TargetInfo.cpp:649
virtual bool areDefaultedSMFStillPOD(const LangOptions &) const
Controls whether explicitly defaulted (= default) special member functions disqualify something from ...
Definition: TargetInfo.cpp:618
unsigned getCharWidth() const
Definition: TargetInfo.h:509
unsigned HasRISCVVTypes
Definition: TargetInfo.h:269
virtual ParsedTargetAttr parseTargetAttr(StringRef Str) const
Definition: TargetInfo.cpp:566
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target,...
Definition: TargetInfo.h:524
unsigned getFractScale() const
getFractScale - Return the number of fractional bits in a 'signed _Fract' type.
Definition: TargetInfo.h:638
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: TargetInfo.cpp:550
virtual bool checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const
Check if the target supports CFProtection branch.
Definition: TargetInfo.cpp:196
unsigned char MaxAtomicInlineWidth
Definition: TargetInfo.h:244
unsigned AllowAMDGPUUnsafeFPAtomics
Definition: TargetInfo.h:272
unsigned getShortFractScale() const
getShortFractScale - Return the number of fractional bits in a 'signed short _Fract' type.
Definition: TargetInfo.h:634
virtual uint64_t getMaxPointerWidth() const
Return the maximum width of pointers on this target.
Definition: TargetInfo.h:488
TargetCXXABI TheCXXABI
Definition: TargetInfo.h:249
unsigned ARMCDECoprocMask
Definition: TargetInfo.h:277
static const char * getTypeFormatModifier(IntType T)
Return the printf format modifier for the specified integer type enum.
Definition: TargetInfo.cpp:268
unsigned getUnsignedShortAccumScale() const
getUnsignedShortAccumScale/IBits - Return the number of fractional/integral bits in a 'unsigned short...
Definition: TargetInfo.h:602
unsigned HasBuiltinMSVaList
Definition: TargetInfo.h:263
unsigned getTypeAlign(IntType T) const
Return the alignment (in bits) of the specified integer type enum.
Definition: TargetInfo.cpp:368
unsigned getShortAlign() const
Definition: TargetInfo.h:515
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
Definition: TargetInfo.cpp:657
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
unsigned[(unsigned) LangAS::FirstTargetAddressSpace] LangASMap
The type of a lookup table which maps from language-specific address spaces to target-specific ones.
Definition: AddressSpaces.h:73
OpenCLTypeKind
OpenCL type kinds.
Definition: TargetInfo.h:206
@ OCLTK_Image
Definition: TargetInfo.h:210
@ OCLTK_Sampler
Definition: TargetInfo.h:214
@ OCLTK_Pipe
Definition: TargetInfo.h:211
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
Definition: CharInfo.h:114
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
static const char * getCFBranchLabelSchemeFlagVal(const CFBranchLabelSchemeKind Scheme)
FloatModeKind
Definition: TargetInfo.h:73
const FunctionProtoType * T
Contains information gathered from parsing the contents of TargetAttr.
Definition: TargetInfo.h:58
const std::string & getConstraintStr() const
Definition: TargetInfo.h:1122
void setTiedOperand(unsigned N, ConstraintInfo &Output)
Indicate that this is an input operand that is tied to the specified output operand.
Definition: TargetInfo.h:1182
bool hasTiedOperand() const
Return true if this input operand is a matching constraint that ties it to an output operand.
Definition: TargetInfo.h:1138
void setRequiresImmediate(int Min, int Max)
Definition: TargetInfo.h:1159
Fields controlling how types are laid out in memory; these may need to be copied for targets like AMD...
Definition: TargetInfo.h:87
const llvm::fltSemantics * DoubleFormat
Definition: TargetInfo.h:141
unsigned UseZeroLengthBitfieldAlignment
Whether zero length bitfields (e.g., int : 0;) force alignment of the next bitfield.
Definition: TargetInfo.h:185
unsigned UseExplicitBitFieldAlignment
Whether explicit bit field alignment attributes are honored.
Definition: TargetInfo.h:194
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:144
const llvm::fltSemantics * LongDoubleFormat
Definition: TargetInfo.h:141
unsigned ZeroLengthBitfieldBoundary
If non-zero, specifies a fixed alignment value for bitfields that follow zero length bitfield,...
Definition: TargetInfo.h:198
const llvm::fltSemantics * Float128Format
Definition: TargetInfo.h:141
unsigned UseLeadingZeroLengthBitfield
Whether zero length bitfield alignment is respected if they are the leading members.
Definition: TargetInfo.h:190
unsigned UseBitFieldTypeAlignment
Control whether the alignment of bit-field types is respected when laying out structures.
Definition: TargetInfo.h:176
unsigned char LargeArrayMinWidth
Definition: TargetInfo.h:97
unsigned MaxAlignedAttribute
If non-zero, specifies a maximum alignment to truncate alignment specified in the aligned attribute o...
Definition: TargetInfo.h:202
const llvm::fltSemantics * Ibm128Format
Definition: TargetInfo.h:141
const llvm::fltSemantics * FloatFormat
Definition: TargetInfo.h:140
const llvm::fltSemantics * HalfFormat
Definition: TargetInfo.h:140
unsigned UseSignedCharForObjCBool
Whether Objective-C's built-in boolean type should be signed char.
Definition: TargetInfo.h:168
unsigned char DefaultAlignForAttributeAligned
Definition: TargetInfo.h:132