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