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