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

Generated by: LCOV version 1.13