LCOV - code coverage report
Current view: top level - include/llvm/ADT - Triple.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 77 78 98.7 %
Date: 2018-06-17 00:07:59 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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     2058437 : 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             :     CoreCLR,
     206             :     Simulator,  // Simulator variants of other systems, e.g., Apple's iOS
     207             :     LastEnvironmentType = Simulator
     208             :   };
     209             :   enum ObjectFormatType {
     210             :     UnknownObjectFormat,
     211             : 
     212             :     COFF,
     213             :     ELF,
     214             :     MachO,
     215             :     Wasm,
     216             :   };
     217             : 
     218             : private:
     219             :   std::string Data;
     220             : 
     221             :   /// The parsed arch type.
     222             :   ArchType Arch;
     223             : 
     224             :   /// The parsed subarchitecture type.
     225             :   SubArchType SubArch;
     226             : 
     227             :   /// The parsed vendor type.
     228             :   VendorType Vendor;
     229             : 
     230             :   /// The parsed OS type.
     231             :   OSType OS;
     232             : 
     233             :   /// The parsed Environment type.
     234             :   EnvironmentType Environment;
     235             : 
     236             :   /// The object format type.
     237             :   ObjectFormatType ObjectFormat;
     238             : 
     239             : public:
     240             :   /// @name Constructors
     241             :   /// @{
     242             : 
     243             :   /// Default constructor is the same as an empty string and leaves all
     244             :   /// triple fields unknown.
     245             :   Triple()
     246      295143 :       : Data(), Arch(), SubArch(), Vendor(), OS(), Environment(),
     247      295942 :         ObjectFormat() {}
     248             : 
     249             :   explicit Triple(const Twine &Str);
     250             :   Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
     251             :   Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
     252             :          const Twine &EnvironmentStr);
     253             : 
     254             :   bool operator==(const Triple &Other) const {
     255         682 :     return Arch == Other.Arch && SubArch == Other.SubArch &&
     256         630 :            Vendor == Other.Vendor && OS == Other.OS &&
     257        1299 :            Environment == Other.Environment &&
     258             :            ObjectFormat == Other.ObjectFormat;
     259             :   }
     260             : 
     261             :   bool operator!=(const Triple &Other) const {
     262             :     return !(*this == Other);
     263             :   }
     264             : 
     265             :   /// @}
     266             :   /// @name Normalization
     267             :   /// @{
     268             : 
     269             :   /// normalize - Turn an arbitrary machine specification into the canonical
     270             :   /// triple form (or something sensible that the Triple class understands if
     271             :   /// nothing better can reasonably be done).  In particular, it handles the
     272             :   /// common case in which otherwise valid components are in the wrong order.
     273             :   static std::string normalize(StringRef Str);
     274             : 
     275             :   /// Return the normalized form of this triple's string.
     276       62985 :   std::string normalize() const { return normalize(Data); }
     277             : 
     278             :   /// @}
     279             :   /// @name Typed Component Access
     280             :   /// @{
     281             : 
     282             :   /// getArch - Get the parsed architecture type of this triple.
     283             :   ArchType getArch() const { return Arch; }
     284             : 
     285             :   /// getSubArch - get the parsed subarchitecture type for this triple.
     286             :   SubArchType getSubArch() const { return SubArch; }
     287             : 
     288             :   /// getVendor - Get the parsed vendor type of this triple.
     289             :   VendorType getVendor() const { return Vendor; }
     290             : 
     291             :   /// getOS - Get the parsed operating system type of this triple.
     292             :   OSType getOS() const { return OS; }
     293             : 
     294             :   /// hasEnvironment - Does this triple have the optional environment
     295             :   /// (fourth) component?
     296             :   bool hasEnvironment() const {
     297       12244 :     return getEnvironmentName() != "";
     298             :   }
     299             : 
     300             :   /// getEnvironment - Get the parsed environment type of this triple.
     301             :   EnvironmentType getEnvironment() const { return Environment; }
     302             : 
     303             :   /// Parse the version number from the OS name component of the
     304             :   /// triple, if present.
     305             :   ///
     306             :   /// For example, "fooos1.2.3" would return (1, 2, 3).
     307             :   ///
     308             :   /// If an entry is not defined, it will be returned as 0.
     309             :   void getEnvironmentVersion(unsigned &Major, unsigned &Minor,
     310             :                              unsigned &Micro) const;
     311             : 
     312             :   /// getFormat - Get the object format for this triple.
     313             :   ObjectFormatType getObjectFormat() const { return ObjectFormat; }
     314             : 
     315             :   /// getOSVersion - Parse the version number from the OS name component of the
     316             :   /// triple, if present.
     317             :   ///
     318             :   /// For example, "fooos1.2.3" would return (1, 2, 3).
     319             :   ///
     320             :   /// If an entry is not defined, it will be returned as 0.
     321             :   void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
     322             : 
     323             :   /// getOSMajorVersion - Return just the major version number, this is
     324             :   /// specialized because it is a common query.
     325             :   unsigned getOSMajorVersion() const {
     326             :     unsigned Maj, Min, Micro;
     327        3115 :     getOSVersion(Maj, Min, Micro);
     328        3115 :     return Maj;
     329             :   }
     330             : 
     331             :   /// getMacOSXVersion - Parse the version number as with getOSVersion and then
     332             :   /// translate generic "darwin" versions to the corresponding OS X versions.
     333             :   /// This may also be called with IOS triples but the OS X version number is
     334             :   /// just set to a constant 10.4.0 in that case.  Returns true if successful.
     335             :   bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
     336             :                         unsigned &Micro) const;
     337             : 
     338             :   /// getiOSVersion - Parse the version number as with getOSVersion.  This should
     339             :   /// only be called with IOS or generic triples.
     340             :   void getiOSVersion(unsigned &Major, unsigned &Minor,
     341             :                      unsigned &Micro) const;
     342             : 
     343             :   /// getWatchOSVersion - Parse the version number as with getOSVersion.  This
     344             :   /// should only be called with WatchOS or generic triples.
     345             :   void getWatchOSVersion(unsigned &Major, unsigned &Minor,
     346             :                          unsigned &Micro) const;
     347             : 
     348             :   /// @}
     349             :   /// @name Direct Component Access
     350             :   /// @{
     351             : 
     352       33288 :   const std::string &str() const { return Data; }
     353             : 
     354       43438 :   const std::string &getTriple() const { return Data; }
     355             : 
     356             :   /// getArchName - Get the architecture (first) component of the
     357             :   /// triple.
     358             :   StringRef getArchName() const;
     359             : 
     360             :   /// getVendorName - Get the vendor (second) component of the triple.
     361             :   StringRef getVendorName() const;
     362             : 
     363             :   /// getOSName - Get the operating system (third) component of the
     364             :   /// triple.
     365             :   StringRef getOSName() const;
     366             : 
     367             :   /// getEnvironmentName - Get the optional environment (fourth)
     368             :   /// component of the triple, or "" if empty.
     369             :   StringRef getEnvironmentName() const;
     370             : 
     371             :   /// getOSAndEnvironmentName - Get the operating system and optional
     372             :   /// environment components as a single string (separated by a '-'
     373             :   /// if the environment component is present).
     374             :   StringRef getOSAndEnvironmentName() const;
     375             : 
     376             :   /// @}
     377             :   /// @name Convenience Predicates
     378             :   /// @{
     379             : 
     380             :   /// Test whether the architecture is 64-bit
     381             :   ///
     382             :   /// Note that this tests for 64-bit pointer width, and nothing else. Note
     383             :   /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
     384             :   /// 16-bit. The inner details of pointer width for particular architectures
     385             :   /// is not summed up in the triple, and so only a coarse grained predicate
     386             :   /// system is provided.
     387             :   bool isArch64Bit() const;
     388             : 
     389             :   /// Test whether the architecture is 32-bit
     390             :   ///
     391             :   /// Note that this tests for 32-bit pointer width, and nothing else.
     392             :   bool isArch32Bit() const;
     393             : 
     394             :   /// Test whether the architecture is 16-bit
     395             :   ///
     396             :   /// Note that this tests for 16-bit pointer width, and nothing else.
     397             :   bool isArch16Bit() const;
     398             : 
     399             :   /// isOSVersionLT - Helper function for doing comparisons against version
     400             :   /// numbers included in the target triple.
     401       30776 :   bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
     402             :                      unsigned Micro = 0) const {
     403             :     unsigned LHS[3];
     404       30776 :     getOSVersion(LHS[0], LHS[1], LHS[2]);
     405             : 
     406       30776 :     if (LHS[0] != Major)
     407       21859 :       return LHS[0] < Major;
     408        8917 :     if (LHS[1] != Minor)
     409        5441 :       return LHS[1] < Minor;
     410        3476 :     if (LHS[2] != Micro)
     411          48 :       return LHS[1] < Micro;
     412             : 
     413             :     return false;
     414             :   }
     415             : 
     416          70 :   bool isOSVersionLT(const Triple &Other) const {
     417             :     unsigned RHS[3];
     418          70 :     Other.getOSVersion(RHS[0], RHS[1], RHS[2]);
     419          70 :     return isOSVersionLT(RHS[0], RHS[1], RHS[2]);
     420             :   }
     421             : 
     422             :   /// isMacOSXVersionLT - Comparison function for checking OS X version
     423             :   /// compatibility, which handles supporting skewed version numbering schemes
     424             :   /// used by the "darwin" triples.
     425       25997 :   bool isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
     426             :                          unsigned Micro = 0) const {
     427             :     assert(isMacOSX() && "Not an OS X triple!");
     428             : 
     429             :     // If this is OS X, expect a sane version number.
     430       25997 :     if (getOS() == Triple::MacOSX)
     431        6288 :       return isOSVersionLT(Major, Minor, Micro);
     432             : 
     433             :     // Otherwise, compare to the "Darwin" number.
     434             :     assert(Major == 10 && "Unexpected major version");
     435       19709 :     return isOSVersionLT(Minor + 4, Micro, 0);
     436             :   }
     437             : 
     438             :   /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
     439             :   /// "darwin" and "osx" as OS X triples.
     440             :   bool isMacOSX() const {
     441     4862930 :     return getOS() == Triple::Darwin || getOS() == Triple::MacOSX;
     442             :   }
     443             : 
     444             :   /// Is this an iOS triple.
     445             :   /// Note: This identifies tvOS as a variant of iOS. If that ever
     446             :   /// changes, i.e., if the two operating systems diverge or their version
     447             :   /// numbers get out of sync, that will need to be changed.
     448             :   /// watchOS has completely different version numbers so it is not included.
     449             :   bool isiOS() const {
     450     3915862 :     return getOS() == Triple::IOS || isTvOS();
     451             :   }
     452             : 
     453             :   /// Is this an Apple tvOS triple.
     454             :   bool isTvOS() const {
     455         204 :     return getOS() == Triple::TvOS;
     456             :   }
     457             : 
     458             :   /// Is this an Apple watchOS triple.
     459             :   bool isWatchOS() const {
     460        3127 :     return getOS() == Triple::WatchOS;
     461             :   }
     462             : 
     463             :   bool isWatchABI() const {
     464       18934 :     return getSubArch() == Triple::ARMSubArch_v7k;
     465             :   }
     466             : 
     467             :   /// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
     468             :   bool isOSDarwin() const {
     469     3618522 :     return isMacOSX() || isiOS() || isWatchOS();
     470             :   }
     471             : 
     472             :   bool isSimulatorEnvironment() const {
     473        3493 :     return getEnvironment() == Triple::Simulator;
     474             :   }
     475             : 
     476             :   bool isOSNetBSD() const {
     477           0 :     return getOS() == Triple::NetBSD;
     478             :   }
     479             : 
     480             :   bool isOSOpenBSD() const {
     481      154714 :     return getOS() == Triple::OpenBSD;
     482             :   }
     483             : 
     484             :   bool isOSFreeBSD() const {
     485       68143 :     return getOS() == Triple::FreeBSD;
     486             :   }
     487             : 
     488             :   bool isOSFuchsia() const {
     489       50408 :     return getOS() == Triple::Fuchsia;
     490             :   }
     491             : 
     492             :   bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
     493             : 
     494             :   bool isOSSolaris() const {
     495       26336 :     return getOS() == Triple::Solaris;
     496             :   }
     497             : 
     498             :   bool isOSIAMCU() const {
     499      446744 :     return getOS() == Triple::ELFIAMCU;
     500             :   }
     501             : 
     502       17808 :   bool isOSUnknown() const { return getOS() == Triple::UnknownOS; }
     503             : 
     504             :   bool isGNUEnvironment() const {
     505      343212 :     EnvironmentType Env = getEnvironment();
     506             :     return Env == Triple::GNU || Env == Triple::GNUABIN32 ||
     507             :            Env == Triple::GNUABI64 || Env == Triple::GNUEABI ||
     508      343350 :            Env == Triple::GNUEABIHF || Env == Triple::GNUX32;
     509             :   }
     510             : 
     511             :   bool isOSContiki() const {
     512         149 :     return getOS() == Triple::Contiki;
     513             :   }
     514             : 
     515             :   /// Tests whether the OS is Haiku.
     516             :   bool isOSHaiku() const {
     517             :     return getOS() == Triple::Haiku;
     518             :   }
     519             : 
     520             :   /// Checks if the environment could be MSVC.
     521             :   bool isWindowsMSVCEnvironment() const {
     522     5649772 :     return getOS() == Triple::Win32 &&
     523      145639 :            (getEnvironment() == Triple::UnknownEnvironment ||
     524             :             getEnvironment() == Triple::MSVC);
     525             :   }
     526             : 
     527             :   /// Checks if the environment is MSVC.
     528             :   bool isKnownWindowsMSVCEnvironment() const {
     529      109415 :     return getOS() == Triple::Win32 && getEnvironment() == Triple::MSVC;
     530             :   }
     531             : 
     532             :   bool isWindowsCoreCLREnvironment() const {
     533         375 :     return getOS() == Triple::Win32 && getEnvironment() == Triple::CoreCLR;
     534             :   }
     535             : 
     536             :   bool isWindowsItaniumEnvironment() const {
     537     5344421 :     return getOS() == Triple::Win32 && getEnvironment() == Triple::Itanium;
     538             :   }
     539             : 
     540             :   bool isWindowsCygwinEnvironment() const {
     541      242561 :     return getOS() == Triple::Win32 && getEnvironment() == Triple::Cygnus;
     542             :   }
     543             : 
     544             :   bool isWindowsGNUEnvironment() const {
     545     7442261 :     return getOS() == Triple::Win32 && getEnvironment() == Triple::GNU;
     546             :   }
     547             : 
     548             :   /// Tests for either Cygwin or MinGW OS
     549             :   bool isOSCygMing() const {
     550             :     return isWindowsCygwinEnvironment() || isWindowsGNUEnvironment();
     551             :   }
     552             : 
     553             :   /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
     554             :   bool isOSMSVCRT() const {
     555             :     return isWindowsMSVCEnvironment() || isWindowsGNUEnvironment() ||
     556             :            isWindowsItaniumEnvironment();
     557             :   }
     558             : 
     559             :   /// Tests whether the OS is Windows.
     560             :   bool isOSWindows() const {
     561     5618212 :     return getOS() == Triple::Win32;
     562             :   }
     563             : 
     564             :   /// Tests whether the OS is NaCl (Native Client)
     565             :   bool isOSNaCl() const {
     566     1617995 :     return getOS() == Triple::NaCl;
     567             :   }
     568             : 
     569             :   /// Tests whether the OS is Linux.
     570             :   bool isOSLinux() const {
     571      171421 :     return getOS() == Triple::Linux;
     572             :   }
     573             : 
     574             :   /// Tests whether the OS is kFreeBSD.
     575             :   bool isOSKFreeBSD() const {
     576             :     return getOS() == Triple::KFreeBSD;
     577             :   }
     578             : 
     579             :   /// Tests whether the OS uses glibc.
     580             :   bool isOSGlibc() const {
     581        2416 :     return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD) &&
     582             :            !isAndroid();
     583             :   }
     584             : 
     585             :   /// Tests whether the OS uses the ELF binary format.
     586             :   bool isOSBinFormatELF() const {
     587      187737 :     return getObjectFormat() == Triple::ELF;
     588             :   }
     589             : 
     590             :   /// Tests whether the OS uses the COFF binary format.
     591             :   bool isOSBinFormatCOFF() const {
     592     1971228 :     return getObjectFormat() == Triple::COFF;
     593             :   }
     594             : 
     595             :   /// Tests whether the environment is MachO.
     596             :   bool isOSBinFormatMachO() const {
     597     1505714 :     return getObjectFormat() == Triple::MachO;
     598             :   }
     599             : 
     600             :   /// Tests whether the OS uses the Wasm binary format.
     601             :   bool isOSBinFormatWasm() const {
     602         230 :     return getObjectFormat() == Triple::Wasm;
     603             :   }
     604             : 
     605             :   /// Tests whether the target is the PS4 CPU
     606             :   bool isPS4CPU() const {
     607      161656 :     return getArch() == Triple::x86_64 &&
     608      128720 :            getVendor() == Triple::SCEI &&
     609         597 :            getOS() == Triple::PS4;
     610             :   }
     611             : 
     612             :   /// Tests whether the target is the PS4 platform
     613             :   bool isPS4() const {
     614       59949 :     return getVendor() == Triple::SCEI &&
     615         255 :            getOS() == Triple::PS4;
     616             :   }
     617             : 
     618             :   /// Tests whether the target is Android
     619      412171 :   bool isAndroid() const { return getEnvironment() == Triple::Android; }
     620             : 
     621         551 :   bool isAndroidVersionLT(unsigned Major) const {
     622             :     assert(isAndroid() && "Not an Android triple!");
     623             : 
     624             :     unsigned Env[3];
     625         551 :     getEnvironmentVersion(Env[0], Env[1], Env[2]);
     626             : 
     627             :     // 64-bit targets did not exist before API level 21 (Lollipop).
     628         551 :     if (isArch64Bit() && Env[0] < 21)
     629         209 :       Env[0] = 21;
     630             : 
     631         551 :     return Env[0] < Major;
     632             :   }
     633             : 
     634             :   /// Tests whether the environment is musl-libc
     635             :   bool isMusl() const {
     636       33587 :     return getEnvironment() == Triple::Musl ||
     637       36444 :            getEnvironment() == Triple::MuslEABI ||
     638             :            getEnvironment() == Triple::MuslEABIHF;
     639             :   }
     640             : 
     641             :   /// Tests whether the target is NVPTX (32- or 64-bit).
     642             :   bool isNVPTX() const {
     643      299324 :     return getArch() == Triple::nvptx || getArch() == Triple::nvptx64;
     644             :   }
     645             : 
     646             :   /// Tests whether the target is Thumb (little and big endian).
     647             :   bool isThumb() const {
     648       51018 :     return getArch() == Triple::thumb || getArch() == Triple::thumbeb;
     649             :   }
     650             : 
     651             :   /// Tests whether the target is ARM (little and big endian).
     652             :   bool isARM() const {
     653       37288 :     return getArch() == Triple::arm || getArch() == Triple::armeb;
     654             :   }
     655             : 
     656             :   /// Tests whether the target is AArch64 (little and big endian).
     657             :   bool isAArch64() const {
     658         130 :     return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be;
     659             :   }
     660             : 
     661             :   /// Tests whether the target supports comdat
     662             :   bool supportsCOMDAT() const {
     663      187975 :     return !isOSBinFormatMachO();
     664             :   }
     665             : 
     666             :   /// Tests whether the target uses emulated TLS as default.
     667             :   bool hasDefaultEmulatedTLS() const {
     668      237006 :     return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment();
     669             :   }
     670             : 
     671             :   /// @}
     672             :   /// @name Mutators
     673             :   /// @{
     674             : 
     675             :   /// setArch - Set the architecture (first) component of the triple
     676             :   /// to a known type.
     677             :   void setArch(ArchType Kind);
     678             : 
     679             :   /// setVendor - Set the vendor (second) component of the triple to a
     680             :   /// known type.
     681             :   void setVendor(VendorType Kind);
     682             : 
     683             :   /// setOS - Set the operating system (third) component of the triple
     684             :   /// to a known type.
     685             :   void setOS(OSType Kind);
     686             : 
     687             :   /// setEnvironment - Set the environment (fourth) component of the triple
     688             :   /// to a known type.
     689             :   void setEnvironment(EnvironmentType Kind);
     690             : 
     691             :   /// setObjectFormat - Set the object file format
     692             :   void setObjectFormat(ObjectFormatType Kind);
     693             : 
     694             :   /// setTriple - Set all components to the new triple \p Str.
     695             :   void setTriple(const Twine &Str);
     696             : 
     697             :   /// setArchName - Set the architecture (first) component of the
     698             :   /// triple by name.
     699             :   void setArchName(StringRef Str);
     700             : 
     701             :   /// setVendorName - Set the vendor (second) component of the triple
     702             :   /// by name.
     703             :   void setVendorName(StringRef Str);
     704             : 
     705             :   /// setOSName - Set the operating system (third) component of the
     706             :   /// triple by name.
     707             :   void setOSName(StringRef Str);
     708             : 
     709             :   /// setEnvironmentName - Set the optional environment (fourth)
     710             :   /// component of the triple by name.
     711             :   void setEnvironmentName(StringRef Str);
     712             : 
     713             :   /// setOSAndEnvironmentName - Set the operating system and optional
     714             :   /// environment components with a single string.
     715             :   void setOSAndEnvironmentName(StringRef Str);
     716             : 
     717             :   /// @}
     718             :   /// @name Helpers to build variants of a particular triple.
     719             :   /// @{
     720             : 
     721             :   /// Form a triple with a 32-bit variant of the current architecture.
     722             :   ///
     723             :   /// This can be used to move across "families" of architectures where useful.
     724             :   ///
     725             :   /// \returns A new triple with a 32-bit architecture or an unknown
     726             :   ///          architecture if no such variant can be found.
     727             :   llvm::Triple get32BitArchVariant() const;
     728             : 
     729             :   /// Form a triple with a 64-bit variant of the current architecture.
     730             :   ///
     731             :   /// This can be used to move across "families" of architectures where useful.
     732             :   ///
     733             :   /// \returns A new triple with a 64-bit architecture or an unknown
     734             :   ///          architecture if no such variant can be found.
     735             :   llvm::Triple get64BitArchVariant() const;
     736             : 
     737             :   /// Form a triple with a big endian variant of the current architecture.
     738             :   ///
     739             :   /// This can be used to move across "families" of architectures where useful.
     740             :   ///
     741             :   /// \returns A new triple with a big endian architecture or an unknown
     742             :   ///          architecture if no such variant can be found.
     743             :   llvm::Triple getBigEndianArchVariant() const;
     744             : 
     745             :   /// Form a triple with a little endian variant of the current architecture.
     746             :   ///
     747             :   /// This can be used to move across "families" of architectures where useful.
     748             :   ///
     749             :   /// \returns A new triple with a little endian architecture or an unknown
     750             :   ///          architecture if no such variant can be found.
     751             :   llvm::Triple getLittleEndianArchVariant() const;
     752             : 
     753             :   /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
     754             :   ///
     755             :   /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
     756             :   /// string then the triple's arch name is used.
     757             :   StringRef getARMCPUForArch(StringRef Arch = StringRef()) const;
     758             : 
     759             :   /// Tests whether the target triple is little endian.
     760             :   ///
     761             :   /// \returns true if the triple is little endian, false otherwise.
     762             :   bool isLittleEndian() const;
     763             : 
     764             :   /// Test whether target triples are compatible.
     765             :   bool isCompatibleWith(const Triple &Other) const;
     766             : 
     767             :   /// Merge target triples.
     768             :   std::string merge(const Triple &Other) const;
     769             : 
     770             :   /// @}
     771             :   /// @name Static helpers for IDs.
     772             :   /// @{
     773             : 
     774             :   /// getArchTypeName - Get the canonical name for the \p Kind architecture.
     775             :   static StringRef getArchTypeName(ArchType Kind);
     776             : 
     777             :   /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
     778             :   /// architecture. This is the prefix used by the architecture specific
     779             :   /// builtins, and is suitable for passing to \see
     780             :   /// Intrinsic::getIntrinsicForGCCBuiltin().
     781             :   ///
     782             :   /// \return - The architecture prefix, or 0 if none is defined.
     783             :   static StringRef getArchTypePrefix(ArchType Kind);
     784             : 
     785             :   /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
     786             :   static StringRef getVendorTypeName(VendorType Kind);
     787             : 
     788             :   /// getOSTypeName - Get the canonical name for the \p Kind operating system.
     789             :   static StringRef getOSTypeName(OSType Kind);
     790             : 
     791             :   /// getEnvironmentTypeName - Get the canonical name for the \p Kind
     792             :   /// environment.
     793             :   static StringRef getEnvironmentTypeName(EnvironmentType Kind);
     794             : 
     795             :   /// @}
     796             :   /// @name Static helpers for converting alternate architecture names.
     797             :   /// @{
     798             : 
     799             :   /// getArchTypeForLLVMName - The canonical type for the given LLVM
     800             :   /// architecture name (e.g., "x86").
     801             :   static ArchType getArchTypeForLLVMName(StringRef Str);
     802             : 
     803             :   /// @}
     804             : };
     805             : 
     806             : } // End llvm namespace
     807             : 
     808             : 
     809             : #endif

Generated by: LCOV version 1.13