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