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