1 //===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_ADT_TRIPLE_H 10 #define LLVM_ADT_TRIPLE_H 11 12 #include "llvm/ADT/Twine.h" 13 14 // Some system headers or GCC predefined macros conflict with identifiers in 15 // this file. Undefine them here. 16 #undef NetBSD 17 #undef mips 18 #undef sparc 19 20 namespace llvm { 21 22 /// Triple - Helper class for working with autoconf configuration names. For 23 /// historical reasons, we also call these 'triples' (they used to contain 24 /// exactly three fields). 25 /// 26 /// Configuration names are strings in the canonical form: 27 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM 28 /// or 29 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT 30 /// 31 /// This class is used for clients which want to support arbitrary 32 /// configuration names, but also want to implement certain special 33 /// behavior for particular configurations. This class isolates the mapping 34 /// from the components of the configuration name to well known IDs. 35 /// 36 /// At its core the Triple class is designed to be a wrapper for a triple 37 /// string; the constructor does not change or normalize the triple string. 38 /// Clients that need to handle the non-canonical triples that users often 39 /// specify should use the normalize method. 40 /// 41 /// See autoconf/config.guess for a glimpse into what configuration names 42 /// look like in practice. 43 class Triple { 44 public: 45 enum ArchType { 46 UnknownArch, 47 48 arm, // ARM (little endian): arm, armv.*, xscale 49 armeb, // ARM (big endian): armeb 50 aarch64, // AArch64 (little endian): aarch64 51 aarch64_be, // AArch64 (big endian): aarch64_be 52 aarch64_32, // AArch64 (little endian) ILP32: aarch64_32 53 arc, // ARC: Synopsys ARC 54 avr, // AVR: Atmel AVR microcontroller 55 bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) 56 bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) 57 hexagon, // Hexagon: hexagon 58 mips, // MIPS: mips, mipsallegrex, mipsr6 59 mipsel, // MIPSEL: mipsel, mipsallegrexe, mipsr6el 60 mips64, // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6 61 mips64el, // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el 62 msp430, // MSP430: msp430 63 ppc, // PPC: powerpc 64 ppc64, // PPC64: powerpc64, ppu 65 ppc64le, // PPC64LE: powerpc64le 66 r600, // R600: AMD GPUs HD2XXX - HD6XXX 67 amdgcn, // AMDGCN: AMD GCN GPUs 68 riscv32, // RISC-V (32-bit): riscv32 69 riscv64, // RISC-V (64-bit): riscv64 70 sparc, // Sparc: sparc 71 sparcv9, // Sparcv9: Sparcv9 72 sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant 73 systemz, // SystemZ: s390x 74 tce, // TCE (http://tce.cs.tut.fi/): tce 75 tcele, // TCE little endian (http://tce.cs.tut.fi/): tcele 76 thumb, // Thumb (little endian): thumb, thumbv.* 77 thumbeb, // Thumb (big endian): thumbeb 78 x86, // X86: i[3-9]86 79 x86_64, // X86-64: amd64, x86_64 80 xcore, // XCore: xcore 81 nvptx, // NVPTX: 32-bit 82 nvptx64, // NVPTX: 64-bit 83 le32, // le32: generic little-endian 32-bit CPU (PNaCl) 84 le64, // le64: generic little-endian 64-bit CPU (PNaCl) 85 amdil, // AMDIL 86 amdil64, // AMDIL with 64-bit pointers 87 hsail, // AMD HSAIL 88 hsail64, // AMD HSAIL with 64-bit pointers 89 spir, // SPIR: standard portable IR for OpenCL 32-bit version 90 spir64, // SPIR: standard portable IR for OpenCL 64-bit version 91 kalimba, // Kalimba: generic kalimba 92 shave, // SHAVE: Movidius vector VLIW processors 93 lanai, // Lanai: Lanai 32-bit 94 wasm32, // WebAssembly with 32-bit pointers 95 wasm64, // WebAssembly with 64-bit pointers 96 renderscript32, // 32-bit RenderScript 97 renderscript64, // 64-bit RenderScript 98 LastArchType = renderscript64 99 }; 100 enum SubArchType { 101 NoSubArch, 102 103 ARMSubArch_v8_5a, 104 ARMSubArch_v8_4a, 105 ARMSubArch_v8_3a, 106 ARMSubArch_v8_2a, 107 ARMSubArch_v8_1a, 108 ARMSubArch_v8, 109 ARMSubArch_v8r, 110 ARMSubArch_v8m_baseline, 111 ARMSubArch_v8m_mainline, 112 ARMSubArch_v8_1m_mainline, 113 ARMSubArch_v7, 114 ARMSubArch_v7em, 115 ARMSubArch_v7m, 116 ARMSubArch_v7s, 117 ARMSubArch_v7k, 118 ARMSubArch_v7ve, 119 ARMSubArch_v6, 120 ARMSubArch_v6m, 121 ARMSubArch_v6k, 122 ARMSubArch_v6t2, 123 ARMSubArch_v5, 124 ARMSubArch_v5te, 125 ARMSubArch_v4t, 126 127 KalimbaSubArch_v3, 128 KalimbaSubArch_v4, 129 KalimbaSubArch_v5, 130 131 MipsSubArch_r6 132 }; 133 enum VendorType { 134 UnknownVendor, 135 136 Apple, 137 PC, 138 SCEI, 139 BGP, 140 BGQ, 141 Freescale, 142 IBM, 143 ImaginationTechnologies, 144 MipsTechnologies, 145 NVIDIA, 146 CSR, 147 Myriad, 148 AMD, 149 Mesa, 150 SUSE, 151 OpenEmbedded, 152 LastVendorType = OpenEmbedded 153 }; 154 enum OSType { 155 UnknownOS, 156 157 Ananas, 158 CloudABI, 159 Darwin, 160 DragonFly, 161 FreeBSD, 162 Fuchsia, 163 IOS, 164 KFreeBSD, 165 Linux, 166 Lv2, // PS3 167 MacOSX, 168 NetBSD, 169 OpenBSD, 170 Solaris, 171 Win32, 172 Haiku, 173 Minix, 174 RTEMS, 175 NaCl, // Native Client 176 CNK, // BG/P Compute-Node Kernel 177 AIX, 178 CUDA, // NVIDIA CUDA 179 NVCL, // NVIDIA OpenCL 180 AMDHSA, // AMD HSA Runtime 181 PS4, 182 ELFIAMCU, 183 TvOS, // Apple tvOS 184 WatchOS, // Apple watchOS 185 Mesa3D, 186 Contiki, 187 AMDPAL, // AMD PAL Runtime 188 HermitCore, // HermitCore Unikernel/Multikernel 189 Hurd, // GNU/Hurd 190 WASI, // Experimental WebAssembly OS 191 Emscripten, 192 LastOSType = Emscripten 193 }; 194 enum EnvironmentType { 195 UnknownEnvironment, 196 197 GNU, 198 GNUABIN32, 199 GNUABI64, 200 GNUEABI, 201 GNUEABIHF, 202 GNUX32, 203 CODE16, 204 EABI, 205 EABIHF, 206 ELFv1, 207 ELFv2, 208 Android, 209 Musl, 210 MuslEABI, 211 MuslEABIHF, 212 213 MSVC, 214 Itanium, 215 Cygnus, 216 CoreCLR, 217 Simulator, // Simulator variants of other systems, e.g., Apple's iOS 218 MacABI, // Mac Catalyst variant of Apple's iOS deployment target. 219 LastEnvironmentType = MacABI 220 }; 221 enum ObjectFormatType { 222 UnknownObjectFormat, 223 224 COFF, 225 ELF, 226 MachO, 227 Wasm, 228 XCOFF, 229 }; 230 231 private: 232 std::string Data; 233 234 /// The parsed arch type. 235 ArchType Arch; 236 237 /// The parsed subarchitecture type. 238 SubArchType SubArch; 239 240 /// The parsed vendor type. 241 VendorType Vendor; 242 243 /// The parsed OS type. 244 OSType OS; 245 246 /// The parsed Environment type. 247 EnvironmentType Environment; 248 249 /// The object format type. 250 ObjectFormatType ObjectFormat; 251 252 public: 253 /// @name Constructors 254 /// @{ 255 256 /// Default constructor is the same as an empty string and leaves all 257 /// triple fields unknown. Triple()258 Triple() 259 : Data(), Arch(), SubArch(), Vendor(), OS(), Environment(), 260 ObjectFormat() {} 261 262 explicit Triple(const Twine &Str); 263 Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr); 264 Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr, 265 const Twine &EnvironmentStr); 266 267 bool operator==(const Triple &Other) const { 268 return Arch == Other.Arch && SubArch == Other.SubArch && 269 Vendor == Other.Vendor && OS == Other.OS && 270 Environment == Other.Environment && 271 ObjectFormat == Other.ObjectFormat; 272 } 273 274 bool operator!=(const Triple &Other) const { 275 return !(*this == Other); 276 } 277 278 /// @} 279 /// @name Normalization 280 /// @{ 281 282 /// normalize - Turn an arbitrary machine specification into the canonical 283 /// triple form (or something sensible that the Triple class understands if 284 /// nothing better can reasonably be done). In particular, it handles the 285 /// common case in which otherwise valid components are in the wrong order. 286 static std::string normalize(StringRef Str); 287 288 /// Return the normalized form of this triple's string. normalize()289 std::string normalize() const { return normalize(Data); } 290 291 /// @} 292 /// @name Typed Component Access 293 /// @{ 294 295 /// getArch - Get the parsed architecture type of this triple. getArch()296 ArchType getArch() const { return Arch; } 297 298 /// getSubArch - get the parsed subarchitecture type for this triple. getSubArch()299 SubArchType getSubArch() const { return SubArch; } 300 301 /// getVendor - Get the parsed vendor type of this triple. getVendor()302 VendorType getVendor() const { return Vendor; } 303 304 /// getOS - Get the parsed operating system type of this triple. getOS()305 OSType getOS() const { return OS; } 306 307 /// hasEnvironment - Does this triple have the optional environment 308 /// (fourth) component? hasEnvironment()309 bool hasEnvironment() const { 310 return getEnvironmentName() != ""; 311 } 312 313 /// getEnvironment - Get the parsed environment type of this triple. getEnvironment()314 EnvironmentType getEnvironment() const { return Environment; } 315 316 /// Parse the version number from the OS name component of the 317 /// triple, if present. 318 /// 319 /// For example, "fooos1.2.3" would return (1, 2, 3). 320 /// 321 /// If an entry is not defined, it will be returned as 0. 322 void getEnvironmentVersion(unsigned &Major, unsigned &Minor, 323 unsigned &Micro) const; 324 325 /// getFormat - Get the object format for this triple. getObjectFormat()326 ObjectFormatType getObjectFormat() const { return ObjectFormat; } 327 328 /// getOSVersion - Parse the version number from the OS name component of the 329 /// triple, if present. 330 /// 331 /// For example, "fooos1.2.3" would return (1, 2, 3). 332 /// 333 /// If an entry is not defined, it will be returned as 0. 334 void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const; 335 336 /// getOSMajorVersion - Return just the major version number, this is 337 /// specialized because it is a common query. getOSMajorVersion()338 unsigned getOSMajorVersion() const { 339 unsigned Maj, Min, Micro; 340 getOSVersion(Maj, Min, Micro); 341 return Maj; 342 } 343 344 /// getMacOSXVersion - Parse the version number as with getOSVersion and then 345 /// translate generic "darwin" versions to the corresponding OS X versions. 346 /// This may also be called with IOS triples but the OS X version number is 347 /// just set to a constant 10.4.0 in that case. Returns true if successful. 348 bool getMacOSXVersion(unsigned &Major, unsigned &Minor, 349 unsigned &Micro) const; 350 351 /// getiOSVersion - Parse the version number as with getOSVersion. This should 352 /// only be called with IOS or generic triples. 353 void getiOSVersion(unsigned &Major, unsigned &Minor, 354 unsigned &Micro) const; 355 356 /// getWatchOSVersion - Parse the version number as with getOSVersion. This 357 /// should only be called with WatchOS or generic triples. 358 void getWatchOSVersion(unsigned &Major, unsigned &Minor, 359 unsigned &Micro) const; 360 361 /// @} 362 /// @name Direct Component Access 363 /// @{ 364 str()365 const std::string &str() const { return Data; } 366 getTriple()367 const std::string &getTriple() const { return Data; } 368 369 /// getArchName - Get the architecture (first) component of the 370 /// triple. 371 StringRef getArchName() const; 372 373 /// getVendorName - Get the vendor (second) component of the triple. 374 StringRef getVendorName() const; 375 376 /// getOSName - Get the operating system (third) component of the 377 /// triple. 378 StringRef getOSName() const; 379 380 /// getEnvironmentName - Get the optional environment (fourth) 381 /// component of the triple, or "" if empty. 382 StringRef getEnvironmentName() const; 383 384 /// getOSAndEnvironmentName - Get the operating system and optional 385 /// environment components as a single string (separated by a '-' 386 /// if the environment component is present). 387 StringRef getOSAndEnvironmentName() const; 388 389 /// @} 390 /// @name Convenience Predicates 391 /// @{ 392 393 /// Test whether the architecture is 64-bit 394 /// 395 /// Note that this tests for 64-bit pointer width, and nothing else. Note 396 /// that we intentionally expose only three predicates, 64-bit, 32-bit, and 397 /// 16-bit. The inner details of pointer width for particular architectures 398 /// is not summed up in the triple, and so only a coarse grained predicate 399 /// system is provided. 400 bool isArch64Bit() const; 401 402 /// Test whether the architecture is 32-bit 403 /// 404 /// Note that this tests for 32-bit pointer width, and nothing else. 405 bool isArch32Bit() const; 406 407 /// Test whether the architecture is 16-bit 408 /// 409 /// Note that this tests for 16-bit pointer width, and nothing else. 410 bool isArch16Bit() const; 411 412 /// isOSVersionLT - Helper function for doing comparisons against version 413 /// numbers included in the target triple. 414 bool isOSVersionLT(unsigned Major, unsigned Minor = 0, 415 unsigned Micro = 0) const { 416 unsigned LHS[3]; 417 getOSVersion(LHS[0], LHS[1], LHS[2]); 418 419 if (LHS[0] != Major) 420 return LHS[0] < Major; 421 if (LHS[1] != Minor) 422 return LHS[1] < Minor; 423 if (LHS[2] != Micro) 424 return LHS[2] < Micro; 425 426 return false; 427 } 428 isOSVersionLT(const Triple & Other)429 bool isOSVersionLT(const Triple &Other) const { 430 unsigned RHS[3]; 431 Other.getOSVersion(RHS[0], RHS[1], RHS[2]); 432 return isOSVersionLT(RHS[0], RHS[1], RHS[2]); 433 } 434 435 /// isMacOSXVersionLT - Comparison function for checking OS X version 436 /// compatibility, which handles supporting skewed version numbering schemes 437 /// used by the "darwin" triples. 438 bool isMacOSXVersionLT(unsigned Major, unsigned Minor = 0, 439 unsigned Micro = 0) const { 440 assert(isMacOSX() && "Not an OS X triple!"); 441 442 // If this is OS X, expect a sane version number. 443 if (getOS() == Triple::MacOSX) 444 return isOSVersionLT(Major, Minor, Micro); 445 446 // Otherwise, compare to the "Darwin" number. 447 assert(Major == 10 && "Unexpected major version"); 448 return isOSVersionLT(Minor + 4, Micro, 0); 449 } 450 451 /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both 452 /// "darwin" and "osx" as OS X triples. isMacOSX()453 bool isMacOSX() const { 454 return getOS() == Triple::Darwin || getOS() == Triple::MacOSX; 455 } 456 457 /// Is this an iOS triple. 458 /// Note: This identifies tvOS as a variant of iOS. If that ever 459 /// changes, i.e., if the two operating systems diverge or their version 460 /// numbers get out of sync, that will need to be changed. 461 /// watchOS has completely different version numbers so it is not included. isiOS()462 bool isiOS() const { 463 return getOS() == Triple::IOS || isTvOS(); 464 } 465 466 /// Is this an Apple tvOS triple. isTvOS()467 bool isTvOS() const { 468 return getOS() == Triple::TvOS; 469 } 470 471 /// Is this an Apple watchOS triple. isWatchOS()472 bool isWatchOS() const { 473 return getOS() == Triple::WatchOS; 474 } 475 isWatchABI()476 bool isWatchABI() const { 477 return getSubArch() == Triple::ARMSubArch_v7k; 478 } 479 480 /// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS). isOSDarwin()481 bool isOSDarwin() const { 482 return isMacOSX() || isiOS() || isWatchOS(); 483 } 484 isSimulatorEnvironment()485 bool isSimulatorEnvironment() const { 486 return getEnvironment() == Triple::Simulator; 487 } 488 isMacCatalystEnvironment()489 bool isMacCatalystEnvironment() const { 490 return getEnvironment() == Triple::MacABI; 491 } 492 isOSNetBSD()493 bool isOSNetBSD() const { 494 return getOS() == Triple::NetBSD; 495 } 496 isOSOpenBSD()497 bool isOSOpenBSD() const { 498 return getOS() == Triple::OpenBSD; 499 } 500 isOSFreeBSD()501 bool isOSFreeBSD() const { 502 return getOS() == Triple::FreeBSD; 503 } 504 isOSFuchsia()505 bool isOSFuchsia() const { 506 return getOS() == Triple::Fuchsia; 507 } 508 isOSDragonFly()509 bool isOSDragonFly() const { return getOS() == Triple::DragonFly; } 510 isOSSolaris()511 bool isOSSolaris() const { 512 return getOS() == Triple::Solaris; 513 } 514 isOSIAMCU()515 bool isOSIAMCU() const { 516 return getOS() == Triple::ELFIAMCU; 517 } 518 isOSUnknown()519 bool isOSUnknown() const { return getOS() == Triple::UnknownOS; } 520 isGNUEnvironment()521 bool isGNUEnvironment() const { 522 EnvironmentType Env = getEnvironment(); 523 return Env == Triple::GNU || Env == Triple::GNUABIN32 || 524 Env == Triple::GNUABI64 || Env == Triple::GNUEABI || 525 Env == Triple::GNUEABIHF || Env == Triple::GNUX32; 526 } 527 isOSContiki()528 bool isOSContiki() const { 529 return getOS() == Triple::Contiki; 530 } 531 532 /// Tests whether the OS is Haiku. isOSHaiku()533 bool isOSHaiku() const { 534 return getOS() == Triple::Haiku; 535 } 536 537 /// Tests whether the OS is Windows. isOSWindows()538 bool isOSWindows() const { 539 return getOS() == Triple::Win32; 540 } 541 542 /// Checks if the environment is MSVC. isKnownWindowsMSVCEnvironment()543 bool isKnownWindowsMSVCEnvironment() const { 544 return isOSWindows() && getEnvironment() == Triple::MSVC; 545 } 546 547 /// Checks if the environment could be MSVC. isWindowsMSVCEnvironment()548 bool isWindowsMSVCEnvironment() const { 549 return isKnownWindowsMSVCEnvironment() || 550 (isOSWindows() && getEnvironment() == Triple::UnknownEnvironment); 551 } 552 isWindowsCoreCLREnvironment()553 bool isWindowsCoreCLREnvironment() const { 554 return isOSWindows() && getEnvironment() == Triple::CoreCLR; 555 } 556 isWindowsItaniumEnvironment()557 bool isWindowsItaniumEnvironment() const { 558 return isOSWindows() && getEnvironment() == Triple::Itanium; 559 } 560 isWindowsCygwinEnvironment()561 bool isWindowsCygwinEnvironment() const { 562 return isOSWindows() && getEnvironment() == Triple::Cygnus; 563 } 564 isWindowsGNUEnvironment()565 bool isWindowsGNUEnvironment() const { 566 return isOSWindows() && getEnvironment() == Triple::GNU; 567 } 568 569 /// Tests for either Cygwin or MinGW OS isOSCygMing()570 bool isOSCygMing() const { 571 return isWindowsCygwinEnvironment() || isWindowsGNUEnvironment(); 572 } 573 574 /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment. isOSMSVCRT()575 bool isOSMSVCRT() const { 576 return isWindowsMSVCEnvironment() || isWindowsGNUEnvironment() || 577 isWindowsItaniumEnvironment(); 578 } 579 580 /// Tests whether the OS is NaCl (Native Client) isOSNaCl()581 bool isOSNaCl() const { 582 return getOS() == Triple::NaCl; 583 } 584 585 /// Tests whether the OS is Linux. isOSLinux()586 bool isOSLinux() const { 587 return getOS() == Triple::Linux; 588 } 589 590 /// Tests whether the OS is kFreeBSD. isOSKFreeBSD()591 bool isOSKFreeBSD() const { 592 return getOS() == Triple::KFreeBSD; 593 } 594 595 /// Tests whether the OS is Hurd. isOSHurd()596 bool isOSHurd() const { 597 return getOS() == Triple::Hurd; 598 } 599 600 /// Tests whether the OS is WASI. isOSWASI()601 bool isOSWASI() const { 602 return getOS() == Triple::WASI; 603 } 604 605 /// Tests whether the OS is Emscripten. isOSEmscripten()606 bool isOSEmscripten() const { 607 return getOS() == Triple::Emscripten; 608 } 609 610 /// Tests whether the OS uses glibc. isOSGlibc()611 bool isOSGlibc() const { 612 return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD || 613 getOS() == Triple::Hurd) && 614 !isAndroid(); 615 } 616 617 /// Tests whether the OS is AIX. isOSAIX()618 bool isOSAIX() const { 619 return getOS() == Triple::AIX; 620 } 621 622 /// Tests whether the OS uses the ELF binary format. isOSBinFormatELF()623 bool isOSBinFormatELF() const { 624 return getObjectFormat() == Triple::ELF; 625 } 626 627 /// Tests whether the OS uses the COFF binary format. isOSBinFormatCOFF()628 bool isOSBinFormatCOFF() const { 629 return getObjectFormat() == Triple::COFF; 630 } 631 632 /// Tests whether the environment is MachO. isOSBinFormatMachO()633 bool isOSBinFormatMachO() const { 634 return getObjectFormat() == Triple::MachO; 635 } 636 637 /// Tests whether the OS uses the Wasm binary format. isOSBinFormatWasm()638 bool isOSBinFormatWasm() const { 639 return getObjectFormat() == Triple::Wasm; 640 } 641 642 /// Tests whether the OS uses the XCOFF binary format. isOSBinFormatXCOFF()643 bool isOSBinFormatXCOFF() const { 644 return getObjectFormat() == Triple::XCOFF; 645 } 646 647 /// Tests whether the target is the PS4 CPU isPS4CPU()648 bool isPS4CPU() const { 649 return getArch() == Triple::x86_64 && 650 getVendor() == Triple::SCEI && 651 getOS() == Triple::PS4; 652 } 653 654 /// Tests whether the target is the PS4 platform isPS4()655 bool isPS4() const { 656 return getVendor() == Triple::SCEI && 657 getOS() == Triple::PS4; 658 } 659 660 /// Tests whether the target is Android isAndroid()661 bool isAndroid() const { return getEnvironment() == Triple::Android; } 662 isAndroidVersionLT(unsigned Major)663 bool isAndroidVersionLT(unsigned Major) const { 664 assert(isAndroid() && "Not an Android triple!"); 665 666 unsigned Env[3]; 667 getEnvironmentVersion(Env[0], Env[1], Env[2]); 668 669 // 64-bit targets did not exist before API level 21 (Lollipop). 670 if (isArch64Bit() && Env[0] < 21) 671 Env[0] = 21; 672 673 return Env[0] < Major; 674 } 675 676 /// Tests whether the environment is musl-libc isMusl()677 bool isMusl() const { 678 return getEnvironment() == Triple::Musl || 679 getEnvironment() == Triple::MuslEABI || 680 getEnvironment() == Triple::MuslEABIHF; 681 } 682 683 /// Tests whether the target is SPIR (32- or 64-bit). isSPIR()684 bool isSPIR() const { 685 return getArch() == Triple::spir || getArch() == Triple::spir64; 686 } 687 688 /// Tests whether the target is NVPTX (32- or 64-bit). isNVPTX()689 bool isNVPTX() const { 690 return getArch() == Triple::nvptx || getArch() == Triple::nvptx64; 691 } 692 693 /// Tests whether the target is Thumb (little and big endian). isThumb()694 bool isThumb() const { 695 return getArch() == Triple::thumb || getArch() == Triple::thumbeb; 696 } 697 698 /// Tests whether the target is ARM (little and big endian). isARM()699 bool isARM() const { 700 return getArch() == Triple::arm || getArch() == Triple::armeb; 701 } 702 703 /// Tests whether the target is AArch64 (little and big endian). isAArch64()704 bool isAArch64() const { 705 return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be; 706 } 707 708 /// Tests whether the target is MIPS 32-bit (little and big endian). isMIPS32()709 bool isMIPS32() const { 710 return getArch() == Triple::mips || getArch() == Triple::mipsel; 711 } 712 713 /// Tests whether the target is MIPS 64-bit (little and big endian). isMIPS64()714 bool isMIPS64() const { 715 return getArch() == Triple::mips64 || getArch() == Triple::mips64el; 716 } 717 718 /// Tests whether the target is MIPS (little and big endian, 32- or 64-bit). isMIPS()719 bool isMIPS() const { 720 return isMIPS32() || isMIPS64(); 721 } 722 723 /// Tests whether the target is 64-bit PowerPC (little and big endian). isPPC64()724 bool isPPC64() const { 725 return getArch() == Triple::ppc64 || getArch() == Triple::ppc64le; 726 } 727 728 /// Tests whether the target is RISC-V (32- and 64-bit). isRISCV()729 bool isRISCV() const { 730 return getArch() == Triple::riscv32 || getArch() == Triple::riscv64; 731 } 732 733 /// Tests whether the target supports comdat supportsCOMDAT()734 bool supportsCOMDAT() const { 735 return !isOSBinFormatMachO(); 736 } 737 738 /// Tests whether the target uses emulated TLS as default. hasDefaultEmulatedTLS()739 bool hasDefaultEmulatedTLS() const { 740 return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment(); 741 } 742 743 /// @} 744 /// @name Mutators 745 /// @{ 746 747 /// setArch - Set the architecture (first) component of the triple 748 /// to a known type. 749 void setArch(ArchType Kind); 750 751 /// setVendor - Set the vendor (second) component of the triple to a 752 /// known type. 753 void setVendor(VendorType Kind); 754 755 /// setOS - Set the operating system (third) component of the triple 756 /// to a known type. 757 void setOS(OSType Kind); 758 759 /// setEnvironment - Set the environment (fourth) component of the triple 760 /// to a known type. 761 void setEnvironment(EnvironmentType Kind); 762 763 /// setObjectFormat - Set the object file format 764 void setObjectFormat(ObjectFormatType Kind); 765 766 /// setTriple - Set all components to the new triple \p Str. 767 void setTriple(const Twine &Str); 768 769 /// setArchName - Set the architecture (first) component of the 770 /// triple by name. 771 void setArchName(StringRef Str); 772 773 /// setVendorName - Set the vendor (second) component of the triple 774 /// by name. 775 void setVendorName(StringRef Str); 776 777 /// setOSName - Set the operating system (third) component of the 778 /// triple by name. 779 void setOSName(StringRef Str); 780 781 /// setEnvironmentName - Set the optional environment (fourth) 782 /// component of the triple by name. 783 void setEnvironmentName(StringRef Str); 784 785 /// setOSAndEnvironmentName - Set the operating system and optional 786 /// environment components with a single string. 787 void setOSAndEnvironmentName(StringRef Str); 788 789 /// @} 790 /// @name Helpers to build variants of a particular triple. 791 /// @{ 792 793 /// Form a triple with a 32-bit variant of the current architecture. 794 /// 795 /// This can be used to move across "families" of architectures where useful. 796 /// 797 /// \returns A new triple with a 32-bit architecture or an unknown 798 /// architecture if no such variant can be found. 799 llvm::Triple get32BitArchVariant() const; 800 801 /// Form a triple with a 64-bit variant of the current architecture. 802 /// 803 /// This can be used to move across "families" of architectures where useful. 804 /// 805 /// \returns A new triple with a 64-bit architecture or an unknown 806 /// architecture if no such variant can be found. 807 llvm::Triple get64BitArchVariant() const; 808 809 /// Form a triple with a big endian variant of the current architecture. 810 /// 811 /// This can be used to move across "families" of architectures where useful. 812 /// 813 /// \returns A new triple with a big endian architecture or an unknown 814 /// architecture if no such variant can be found. 815 llvm::Triple getBigEndianArchVariant() const; 816 817 /// Form a triple with a little endian variant of the current architecture. 818 /// 819 /// This can be used to move across "families" of architectures where useful. 820 /// 821 /// \returns A new triple with a little endian architecture or an unknown 822 /// architecture if no such variant can be found. 823 llvm::Triple getLittleEndianArchVariant() const; 824 825 /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting. 826 /// 827 /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty 828 /// string then the triple's arch name is used. 829 StringRef getARMCPUForArch(StringRef Arch = StringRef()) const; 830 831 /// Tests whether the target triple is little endian. 832 /// 833 /// \returns true if the triple is little endian, false otherwise. 834 bool isLittleEndian() const; 835 836 /// Test whether target triples are compatible. 837 bool isCompatibleWith(const Triple &Other) const; 838 839 /// Merge target triples. 840 std::string merge(const Triple &Other) const; 841 842 /// @} 843 /// @name Static helpers for IDs. 844 /// @{ 845 846 /// getArchTypeName - Get the canonical name for the \p Kind architecture. 847 static StringRef getArchTypeName(ArchType Kind); 848 849 /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind 850 /// architecture. This is the prefix used by the architecture specific 851 /// builtins, and is suitable for passing to \see 852 /// Intrinsic::getIntrinsicForGCCBuiltin(). 853 /// 854 /// \return - The architecture prefix, or 0 if none is defined. 855 static StringRef getArchTypePrefix(ArchType Kind); 856 857 /// getVendorTypeName - Get the canonical name for the \p Kind vendor. 858 static StringRef getVendorTypeName(VendorType Kind); 859 860 /// getOSTypeName - Get the canonical name for the \p Kind operating system. 861 static StringRef getOSTypeName(OSType Kind); 862 863 /// getEnvironmentTypeName - Get the canonical name for the \p Kind 864 /// environment. 865 static StringRef getEnvironmentTypeName(EnvironmentType Kind); 866 867 /// @} 868 /// @name Static helpers for converting alternate architecture names. 869 /// @{ 870 871 /// getArchTypeForLLVMName - The canonical type for the given LLVM 872 /// architecture name (e.g., "x86"). 873 static ArchType getArchTypeForLLVMName(StringRef Str); 874 875 /// @} 876 }; 877 878 } // End llvm namespace 879 880 881 #endif 882