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