1 //===--- TargetInfo.cpp - Information about Target machine ----------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the TargetInfo and TargetInfoImpl interfaces.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Basic/TargetInfo.h"
14 #include "clang/Basic/AddressSpaces.h"
15 #include "clang/Basic/CharInfo.h"
16 #include "clang/Basic/Diagnostic.h"
17 #include "clang/Basic/LangOptions.h"
18 #include "llvm/ADT/APFloat.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/TargetParser.h"
23 using namespace clang
;
25 static const LangASMap DefaultAddrSpaceMap
= {0};
27 // TargetInfo Constructor.
28 TargetInfo::TargetInfo(const llvm::Triple
&T
) : Triple(T
) {
29 // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
30 // SPARC. These should be overridden by concrete targets as needed.
31 BigEndian
= !T
.isLittleEndian();
34 NoAsmVariants
= false;
35 HasLegalHalfType
= false;
43 PointerWidth
= PointerAlign
= 32;
44 BoolWidth
= BoolAlign
= 8;
45 IntWidth
= IntAlign
= 32;
46 LongWidth
= LongAlign
= 32;
47 LongLongWidth
= LongLongAlign
= 64;
50 // Fixed point default bit widths
51 ShortAccumWidth
= ShortAccumAlign
= 16;
52 AccumWidth
= AccumAlign
= 32;
53 LongAccumWidth
= LongAccumAlign
= 64;
54 ShortFractWidth
= ShortFractAlign
= 8;
55 FractWidth
= FractAlign
= 16;
56 LongFractWidth
= LongFractAlign
= 32;
58 // Fixed point default integral and fractional bit sizes
59 // We give the _Accum 1 fewer fractional bits than their corresponding _Fract
60 // types by default to have the same number of fractional bits between _Accum
62 PaddingOnUnsignedFixedPoint
= false;
68 DefaultAlignForAttributeAligned
= 128;
70 // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
71 // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
72 // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
73 // This alignment guarantee also applies to Windows and Android. On Darwin
74 // and OpenBSD, the alignment is 16 bytes on both 64-bit and 32-bit systems.
75 if (T
.isGNUEnvironment() || T
.isWindowsMSVCEnvironment() || T
.isAndroid())
76 NewAlign
= Triple
.isArch64Bit() ? 128 : Triple
.isArch32Bit() ? 64 : 0;
77 else if (T
.isOSDarwin() || T
.isOSOpenBSD())
80 NewAlign
= 0; // Infer from basic type alignment.
91 LargeArrayMinWidth
= 0;
93 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 0;
97 SizeType
= UnsignedLong
;
98 PtrDiffType
= SignedLong
;
99 IntMaxType
= SignedLongLong
;
100 IntPtrType
= SignedLong
;
101 WCharType
= SignedInt
;
102 WIntType
= SignedInt
;
103 Char16Type
= UnsignedShort
;
104 Char32Type
= UnsignedInt
;
105 Int64Type
= SignedLongLong
;
106 Int16Type
= SignedShort
;
107 SigAtomicType
= SignedInt
;
108 ProcessIDType
= SignedInt
;
109 UseSignedCharForObjCBool
= true;
110 UseBitFieldTypeAlignment
= true;
111 UseZeroLengthBitfieldAlignment
= false;
112 UseLeadingZeroLengthBitfield
= true;
113 UseExplicitBitFieldAlignment
= true;
114 ZeroLengthBitfieldBoundary
= 0;
115 MaxAlignedAttribute
= 0;
116 HalfFormat
= &llvm::APFloat::IEEEhalf();
117 FloatFormat
= &llvm::APFloat::IEEEsingle();
118 DoubleFormat
= &llvm::APFloat::IEEEdouble();
119 LongDoubleFormat
= &llvm::APFloat::IEEEdouble();
120 Float128Format
= &llvm::APFloat::IEEEquad();
121 Ibm128Format
= &llvm::APFloat::PPCDoubleDouble();
122 MCountName
= "mcount";
123 UserLabelPrefix
= "_";
126 HasAlignMac68kSupport
= false;
127 HasBuiltinMSVaList
= false;
128 IsRenderScriptTarget
= false;
129 HasAArch64SVETypes
= false;
130 HasRISCVVTypes
= false;
131 AllowAMDGPUUnsafeFPAtomics
= false;
132 ARMCDECoprocMask
= 0;
134 // Default to no types using fpret.
135 RealTypeUsesObjCFPRetMask
= 0;
137 // Default to not using fp2ret for __Complex long double
138 ComplexLongDoubleUsesFP2Ret
= false;
140 // Set the C++ ABI based on the triple.
141 TheCXXABI
.set(Triple
.isKnownWindowsMSVCEnvironment()
142 ? TargetCXXABI::Microsoft
143 : TargetCXXABI::GenericItanium
);
145 // Default to an empty address space map.
146 AddrSpaceMap
= &DefaultAddrSpaceMap
;
147 UseAddrSpaceMapMangling
= false;
149 // Default to an unknown platform name.
150 PlatformName
= "unknown";
151 PlatformMinVersion
= VersionTuple();
153 MaxOpenCLWorkGroupSize
= 1024;
155 MaxBitIntWidth
.reset();
157 ProgramAddrSpace
= 0;
160 // Out of line virtual dtor for TargetInfo.
161 TargetInfo::~TargetInfo() {}
163 void TargetInfo::resetDataLayout(StringRef DL
, const char *ULP
) {
164 DataLayoutString
= DL
.str();
165 UserLabelPrefix
= ULP
;
169 TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine
&Diags
) const {
170 Diags
.Report(diag::err_opt_not_valid_on_target
) << "cf-protection=branch";
175 TargetInfo::checkCFProtectionReturnSupported(DiagnosticsEngine
&Diags
) const {
176 Diags
.Report(diag::err_opt_not_valid_on_target
) << "cf-protection=return";
180 /// getTypeName - Return the user string for the specified integer type enum.
181 /// For example, SignedShort -> "short".
182 const char *TargetInfo::getTypeName(IntType T
) {
184 default: llvm_unreachable("not an integer!");
185 case SignedChar
: return "signed char";
186 case UnsignedChar
: return "unsigned char";
187 case SignedShort
: return "short";
188 case UnsignedShort
: return "unsigned short";
189 case SignedInt
: return "int";
190 case UnsignedInt
: return "unsigned int";
191 case SignedLong
: return "long int";
192 case UnsignedLong
: return "long unsigned int";
193 case SignedLongLong
: return "long long int";
194 case UnsignedLongLong
: return "long long unsigned int";
198 /// getTypeConstantSuffix - Return the constant suffix for the specified
199 /// integer type enum. For example, SignedLong -> "L".
200 const char *TargetInfo::getTypeConstantSuffix(IntType T
) const {
202 default: llvm_unreachable("not an integer!");
205 case SignedInt
: return "";
206 case SignedLong
: return "L";
207 case SignedLongLong
: return "LL";
209 if (getCharWidth() < getIntWidth())
213 if (getShortWidth() < getIntWidth())
216 case UnsignedInt
: return "U";
217 case UnsignedLong
: return "UL";
218 case UnsignedLongLong
: return "ULL";
222 /// getTypeFormatModifier - Return the printf format modifier for the
223 /// specified integer type enum. For example, SignedLong -> "l".
225 const char *TargetInfo::getTypeFormatModifier(IntType T
) {
227 default: llvm_unreachable("not an integer!");
229 case UnsignedChar
: return "hh";
231 case UnsignedShort
: return "h";
233 case UnsignedInt
: return "";
235 case UnsignedLong
: return "l";
237 case UnsignedLongLong
: return "ll";
241 /// getTypeWidth - Return the width (in bits) of the specified integer type
242 /// enum. For example, SignedInt -> getIntWidth().
243 unsigned TargetInfo::getTypeWidth(IntType T
) const {
245 default: llvm_unreachable("not an integer!");
247 case UnsignedChar
: return getCharWidth();
249 case UnsignedShort
: return getShortWidth();
251 case UnsignedInt
: return getIntWidth();
253 case UnsignedLong
: return getLongWidth();
255 case UnsignedLongLong
: return getLongLongWidth();
259 TargetInfo::IntType
TargetInfo::getIntTypeByWidth(
260 unsigned BitWidth
, bool IsSigned
) const {
261 if (getCharWidth() == BitWidth
)
262 return IsSigned
? SignedChar
: UnsignedChar
;
263 if (getShortWidth() == BitWidth
)
264 return IsSigned
? SignedShort
: UnsignedShort
;
265 if (getIntWidth() == BitWidth
)
266 return IsSigned
? SignedInt
: UnsignedInt
;
267 if (getLongWidth() == BitWidth
)
268 return IsSigned
? SignedLong
: UnsignedLong
;
269 if (getLongLongWidth() == BitWidth
)
270 return IsSigned
? SignedLongLong
: UnsignedLongLong
;
274 TargetInfo::IntType
TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth
,
275 bool IsSigned
) const {
276 if (getCharWidth() >= BitWidth
)
277 return IsSigned
? SignedChar
: UnsignedChar
;
278 if (getShortWidth() >= BitWidth
)
279 return IsSigned
? SignedShort
: UnsignedShort
;
280 if (getIntWidth() >= BitWidth
)
281 return IsSigned
? SignedInt
: UnsignedInt
;
282 if (getLongWidth() >= BitWidth
)
283 return IsSigned
? SignedLong
: UnsignedLong
;
284 if (getLongLongWidth() >= BitWidth
)
285 return IsSigned
? SignedLongLong
: UnsignedLongLong
;
289 FloatModeKind
TargetInfo::getRealTypeByWidth(unsigned BitWidth
,
290 FloatModeKind ExplicitType
) const {
291 if (getHalfWidth() == BitWidth
)
292 return FloatModeKind::Half
;
293 if (getFloatWidth() == BitWidth
)
294 return FloatModeKind::Float
;
295 if (getDoubleWidth() == BitWidth
)
296 return FloatModeKind::Double
;
300 if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
301 return FloatModeKind::LongDouble
;
304 // The caller explicitly asked for an IEEE compliant type but we still
305 // have to check if the target supports it.
306 if (ExplicitType
== FloatModeKind::Float128
)
307 return hasFloat128Type() ? FloatModeKind::Float128
308 : FloatModeKind::NoFloat
;
309 if (ExplicitType
== FloatModeKind::Ibm128
)
310 return hasIbm128Type() ? FloatModeKind::Ibm128
311 : FloatModeKind::NoFloat
;
312 if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
313 &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
314 return FloatModeKind::LongDouble
;
315 if (hasFloat128Type())
316 return FloatModeKind::Float128
;
320 return FloatModeKind::NoFloat
;
323 /// getTypeAlign - Return the alignment (in bits) of the specified integer type
324 /// enum. For example, SignedInt -> getIntAlign().
325 unsigned TargetInfo::getTypeAlign(IntType T
) const {
327 default: llvm_unreachable("not an integer!");
329 case UnsignedChar
: return getCharAlign();
331 case UnsignedShort
: return getShortAlign();
333 case UnsignedInt
: return getIntAlign();
335 case UnsignedLong
: return getLongAlign();
337 case UnsignedLongLong
: return getLongLongAlign();
341 /// isTypeSigned - Return whether an integer types is signed. Returns true if
342 /// the type is signed; false otherwise.
343 bool TargetInfo::isTypeSigned(IntType T
) {
345 default: llvm_unreachable("not an integer!");
356 case UnsignedLongLong
:
361 /// adjust - Set forced language options.
362 /// Apply changes to the target information with respect to certain
363 /// language options which change the target configuration and adjust
364 /// the language based on the target options where applicable.
365 void TargetInfo::adjust(DiagnosticsEngine
&Diags
, LangOptions
&Opts
) {
366 if (Opts
.NoBitFieldTypeAlign
)
367 UseBitFieldTypeAlignment
= false;
369 switch (Opts
.WCharSize
) {
370 default: llvm_unreachable("invalid wchar_t width");
372 case 1: WCharType
= Opts
.WCharIsSigned
? SignedChar
: UnsignedChar
; break;
373 case 2: WCharType
= Opts
.WCharIsSigned
? SignedShort
: UnsignedShort
; break;
374 case 4: WCharType
= Opts
.WCharIsSigned
? SignedInt
: UnsignedInt
; break;
377 if (Opts
.AlignDouble
) {
378 DoubleAlign
= LongLongAlign
= 64;
379 LongDoubleAlign
= 64;
383 // OpenCL C requires specific widths for types, irrespective of
384 // what these normally are for the target.
385 // We also define long long and long double here, although the
386 // OpenCL standard only mentions these as "reserved".
387 IntWidth
= IntAlign
= 32;
388 LongWidth
= LongAlign
= 64;
389 LongLongWidth
= LongLongAlign
= 128;
390 HalfWidth
= HalfAlign
= 16;
391 FloatWidth
= FloatAlign
= 32;
393 // Embedded 32-bit targets (OpenCL EP) might have double C type
394 // defined as float. Let's not override this as it might lead
395 // to generating illegal code that uses 64bit doubles.
396 if (DoubleWidth
!= FloatWidth
) {
397 DoubleWidth
= DoubleAlign
= 64;
398 DoubleFormat
= &llvm::APFloat::IEEEdouble();
400 LongDoubleWidth
= LongDoubleAlign
= 128;
402 unsigned MaxPointerWidth
= getMaxPointerWidth();
403 assert(MaxPointerWidth
== 32 || MaxPointerWidth
== 64);
404 bool Is32BitArch
= MaxPointerWidth
== 32;
405 SizeType
= Is32BitArch
? UnsignedInt
: UnsignedLong
;
406 PtrDiffType
= Is32BitArch
? SignedInt
: SignedLong
;
407 IntPtrType
= Is32BitArch
? SignedInt
: SignedLong
;
409 IntMaxType
= SignedLongLong
;
410 Int64Type
= SignedLong
;
412 HalfFormat
= &llvm::APFloat::IEEEhalf();
413 FloatFormat
= &llvm::APFloat::IEEEsingle();
414 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
416 // OpenCL C v3.0 s6.7.5 - The generic address space requires support for
417 // OpenCL C 2.0 or OpenCL C 3.0 with the __opencl_c_generic_address_space
419 // OpenCL C v3.0 s6.2.1 - OpenCL pipes require support of OpenCL C 2.0
420 // or later and __opencl_c_pipes feature
421 // FIXME: These language options are also defined in setLangDefaults()
422 // for OpenCL C 2.0 but with no access to target capabilities. Target
423 // should be immutable once created and thus these language options need
424 // to be defined only once.
425 if (Opts
.getOpenCLCompatibleVersion() == 300) {
426 const auto &OpenCLFeaturesMap
= getSupportedOpenCLOpts();
427 Opts
.OpenCLGenericAddressSpace
= hasFeatureEnabled(
428 OpenCLFeaturesMap
, "__opencl_c_generic_address_space");
430 hasFeatureEnabled(OpenCLFeaturesMap
, "__opencl_c_pipes");
432 hasFeatureEnabled(OpenCLFeaturesMap
, "__opencl_c_device_enqueue");
436 if (Opts
.DoubleSize
) {
437 if (Opts
.DoubleSize
== 32) {
439 LongDoubleWidth
= 32;
440 DoubleFormat
= &llvm::APFloat::IEEEsingle();
441 LongDoubleFormat
= &llvm::APFloat::IEEEsingle();
442 } else if (Opts
.DoubleSize
== 64) {
444 LongDoubleWidth
= 64;
445 DoubleFormat
= &llvm::APFloat::IEEEdouble();
446 LongDoubleFormat
= &llvm::APFloat::IEEEdouble();
450 if (Opts
.LongDoubleSize
) {
451 if (Opts
.LongDoubleSize
== DoubleWidth
) {
452 LongDoubleWidth
= DoubleWidth
;
453 LongDoubleAlign
= DoubleAlign
;
454 LongDoubleFormat
= DoubleFormat
;
455 } else if (Opts
.LongDoubleSize
== 128) {
456 LongDoubleWidth
= LongDoubleAlign
= 128;
457 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
458 } else if (Opts
.LongDoubleSize
== 80) {
459 LongDoubleFormat
= &llvm::APFloat::x87DoubleExtended();
460 if (getTriple().isWindowsMSVCEnvironment()) {
461 LongDoubleWidth
= 128;
462 LongDoubleAlign
= 128;
464 if (getTriple().getArch() == llvm::Triple::x86
) {
465 LongDoubleWidth
= 96;
466 LongDoubleAlign
= 32;
468 LongDoubleWidth
= 128;
469 LongDoubleAlign
= 128;
475 if (Opts
.NewAlignOverride
)
476 NewAlign
= Opts
.NewAlignOverride
* getCharWidth();
478 // Each unsigned fixed point type has the same number of fractional bits as
479 // its corresponding signed type.
480 PaddingOnUnsignedFixedPoint
|= Opts
.PaddingOnUnsignedFixedPoint
;
481 CheckFixedPointBits();
483 if (Opts
.ProtectParens
&& !checkArithmeticFenceSupported()) {
484 Diags
.Report(diag::err_opt_not_valid_on_target
) << "-fprotect-parens";
485 Opts
.ProtectParens
= false;
488 if (Opts
.MaxBitIntWidth
)
489 MaxBitIntWidth
= Opts
.MaxBitIntWidth
;
492 bool TargetInfo::initFeatureMap(
493 llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
, StringRef CPU
,
494 const std::vector
<std::string
> &FeatureVec
) const {
495 for (const auto &F
: FeatureVec
) {
497 // Apply the feature via the target.
498 bool Enabled
= Name
[0] == '+';
499 setFeatureEnabled(Features
, Name
.substr(1), Enabled
);
504 TargetInfo::CallingConvKind
505 TargetInfo::getCallingConvKind(bool ClangABICompat4
) const {
506 if (getCXXABI() != TargetCXXABI::Microsoft
&&
507 (ClangABICompat4
|| getTriple().isPS4()))
508 return CCK_ClangABI4OrPS4
;
512 LangAS
TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK
) const {
516 return LangAS::opencl_global
;
519 return LangAS::opencl_constant
;
522 return LangAS::Default
;
526 //===----------------------------------------------------------------------===//
529 static StringRef
removeGCCRegisterPrefix(StringRef Name
) {
530 if (Name
[0] == '%' || Name
[0] == '#')
531 Name
= Name
.substr(1);
536 /// isValidClobber - Returns whether the passed in string is
537 /// a valid clobber in an inline asm statement. This is used by
539 bool TargetInfo::isValidClobber(StringRef Name
) const {
540 return (isValidGCCRegisterName(Name
) || Name
== "memory" || Name
== "cc" ||
544 /// isValidGCCRegisterName - Returns whether the passed in string
545 /// is a valid register name according to GCC. This is used by Sema for
546 /// inline asm statements.
547 bool TargetInfo::isValidGCCRegisterName(StringRef Name
) const {
551 // Get rid of any register prefix.
552 Name
= removeGCCRegisterPrefix(Name
);
556 ArrayRef
<const char *> Names
= getGCCRegNames();
558 // If we have a number it maps to an entry in the register name array.
559 if (isDigit(Name
[0])) {
561 if (!Name
.getAsInteger(0, n
))
562 return n
< Names
.size();
565 // Check register names.
566 if (llvm::is_contained(Names
, Name
))
569 // Check any additional names that we have.
570 for (const AddlRegName
&ARN
: getGCCAddlRegNames())
571 for (const char *AN
: ARN
.Names
) {
574 // Make sure the register that the additional name is for is within
575 // the bounds of the register names from above.
576 if (AN
== Name
&& ARN
.RegNum
< Names
.size())
580 // Now check aliases.
581 for (const GCCRegAlias
&GRA
: getGCCRegAliases())
582 for (const char *A
: GRA
.Aliases
) {
592 StringRef
TargetInfo::getNormalizedGCCRegisterName(StringRef Name
,
593 bool ReturnCanonical
) const {
594 assert(isValidGCCRegisterName(Name
) && "Invalid register passed in");
596 // Get rid of any register prefix.
597 Name
= removeGCCRegisterPrefix(Name
);
599 ArrayRef
<const char *> Names
= getGCCRegNames();
601 // First, check if we have a number.
602 if (isDigit(Name
[0])) {
604 if (!Name
.getAsInteger(0, n
)) {
605 assert(n
< Names
.size() && "Out of bounds register number!");
610 // Check any additional names that we have.
611 for (const AddlRegName
&ARN
: getGCCAddlRegNames())
612 for (const char *AN
: ARN
.Names
) {
615 // Make sure the register that the additional name is for is within
616 // the bounds of the register names from above.
617 if (AN
== Name
&& ARN
.RegNum
< Names
.size())
618 return ReturnCanonical
? Names
[ARN
.RegNum
] : Name
;
621 // Now check aliases.
622 for (const GCCRegAlias
&RA
: getGCCRegAliases())
623 for (const char *A
: RA
.Aliases
) {
633 bool TargetInfo::validateOutputConstraint(ConstraintInfo
&Info
) const {
634 const char *Name
= Info
.getConstraintStr().c_str();
635 // An output constraint must start with '=' or '+'
636 if (*Name
!= '=' && *Name
!= '+')
640 Info
.setIsReadWrite();
646 if (!validateAsmConstraint(Name
, Info
)) {
647 // FIXME: We temporarily return false
648 // so we can add more constraints as we hit it.
649 // Eventually, an unknown constraint should just be treated as 'g'.
653 case '&': // early clobber.
654 Info
.setEarlyClobber();
656 case '%': // commutative.
657 // FIXME: Check that there is a another register after this one.
659 case 'r': // general register.
660 Info
.setAllowsRegister();
662 case 'm': // memory operand.
663 case 'o': // offsetable memory operand.
664 case 'V': // non-offsetable memory operand.
665 case '<': // autodecrement memory operand.
666 case '>': // autoincrement memory operand.
667 Info
.setAllowsMemory();
669 case 'g': // general register, memory operand or immediate integer.
670 case 'X': // any operand.
671 Info
.setAllowsRegister();
672 Info
.setAllowsMemory();
674 case ',': // multiple alternative constraint. Pass it.
675 // Handle additional optional '=' or '+' modifiers.
676 if (Name
[1] == '=' || Name
[1] == '+')
679 case '#': // Ignore as constraint.
680 while (Name
[1] && Name
[1] != ',')
683 case '?': // Disparage slightly code.
684 case '!': // Disparage severely.
685 case '*': // Ignore for choosing register preferences.
686 case 'i': // Ignore i,n,E,F as output constraints (match from the other
697 // Early clobber with a read-write constraint which doesn't permit registers
699 if (Info
.earlyClobber() && Info
.isReadWrite() && !Info
.allowsRegister())
702 // If a constraint allows neither memory nor register operands it contains
703 // only modifiers. Reject it.
704 return Info
.allowsMemory() || Info
.allowsRegister();
707 bool TargetInfo::resolveSymbolicName(const char *&Name
,
708 ArrayRef
<ConstraintInfo
> OutputConstraints
,
709 unsigned &Index
) const {
710 assert(*Name
== '[' && "Symbolic name did not start with '['");
712 const char *Start
= Name
;
713 while (*Name
&& *Name
!= ']')
721 std::string
SymbolicName(Start
, Name
- Start
);
723 for (Index
= 0; Index
!= OutputConstraints
.size(); ++Index
)
724 if (SymbolicName
== OutputConstraints
[Index
].getName())
730 bool TargetInfo::validateInputConstraint(
731 MutableArrayRef
<ConstraintInfo
> OutputConstraints
,
732 ConstraintInfo
&Info
) const {
733 const char *Name
= Info
.ConstraintStr
.c_str();
741 // Check if we have a matching constraint
742 if (*Name
>= '0' && *Name
<= '9') {
743 const char *DigitStart
= Name
;
744 while (Name
[1] >= '0' && Name
[1] <= '9')
746 const char *DigitEnd
= Name
;
748 if (StringRef(DigitStart
, DigitEnd
- DigitStart
+ 1)
749 .getAsInteger(10, i
))
752 // Check if matching constraint is out of bounds.
753 if (i
>= OutputConstraints
.size()) return false;
755 // A number must refer to an output only operand.
756 if (OutputConstraints
[i
].isReadWrite())
759 // If the constraint is already tied, it must be tied to the
760 // same operand referenced to by the number.
761 if (Info
.hasTiedOperand() && Info
.getTiedOperand() != i
)
764 // The constraint should have the same info as the respective
765 // output constraint.
766 Info
.setTiedOperand(i
, OutputConstraints
[i
]);
767 } else if (!validateAsmConstraint(Name
, Info
)) {
768 // FIXME: This error return is in place temporarily so we can
769 // add more constraints as we hit it. Eventually, an unknown
770 // constraint should just be treated as 'g'.
776 if (!resolveSymbolicName(Name
, OutputConstraints
, Index
))
779 // If the constraint is already tied, it must be tied to the
780 // same operand referenced to by the number.
781 if (Info
.hasTiedOperand() && Info
.getTiedOperand() != Index
)
784 // A number must refer to an output only operand.
785 if (OutputConstraints
[Index
].isReadWrite())
788 Info
.setTiedOperand(Index
, OutputConstraints
[Index
]);
791 case '%': // commutative
792 // FIXME: Fail if % is used with the last operand.
794 case 'i': // immediate integer.
796 case 'n': // immediate integer with a known value.
797 Info
.setRequiresImmediate();
799 case 'I': // Various constant constraints with target-specific meanings.
807 if (!validateAsmConstraint(Name
, Info
))
810 case 'r': // general register.
811 Info
.setAllowsRegister();
813 case 'm': // memory operand.
814 case 'o': // offsettable memory operand.
815 case 'V': // non-offsettable memory operand.
816 case '<': // autodecrement memory operand.
817 case '>': // autoincrement memory operand.
818 Info
.setAllowsMemory();
820 case 'g': // general register, memory operand or immediate integer.
821 case 'X': // any operand.
822 Info
.setAllowsRegister();
823 Info
.setAllowsMemory();
825 case 'E': // immediate floating point.
826 case 'F': // immediate floating point.
827 case 'p': // address operand.
829 case ',': // multiple alternative constraint. Ignore comma.
831 case '#': // Ignore as constraint.
832 while (Name
[1] && Name
[1] != ',')
835 case '?': // Disparage slightly code.
836 case '!': // Disparage severely.
837 case '*': // Ignore for choosing register preferences.
847 void TargetInfo::CheckFixedPointBits() const {
848 // Check that the number of fractional and integral bits (and maybe sign) can
849 // fit into the bits given for a fixed point type.
850 assert(ShortAccumScale
+ getShortAccumIBits() + 1 <= ShortAccumWidth
);
851 assert(AccumScale
+ getAccumIBits() + 1 <= AccumWidth
);
852 assert(LongAccumScale
+ getLongAccumIBits() + 1 <= LongAccumWidth
);
853 assert(getUnsignedShortAccumScale() + getUnsignedShortAccumIBits() <=
855 assert(getUnsignedAccumScale() + getUnsignedAccumIBits() <= AccumWidth
);
856 assert(getUnsignedLongAccumScale() + getUnsignedLongAccumIBits() <=
859 assert(getShortFractScale() + 1 <= ShortFractWidth
);
860 assert(getFractScale() + 1 <= FractWidth
);
861 assert(getLongFractScale() + 1 <= LongFractWidth
);
862 assert(getUnsignedShortFractScale() <= ShortFractWidth
);
863 assert(getUnsignedFractScale() <= FractWidth
);
864 assert(getUnsignedLongFractScale() <= LongFractWidth
);
866 // Each unsigned fract type has either the same number of fractional bits
867 // as, or one more fractional bit than, its corresponding signed fract type.
868 assert(getShortFractScale() == getUnsignedShortFractScale() ||
869 getShortFractScale() == getUnsignedShortFractScale() - 1);
870 assert(getFractScale() == getUnsignedFractScale() ||
871 getFractScale() == getUnsignedFractScale() - 1);
872 assert(getLongFractScale() == getUnsignedLongFractScale() ||
873 getLongFractScale() == getUnsignedLongFractScale() - 1);
875 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
876 // fractional bits is nondecreasing for each of the following sets of
877 // fixed-point types:
878 // - signed fract types
879 // - unsigned fract types
880 // - signed accum types
881 // - unsigned accum types.
882 assert(getLongFractScale() >= getFractScale() &&
883 getFractScale() >= getShortFractScale());
884 assert(getUnsignedLongFractScale() >= getUnsignedFractScale() &&
885 getUnsignedFractScale() >= getUnsignedShortFractScale());
886 assert(LongAccumScale
>= AccumScale
&& AccumScale
>= ShortAccumScale
);
887 assert(getUnsignedLongAccumScale() >= getUnsignedAccumScale() &&
888 getUnsignedAccumScale() >= getUnsignedShortAccumScale());
890 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
891 // integral bits is nondecreasing for each of the following sets of
892 // fixed-point types:
893 // - signed accum types
894 // - unsigned accum types
895 assert(getLongAccumIBits() >= getAccumIBits() &&
896 getAccumIBits() >= getShortAccumIBits());
897 assert(getUnsignedLongAccumIBits() >= getUnsignedAccumIBits() &&
898 getUnsignedAccumIBits() >= getUnsignedShortAccumIBits());
900 // Each signed accum type has at least as many integral bits as its
901 // corresponding unsigned accum type.
902 assert(getShortAccumIBits() >= getUnsignedShortAccumIBits());
903 assert(getAccumIBits() >= getUnsignedAccumIBits());
904 assert(getLongAccumIBits() >= getUnsignedLongAccumIBits());
907 void TargetInfo::copyAuxTarget(const TargetInfo
*Aux
) {
908 auto *Target
= static_cast<TransferrableTargetInfo
*>(this);
909 auto *Src
= static_cast<const TransferrableTargetInfo
*>(Aux
);