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