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/ADT/StringExtras.h"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/TargetParser/TargetParser.h"
24#include <cstdlib>
25using namespace clang;
26
27static const LangASMap DefaultAddrSpaceMap = {0};
28// The fake address space map must have a distinct entry for each
29// language-specific address space.
31 0, // Default
32 1, // opencl_global
33 3, // opencl_local
34 2, // opencl_constant
35 0, // opencl_private
36 4, // opencl_generic
37 5, // opencl_global_device
38 6, // opencl_global_host
39 7, // cuda_device
40 8, // cuda_constant
41 9, // cuda_shared
42 1, // sycl_global
43 5, // sycl_global_device
44 6, // sycl_global_host
45 3, // sycl_local
46 0, // sycl_private
47 10, // ptr32_sptr
48 11, // ptr32_uptr
49 12, // ptr64
50 13, // hlsl_groupshared
51 14, // hlsl_constant
52 15, // hlsl_private
53 16, // hlsl_device
54 17, // hlsl_input
55 20, // wasm_funcref
56};
57
58// TargetInfo Constructor.
59TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
60 // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
61 // SPARC. These should be overridden by concrete targets as needed.
62 BigEndian = !T.isLittleEndian();
63 TLSSupported = true;
64 VLASupported = true;
65 NoAsmVariants = false;
66 HasFastHalfType = false;
67 HalfArgsAndReturns = false;
68 HasFloat128 = false;
69 HasIbm128 = false;
70 HasFloat16 = false;
71 HasBFloat16 = false;
72 HasFullBFloat16 = false;
73 HasLongDouble = true;
74 HasFPReturn = true;
75 HasStrictFP = false;
77 BoolWidth = BoolAlign = 8;
79 IntWidth = IntAlign = 32;
80 LongWidth = LongAlign = 32;
82 Int128Align = 128;
83
84 // Fixed point default bit widths
91
92 // Fixed point default integral and fractional bit sizes
93 // We give the _Accum 1 fewer fractional bits than their corresponding _Fract
94 // types by default to have the same number of fractional bits between _Accum
95 // and _Fract types.
98 AccumScale = 15;
99 LongAccumScale = 31;
100
101 SuitableAlign = 64;
103 MinGlobalAlign = 0;
104 // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
105 // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
106 // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
107 // This alignment guarantee also applies to Windows and Android. On Darwin
108 // and OpenBSD, the alignment is 16 bytes on both 64-bit and 32-bit systems.
109 if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid() ||
110 T.isOHOSFamily())
111 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
112 else if (T.isOSDarwin() || T.isOSOpenBSD())
113 NewAlign = 128;
114 else
115 NewAlign = 0; // Infer from basic type alignment.
116 HalfWidth = 16;
117 HalfAlign = 16;
118 FloatWidth = 32;
119 FloatAlign = 32;
120 DoubleWidth = 64;
121 DoubleAlign = 64;
122 LongDoubleWidth = 64;
123 LongDoubleAlign = 64;
124 Float128Align = 128;
125 Ibm128Align = 128;
127 LargeArrayAlign = 0;
129 MaxVectorAlign = 0;
130 MaxTLSAlign = 0;
151 HalfFormat = &llvm::APFloat::IEEEhalf();
152 FloatFormat = &llvm::APFloat::IEEEsingle();
153 DoubleFormat = &llvm::APFloat::IEEEdouble();
154 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
155 Float128Format = &llvm::APFloat::IEEEquad();
156 Ibm128Format = &llvm::APFloat::PPCDoubleDouble();
157 MCountName = "mcount";
158 UserLabelPrefix = "_";
159 RegParmMax = 0;
160 SSERegParmMax = 0;
161 HasAlignMac68kSupport = false;
162 HasBuiltinMSVaList = false;
163 HasAArch64ACLETypes = false;
164 HasRISCVVTypes = false;
166 HasUnalignedAccess = false;
168
169 // Default to no types using fpret.
171
172 // Default to not using fp2ret for __Complex long double
174
175 // Set the C++ ABI based on the triple.
176 TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment() || Triple.isUEFI()
177 ? TargetCXXABI::Microsoft
178 : TargetCXXABI::GenericItanium);
179
180 HasMicrosoftRecordLayout = TheCXXABI.isMicrosoft();
181
182 // Default to an empty address space map.
185
186 // Default to an unknown platform name.
187 PlatformName = "unknown";
188 PlatformMinVersion = VersionTuple();
189
191
192 MaxBitIntWidth.reset();
193}
194
195// Out of line virtual dtor for TargetInfo.
197
198void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) {
199 DataLayoutString = DL.str();
200 UserLabelPrefix = ULP;
201}
202
203bool
205 Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
206 return false;
207}
208
210 // if this hook is called, the target should override it to return a
211 // non-default scheme
212 llvm::report_fatal_error("not implemented");
213}
214
216 const CFBranchLabelSchemeKind Scheme, DiagnosticsEngine &Diags) const {
218 Diags.Report(diag::err_opt_not_valid_on_target)
219 << (Twine("mcf-branch-label-scheme=") +
221 .str();
222 return false;
223}
224
225bool
227 Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return";
228 return false;
229}
230
231/// getTypeName - Return the user string for the specified integer type enum.
232/// For example, SignedShort -> "short".
234 switch (T) {
235 default: llvm_unreachable("not an integer!");
236 case SignedChar: return "signed char";
237 case UnsignedChar: return "unsigned char";
238 case SignedShort: return "short";
239 case UnsignedShort: return "unsigned short";
240 case SignedInt: return "int";
241 case UnsignedInt: return "unsigned int";
242 case SignedLong: return "long int";
243 case UnsignedLong: return "long unsigned int";
244 case SignedLongLong: return "long long int";
245 case UnsignedLongLong: return "long long unsigned int";
246 }
247}
248
249/// getTypeConstantSuffix - Return the constant suffix for the specified
250/// integer type enum. For example, SignedLong -> "L".
252 switch (T) {
253 default: llvm_unreachable("not an integer!");
254 case SignedChar:
255 case SignedShort:
256 case SignedInt: return "";
257 case SignedLong: return "L";
258 case SignedLongLong: return "LL";
259 case UnsignedChar:
260 if (getCharWidth() < getIntWidth())
261 return "";
262 [[fallthrough]];
263 case UnsignedShort:
264 if (getShortWidth() < getIntWidth())
265 return "";
266 [[fallthrough]];
267 case UnsignedInt: return "U";
268 case UnsignedLong: return "UL";
269 case UnsignedLongLong: return "ULL";
270 }
271}
272
273/// getTypeFormatModifier - Return the printf format modifier for the
274/// specified integer type enum. For example, SignedLong -> "l".
275
277 switch (T) {
278 default: llvm_unreachable("not an integer!");
279 case SignedChar:
280 case UnsignedChar: return "hh";
281 case SignedShort:
282 case UnsignedShort: return "h";
283 case SignedInt:
284 case UnsignedInt: return "";
285 case SignedLong:
286 case UnsignedLong: return "l";
287 case SignedLongLong:
288 case UnsignedLongLong: return "ll";
289 }
290}
291
292/// getTypeWidth - Return the width (in bits) of the specified integer type
293/// enum. For example, SignedInt -> getIntWidth().
295 switch (T) {
296 default: llvm_unreachable("not an integer!");
297 case SignedChar:
298 case UnsignedChar: return getCharWidth();
299 case SignedShort:
300 case UnsignedShort: return getShortWidth();
301 case SignedInt:
302 case UnsignedInt: return getIntWidth();
303 case SignedLong:
304 case UnsignedLong: return getLongWidth();
305 case SignedLongLong:
306 case UnsignedLongLong: return getLongLongWidth();
307 };
308}
309
311 unsigned BitWidth, bool IsSigned) const {
312 if (getCharWidth() == BitWidth)
313 return IsSigned ? SignedChar : UnsignedChar;
314 if (getShortWidth() == BitWidth)
315 return IsSigned ? SignedShort : UnsignedShort;
316 if (getIntWidth() == BitWidth)
317 return IsSigned ? SignedInt : UnsignedInt;
318 if (getLongWidth() == BitWidth)
319 return IsSigned ? SignedLong : UnsignedLong;
320 if (getLongLongWidth() == BitWidth)
321 return IsSigned ? SignedLongLong : UnsignedLongLong;
322 return NoInt;
323}
324
326 bool IsSigned) const {
327 if (getCharWidth() >= BitWidth)
328 return IsSigned ? SignedChar : UnsignedChar;
329 if (getShortWidth() >= BitWidth)
330 return IsSigned ? SignedShort : UnsignedShort;
331 if (getIntWidth() >= BitWidth)
332 return IsSigned ? SignedInt : UnsignedInt;
333 if (getLongWidth() >= BitWidth)
334 return IsSigned ? SignedLong : UnsignedLong;
335 if (getLongLongWidth() >= BitWidth)
336 return IsSigned ? SignedLongLong : UnsignedLongLong;
337 return NoInt;
338}
339
341 FloatModeKind ExplicitType) const {
342 if (getHalfWidth() == BitWidth)
343 return FloatModeKind::Half;
344 if (getFloatWidth() == BitWidth)
346 if (getDoubleWidth() == BitWidth)
348
349 switch (BitWidth) {
350 case 96:
351 if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
353 break;
354 case 128:
355 // The caller explicitly asked for an IEEE compliant type but we still
356 // have to check if the target supports it.
357 if (ExplicitType == FloatModeKind::Float128)
360 if (ExplicitType == FloatModeKind::Ibm128)
363 if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
364 &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
366 if (hasFloat128Type())
368 break;
369 }
370
372}
373
374/// getTypeAlign - Return the alignment (in bits) of the specified integer type
375/// enum. For example, SignedInt -> getIntAlign().
377 switch (T) {
378 default: llvm_unreachable("not an integer!");
379 case SignedChar:
380 case UnsignedChar: return getCharAlign();
381 case SignedShort:
382 case UnsignedShort: return getShortAlign();
383 case SignedInt:
384 case UnsignedInt: return getIntAlign();
385 case SignedLong:
386 case UnsignedLong: return getLongAlign();
387 case SignedLongLong:
388 case UnsignedLongLong: return getLongLongAlign();
389 };
390}
391
392/// isTypeSigned - Return whether an integer types is signed. Returns true if
393/// the type is signed; false otherwise.
395 switch (T) {
396 default: llvm_unreachable("not an integer!");
397 case SignedChar:
398 case SignedShort:
399 case SignedInt:
400 case SignedLong:
401 case SignedLongLong:
402 return true;
403 case UnsignedChar:
404 case UnsignedShort:
405 case UnsignedInt:
406 case UnsignedLong:
407 case UnsignedLongLong:
408 return false;
409 };
410}
411
412/// adjust - Set forced language options.
413/// Apply changes to the target information with respect to certain
414/// language options which change the target configuration and adjust
415/// the language based on the target options where applicable.
417 const TargetInfo *Aux) {
418 if (Opts.NoBitFieldTypeAlign)
420
421 switch (Opts.WCharSize) {
422 default: llvm_unreachable("invalid wchar_t width");
423 case 0: break;
424 case 1: WCharType = Opts.WCharIsSigned ? SignedChar : UnsignedChar; break;
425 case 2: WCharType = Opts.WCharIsSigned ? SignedShort : UnsignedShort; break;
426 case 4: WCharType = Opts.WCharIsSigned ? SignedInt : UnsignedInt; break;
427 }
428
429 if (Opts.AlignDouble) {
431 LongDoubleAlign = 64;
432 }
433
434 // HLSL explicitly defines the sizes and formats of some data types, and we
435 // need to conform to those regardless of what architecture you are targeting.
436 if (Opts.HLSL) {
437 BoolWidth = BoolAlign = 32;
438 LongWidth = LongAlign = 64;
439 if (!Opts.NativeHalfType) {
440 HalfFormat = &llvm::APFloat::IEEEsingle();
441 HalfWidth = HalfAlign = 32;
442 }
443 }
444
445 if (Opts.OpenCL) {
446 // OpenCL C requires specific widths for types, irrespective of
447 // what these normally are for the target.
448 // We also define long long and long double here, although the
449 // OpenCL standard only mentions these as "reserved".
450 ShortWidth = ShortAlign = 16;
451 IntWidth = IntAlign = 32;
452 LongWidth = LongAlign = 64;
454 HalfWidth = HalfAlign = 16;
455 FloatWidth = FloatAlign = 32;
456
457 // Embedded 32-bit targets (OpenCL EP) might have double C type
458 // defined as float. Let's not override this as it might lead
459 // to generating illegal code that uses 64bit doubles.
460 if (DoubleWidth != FloatWidth) {
462 DoubleFormat = &llvm::APFloat::IEEEdouble();
463 }
465
466 unsigned MaxPointerWidth = getMaxPointerWidth();
467 assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
468 bool Is32BitArch = MaxPointerWidth == 32;
469 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
470 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
471 IntPtrType = Is32BitArch ? SignedInt : SignedLong;
472
475
476 HalfFormat = &llvm::APFloat::IEEEhalf();
477 FloatFormat = &llvm::APFloat::IEEEsingle();
478 LongDoubleFormat = &llvm::APFloat::IEEEquad();
479
480 // OpenCL C v3.0 s6.7.5 - The generic address space requires support for
481 // OpenCL C 2.0 or OpenCL C 3.0 with the __opencl_c_generic_address_space
482 // feature
483 // OpenCL C v3.0 s6.2.1 - OpenCL pipes require support of OpenCL C 2.0
484 // or later and __opencl_c_pipes feature
485 // FIXME: These language options are also defined in setLangDefaults()
486 // for OpenCL C 2.0 but with no access to target capabilities. Target
487 // should be immutable once created and thus these language options need
488 // to be defined only once.
489 if (Opts.getOpenCLCompatibleVersion() == 300) {
490 const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
491 Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
492 OpenCLFeaturesMap, "__opencl_c_generic_address_space");
493 Opts.OpenCLPipes =
494 hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes");
495 Opts.Blocks =
496 hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_device_enqueue");
497 }
498 }
499
500 if (Opts.DoubleSize) {
501 if (Opts.DoubleSize == 32) {
502 DoubleWidth = 32;
503 LongDoubleWidth = 32;
504 DoubleFormat = &llvm::APFloat::IEEEsingle();
505 LongDoubleFormat = &llvm::APFloat::IEEEsingle();
506 } else if (Opts.DoubleSize == 64) {
507 DoubleWidth = 64;
508 LongDoubleWidth = 64;
509 DoubleFormat = &llvm::APFloat::IEEEdouble();
510 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
511 }
512 }
513
514 if (Opts.LongDoubleSize) {
515 if (Opts.LongDoubleSize == DoubleWidth) {
519 } else if (Opts.LongDoubleSize == 128) {
521 LongDoubleFormat = &llvm::APFloat::IEEEquad();
522 } else if (Opts.LongDoubleSize == 80) {
523 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
524 if (getTriple().isWindowsMSVCEnvironment()) {
525 LongDoubleWidth = 128;
526 LongDoubleAlign = 128;
527 } else { // Linux
528 if (getTriple().getArch() == llvm::Triple::x86) {
529 LongDoubleWidth = 96;
530 LongDoubleAlign = 32;
531 } else {
532 LongDoubleWidth = 128;
533 LongDoubleAlign = 128;
534 }
535 }
536 }
537 }
538
539 if (Opts.NewAlignOverride)
540 NewAlign = Opts.NewAlignOverride * getCharWidth();
541
542 // Each unsigned fixed point type has the same number of fractional bits as
543 // its corresponding signed type.
544 PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
545 CheckFixedPointBits();
546
547 if (Opts.ProtectParens && !checkArithmeticFenceSupported()) {
548 Diags.Report(diag::err_opt_not_valid_on_target) << "-fprotect-parens";
549 Opts.ProtectParens = false;
550 }
551
552 if (Opts.MaxBitIntWidth)
553 MaxBitIntWidth = static_cast<unsigned>(Opts.MaxBitIntWidth);
554
555 if (Opts.FakeAddressSpaceMap)
557
558 // Check if it's CUDA device compilation; ensure layout consistency with host.
559 if (Opts.CUDA && Opts.CUDAIsDevice && Aux && !HasMicrosoftRecordLayout)
561}
562
564 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
565 const std::vector<std::string> &FeatureVec) const {
566 for (StringRef Name : FeatureVec) {
567 if (Name.empty())
568 continue;
569 // Apply the feature via the target.
570 if (Name[0] != '+' && Name[0] != '-')
571 Diags.Report(diag::warn_fe_backend_invalid_feature_flag) << Name;
572 else
573 setFeatureEnabled(Features, Name.substr(1), Name[0] == '+');
574 }
575 return true;
576}
577
580 if (Features == "default")
581 return Ret;
582 SmallVector<StringRef, 1> AttrFeatures;
583 Features.split(AttrFeatures, ",");
584
585 // Grab the various features and prepend a "+" to turn on the feature to
586 // the backend and add them to our existing set of features.
587 for (auto &Feature : AttrFeatures) {
588 // Go ahead and trim whitespace rather than either erroring or
589 // accepting it weirdly.
590 Feature = Feature.trim();
591
592 // TODO: Support the fpmath option. It will require checking
593 // overall feature validity for the function with the rest of the
594 // attributes on the function.
595 if (Feature.starts_with("fpmath="))
596 continue;
597
598 if (Feature.starts_with("branch-protection=")) {
599 Ret.BranchProtection = Feature.split('=').second.trim();
600 continue;
601 }
602
603 // While we're here iterating check for a different target cpu.
604 if (Feature.starts_with("arch=")) {
605 if (!Ret.CPU.empty())
606 Ret.Duplicate = "arch=";
607 else
608 Ret.CPU = Feature.split("=").second.trim();
609 } else if (Feature.starts_with("tune=")) {
610 if (!Ret.Tune.empty())
611 Ret.Duplicate = "tune=";
612 else
613 Ret.Tune = Feature.split("=").second.trim();
614 } else if (Feature.starts_with("no-"))
615 Ret.Features.push_back("-" + Feature.split("-").second.str());
616 else
617 Ret.Features.push_back("+" + Feature.str());
618 }
619 return Ret;
620}
621
623TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
624 if (getCXXABI() != TargetCXXABI::Microsoft &&
625 (ClangABICompat4 || getTriple().isPS4()))
626 return CCK_ClangABI4OrPS4;
627 return CCK_Default;
628}
629
631 const LangOptions &LangOpts) const {
632 if (getCXXABI() == TargetCXXABI::Microsoft &&
633 LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver21)
634 return true;
635 return false;
636}
637
639 return LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver15;
640}
641
643 switch (TK) {
644 case OCLTK_Image:
645 case OCLTK_Pipe:
647
648 case OCLTK_Sampler:
650
651 default:
652 return LangAS::Default;
653 }
654}
655
656//===----------------------------------------------------------------------===//
657
658
659static StringRef removeGCCRegisterPrefix(StringRef Name) {
660 if (Name[0] == '%' || Name[0] == '#')
661 Name = Name.substr(1);
662
663 return Name;
664}
665
666/// isValidClobber - Returns whether the passed in string is
667/// a valid clobber in an inline asm statement. This is used by
668/// Sema.
669bool TargetInfo::isValidClobber(StringRef Name) const {
670 return (isValidGCCRegisterName(Name) || Name == "memory" || Name == "cc" ||
671 Name == "unwind");
672}
673
674/// isValidGCCRegisterName - Returns whether the passed in string
675/// is a valid register name according to GCC. This is used by Sema for
676/// inline asm statements.
677bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
678 if (Name.empty())
679 return false;
680
681 // Get rid of any register prefix.
682 Name = removeGCCRegisterPrefix(Name);
683 if (Name.empty())
684 return false;
685
687
688 // If we have a number it maps to an entry in the register name array.
689 if (isDigit(Name[0])) {
690 unsigned n;
691 if (!Name.getAsInteger(0, n))
692 return n < Names.size();
693 }
694
695 // Check register names.
696 if (llvm::is_contained(Names, Name))
697 return true;
698
699 // Check any additional names that we have.
700 for (const AddlRegName &ARN : getGCCAddlRegNames())
701 for (const char *AN : ARN.Names) {
702 if (!AN)
703 break;
704 // Make sure the register that the additional name is for is within
705 // the bounds of the register names from above.
706 if (AN == Name && ARN.RegNum < Names.size())
707 return true;
708 }
709
710 // Now check aliases.
711 for (const GCCRegAlias &GRA : getGCCRegAliases())
712 for (const char *A : GRA.Aliases) {
713 if (!A)
714 break;
715 if (A == Name)
716 return true;
717 }
718
719 return false;
720}
721
723 bool ReturnCanonical) const {
724 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
725
726 // Get rid of any register prefix.
727 Name = removeGCCRegisterPrefix(Name);
728
730
731 // First, check if we have a number.
732 if (isDigit(Name[0])) {
733 unsigned n;
734 if (!Name.getAsInteger(0, n)) {
735 assert(n < Names.size() && "Out of bounds register number!");
736 return Names[n];
737 }
738 }
739
740 // Check any additional names that we have.
741 for (const AddlRegName &ARN : getGCCAddlRegNames())
742 for (const char *AN : ARN.Names) {
743 if (!AN)
744 break;
745 // Make sure the register that the additional name is for is within
746 // the bounds of the register names from above.
747 if (AN == Name && ARN.RegNum < Names.size())
748 return ReturnCanonical ? Names[ARN.RegNum] : Name;
749 }
750
751 // Now check aliases.
752 for (const GCCRegAlias &RA : getGCCRegAliases())
753 for (const char *A : RA.Aliases) {
754 if (!A)
755 break;
756 if (A == Name)
757 return RA.Register;
758 }
759
760 return Name;
761}
762
764 const char *Name = Info.getConstraintStr().c_str();
765 // An output constraint must start with '=' or '+'
766 if (*Name != '=' && *Name != '+')
767 return false;
768
769 if (*Name == '+')
770 Info.setIsReadWrite();
771
772 Name++;
773 while (*Name) {
774 switch (*Name) {
775 default:
776 if (!validateAsmConstraint(Name, Info)) {
777 // FIXME: We temporarily return false
778 // so we can add more constraints as we hit it.
779 // Eventually, an unknown constraint should just be treated as 'g'.
780 return false;
781 }
782 break;
783 case '&': // early clobber.
784 Info.setEarlyClobber();
785 break;
786 case '%': // commutative.
787 // FIXME: Check that there is a another register after this one.
788 break;
789 case 'r': // general register.
790 Info.setAllowsRegister();
791 break;
792 case 'm': // memory operand.
793 case 'o': // offsetable memory operand.
794 case 'V': // non-offsetable memory operand.
795 case '<': // autodecrement memory operand.
796 case '>': // autoincrement memory operand.
797 Info.setAllowsMemory();
798 break;
799 case 'g': // general register, memory operand or immediate integer.
800 case 'X': // any operand.
801 Info.setAllowsRegister();
802 Info.setAllowsMemory();
803 break;
804 case ',': // multiple alternative constraint. Pass it.
805 // Handle additional optional '=' or '+' modifiers.
806 if (Name[1] == '=' || Name[1] == '+')
807 Name++;
808 break;
809 case '#': // Ignore as constraint.
810 while (Name[1] && Name[1] != ',')
811 Name++;
812 break;
813 case '?': // Disparage slightly code.
814 case '!': // Disparage severely.
815 case '*': // Ignore for choosing register preferences.
816 case 'i': // Ignore i,n,E,F as output constraints (match from the other
817 // chars)
818 case 'n':
819 case 'E':
820 case 'F':
821 break; // Pass them.
822 }
823
824 Name++;
825 }
826
827 // Early clobber with a read-write constraint which doesn't permit registers
828 // is invalid.
829 if (Info.earlyClobber() && Info.isReadWrite() && !Info.allowsRegister())
830 return false;
831
832 // If a constraint allows neither memory nor register operands it contains
833 // only modifiers. Reject it.
834 return Info.allowsMemory() || Info.allowsRegister();
835}
836
837bool TargetInfo::resolveSymbolicName(const char *&Name,
838 ArrayRef<ConstraintInfo> OutputConstraints,
839 unsigned &Index) const {
840 assert(*Name == '[' && "Symbolic name did not start with '['");
841 Name++;
842 const char *Start = Name;
843 while (*Name && *Name != ']')
844 Name++;
845
846 if (!*Name) {
847 // Missing ']'
848 return false;
849 }
850
851 std::string SymbolicName(Start, Name - Start);
852
853 for (Index = 0; Index != OutputConstraints.size(); ++Index)
854 if (SymbolicName == OutputConstraints[Index].getName())
855 return true;
856
857 return false;
858}
859
861 MutableArrayRef<ConstraintInfo> OutputConstraints,
862 ConstraintInfo &Info) const {
863 const char *Name = Info.ConstraintStr.c_str();
864
865 if (!*Name)
866 return false;
867
868 while (*Name) {
869 switch (*Name) {
870 default:
871 // Check if we have a matching constraint
872 if (*Name >= '0' && *Name <= '9') {
873 const char *DigitStart = Name;
874 while (Name[1] >= '0' && Name[1] <= '9')
875 Name++;
876 const char *DigitEnd = Name;
877 unsigned i;
878 if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
879 .getAsInteger(10, i))
880 return false;
881
882 // Check if matching constraint is out of bounds.
883 if (i >= OutputConstraints.size()) return false;
884
885 // A number must refer to an output only operand.
886 if (OutputConstraints[i].isReadWrite())
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() != i)
892 return false;
893
894 // The constraint should have the same info as the respective
895 // output constraint.
896 Info.setTiedOperand(i, OutputConstraints[i]);
897 } else if (!validateAsmConstraint(Name, Info)) {
898 // FIXME: This error return is in place temporarily so we can
899 // add more constraints as we hit it. Eventually, an unknown
900 // constraint should just be treated as 'g'.
901 return false;
902 }
903 break;
904 case '[': {
905 unsigned Index = 0;
906 if (!resolveSymbolicName(Name, OutputConstraints, Index))
907 return false;
908
909 // If the constraint is already tied, it must be tied to the
910 // same operand referenced to by the number.
911 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
912 return false;
913
914 // A number must refer to an output only operand.
915 if (OutputConstraints[Index].isReadWrite())
916 return false;
917
918 Info.setTiedOperand(Index, OutputConstraints[Index]);
919 break;
920 }
921 case '%': // commutative
922 // FIXME: Fail if % is used with the last operand.
923 break;
924 case 'i': // immediate integer.
925 break;
926 case 'n': // immediate integer with a known value.
928 break;
929 case 'I': // Various constant constraints with target-specific meanings.
930 case 'J':
931 case 'K':
932 case 'L':
933 case 'M':
934 case 'N':
935 case 'O':
936 case 'P':
937 if (!validateAsmConstraint(Name, Info))
938 return false;
939 break;
940 case 'r': // general register.
941 Info.setAllowsRegister();
942 break;
943 case 'm': // memory operand.
944 case 'o': // offsettable memory operand.
945 case 'V': // non-offsettable memory operand.
946 case '<': // autodecrement memory operand.
947 case '>': // autoincrement memory operand.
948 Info.setAllowsMemory();
949 break;
950 case 'g': // general register, memory operand or immediate integer.
951 case 'X': // any operand.
952 Info.setAllowsRegister();
953 Info.setAllowsMemory();
954 break;
955 case 'E': // immediate floating point.
956 case 'F': // immediate floating point.
957 case 'p': // address operand.
958 break;
959 case ',': // multiple alternative constraint. Ignore comma.
960 break;
961 case '#': // Ignore as constraint.
962 while (Name[1] && Name[1] != ',')
963 Name++;
964 break;
965 case '?': // Disparage slightly code.
966 case '!': // Disparage severely.
967 case '*': // Ignore for choosing register preferences.
968 break; // Pass them.
969 }
970
971 Name++;
972 }
973
974 return true;
975}
976
977bool TargetInfo::validatePointerAuthKey(const llvm::APSInt &value) const {
978 return false;
979}
980
981void TargetInfo::CheckFixedPointBits() const {
982 // Check that the number of fractional and integral bits (and maybe sign) can
983 // fit into the bits given for a fixed point type.
985 assert(AccumScale + getAccumIBits() + 1 <= AccumWidth);
992
993 assert(getShortFractScale() + 1 <= ShortFractWidth);
994 assert(getFractScale() + 1 <= FractWidth);
995 assert(getLongFractScale() + 1 <= LongFractWidth);
999
1000 // Each unsigned fract type has either the same number of fractional bits
1001 // as, or one more fractional bit than, its corresponding signed fract type.
1004 assert(getFractScale() == getUnsignedFractScale() ||
1008
1009 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
1010 // fractional bits is nondecreasing for each of the following sets of
1011 // fixed-point types:
1012 // - signed fract types
1013 // - unsigned fract types
1014 // - signed accum types
1015 // - unsigned accum types.
1016 assert(getLongFractScale() >= getFractScale() &&
1023
1024 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
1025 // integral bits is nondecreasing for each of the following sets of
1026 // fixed-point types:
1027 // - signed accum types
1028 // - unsigned accum types
1029 assert(getLongAccumIBits() >= getAccumIBits() &&
1033
1034 // Each signed accum type has at least as many integral bits as its
1035 // corresponding unsigned accum type.
1037 assert(getAccumIBits() >= getUnsignedAccumIBits());
1039}
1040
1042 auto *Target = static_cast<TransferrableTargetInfo*>(this);
1043 auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
1044 *Target = *Src;
1045}
1046
1047std::string
1049 SmallVectorImpl<ConstraintInfo> *OutCons) const {
1050 std::string Result;
1051
1052 for (const char *I = Constraint.begin(), *E = Constraint.end(); I < E; I++) {
1053 switch (*I) {
1054 default:
1056 break;
1057 // Ignore these
1058 case '*':
1059 case '?':
1060 case '!':
1061 case '=': // Will see this and the following in mult-alt constraints.
1062 case '+':
1063 break;
1064 case '#': // Ignore the rest of the constraint alternative.
1065 while (I + 1 != E && I[1] != ',')
1066 I++;
1067 break;
1068 case '&':
1069 case '%':
1070 Result += *I;
1071 while (I + 1 != E && I[1] == *I)
1072 I++;
1073 break;
1074 case ',':
1075 Result += "|";
1076 break;
1077 case 'g':
1078 Result += "imr";
1079 break;
1080 case '[': {
1081 assert(OutCons &&
1082 "Must pass output names to constraints with a symbolic name");
1083 unsigned Index;
1084 bool ResolveResult = resolveSymbolicName(I, *OutCons, Index);
1085 assert(ResolveResult && "Could not resolve symbolic name");
1086 (void)ResolveResult;
1087 Result += llvm::utostr(Index);
1088 break;
1089 }
1090 }
1091 }
1092 return Result;
1093}
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
std::string simplifyConstraint(StringRef Constraint, SmallVectorImpl< ConstraintInfo > *OutCons=nullptr) 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.
virtual std::string convertConstraint(const char *&Constraint) const
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
@ Result
The result type of a method or function.
Definition TypeBase.h:905
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