Thanks to visit codestin.com
Credit goes to clang.llvm.org

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