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