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