1 //===--- TargetInfo.cpp - Information about Target machine ----------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the TargetInfo and TargetInfoImpl interfaces. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/Basic/TargetInfo.h" 15 #include "clang/Basic/AddressSpaces.h" 16 #include "clang/Basic/CharInfo.h" 17 #include "clang/Basic/Diagnostic.h" 18 #include "clang/Basic/LangOptions.h" 19 #include "llvm/ADT/APFloat.h" 20 #include "llvm/ADT/STLExtras.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 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.NewAlignOverride) 377 NewAlign = Opts.NewAlignOverride * getCharWidth(); 378 379 // Each unsigned fixed point type has the same number of fractional bits as 380 // its corresponding signed type. 381 PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint; 382 CheckFixedPointBits(); 383 } 384 385 bool TargetInfo::initFeatureMap( 386 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU, 387 const std::vector<std::string> &FeatureVec) const { 388 for (const auto &F : FeatureVec) { 389 StringRef Name = F; 390 // Apply the feature via the target. 391 bool Enabled = Name[0] == '+'; 392 setFeatureEnabled(Features, Name.substr(1), Enabled); 393 } 394 return true; 395 } 396 397 TargetInfo::CallingConvKind 398 TargetInfo::getCallingConvKind(bool ClangABICompat4) const { 399 if (getCXXABI() != TargetCXXABI::Microsoft && 400 (ClangABICompat4 || getTriple().getOS() == llvm::Triple::PS4)) 401 return CCK_ClangABI4OrPS4; 402 return CCK_Default; 403 } 404 405 LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const { 406 switch (TK) { 407 case OCLTK_Image: 408 case OCLTK_Pipe: 409 return LangAS::opencl_global; 410 411 case OCLTK_Sampler: 412 return LangAS::opencl_constant; 413 414 default: 415 return LangAS::Default; 416 } 417 } 418 419 //===----------------------------------------------------------------------===// 420 421 422 static StringRef removeGCCRegisterPrefix(StringRef Name) { 423 if (Name[0] == '%' || Name[0] == '#') 424 Name = Name.substr(1); 425 426 return Name; 427 } 428 429 /// isValidClobber - Returns whether the passed in string is 430 /// a valid clobber in an inline asm statement. This is used by 431 /// Sema. 432 bool TargetInfo::isValidClobber(StringRef Name) const { 433 return (isValidGCCRegisterName(Name) || 434 Name == "memory" || Name == "cc"); 435 } 436 437 /// isValidGCCRegisterName - Returns whether the passed in string 438 /// is a valid register name according to GCC. This is used by Sema for 439 /// inline asm statements. 440 bool TargetInfo::isValidGCCRegisterName(StringRef Name) const { 441 if (Name.empty()) 442 return false; 443 444 // Get rid of any register prefix. 445 Name = removeGCCRegisterPrefix(Name); 446 if (Name.empty()) 447 return false; 448 449 ArrayRef<const char *> Names = getGCCRegNames(); 450 451 // If we have a number it maps to an entry in the register name array. 452 if (isDigit(Name[0])) { 453 unsigned n; 454 if (!Name.getAsInteger(0, n)) 455 return n < Names.size(); 456 } 457 458 // Check register names. 459 if (std::find(Names.begin(), Names.end(), Name) != Names.end()) 460 return true; 461 462 // Check any additional names that we have. 463 for (const AddlRegName &ARN : getGCCAddlRegNames()) 464 for (const char *AN : ARN.Names) { 465 if (!AN) 466 break; 467 // Make sure the register that the additional name is for is within 468 // the bounds of the register names from above. 469 if (AN == Name && ARN.RegNum < Names.size()) 470 return true; 471 } 472 473 // Now check aliases. 474 for (const GCCRegAlias &GRA : getGCCRegAliases()) 475 for (const char *A : GRA.Aliases) { 476 if (!A) 477 break; 478 if (A == Name) 479 return true; 480 } 481 482 return false; 483 } 484 485 StringRef TargetInfo::getNormalizedGCCRegisterName(StringRef Name, 486 bool ReturnCanonical) const { 487 assert(isValidGCCRegisterName(Name) && "Invalid register passed in"); 488 489 // Get rid of any register prefix. 490 Name = removeGCCRegisterPrefix(Name); 491 492 ArrayRef<const char *> Names = getGCCRegNames(); 493 494 // First, check if we have a number. 495 if (isDigit(Name[0])) { 496 unsigned n; 497 if (!Name.getAsInteger(0, n)) { 498 assert(n < Names.size() && "Out of bounds register number!"); 499 return Names[n]; 500 } 501 } 502 503 // Check any additional names that we have. 504 for (const AddlRegName &ARN : getGCCAddlRegNames()) 505 for (const char *AN : ARN.Names) { 506 if (!AN) 507 break; 508 // Make sure the register that the additional name is for is within 509 // the bounds of the register names from above. 510 if (AN == Name && ARN.RegNum < Names.size()) 511 return ReturnCanonical ? Names[ARN.RegNum] : Name; 512 } 513 514 // Now check aliases. 515 for (const GCCRegAlias &RA : getGCCRegAliases()) 516 for (const char *A : RA.Aliases) { 517 if (!A) 518 break; 519 if (A == Name) 520 return RA.Register; 521 } 522 523 return Name; 524 } 525 526 bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const { 527 const char *Name = Info.getConstraintStr().c_str(); 528 // An output constraint must start with '=' or '+' 529 if (*Name != '=' && *Name != '+') 530 return false; 531 532 if (*Name == '+') 533 Info.setIsReadWrite(); 534 535 Name++; 536 while (*Name) { 537 switch (*Name) { 538 default: 539 if (!validateAsmConstraint(Name, Info)) { 540 // FIXME: We temporarily return false 541 // so we can add more constraints as we hit it. 542 // Eventually, an unknown constraint should just be treated as 'g'. 543 return false; 544 } 545 break; 546 case '&': // early clobber. 547 Info.setEarlyClobber(); 548 break; 549 case '%': // commutative. 550 // FIXME: Check that there is a another register after this one. 551 break; 552 case 'r': // general register. 553 Info.setAllowsRegister(); 554 break; 555 case 'm': // memory operand. 556 case 'o': // offsetable memory operand. 557 case 'V': // non-offsetable memory operand. 558 case '<': // autodecrement memory operand. 559 case '>': // autoincrement memory operand. 560 Info.setAllowsMemory(); 561 break; 562 case 'g': // general register, memory operand or immediate integer. 563 case 'X': // any operand. 564 Info.setAllowsRegister(); 565 Info.setAllowsMemory(); 566 break; 567 case ',': // multiple alternative constraint. Pass it. 568 // Handle additional optional '=' or '+' modifiers. 569 if (Name[1] == '=' || Name[1] == '+') 570 Name++; 571 break; 572 case '#': // Ignore as constraint. 573 while (Name[1] && Name[1] != ',') 574 Name++; 575 break; 576 case '?': // Disparage slightly code. 577 case '!': // Disparage severely. 578 case '*': // Ignore for choosing register preferences. 579 case 'i': // Ignore i,n,E,F as output constraints (match from the other 580 // chars) 581 case 'n': 582 case 'E': 583 case 'F': 584 break; // Pass them. 585 } 586 587 Name++; 588 } 589 590 // Early clobber with a read-write constraint which doesn't permit registers 591 // is invalid. 592 if (Info.earlyClobber() && Info.isReadWrite() && !Info.allowsRegister()) 593 return false; 594 595 // If a constraint allows neither memory nor register operands it contains 596 // only modifiers. Reject it. 597 return Info.allowsMemory() || Info.allowsRegister(); 598 } 599 600 bool TargetInfo::resolveSymbolicName(const char *&Name, 601 ArrayRef<ConstraintInfo> OutputConstraints, 602 unsigned &Index) const { 603 assert(*Name == '[' && "Symbolic name did not start with '['"); 604 Name++; 605 const char *Start = Name; 606 while (*Name && *Name != ']') 607 Name++; 608 609 if (!*Name) { 610 // Missing ']' 611 return false; 612 } 613 614 std::string SymbolicName(Start, Name - Start); 615 616 for (Index = 0; Index != OutputConstraints.size(); ++Index) 617 if (SymbolicName == OutputConstraints[Index].getName()) 618 return true; 619 620 return false; 621 } 622 623 bool TargetInfo::validateInputConstraint( 624 MutableArrayRef<ConstraintInfo> OutputConstraints, 625 ConstraintInfo &Info) const { 626 const char *Name = Info.ConstraintStr.c_str(); 627 628 if (!*Name) 629 return false; 630 631 while (*Name) { 632 switch (*Name) { 633 default: 634 // Check if we have a matching constraint 635 if (*Name >= '0' && *Name <= '9') { 636 const char *DigitStart = Name; 637 while (Name[1] >= '0' && Name[1] <= '9') 638 Name++; 639 const char *DigitEnd = Name; 640 unsigned i; 641 if (StringRef(DigitStart, DigitEnd - DigitStart + 1) 642 .getAsInteger(10, i)) 643 return false; 644 645 // Check if matching constraint is out of bounds. 646 if (i >= OutputConstraints.size()) return false; 647 648 // A number must refer to an output only operand. 649 if (OutputConstraints[i].isReadWrite()) 650 return false; 651 652 // If the constraint is already tied, it must be tied to the 653 // same operand referenced to by the number. 654 if (Info.hasTiedOperand() && Info.getTiedOperand() != i) 655 return false; 656 657 // The constraint should have the same info as the respective 658 // output constraint. 659 Info.setTiedOperand(i, OutputConstraints[i]); 660 } else if (!validateAsmConstraint(Name, Info)) { 661 // FIXME: This error return is in place temporarily so we can 662 // add more constraints as we hit it. Eventually, an unknown 663 // constraint should just be treated as 'g'. 664 return false; 665 } 666 break; 667 case '[': { 668 unsigned Index = 0; 669 if (!resolveSymbolicName(Name, OutputConstraints, Index)) 670 return false; 671 672 // If the constraint is already tied, it must be tied to the 673 // same operand referenced to by the number. 674 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index) 675 return false; 676 677 // A number must refer to an output only operand. 678 if (OutputConstraints[Index].isReadWrite()) 679 return false; 680 681 Info.setTiedOperand(Index, OutputConstraints[Index]); 682 break; 683 } 684 case '%': // commutative 685 // FIXME: Fail if % is used with the last operand. 686 break; 687 case 'i': // immediate integer. 688 case 'n': // immediate integer with a known value. 689 break; 690 case 'I': // Various constant constraints with target-specific meanings. 691 case 'J': 692 case 'K': 693 case 'L': 694 case 'M': 695 case 'N': 696 case 'O': 697 case 'P': 698 if (!validateAsmConstraint(Name, Info)) 699 return false; 700 break; 701 case 'r': // general register. 702 Info.setAllowsRegister(); 703 break; 704 case 'm': // memory operand. 705 case 'o': // offsettable memory operand. 706 case 'V': // non-offsettable memory operand. 707 case '<': // autodecrement memory operand. 708 case '>': // autoincrement memory operand. 709 Info.setAllowsMemory(); 710 break; 711 case 'g': // general register, memory operand or immediate integer. 712 case 'X': // any operand. 713 Info.setAllowsRegister(); 714 Info.setAllowsMemory(); 715 break; 716 case 'E': // immediate floating point. 717 case 'F': // immediate floating point. 718 case 'p': // address operand. 719 break; 720 case ',': // multiple alternative constraint. Ignore comma. 721 break; 722 case '#': // Ignore as constraint. 723 while (Name[1] && Name[1] != ',') 724 Name++; 725 break; 726 case '?': // Disparage slightly code. 727 case '!': // Disparage severely. 728 case '*': // Ignore for choosing register preferences. 729 break; // Pass them. 730 } 731 732 Name++; 733 } 734 735 return true; 736 } 737 738 void TargetInfo::CheckFixedPointBits() const { 739 // Check that the number of fractional and integral bits (and maybe sign) can 740 // fit into the bits given for a fixed point type. 741 assert(ShortAccumScale + getShortAccumIBits() + 1 <= ShortAccumWidth); 742 assert(AccumScale + getAccumIBits() + 1 <= AccumWidth); 743 assert(LongAccumScale + getLongAccumIBits() + 1 <= LongAccumWidth); 744 assert(getUnsignedShortAccumScale() + getUnsignedShortAccumIBits() <= 745 ShortAccumWidth); 746 assert(getUnsignedAccumScale() + getUnsignedAccumIBits() <= AccumWidth); 747 assert(getUnsignedLongAccumScale() + getUnsignedLongAccumIBits() <= 748 LongAccumWidth); 749 750 assert(getShortFractScale() + 1 <= ShortFractWidth); 751 assert(getFractScale() + 1 <= FractWidth); 752 assert(getLongFractScale() + 1 <= LongFractWidth); 753 assert(getUnsignedShortFractScale() <= ShortFractWidth); 754 assert(getUnsignedFractScale() <= FractWidth); 755 assert(getUnsignedLongFractScale() <= LongFractWidth); 756 757 // Each unsigned fract type has either the same number of fractional bits 758 // as, or one more fractional bit than, its corresponding signed fract type. 759 assert(getShortFractScale() == getUnsignedShortFractScale() || 760 getShortFractScale() == getUnsignedShortFractScale() - 1); 761 assert(getFractScale() == getUnsignedFractScale() || 762 getFractScale() == getUnsignedFractScale() - 1); 763 assert(getLongFractScale() == getUnsignedLongFractScale() || 764 getLongFractScale() == getUnsignedLongFractScale() - 1); 765 766 // When arranged in order of increasing rank (see 6.3.1.3a), the number of 767 // fractional bits is nondecreasing for each of the following sets of 768 // fixed-point types: 769 // - signed fract types 770 // - unsigned fract types 771 // - signed accum types 772 // - unsigned accum types. 773 assert(getLongFractScale() >= getFractScale() && 774 getFractScale() >= getShortFractScale()); 775 assert(getUnsignedLongFractScale() >= getUnsignedFractScale() && 776 getUnsignedFractScale() >= getUnsignedShortFractScale()); 777 assert(LongAccumScale >= AccumScale && AccumScale >= ShortAccumScale); 778 assert(getUnsignedLongAccumScale() >= getUnsignedAccumScale() && 779 getUnsignedAccumScale() >= getUnsignedShortAccumScale()); 780 781 // When arranged in order of increasing rank (see 6.3.1.3a), the number of 782 // integral bits is nondecreasing for each of the following sets of 783 // fixed-point types: 784 // - signed accum types 785 // - unsigned accum types 786 assert(getLongAccumIBits() >= getAccumIBits() && 787 getAccumIBits() >= getShortAccumIBits()); 788 assert(getUnsignedLongAccumIBits() >= getUnsignedAccumIBits() && 789 getUnsignedAccumIBits() >= getUnsignedShortAccumIBits()); 790 791 // Each signed accum type has at least as many integral bits as its 792 // corresponding unsigned accum type. 793 assert(getShortAccumIBits() >= getUnsignedShortAccumIBits()); 794 assert(getAccumIBits() >= getUnsignedAccumIBits()); 795 assert(getLongAccumIBits() >= getUnsignedLongAccumIBits()); 796 } 797