1 //===--- Triple.cpp - Target triple helper class --------------------------===// 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 #include "llvm/ADT/Triple.h" 11 #include "llvm/ADT/SmallString.h" 12 #include "llvm/ADT/StringSwitch.h" 13 #include "llvm/ADT/STLExtras.h" 14 #include "llvm/Support/ErrorHandling.h" 15 #include <cstring> 16 using namespace llvm; 17 18 const char *Triple::getArchTypeName(ArchType Kind) { 19 switch (Kind) { 20 case UnknownArch: return "unknown"; 21 22 case arm: return "arm"; 23 case cellspu: return "cellspu"; 24 case hexagon: return "hexagon"; 25 case mips: return "mips"; 26 case mipsel: return "mipsel"; 27 case mips64: return "mips64"; 28 case mips64el:return "mips64el"; 29 case msp430: return "msp430"; 30 case ppc64: return "powerpc64"; 31 case ppc: return "powerpc"; 32 case r600: return "r600"; 33 case sparc: return "sparc"; 34 case sparcv9: return "sparcv9"; 35 case tce: return "tce"; 36 case thumb: return "thumb"; 37 case x86: return "i386"; 38 case x86_64: return "x86_64"; 39 case xcore: return "xcore"; 40 case mblaze: return "mblaze"; 41 case nvptx: return "nvptx"; 42 case nvptx64: return "nvptx64"; 43 case le32: return "le32"; 44 case amdil: return "amdil"; 45 case spir: return "spir"; 46 case spir64: return "spir64"; 47 } 48 49 llvm_unreachable("Invalid ArchType!"); 50 } 51 52 const char *Triple::getArchTypePrefix(ArchType Kind) { 53 switch (Kind) { 54 default: 55 return 0; 56 57 case arm: 58 case thumb: return "arm"; 59 60 case cellspu: return "spu"; 61 62 case ppc64: 63 case ppc: return "ppc"; 64 65 case mblaze: return "mblaze"; 66 67 case mips: 68 case mipsel: 69 case mips64: 70 case mips64el:return "mips"; 71 72 case hexagon: return "hexagon"; 73 74 case r600: return "r600"; 75 76 case sparcv9: 77 case sparc: return "sparc"; 78 79 case x86: 80 case x86_64: return "x86"; 81 82 case xcore: return "xcore"; 83 84 case nvptx: return "nvptx"; 85 case nvptx64: return "nvptx"; 86 case le32: return "le32"; 87 case amdil: return "amdil"; 88 case spir: return "spir"; 89 case spir64: return "spir"; 90 } 91 } 92 93 const char *Triple::getVendorTypeName(VendorType Kind) { 94 switch (Kind) { 95 case UnknownVendor: return "unknown"; 96 97 case Apple: return "apple"; 98 case PC: return "pc"; 99 case SCEI: return "scei"; 100 case BGP: return "bgp"; 101 case BGQ: return "bgq"; 102 case Freescale: return "fsl"; 103 case IBM: return "ibm"; 104 } 105 106 llvm_unreachable("Invalid VendorType!"); 107 } 108 109 const char *Triple::getOSTypeName(OSType Kind) { 110 switch (Kind) { 111 case UnknownOS: return "unknown"; 112 113 case AuroraUX: return "auroraux"; 114 case Cygwin: return "cygwin"; 115 case Darwin: return "darwin"; 116 case DragonFly: return "dragonfly"; 117 case FreeBSD: return "freebsd"; 118 case IOS: return "ios"; 119 case KFreeBSD: return "kfreebsd"; 120 case Linux: return "linux"; 121 case Lv2: return "lv2"; 122 case MacOSX: return "macosx"; 123 case MinGW32: return "mingw32"; 124 case NetBSD: return "netbsd"; 125 case OpenBSD: return "openbsd"; 126 case Solaris: return "solaris"; 127 case Win32: return "win32"; 128 case Haiku: return "haiku"; 129 case Minix: return "minix"; 130 case RTEMS: return "rtems"; 131 case NativeClient: return "nacl"; 132 case CNK: return "cnk"; 133 case Bitrig: return "bitrig"; 134 case AIX: return "aix"; 135 } 136 137 llvm_unreachable("Invalid OSType"); 138 } 139 140 const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) { 141 switch (Kind) { 142 case UnknownEnvironment: return "unknown"; 143 case GNU: return "gnu"; 144 case GNUEABIHF: return "gnueabihf"; 145 case GNUEABI: return "gnueabi"; 146 case EABI: return "eabi"; 147 case MachO: return "macho"; 148 case Android: return "android"; 149 case ELF: return "elf"; 150 } 151 152 llvm_unreachable("Invalid EnvironmentType!"); 153 } 154 155 Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { 156 return StringSwitch<Triple::ArchType>(Name) 157 .Case("arm", arm) 158 .Case("cellspu", cellspu) 159 .Case("mips", mips) 160 .Case("mipsel", mipsel) 161 .Case("mips64", mips64) 162 .Case("mips64el", mips64el) 163 .Case("msp430", msp430) 164 .Case("ppc64", ppc64) 165 .Case("ppc32", ppc) 166 .Case("ppc", ppc) 167 .Case("mblaze", mblaze) 168 .Case("r600", r600) 169 .Case("hexagon", hexagon) 170 .Case("sparc", sparc) 171 .Case("sparcv9", sparcv9) 172 .Case("tce", tce) 173 .Case("thumb", thumb) 174 .Case("x86", x86) 175 .Case("x86-64", x86_64) 176 .Case("xcore", xcore) 177 .Case("nvptx", nvptx) 178 .Case("nvptx64", nvptx64) 179 .Case("le32", le32) 180 .Case("amdil", amdil) 181 .Case("spir", spir) 182 .Case("spir64", spir64) 183 .Default(UnknownArch); 184 } 185 186 // Returns architecture name that is understood by the target assembler. 187 const char *Triple::getArchNameForAssembler() { 188 if (!isOSDarwin() && getVendor() != Triple::Apple) 189 return NULL; 190 191 return StringSwitch<const char*>(getArchName()) 192 .Case("i386", "i386") 193 .Case("x86_64", "x86_64") 194 .Case("powerpc", "ppc") 195 .Case("powerpc64", "ppc64") 196 .Cases("mblaze", "microblaze", "mblaze") 197 .Case("arm", "arm") 198 .Cases("armv4t", "thumbv4t", "armv4t") 199 .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5") 200 .Cases("armv6", "thumbv6", "armv6") 201 .Cases("armv7", "thumbv7", "armv7") 202 .Case("r600", "r600") 203 .Case("nvptx", "nvptx") 204 .Case("nvptx64", "nvptx64") 205 .Case("le32", "le32") 206 .Case("amdil", "amdil") 207 .Case("spir", "spir") 208 .Case("spir64", "spir64") 209 .Default(NULL); 210 } 211 212 static Triple::ArchType parseArch(StringRef ArchName) { 213 return StringSwitch<Triple::ArchType>(ArchName) 214 .Cases("i386", "i486", "i586", "i686", Triple::x86) 215 // FIXME: Do we need to support these? 216 .Cases("i786", "i886", "i986", Triple::x86) 217 .Cases("amd64", "x86_64", Triple::x86_64) 218 .Case("powerpc", Triple::ppc) 219 .Cases("powerpc64", "ppu", Triple::ppc64) 220 .Case("mblaze", Triple::mblaze) 221 .Cases("arm", "xscale", Triple::arm) 222 // FIXME: It would be good to replace these with explicit names for all the 223 // various suffixes supported. 224 .StartsWith("armv", Triple::arm) 225 .Case("thumb", Triple::thumb) 226 .StartsWith("thumbv", Triple::thumb) 227 .Cases("spu", "cellspu", Triple::cellspu) 228 .Case("msp430", Triple::msp430) 229 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips) 230 .Cases("mipsel", "mipsallegrexel", Triple::mipsel) 231 .Cases("mips64", "mips64eb", Triple::mips64) 232 .Case("mips64el", Triple::mips64el) 233 .Case("r600", Triple::r600) 234 .Case("hexagon", Triple::hexagon) 235 .Case("sparc", Triple::sparc) 236 .Case("sparcv9", Triple::sparcv9) 237 .Case("tce", Triple::tce) 238 .Case("xcore", Triple::xcore) 239 .Case("nvptx", Triple::nvptx) 240 .Case("nvptx64", Triple::nvptx64) 241 .Case("le32", Triple::le32) 242 .Case("amdil", Triple::amdil) 243 .Case("spir", Triple::spir) 244 .Case("spir64", Triple::spir64) 245 .Default(Triple::UnknownArch); 246 } 247 248 static Triple::VendorType parseVendor(StringRef VendorName) { 249 return StringSwitch<Triple::VendorType>(VendorName) 250 .Case("apple", Triple::Apple) 251 .Case("pc", Triple::PC) 252 .Case("scei", Triple::SCEI) 253 .Case("bgp", Triple::BGP) 254 .Case("bgq", Triple::BGQ) 255 .Case("fsl", Triple::Freescale) 256 .Case("ibm", Triple::IBM) 257 .Default(Triple::UnknownVendor); 258 } 259 260 static Triple::OSType parseOS(StringRef OSName) { 261 return StringSwitch<Triple::OSType>(OSName) 262 .StartsWith("auroraux", Triple::AuroraUX) 263 .StartsWith("cygwin", Triple::Cygwin) 264 .StartsWith("darwin", Triple::Darwin) 265 .StartsWith("dragonfly", Triple::DragonFly) 266 .StartsWith("freebsd", Triple::FreeBSD) 267 .StartsWith("ios", Triple::IOS) 268 .StartsWith("kfreebsd", Triple::KFreeBSD) 269 .StartsWith("linux", Triple::Linux) 270 .StartsWith("lv2", Triple::Lv2) 271 .StartsWith("macosx", Triple::MacOSX) 272 .StartsWith("mingw32", Triple::MinGW32) 273 .StartsWith("netbsd", Triple::NetBSD) 274 .StartsWith("openbsd", Triple::OpenBSD) 275 .StartsWith("solaris", Triple::Solaris) 276 .StartsWith("win32", Triple::Win32) 277 .StartsWith("haiku", Triple::Haiku) 278 .StartsWith("minix", Triple::Minix) 279 .StartsWith("rtems", Triple::RTEMS) 280 .StartsWith("nacl", Triple::NativeClient) 281 .StartsWith("cnk", Triple::CNK) 282 .StartsWith("bitrig", Triple::Bitrig) 283 .StartsWith("aix", Triple::AIX) 284 .Default(Triple::UnknownOS); 285 } 286 287 static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) { 288 return StringSwitch<Triple::EnvironmentType>(EnvironmentName) 289 .StartsWith("eabi", Triple::EABI) 290 .StartsWith("gnueabihf", Triple::GNUEABIHF) 291 .StartsWith("gnueabi", Triple::GNUEABI) 292 .StartsWith("gnu", Triple::GNU) 293 .StartsWith("macho", Triple::MachO) 294 .StartsWith("android", Triple::Android) 295 .StartsWith("elf", Triple::ELF) 296 .Default(Triple::UnknownEnvironment); 297 } 298 299 /// \brief Construct a triple from the string representation provided. 300 /// 301 /// This stores the string representation and parses the various pieces into 302 /// enum members. 303 Triple::Triple(const Twine &Str) 304 : Data(Str.str()), 305 Arch(parseArch(getArchName())), 306 Vendor(parseVendor(getVendorName())), 307 OS(parseOS(getOSName())), 308 Environment(parseEnvironment(getEnvironmentName())) { 309 } 310 311 /// \brief Construct a triple from string representations of the architecture, 312 /// vendor, and OS. 313 /// 314 /// This joins each argument into a canonical string representation and parses 315 /// them into enum members. It leaves the environment unknown and omits it from 316 /// the string representation. 317 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr) 318 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()), 319 Arch(parseArch(ArchStr.str())), 320 Vendor(parseVendor(VendorStr.str())), 321 OS(parseOS(OSStr.str())), 322 Environment() { 323 } 324 325 /// \brief Construct a triple from string representations of the architecture, 326 /// vendor, OS, and environment. 327 /// 328 /// This joins each argument into a canonical string representation and parses 329 /// them into enum members. 330 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr, 331 const Twine &EnvironmentStr) 332 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') + 333 EnvironmentStr).str()), 334 Arch(parseArch(ArchStr.str())), 335 Vendor(parseVendor(VendorStr.str())), 336 OS(parseOS(OSStr.str())), 337 Environment(parseEnvironment(EnvironmentStr.str())) { 338 } 339 340 std::string Triple::normalize(StringRef Str) { 341 // Parse into components. 342 SmallVector<StringRef, 4> Components; 343 Str.split(Components, "-"); 344 345 // If the first component corresponds to a known architecture, preferentially 346 // use it for the architecture. If the second component corresponds to a 347 // known vendor, preferentially use it for the vendor, etc. This avoids silly 348 // component movement when a component parses as (eg) both a valid arch and a 349 // valid os. 350 ArchType Arch = UnknownArch; 351 if (Components.size() > 0) 352 Arch = parseArch(Components[0]); 353 VendorType Vendor = UnknownVendor; 354 if (Components.size() > 1) 355 Vendor = parseVendor(Components[1]); 356 OSType OS = UnknownOS; 357 if (Components.size() > 2) 358 OS = parseOS(Components[2]); 359 EnvironmentType Environment = UnknownEnvironment; 360 if (Components.size() > 3) 361 Environment = parseEnvironment(Components[3]); 362 363 // Note which components are already in their final position. These will not 364 // be moved. 365 bool Found[4]; 366 Found[0] = Arch != UnknownArch; 367 Found[1] = Vendor != UnknownVendor; 368 Found[2] = OS != UnknownOS; 369 Found[3] = Environment != UnknownEnvironment; 370 371 // If they are not there already, permute the components into their canonical 372 // positions by seeing if they parse as a valid architecture, and if so moving 373 // the component to the architecture position etc. 374 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) { 375 if (Found[Pos]) 376 continue; // Already in the canonical position. 377 378 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) { 379 // Do not reparse any components that already matched. 380 if (Idx < array_lengthof(Found) && Found[Idx]) 381 continue; 382 383 // Does this component parse as valid for the target position? 384 bool Valid = false; 385 StringRef Comp = Components[Idx]; 386 switch (Pos) { 387 default: llvm_unreachable("unexpected component type!"); 388 case 0: 389 Arch = parseArch(Comp); 390 Valid = Arch != UnknownArch; 391 break; 392 case 1: 393 Vendor = parseVendor(Comp); 394 Valid = Vendor != UnknownVendor; 395 break; 396 case 2: 397 OS = parseOS(Comp); 398 Valid = OS != UnknownOS; 399 break; 400 case 3: 401 Environment = parseEnvironment(Comp); 402 Valid = Environment != UnknownEnvironment; 403 break; 404 } 405 if (!Valid) 406 continue; // Nope, try the next component. 407 408 // Move the component to the target position, pushing any non-fixed 409 // components that are in the way to the right. This tends to give 410 // good results in the common cases of a forgotten vendor component 411 // or a wrongly positioned environment. 412 if (Pos < Idx) { 413 // Insert left, pushing the existing components to the right. For 414 // example, a-b-i386 -> i386-a-b when moving i386 to the front. 415 StringRef CurrentComponent(""); // The empty component. 416 // Replace the component we are moving with an empty component. 417 std::swap(CurrentComponent, Components[Idx]); 418 // Insert the component being moved at Pos, displacing any existing 419 // components to the right. 420 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) { 421 // Skip over any fixed components. 422 while (i < array_lengthof(Found) && Found[i]) 423 ++i; 424 // Place the component at the new position, getting the component 425 // that was at this position - it will be moved right. 426 std::swap(CurrentComponent, Components[i]); 427 } 428 } else if (Pos > Idx) { 429 // Push right by inserting empty components until the component at Idx 430 // reaches the target position Pos. For example, pc-a -> -pc-a when 431 // moving pc to the second position. 432 do { 433 // Insert one empty component at Idx. 434 StringRef CurrentComponent(""); // The empty component. 435 for (unsigned i = Idx; i < Components.size();) { 436 // Place the component at the new position, getting the component 437 // that was at this position - it will be moved right. 438 std::swap(CurrentComponent, Components[i]); 439 // If it was placed on top of an empty component then we are done. 440 if (CurrentComponent.empty()) 441 break; 442 // Advance to the next component, skipping any fixed components. 443 while (++i < array_lengthof(Found) && Found[i]) 444 ; 445 } 446 // The last component was pushed off the end - append it. 447 if (!CurrentComponent.empty()) 448 Components.push_back(CurrentComponent); 449 450 // Advance Idx to the component's new position. 451 while (++Idx < array_lengthof(Found) && Found[Idx]) 452 ; 453 } while (Idx < Pos); // Add more until the final position is reached. 454 } 455 assert(Pos < Components.size() && Components[Pos] == Comp && 456 "Component moved wrong!"); 457 Found[Pos] = true; 458 break; 459 } 460 } 461 462 // Special case logic goes here. At this point Arch, Vendor and OS have the 463 // correct values for the computed components. 464 465 // Stick the corrected components back together to form the normalized string. 466 std::string Normalized; 467 for (unsigned i = 0, e = Components.size(); i != e; ++i) { 468 if (i) Normalized += '-'; 469 Normalized += Components[i]; 470 } 471 return Normalized; 472 } 473 474 StringRef Triple::getArchName() const { 475 return StringRef(Data).split('-').first; // Isolate first component 476 } 477 478 StringRef Triple::getVendorName() const { 479 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component 480 return Tmp.split('-').first; // Isolate second component 481 } 482 483 StringRef Triple::getOSName() const { 484 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component 485 Tmp = Tmp.split('-').second; // Strip second component 486 return Tmp.split('-').first; // Isolate third component 487 } 488 489 StringRef Triple::getEnvironmentName() const { 490 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component 491 Tmp = Tmp.split('-').second; // Strip second component 492 return Tmp.split('-').second; // Strip third component 493 } 494 495 StringRef Triple::getOSAndEnvironmentName() const { 496 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component 497 return Tmp.split('-').second; // Strip second component 498 } 499 500 static unsigned EatNumber(StringRef &Str) { 501 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number"); 502 unsigned Result = 0; 503 504 do { 505 // Consume the leading digit. 506 Result = Result*10 + (Str[0] - '0'); 507 508 // Eat the digit. 509 Str = Str.substr(1); 510 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9'); 511 512 return Result; 513 } 514 515 void Triple::getOSVersion(unsigned &Major, unsigned &Minor, 516 unsigned &Micro) const { 517 StringRef OSName = getOSName(); 518 519 // Assume that the OS portion of the triple starts with the canonical name. 520 StringRef OSTypeName = getOSTypeName(getOS()); 521 if (OSName.startswith(OSTypeName)) 522 OSName = OSName.substr(OSTypeName.size()); 523 524 // Any unset version defaults to 0. 525 Major = Minor = Micro = 0; 526 527 // Parse up to three components. 528 unsigned *Components[3] = { &Major, &Minor, &Micro }; 529 for (unsigned i = 0; i != 3; ++i) { 530 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9') 531 break; 532 533 // Consume the leading number. 534 *Components[i] = EatNumber(OSName); 535 536 // Consume the separator, if present. 537 if (OSName.startswith(".")) 538 OSName = OSName.substr(1); 539 } 540 } 541 542 bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor, 543 unsigned &Micro) const { 544 getOSVersion(Major, Minor, Micro); 545 546 switch (getOS()) { 547 default: llvm_unreachable("unexpected OS for Darwin triple"); 548 case Darwin: 549 // Default to darwin8, i.e., MacOSX 10.4. 550 if (Major == 0) 551 Major = 8; 552 // Darwin version numbers are skewed from OS X versions. 553 if (Major < 4) 554 return false; 555 Micro = 0; 556 Minor = Major - 4; 557 Major = 10; 558 break; 559 case MacOSX: 560 // Default to 10.4. 561 if (Major == 0) { 562 Major = 10; 563 Minor = 4; 564 } 565 if (Major != 10) 566 return false; 567 break; 568 case IOS: 569 // Ignore the version from the triple. This is only handled because the 570 // the clang driver combines OS X and IOS support into a common Darwin 571 // toolchain that wants to know the OS X version number even when targeting 572 // IOS. 573 Major = 10; 574 Minor = 4; 575 Micro = 0; 576 break; 577 } 578 return true; 579 } 580 581 void Triple::getiOSVersion(unsigned &Major, unsigned &Minor, 582 unsigned &Micro) const { 583 switch (getOS()) { 584 default: llvm_unreachable("unexpected OS for Darwin triple"); 585 case Darwin: 586 case MacOSX: 587 // Ignore the version from the triple. This is only handled because the 588 // the clang driver combines OS X and IOS support into a common Darwin 589 // toolchain that wants to know the iOS version number even when targeting 590 // OS X. 591 Major = 3; 592 Minor = 0; 593 Micro = 0; 594 break; 595 case IOS: 596 getOSVersion(Major, Minor, Micro); 597 // Default to 3.0. 598 if (Major == 0) 599 Major = 3; 600 break; 601 } 602 } 603 604 void Triple::setTriple(const Twine &Str) { 605 *this = Triple(Str); 606 } 607 608 void Triple::setArch(ArchType Kind) { 609 setArchName(getArchTypeName(Kind)); 610 } 611 612 void Triple::setVendor(VendorType Kind) { 613 setVendorName(getVendorTypeName(Kind)); 614 } 615 616 void Triple::setOS(OSType Kind) { 617 setOSName(getOSTypeName(Kind)); 618 } 619 620 void Triple::setEnvironment(EnvironmentType Kind) { 621 setEnvironmentName(getEnvironmentTypeName(Kind)); 622 } 623 624 void Triple::setArchName(StringRef Str) { 625 // Work around a miscompilation bug for Twines in gcc 4.0.3. 626 SmallString<64> Triple; 627 Triple += Str; 628 Triple += "-"; 629 Triple += getVendorName(); 630 Triple += "-"; 631 Triple += getOSAndEnvironmentName(); 632 setTriple(Triple.str()); 633 } 634 635 void Triple::setVendorName(StringRef Str) { 636 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName()); 637 } 638 639 void Triple::setOSName(StringRef Str) { 640 if (hasEnvironment()) 641 setTriple(getArchName() + "-" + getVendorName() + "-" + Str + 642 "-" + getEnvironmentName()); 643 else 644 setTriple(getArchName() + "-" + getVendorName() + "-" + Str); 645 } 646 647 void Triple::setEnvironmentName(StringRef Str) { 648 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() + 649 "-" + Str); 650 } 651 652 void Triple::setOSAndEnvironmentName(StringRef Str) { 653 setTriple(getArchName() + "-" + getVendorName() + "-" + Str); 654 } 655 656 static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) { 657 switch (Arch) { 658 case llvm::Triple::UnknownArch: 659 return 0; 660 661 case llvm::Triple::msp430: 662 return 16; 663 664 case llvm::Triple::amdil: 665 case llvm::Triple::arm: 666 case llvm::Triple::cellspu: 667 case llvm::Triple::hexagon: 668 case llvm::Triple::le32: 669 case llvm::Triple::mblaze: 670 case llvm::Triple::mips: 671 case llvm::Triple::mipsel: 672 case llvm::Triple::nvptx: 673 case llvm::Triple::ppc: 674 case llvm::Triple::r600: 675 case llvm::Triple::sparc: 676 case llvm::Triple::tce: 677 case llvm::Triple::thumb: 678 case llvm::Triple::x86: 679 case llvm::Triple::xcore: 680 case llvm::Triple::spir: 681 return 32; 682 683 case llvm::Triple::mips64: 684 case llvm::Triple::mips64el: 685 case llvm::Triple::nvptx64: 686 case llvm::Triple::ppc64: 687 case llvm::Triple::sparcv9: 688 case llvm::Triple::x86_64: 689 case llvm::Triple::spir64: 690 return 64; 691 } 692 llvm_unreachable("Invalid architecture value"); 693 } 694 695 bool Triple::isArch64Bit() const { 696 return getArchPointerBitWidth(getArch()) == 64; 697 } 698 699 bool Triple::isArch32Bit() const { 700 return getArchPointerBitWidth(getArch()) == 32; 701 } 702 703 bool Triple::isArch16Bit() const { 704 return getArchPointerBitWidth(getArch()) == 16; 705 } 706 707 Triple Triple::get32BitArchVariant() const { 708 Triple T(*this); 709 switch (getArch()) { 710 case Triple::UnknownArch: 711 case Triple::msp430: 712 T.setArch(UnknownArch); 713 break; 714 715 case Triple::amdil: 716 case Triple::spir: 717 case Triple::arm: 718 case Triple::cellspu: 719 case Triple::hexagon: 720 case Triple::le32: 721 case Triple::mblaze: 722 case Triple::mips: 723 case Triple::mipsel: 724 case Triple::nvptx: 725 case Triple::ppc: 726 case Triple::r600: 727 case Triple::sparc: 728 case Triple::tce: 729 case Triple::thumb: 730 case Triple::x86: 731 case Triple::xcore: 732 // Already 32-bit. 733 break; 734 735 case Triple::mips64: T.setArch(Triple::mips); break; 736 case Triple::mips64el: T.setArch(Triple::mipsel); break; 737 case Triple::nvptx64: T.setArch(Triple::nvptx); break; 738 case Triple::ppc64: T.setArch(Triple::ppc); break; 739 case Triple::sparcv9: T.setArch(Triple::sparc); break; 740 case Triple::x86_64: T.setArch(Triple::x86); break; 741 case Triple::spir64: T.setArch(Triple::spir); break; 742 } 743 return T; 744 } 745 746 Triple Triple::get64BitArchVariant() const { 747 Triple T(*this); 748 switch (getArch()) { 749 case Triple::UnknownArch: 750 case Triple::amdil: 751 case Triple::arm: 752 case Triple::cellspu: 753 case Triple::hexagon: 754 case Triple::le32: 755 case Triple::mblaze: 756 case Triple::msp430: 757 case Triple::r600: 758 case Triple::tce: 759 case Triple::thumb: 760 case Triple::xcore: 761 T.setArch(UnknownArch); 762 break; 763 764 case Triple::spir64: 765 case Triple::mips64: 766 case Triple::mips64el: 767 case Triple::nvptx64: 768 case Triple::ppc64: 769 case Triple::sparcv9: 770 case Triple::x86_64: 771 // Already 64-bit. 772 break; 773 774 case Triple::mips: T.setArch(Triple::mips64); break; 775 case Triple::mipsel: T.setArch(Triple::mips64el); break; 776 case Triple::nvptx: T.setArch(Triple::nvptx64); break; 777 case Triple::ppc: T.setArch(Triple::ppc64); break; 778 case Triple::sparc: T.setArch(Triple::sparcv9); break; 779 case Triple::x86: T.setArch(Triple::x86_64); break; 780 case Triple::spir: T.setArch(Triple::spir64); break; 781 } 782 return T; 783 } 784