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