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