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