xref: /freebsd/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp (revision ee0fe82ee2892f5ece189db0eab38913aaab5f0f)
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 
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"
22 #include <cstdlib>
23 using namespace clang;
24 
25 static const LangASMap DefaultAddrSpaceMap = {0};
26 
27 // TargetInfo Constructor.
28 TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), 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();
32   TLSSupported = true;
33   VLASupported = true;
34   NoAsmVariants = false;
35   HasLegalHalfType = false;
36   HasFloat128 = false;
37   HasFloat16 = false;
38   PointerWidth = PointerAlign = 32;
39   BoolWidth = BoolAlign = 8;
40   IntWidth = IntAlign = 32;
41   LongWidth = LongAlign = 32;
42   LongLongWidth = LongLongAlign = 64;
43 
44   // Fixed point default bit widths
45   ShortAccumWidth = ShortAccumAlign = 16;
46   AccumWidth = AccumAlign = 32;
47   LongAccumWidth = LongAccumAlign = 64;
48   ShortFractWidth = ShortFractAlign = 8;
49   FractWidth = FractAlign = 16;
50   LongFractWidth = LongFractAlign = 32;
51 
52   // Fixed point default integral and fractional bit sizes
53   // We give the _Accum 1 fewer fractional bits than their corresponding _Fract
54   // types by default to have the same number of fractional bits between _Accum
55   // and _Fract types.
56   PaddingOnUnsignedFixedPoint = false;
57   ShortAccumScale = 7;
58   AccumScale = 15;
59   LongAccumScale = 31;
60 
61   SuitableAlign = 64;
62   DefaultAlignForAttributeAligned = 128;
63   MinGlobalAlign = 0;
64   // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
65   // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
66   // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
67   // This alignment guarantee also applies to Windows and Android.
68   if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
69     NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
70   else
71     NewAlign = 0; // Infer from basic type alignment.
72   HalfWidth = 16;
73   HalfAlign = 16;
74   FloatWidth = 32;
75   FloatAlign = 32;
76   DoubleWidth = 64;
77   DoubleAlign = 64;
78   LongDoubleWidth = 64;
79   LongDoubleAlign = 64;
80   Float128Align = 128;
81   LargeArrayMinWidth = 0;
82   LargeArrayAlign = 0;
83   MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
84   MaxVectorAlign = 0;
85   MaxTLSAlign = 0;
86   SimdDefaultAlign = 0;
87   SizeType = UnsignedLong;
88   PtrDiffType = SignedLong;
89   IntMaxType = SignedLongLong;
90   IntPtrType = SignedLong;
91   WCharType = SignedInt;
92   WIntType = SignedInt;
93   Char16Type = UnsignedShort;
94   Char32Type = UnsignedInt;
95   Int64Type = SignedLongLong;
96   SigAtomicType = SignedInt;
97   ProcessIDType = SignedInt;
98   UseSignedCharForObjCBool = true;
99   UseBitFieldTypeAlignment = true;
100   UseZeroLengthBitfieldAlignment = false;
101   UseExplicitBitFieldAlignment = true;
102   ZeroLengthBitfieldBoundary = 0;
103   HalfFormat = &llvm::APFloat::IEEEhalf();
104   FloatFormat = &llvm::APFloat::IEEEsingle();
105   DoubleFormat = &llvm::APFloat::IEEEdouble();
106   LongDoubleFormat = &llvm::APFloat::IEEEdouble();
107   Float128Format = &llvm::APFloat::IEEEquad();
108   MCountName = "mcount";
109   RegParmMax = 0;
110   SSERegParmMax = 0;
111   HasAlignMac68kSupport = false;
112   HasBuiltinMSVaList = false;
113   IsRenderScriptTarget = false;
114 
115   // Default to no types using fpret.
116   RealTypeUsesObjCFPRet = 0;
117 
118   // Default to not using fp2ret for __Complex long double
119   ComplexLongDoubleUsesFP2Ret = false;
120 
121   // Set the C++ ABI based on the triple.
122   TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment()
123                     ? TargetCXXABI::Microsoft
124                     : TargetCXXABI::GenericItanium);
125 
126   // Default to an empty address space map.
127   AddrSpaceMap = &DefaultAddrSpaceMap;
128   UseAddrSpaceMapMangling = false;
129 
130   // Default to an unknown platform name.
131   PlatformName = "unknown";
132   PlatformMinVersion = VersionTuple();
133 }
134 
135 // Out of line virtual dtor for TargetInfo.
136 TargetInfo::~TargetInfo() {}
137 
138 bool
139 TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const {
140   Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
141   return false;
142 }
143 
144 bool
145 TargetInfo::checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const {
146   Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return";
147   return false;
148 }
149 
150 /// getTypeName - Return the user string for the specified integer type enum.
151 /// For example, SignedShort -> "short".
152 const char *TargetInfo::getTypeName(IntType T) {
153   switch (T) {
154   default: llvm_unreachable("not an integer!");
155   case SignedChar:       return "signed char";
156   case UnsignedChar:     return "unsigned char";
157   case SignedShort:      return "short";
158   case UnsignedShort:    return "unsigned short";
159   case SignedInt:        return "int";
160   case UnsignedInt:      return "unsigned int";
161   case SignedLong:       return "long int";
162   case UnsignedLong:     return "long unsigned int";
163   case SignedLongLong:   return "long long int";
164   case UnsignedLongLong: return "long long unsigned int";
165   }
166 }
167 
168 /// getTypeConstantSuffix - Return the constant suffix for the specified
169 /// integer type enum. For example, SignedLong -> "L".
170 const char *TargetInfo::getTypeConstantSuffix(IntType T) const {
171   switch (T) {
172   default: llvm_unreachable("not an integer!");
173   case SignedChar:
174   case SignedShort:
175   case SignedInt:        return "";
176   case SignedLong:       return "L";
177   case SignedLongLong:   return "LL";
178   case UnsignedChar:
179     if (getCharWidth() < getIntWidth())
180       return "";
181     LLVM_FALLTHROUGH;
182   case UnsignedShort:
183     if (getShortWidth() < getIntWidth())
184       return "";
185     LLVM_FALLTHROUGH;
186   case UnsignedInt:      return "U";
187   case UnsignedLong:     return "UL";
188   case UnsignedLongLong: return "ULL";
189   }
190 }
191 
192 /// getTypeFormatModifier - Return the printf format modifier for the
193 /// specified integer type enum. For example, SignedLong -> "l".
194 
195 const char *TargetInfo::getTypeFormatModifier(IntType T) {
196   switch (T) {
197   default: llvm_unreachable("not an integer!");
198   case SignedChar:
199   case UnsignedChar:     return "hh";
200   case SignedShort:
201   case UnsignedShort:    return "h";
202   case SignedInt:
203   case UnsignedInt:      return "";
204   case SignedLong:
205   case UnsignedLong:     return "l";
206   case SignedLongLong:
207   case UnsignedLongLong: return "ll";
208   }
209 }
210 
211 /// getTypeWidth - Return the width (in bits) of the specified integer type
212 /// enum. For example, SignedInt -> getIntWidth().
213 unsigned TargetInfo::getTypeWidth(IntType T) const {
214   switch (T) {
215   default: llvm_unreachable("not an integer!");
216   case SignedChar:
217   case UnsignedChar:     return getCharWidth();
218   case SignedShort:
219   case UnsignedShort:    return getShortWidth();
220   case SignedInt:
221   case UnsignedInt:      return getIntWidth();
222   case SignedLong:
223   case UnsignedLong:     return getLongWidth();
224   case SignedLongLong:
225   case UnsignedLongLong: return getLongLongWidth();
226   };
227 }
228 
229 TargetInfo::IntType TargetInfo::getIntTypeByWidth(
230     unsigned BitWidth, bool IsSigned) const {
231   if (getCharWidth() == BitWidth)
232     return IsSigned ? SignedChar : UnsignedChar;
233   if (getShortWidth() == BitWidth)
234     return IsSigned ? SignedShort : UnsignedShort;
235   if (getIntWidth() == BitWidth)
236     return IsSigned ? SignedInt : UnsignedInt;
237   if (getLongWidth() == BitWidth)
238     return IsSigned ? SignedLong : UnsignedLong;
239   if (getLongLongWidth() == BitWidth)
240     return IsSigned ? SignedLongLong : UnsignedLongLong;
241   return NoInt;
242 }
243 
244 TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth,
245                                                        bool IsSigned) const {
246   if (getCharWidth() >= BitWidth)
247     return IsSigned ? SignedChar : UnsignedChar;
248   if (getShortWidth() >= BitWidth)
249     return IsSigned ? SignedShort : UnsignedShort;
250   if (getIntWidth() >= BitWidth)
251     return IsSigned ? SignedInt : UnsignedInt;
252   if (getLongWidth() >= BitWidth)
253     return IsSigned ? SignedLong : UnsignedLong;
254   if (getLongLongWidth() >= BitWidth)
255     return IsSigned ? SignedLongLong : UnsignedLongLong;
256   return NoInt;
257 }
258 
259 TargetInfo::RealType TargetInfo::getRealTypeByWidth(unsigned BitWidth) const {
260   if (getFloatWidth() == BitWidth)
261     return Float;
262   if (getDoubleWidth() == BitWidth)
263     return Double;
264 
265   switch (BitWidth) {
266   case 96:
267     if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
268       return LongDouble;
269     break;
270   case 128:
271     if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
272         &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
273       return LongDouble;
274     if (hasFloat128Type())
275       return Float128;
276     break;
277   }
278 
279   return NoFloat;
280 }
281 
282 /// getTypeAlign - Return the alignment (in bits) of the specified integer type
283 /// enum. For example, SignedInt -> getIntAlign().
284 unsigned TargetInfo::getTypeAlign(IntType T) const {
285   switch (T) {
286   default: llvm_unreachable("not an integer!");
287   case SignedChar:
288   case UnsignedChar:     return getCharAlign();
289   case SignedShort:
290   case UnsignedShort:    return getShortAlign();
291   case SignedInt:
292   case UnsignedInt:      return getIntAlign();
293   case SignedLong:
294   case UnsignedLong:     return getLongAlign();
295   case SignedLongLong:
296   case UnsignedLongLong: return getLongLongAlign();
297   };
298 }
299 
300 /// isTypeSigned - Return whether an integer types is signed. Returns true if
301 /// the type is signed; false otherwise.
302 bool TargetInfo::isTypeSigned(IntType T) {
303   switch (T) {
304   default: llvm_unreachable("not an integer!");
305   case SignedChar:
306   case SignedShort:
307   case SignedInt:
308   case SignedLong:
309   case SignedLongLong:
310     return true;
311   case UnsignedChar:
312   case UnsignedShort:
313   case UnsignedInt:
314   case UnsignedLong:
315   case UnsignedLongLong:
316     return false;
317   };
318 }
319 
320 /// adjust - Set forced language options.
321 /// Apply changes to the target information with respect to certain
322 /// language options which change the target configuration and adjust
323 /// the language based on the target options where applicable.
324 void TargetInfo::adjust(LangOptions &Opts) {
325   if (Opts.NoBitFieldTypeAlign)
326     UseBitFieldTypeAlignment = false;
327 
328   switch (Opts.WCharSize) {
329   default: llvm_unreachable("invalid wchar_t width");
330   case 0: break;
331   case 1: WCharType = Opts.WCharIsSigned ? SignedChar : UnsignedChar; break;
332   case 2: WCharType = Opts.WCharIsSigned ? SignedShort : UnsignedShort; break;
333   case 4: WCharType = Opts.WCharIsSigned ? SignedInt : UnsignedInt; break;
334   }
335 
336   if (Opts.AlignDouble) {
337     DoubleAlign = LongLongAlign = 64;
338     LongDoubleAlign = 64;
339   }
340 
341   if (Opts.OpenCL) {
342     // OpenCL C requires specific widths for types, irrespective of
343     // what these normally are for the target.
344     // We also define long long and long double here, although the
345     // OpenCL standard only mentions these as "reserved".
346     IntWidth = IntAlign = 32;
347     LongWidth = LongAlign = 64;
348     LongLongWidth = LongLongAlign = 128;
349     HalfWidth = HalfAlign = 16;
350     FloatWidth = FloatAlign = 32;
351 
352     // Embedded 32-bit targets (OpenCL EP) might have double C type
353     // defined as float. Let's not override this as it might lead
354     // to generating illegal code that uses 64bit doubles.
355     if (DoubleWidth != FloatWidth) {
356       DoubleWidth = DoubleAlign = 64;
357       DoubleFormat = &llvm::APFloat::IEEEdouble();
358     }
359     LongDoubleWidth = LongDoubleAlign = 128;
360 
361     unsigned MaxPointerWidth = getMaxPointerWidth();
362     assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
363     bool Is32BitArch = MaxPointerWidth == 32;
364     SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
365     PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
366     IntPtrType = Is32BitArch ? SignedInt : SignedLong;
367 
368     IntMaxType = SignedLongLong;
369     Int64Type = SignedLong;
370 
371     HalfFormat = &llvm::APFloat::IEEEhalf();
372     FloatFormat = &llvm::APFloat::IEEEsingle();
373     LongDoubleFormat = &llvm::APFloat::IEEEquad();
374   }
375 
376   if (Opts.LongDoubleSize) {
377     if (Opts.LongDoubleSize == DoubleWidth) {
378       LongDoubleWidth = DoubleWidth;
379       LongDoubleAlign = DoubleAlign;
380       LongDoubleFormat = DoubleFormat;
381     } else if (Opts.LongDoubleSize == 128) {
382       LongDoubleWidth = LongDoubleAlign = 128;
383       LongDoubleFormat = &llvm::APFloat::IEEEquad();
384     }
385   }
386 
387   if (Opts.NewAlignOverride)
388     NewAlign = Opts.NewAlignOverride * getCharWidth();
389 
390   // Each unsigned fixed point type has the same number of fractional bits as
391   // its corresponding signed type.
392   PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
393   CheckFixedPointBits();
394 }
395 
396 bool TargetInfo::initFeatureMap(
397     llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
398     const std::vector<std::string> &FeatureVec) const {
399   for (const auto &F : FeatureVec) {
400     StringRef Name = F;
401     // Apply the feature via the target.
402     bool Enabled = Name[0] == '+';
403     setFeatureEnabled(Features, Name.substr(1), Enabled);
404   }
405   return true;
406 }
407 
408 TargetInfo::CallingConvKind
409 TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
410   if (getCXXABI() != TargetCXXABI::Microsoft &&
411       (ClangABICompat4 || getTriple().getOS() == llvm::Triple::PS4))
412     return CCK_ClangABI4OrPS4;
413   return CCK_Default;
414 }
415 
416 LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
417   switch (TK) {
418   case OCLTK_Image:
419   case OCLTK_Pipe:
420     return LangAS::opencl_global;
421 
422   case OCLTK_Sampler:
423     return LangAS::opencl_constant;
424 
425   default:
426     return LangAS::Default;
427   }
428 }
429 
430 //===----------------------------------------------------------------------===//
431 
432 
433 static StringRef removeGCCRegisterPrefix(StringRef Name) {
434   if (Name[0] == '%' || Name[0] == '#')
435     Name = Name.substr(1);
436 
437   return Name;
438 }
439 
440 /// isValidClobber - Returns whether the passed in string is
441 /// a valid clobber in an inline asm statement. This is used by
442 /// Sema.
443 bool TargetInfo::isValidClobber(StringRef Name) const {
444   return (isValidGCCRegisterName(Name) ||
445           Name == "memory" || Name == "cc");
446 }
447 
448 /// isValidGCCRegisterName - Returns whether the passed in string
449 /// is a valid register name according to GCC. This is used by Sema for
450 /// inline asm statements.
451 bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
452   if (Name.empty())
453     return false;
454 
455   // Get rid of any register prefix.
456   Name = removeGCCRegisterPrefix(Name);
457   if (Name.empty())
458     return false;
459 
460   ArrayRef<const char *> Names = getGCCRegNames();
461 
462   // If we have a number it maps to an entry in the register name array.
463   if (isDigit(Name[0])) {
464     unsigned n;
465     if (!Name.getAsInteger(0, n))
466       return n < Names.size();
467   }
468 
469   // Check register names.
470   if (llvm::is_contained(Names, Name))
471     return true;
472 
473   // Check any additional names that we have.
474   for (const AddlRegName &ARN : getGCCAddlRegNames())
475     for (const char *AN : ARN.Names) {
476       if (!AN)
477         break;
478       // Make sure the register that the additional name is for is within
479       // the bounds of the register names from above.
480       if (AN == Name && ARN.RegNum < Names.size())
481         return true;
482     }
483 
484   // Now check aliases.
485   for (const GCCRegAlias &GRA : getGCCRegAliases())
486     for (const char *A : GRA.Aliases) {
487       if (!A)
488         break;
489       if (A == Name)
490         return true;
491     }
492 
493   return false;
494 }
495 
496 StringRef TargetInfo::getNormalizedGCCRegisterName(StringRef Name,
497                                                    bool ReturnCanonical) const {
498   assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
499 
500   // Get rid of any register prefix.
501   Name = removeGCCRegisterPrefix(Name);
502 
503   ArrayRef<const char *> Names = getGCCRegNames();
504 
505   // First, check if we have a number.
506   if (isDigit(Name[0])) {
507     unsigned n;
508     if (!Name.getAsInteger(0, n)) {
509       assert(n < Names.size() && "Out of bounds register number!");
510       return Names[n];
511     }
512   }
513 
514   // Check any additional names that we have.
515   for (const AddlRegName &ARN : getGCCAddlRegNames())
516     for (const char *AN : ARN.Names) {
517       if (!AN)
518         break;
519       // Make sure the register that the additional name is for is within
520       // the bounds of the register names from above.
521       if (AN == Name && ARN.RegNum < Names.size())
522         return ReturnCanonical ? Names[ARN.RegNum] : Name;
523     }
524 
525   // Now check aliases.
526   for (const GCCRegAlias &RA : getGCCRegAliases())
527     for (const char *A : RA.Aliases) {
528       if (!A)
529         break;
530       if (A == Name)
531         return RA.Register;
532     }
533 
534   return Name;
535 }
536 
537 bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
538   const char *Name = Info.getConstraintStr().c_str();
539   // An output constraint must start with '=' or '+'
540   if (*Name != '=' && *Name != '+')
541     return false;
542 
543   if (*Name == '+')
544     Info.setIsReadWrite();
545 
546   Name++;
547   while (*Name) {
548     switch (*Name) {
549     default:
550       if (!validateAsmConstraint(Name, Info)) {
551         // FIXME: We temporarily return false
552         // so we can add more constraints as we hit it.
553         // Eventually, an unknown constraint should just be treated as 'g'.
554         return false;
555       }
556       break;
557     case '&': // early clobber.
558       Info.setEarlyClobber();
559       break;
560     case '%': // commutative.
561       // FIXME: Check that there is a another register after this one.
562       break;
563     case 'r': // general register.
564       Info.setAllowsRegister();
565       break;
566     case 'm': // memory operand.
567     case 'o': // offsetable memory operand.
568     case 'V': // non-offsetable memory operand.
569     case '<': // autodecrement memory operand.
570     case '>': // autoincrement memory operand.
571       Info.setAllowsMemory();
572       break;
573     case 'g': // general register, memory operand or immediate integer.
574     case 'X': // any operand.
575       Info.setAllowsRegister();
576       Info.setAllowsMemory();
577       break;
578     case ',': // multiple alternative constraint.  Pass it.
579       // Handle additional optional '=' or '+' modifiers.
580       if (Name[1] == '=' || Name[1] == '+')
581         Name++;
582       break;
583     case '#': // Ignore as constraint.
584       while (Name[1] && Name[1] != ',')
585         Name++;
586       break;
587     case '?': // Disparage slightly code.
588     case '!': // Disparage severely.
589     case '*': // Ignore for choosing register preferences.
590     case 'i': // Ignore i,n,E,F as output constraints (match from the other
591               // chars)
592     case 'n':
593     case 'E':
594     case 'F':
595       break;  // Pass them.
596     }
597 
598     Name++;
599   }
600 
601   // Early clobber with a read-write constraint which doesn't permit registers
602   // is invalid.
603   if (Info.earlyClobber() && Info.isReadWrite() && !Info.allowsRegister())
604     return false;
605 
606   // If a constraint allows neither memory nor register operands it contains
607   // only modifiers. Reject it.
608   return Info.allowsMemory() || Info.allowsRegister();
609 }
610 
611 bool TargetInfo::resolveSymbolicName(const char *&Name,
612                                      ArrayRef<ConstraintInfo> OutputConstraints,
613                                      unsigned &Index) const {
614   assert(*Name == '[' && "Symbolic name did not start with '['");
615   Name++;
616   const char *Start = Name;
617   while (*Name && *Name != ']')
618     Name++;
619 
620   if (!*Name) {
621     // Missing ']'
622     return false;
623   }
624 
625   std::string SymbolicName(Start, Name - Start);
626 
627   for (Index = 0; Index != OutputConstraints.size(); ++Index)
628     if (SymbolicName == OutputConstraints[Index].getName())
629       return true;
630 
631   return false;
632 }
633 
634 bool TargetInfo::validateInputConstraint(
635                               MutableArrayRef<ConstraintInfo> OutputConstraints,
636                               ConstraintInfo &Info) const {
637   const char *Name = Info.ConstraintStr.c_str();
638 
639   if (!*Name)
640     return false;
641 
642   while (*Name) {
643     switch (*Name) {
644     default:
645       // Check if we have a matching constraint
646       if (*Name >= '0' && *Name <= '9') {
647         const char *DigitStart = Name;
648         while (Name[1] >= '0' && Name[1] <= '9')
649           Name++;
650         const char *DigitEnd = Name;
651         unsigned i;
652         if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
653                 .getAsInteger(10, i))
654           return false;
655 
656         // Check if matching constraint is out of bounds.
657         if (i >= OutputConstraints.size()) return false;
658 
659         // A number must refer to an output only operand.
660         if (OutputConstraints[i].isReadWrite())
661           return false;
662 
663         // If the constraint is already tied, it must be tied to the
664         // same operand referenced to by the number.
665         if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
666           return false;
667 
668         // The constraint should have the same info as the respective
669         // output constraint.
670         Info.setTiedOperand(i, OutputConstraints[i]);
671       } else if (!validateAsmConstraint(Name, Info)) {
672         // FIXME: This error return is in place temporarily so we can
673         // add more constraints as we hit it.  Eventually, an unknown
674         // constraint should just be treated as 'g'.
675         return false;
676       }
677       break;
678     case '[': {
679       unsigned Index = 0;
680       if (!resolveSymbolicName(Name, OutputConstraints, Index))
681         return false;
682 
683       // If the constraint is already tied, it must be tied to the
684       // same operand referenced to by the number.
685       if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
686         return false;
687 
688       // A number must refer to an output only operand.
689       if (OutputConstraints[Index].isReadWrite())
690         return false;
691 
692       Info.setTiedOperand(Index, OutputConstraints[Index]);
693       break;
694     }
695     case '%': // commutative
696       // FIXME: Fail if % is used with the last operand.
697       break;
698     case 'i': // immediate integer.
699       break;
700     case 'n': // immediate integer with a known value.
701       Info.setRequiresImmediate();
702       break;
703     case 'I':  // Various constant constraints with target-specific meanings.
704     case 'J':
705     case 'K':
706     case 'L':
707     case 'M':
708     case 'N':
709     case 'O':
710     case 'P':
711       if (!validateAsmConstraint(Name, Info))
712         return false;
713       break;
714     case 'r': // general register.
715       Info.setAllowsRegister();
716       break;
717     case 'm': // memory operand.
718     case 'o': // offsettable memory operand.
719     case 'V': // non-offsettable memory operand.
720     case '<': // autodecrement memory operand.
721     case '>': // autoincrement memory operand.
722       Info.setAllowsMemory();
723       break;
724     case 'g': // general register, memory operand or immediate integer.
725     case 'X': // any operand.
726       Info.setAllowsRegister();
727       Info.setAllowsMemory();
728       break;
729     case 'E': // immediate floating point.
730     case 'F': // immediate floating point.
731     case 'p': // address operand.
732       break;
733     case ',': // multiple alternative constraint.  Ignore comma.
734       break;
735     case '#': // Ignore as constraint.
736       while (Name[1] && Name[1] != ',')
737         Name++;
738       break;
739     case '?': // Disparage slightly code.
740     case '!': // Disparage severely.
741     case '*': // Ignore for choosing register preferences.
742       break;  // Pass them.
743     }
744 
745     Name++;
746   }
747 
748   return true;
749 }
750 
751 void TargetInfo::CheckFixedPointBits() const {
752   // Check that the number of fractional and integral bits (and maybe sign) can
753   // fit into the bits given for a fixed point type.
754   assert(ShortAccumScale + getShortAccumIBits() + 1 <= ShortAccumWidth);
755   assert(AccumScale + getAccumIBits() + 1 <= AccumWidth);
756   assert(LongAccumScale + getLongAccumIBits() + 1 <= LongAccumWidth);
757   assert(getUnsignedShortAccumScale() + getUnsignedShortAccumIBits() <=
758          ShortAccumWidth);
759   assert(getUnsignedAccumScale() + getUnsignedAccumIBits() <= AccumWidth);
760   assert(getUnsignedLongAccumScale() + getUnsignedLongAccumIBits() <=
761          LongAccumWidth);
762 
763   assert(getShortFractScale() + 1 <= ShortFractWidth);
764   assert(getFractScale() + 1 <= FractWidth);
765   assert(getLongFractScale() + 1 <= LongFractWidth);
766   assert(getUnsignedShortFractScale() <= ShortFractWidth);
767   assert(getUnsignedFractScale() <= FractWidth);
768   assert(getUnsignedLongFractScale() <= LongFractWidth);
769 
770   // Each unsigned fract type has either the same number of fractional bits
771   // as, or one more fractional bit than, its corresponding signed fract type.
772   assert(getShortFractScale() == getUnsignedShortFractScale() ||
773          getShortFractScale() == getUnsignedShortFractScale() - 1);
774   assert(getFractScale() == getUnsignedFractScale() ||
775          getFractScale() == getUnsignedFractScale() - 1);
776   assert(getLongFractScale() == getUnsignedLongFractScale() ||
777          getLongFractScale() == getUnsignedLongFractScale() - 1);
778 
779   // When arranged in order of increasing rank (see 6.3.1.3a), the number of
780   // fractional bits is nondecreasing for each of the following sets of
781   // fixed-point types:
782   // - signed fract types
783   // - unsigned fract types
784   // - signed accum types
785   // - unsigned accum types.
786   assert(getLongFractScale() >= getFractScale() &&
787          getFractScale() >= getShortFractScale());
788   assert(getUnsignedLongFractScale() >= getUnsignedFractScale() &&
789          getUnsignedFractScale() >= getUnsignedShortFractScale());
790   assert(LongAccumScale >= AccumScale && AccumScale >= ShortAccumScale);
791   assert(getUnsignedLongAccumScale() >= getUnsignedAccumScale() &&
792          getUnsignedAccumScale() >= getUnsignedShortAccumScale());
793 
794   // When arranged in order of increasing rank (see 6.3.1.3a), the number of
795   // integral bits is nondecreasing for each of the following sets of
796   // fixed-point types:
797   // - signed accum types
798   // - unsigned accum types
799   assert(getLongAccumIBits() >= getAccumIBits() &&
800          getAccumIBits() >= getShortAccumIBits());
801   assert(getUnsignedLongAccumIBits() >= getUnsignedAccumIBits() &&
802          getUnsignedAccumIBits() >= getUnsignedShortAccumIBits());
803 
804   // Each signed accum type has at least as many integral bits as its
805   // corresponding unsigned accum type.
806   assert(getShortAccumIBits() >= getUnsignedShortAccumIBits());
807   assert(getAccumIBits() >= getUnsignedAccumIBits());
808   assert(getLongAccumIBits() >= getUnsignedLongAccumIBits());
809 }
810 
811 void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
812   auto *Target = static_cast<TransferrableTargetInfo*>(this);
813   auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
814   *Target = *Src;
815 }
816