Triple.h revision 296417
1193323Sed//===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open Source
6193323Sed// License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed
10193323Sed#ifndef LLVM_ADT_TRIPLE_H
11193323Sed#define LLVM_ADT_TRIPLE_H
12193323Sed
13226633Sdim#include "llvm/ADT/Twine.h"
14193323Sed
15198090Srdivacky// Some system headers or GCC predefined macros conflict with identifiers in
16198090Srdivacky// this file.  Undefine them here.
17261991Sdim#undef NetBSD
18198090Srdivacky#undef mips
19198090Srdivacky#undef sparc
20198090Srdivacky
21193323Sednamespace llvm {
22193323Sed
23261991Sdim/// Triple - Helper class for working with autoconf configuration names. For
24261991Sdim/// historical reasons, we also call these 'triples' (they used to contain
25261991Sdim/// exactly three fields).
26193323Sed///
27261991Sdim/// Configuration names are strings in the canonical form:
28193323Sed///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM
29193323Sed/// or
30193323Sed///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
31193323Sed///
32193323Sed/// This class is used for clients which want to support arbitrary
33261991Sdim/// configuration names, but also want to implement certain special
34261991Sdim/// behavior for particular configurations. This class isolates the mapping
35261991Sdim/// from the components of the configuration name to well known IDs.
36193323Sed///
37198090Srdivacky/// At its core the Triple class is designed to be a wrapper for a triple
38212904Sdim/// string; the constructor does not change or normalize the triple string.
39212904Sdim/// Clients that need to handle the non-canonical triples that users often
40212904Sdim/// specify should use the normalize method.
41198090Srdivacky///
42261991Sdim/// See autoconf/config.guess for a glimpse into what configuration names
43261991Sdim/// look like in practice.
44193323Sedclass Triple {
45193323Sedpublic:
46193323Sed  enum ArchType {
47193323Sed    UnknownArch,
48218893Sdim
49276479Sdim    arm,        // ARM (little endian): arm, armv.*, xscale
50276479Sdim    armeb,      // ARM (big endian): armeb
51276479Sdim    aarch64,    // AArch64 (little endian): aarch64
52276479Sdim    aarch64_be, // AArch64 (big endian): aarch64_be
53296417Sdim    avr,        // AVR: Atmel AVR microcontroller
54288943Sdim    bpfel,      // eBPF or extended BPF or 64-bit BPF (little endian)
55288943Sdim    bpfeb,      // eBPF or extended BPF or 64-bit BPF (big endian)
56276479Sdim    hexagon,    // Hexagon: hexagon
57276479Sdim    mips,       // MIPS: mips, mipsallegrex
58276479Sdim    mipsel,     // MIPSEL: mipsel, mipsallegrexel
59276479Sdim    mips64,     // MIPS64: mips64
60276479Sdim    mips64el,   // MIPS64EL: mips64el
61276479Sdim    msp430,     // MSP430: msp430
62276479Sdim    ppc,        // PPC: powerpc
63276479Sdim    ppc64,      // PPC64: powerpc64, ppu
64276479Sdim    ppc64le,    // PPC64LE: powerpc64le
65276479Sdim    r600,       // R600: AMD GPUs HD2XXX - HD6XXX
66280031Sdim    amdgcn,     // AMDGCN: AMD GCN GPUs
67276479Sdim    sparc,      // Sparc: sparc
68276479Sdim    sparcv9,    // Sparcv9: Sparcv9
69288943Sdim    sparcel,    // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant
70276479Sdim    systemz,    // SystemZ: s390x
71276479Sdim    tce,        // TCE (http://tce.cs.tut.fi/): tce
72276479Sdim    thumb,      // Thumb (little endian): thumb, thumbv.*
73276479Sdim    thumbeb,    // Thumb (big endian): thumbeb
74276479Sdim    x86,        // X86: i[3-9]86
75276479Sdim    x86_64,     // X86-64: amd64, x86_64
76276479Sdim    xcore,      // XCore: xcore
77276479Sdim    nvptx,      // NVPTX: 32-bit
78276479Sdim    nvptx64,    // NVPTX: 64-bit
79296417Sdim    le32,       // le32: generic little-endian 32-bit CPU (PNaCl)
80296417Sdim    le64,       // le64: generic little-endian 64-bit CPU (PNaCl)
81280031Sdim    amdil,      // AMDIL
82280031Sdim    amdil64,    // AMDIL with 64-bit pointers
83280031Sdim    hsail,      // AMD HSAIL
84280031Sdim    hsail64,    // AMD HSAIL with 64-bit pointers
85276479Sdim    spir,       // SPIR: standard portable IR for OpenCL 32-bit version
86276479Sdim    spir64,     // SPIR: standard portable IR for OpenCL 64-bit version
87288943Sdim    kalimba,    // Kalimba: generic kalimba
88288943Sdim    shave,      // SHAVE: Movidius vector VLIW processors
89288943Sdim    wasm32,     // WebAssembly with 32-bit pointers
90288943Sdim    wasm64,     // WebAssembly with 64-bit pointers
91288943Sdim    LastArchType = wasm64
92193323Sed  };
93276479Sdim  enum SubArchType {
94276479Sdim    NoSubArch,
95276479Sdim
96296417Sdim    ARMSubArch_v8_2a,
97288943Sdim    ARMSubArch_v8_1a,
98276479Sdim    ARMSubArch_v8,
99276479Sdim    ARMSubArch_v7,
100276479Sdim    ARMSubArch_v7em,
101276479Sdim    ARMSubArch_v7m,
102276479Sdim    ARMSubArch_v7s,
103296417Sdim    ARMSubArch_v7k,
104276479Sdim    ARMSubArch_v6,
105276479Sdim    ARMSubArch_v6m,
106288943Sdim    ARMSubArch_v6k,
107276479Sdim    ARMSubArch_v6t2,
108276479Sdim    ARMSubArch_v5,
109276479Sdim    ARMSubArch_v5te,
110280031Sdim    ARMSubArch_v4t,
111280031Sdim
112280031Sdim    KalimbaSubArch_v3,
113280031Sdim    KalimbaSubArch_v4,
114280031Sdim    KalimbaSubArch_v5
115276479Sdim  };
116193323Sed  enum VendorType {
117193323Sed    UnknownVendor,
118193323Sed
119218893Sdim    Apple,
120221345Sdim    PC,
121234353Sdim    SCEI,
122234353Sdim    BGP,
123243830Sdim    BGQ,
124243830Sdim    Freescale,
125261991Sdim    IBM,
126276479Sdim    ImaginationTechnologies,
127276479Sdim    MipsTechnologies,
128276479Sdim    NVIDIA,
129288943Sdim    CSR,
130296417Sdim    Myriad,
131296417Sdim    LastVendorType = Myriad
132193323Sed  };
133193323Sed  enum OSType {
134193323Sed    UnknownOS,
135193323Sed
136288943Sdim    CloudABI,
137193323Sed    Darwin,
138193323Sed    DragonFly,
139193323Sed    FreeBSD,
140221345Sdim    IOS,
141226633Sdim    KFreeBSD,
142195340Sed    Linux,
143199989Srdivacky    Lv2,        // PS3
144221345Sdim    MacOSX,
145198090Srdivacky    NetBSD,
146198090Srdivacky    OpenBSD,
147198090Srdivacky    Solaris,
148198396Srdivacky    Win32,
149210299Sed    Haiku,
150224145Sdim    Minix,
151226633Sdim    RTEMS,
152249423Sdim    NaCl,       // Native Client
153249423Sdim    CNK,        // BG/P Compute-Node Kernel
154243830Sdim    Bitrig,
155261991Sdim    AIX,
156261991Sdim    CUDA,       // NVIDIA CUDA
157280031Sdim    NVCL,       // NVIDIA OpenCL
158288943Sdim    AMDHSA,     // AMD HSA Runtime
159288943Sdim    PS4,
160296417Sdim    ELFIAMCU,
161296417Sdim    TvOS,       // Apple tvOS
162296417Sdim    WatchOS,    // Apple watchOS
163296417Sdim    LastOSType = WatchOS
164193323Sed  };
165218893Sdim  enum EnvironmentType {
166218893Sdim    UnknownEnvironment,
167218893Sdim
168218893Sdim    GNU,
169218893Sdim    GNUEABI,
170234353Sdim    GNUEABIHF,
171249423Sdim    GNUX32,
172276479Sdim    CODE16,
173218893Sdim    EABI,
174276479Sdim    EABIHF,
175243830Sdim    Android,
176276479Sdim
177276479Sdim    MSVC,
178276479Sdim    Itanium,
179276479Sdim    Cygnus,
180296417Sdim    AMDOpenCL,
181296417Sdim    CoreCLR,
182296417Sdim    LastEnvironmentType = CoreCLR
183218893Sdim  };
184276479Sdim  enum ObjectFormatType {
185276479Sdim    UnknownObjectFormat,
186218893Sdim
187276479Sdim    COFF,
188276479Sdim    ELF,
189276479Sdim    MachO,
190276479Sdim  };
191276479Sdim
192193323Sedprivate:
193193323Sed  std::string Data;
194193323Sed
195234353Sdim  /// The parsed arch type.
196234353Sdim  ArchType Arch;
197193323Sed
198276479Sdim  /// The parsed subarchitecture type.
199276479Sdim  SubArchType SubArch;
200276479Sdim
201193323Sed  /// The parsed vendor type.
202234353Sdim  VendorType Vendor;
203193323Sed
204193323Sed  /// The parsed OS type.
205234353Sdim  OSType OS;
206193323Sed
207218893Sdim  /// The parsed Environment type.
208234353Sdim  EnvironmentType Environment;
209218893Sdim
210276479Sdim  /// The object format type.
211276479Sdim  ObjectFormatType ObjectFormat;
212276479Sdim
213193323Sedpublic:
214193323Sed  /// @name Constructors
215193323Sed  /// @{
216218893Sdim
217296417Sdim  /// Default constructor is the same as an empty string and leaves all
218234353Sdim  /// triple fields unknown.
219276479Sdim  Triple() : Data(), Arch(), Vendor(), OS(), Environment(), ObjectFormat() {}
220193323Sed
221234353Sdim  explicit Triple(const Twine &Str);
222234353Sdim  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
223226633Sdim  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
224234353Sdim         const Twine &EnvironmentStr);
225218893Sdim
226288943Sdim  bool operator==(const Triple &Other) const {
227288943Sdim    return Arch == Other.Arch && SubArch == Other.SubArch &&
228288943Sdim           Vendor == Other.Vendor && OS == Other.OS &&
229288943Sdim           Environment == Other.Environment &&
230288943Sdim           ObjectFormat == Other.ObjectFormat;
231288943Sdim  }
232288943Sdim
233193323Sed  /// @}
234212904Sdim  /// @name Normalization
235212904Sdim  /// @{
236212904Sdim
237212904Sdim  /// normalize - Turn an arbitrary machine specification into the canonical
238212904Sdim  /// triple form (or something sensible that the Triple class understands if
239212904Sdim  /// nothing better can reasonably be done).  In particular, it handles the
240212904Sdim  /// common case in which otherwise valid components are in the wrong order.
241212904Sdim  static std::string normalize(StringRef Str);
242212904Sdim
243296417Sdim  /// Return the normalized form of this triple's string.
244288943Sdim  std::string normalize() const { return normalize(Data); }
245288943Sdim
246212904Sdim  /// @}
247193323Sed  /// @name Typed Component Access
248193323Sed  /// @{
249218893Sdim
250193323Sed  /// getArch - Get the parsed architecture type of this triple.
251234353Sdim  ArchType getArch() const { return Arch; }
252218893Sdim
253276479Sdim  /// getSubArch - get the parsed subarchitecture type for this triple.
254276479Sdim  SubArchType getSubArch() const { return SubArch; }
255276479Sdim
256193323Sed  /// getVendor - Get the parsed vendor type of this triple.
257234353Sdim  VendorType getVendor() const { return Vendor; }
258218893Sdim
259193323Sed  /// getOS - Get the parsed operating system type of this triple.
260234353Sdim  OSType getOS() const { return OS; }
261193323Sed
262193323Sed  /// hasEnvironment - Does this triple have the optional environment
263193323Sed  /// (fourth) component?
264193323Sed  bool hasEnvironment() const {
265193323Sed    return getEnvironmentName() != "";
266193323Sed  }
267193323Sed
268218893Sdim  /// getEnvironment - Get the parsed environment type of this triple.
269234353Sdim  EnvironmentType getEnvironment() const { return Environment; }
270234353Sdim
271296417Sdim  /// Parse the version number from the OS name component of the
272288943Sdim  /// triple, if present.
273288943Sdim  ///
274288943Sdim  /// For example, "fooos1.2.3" would return (1, 2, 3).
275288943Sdim  ///
276288943Sdim  /// If an entry is not defined, it will be returned as 0.
277288943Sdim  void getEnvironmentVersion(unsigned &Major, unsigned &Minor,
278288943Sdim                             unsigned &Micro) const;
279288943Sdim
280276479Sdim  /// getFormat - Get the object format for this triple.
281276479Sdim  ObjectFormatType getObjectFormat() const { return ObjectFormat; }
282276479Sdim
283234353Sdim  /// getOSVersion - Parse the version number from the OS name component of the
284234353Sdim  /// triple, if present.
285234353Sdim  ///
286234353Sdim  /// For example, "fooos1.2.3" would return (1, 2, 3).
287234353Sdim  ///
288234353Sdim  /// If an entry is not defined, it will be returned as 0.
289234353Sdim  void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
290234353Sdim
291234353Sdim  /// getOSMajorVersion - Return just the major version number, this is
292234353Sdim  /// specialized because it is a common query.
293234353Sdim  unsigned getOSMajorVersion() const {
294234353Sdim    unsigned Maj, Min, Micro;
295234353Sdim    getOSVersion(Maj, Min, Micro);
296234353Sdim    return Maj;
297218893Sdim  }
298218893Sdim
299234353Sdim  /// getMacOSXVersion - Parse the version number as with getOSVersion and then
300234353Sdim  /// translate generic "darwin" versions to the corresponding OS X versions.
301234353Sdim  /// This may also be called with IOS triples but the OS X version number is
302234353Sdim  /// just set to a constant 10.4.0 in that case.  Returns true if successful.
303234353Sdim  bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
304234353Sdim                        unsigned &Micro) const;
305234353Sdim
306239462Sdim  /// getiOSVersion - Parse the version number as with getOSVersion.  This should
307296417Sdim  /// only be called with IOS or generic triples.
308239462Sdim  void getiOSVersion(unsigned &Major, unsigned &Minor,
309239462Sdim                     unsigned &Micro) const;
310239462Sdim
311296417Sdim  /// getWatchOSVersion - Parse the version number as with getOSVersion.  This
312296417Sdim  /// should only be called with WatchOS or generic triples.
313296417Sdim  void getWatchOSVersion(unsigned &Major, unsigned &Minor,
314296417Sdim                         unsigned &Micro) const;
315296417Sdim
316193323Sed  /// @}
317193323Sed  /// @name Direct Component Access
318193323Sed  /// @{
319193323Sed
320199481Srdivacky  const std::string &str() const { return Data; }
321199481Srdivacky
322193323Sed  const std::string &getTriple() const { return Data; }
323193323Sed
324193323Sed  /// getArchName - Get the architecture (first) component of the
325193323Sed  /// triple.
326198090Srdivacky  StringRef getArchName() const;
327193323Sed
328193323Sed  /// getVendorName - Get the vendor (second) component of the triple.
329198090Srdivacky  StringRef getVendorName() const;
330193323Sed
331193323Sed  /// getOSName - Get the operating system (third) component of the
332193323Sed  /// triple.
333198090Srdivacky  StringRef getOSName() const;
334193323Sed
335193323Sed  /// getEnvironmentName - Get the optional environment (fourth)
336193323Sed  /// component of the triple, or "" if empty.
337198090Srdivacky  StringRef getEnvironmentName() const;
338193323Sed
339193323Sed  /// getOSAndEnvironmentName - Get the operating system and optional
340193323Sed  /// environment components as a single string (separated by a '-'
341193323Sed  /// if the environment component is present).
342198090Srdivacky  StringRef getOSAndEnvironmentName() const;
343193323Sed
344234353Sdim  /// @}
345234353Sdim  /// @name Convenience Predicates
346234353Sdim  /// @{
347234353Sdim
348296417Sdim  /// Test whether the architecture is 64-bit
349221345Sdim  ///
350234353Sdim  /// Note that this tests for 64-bit pointer width, and nothing else. Note
351234353Sdim  /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
352234353Sdim  /// 16-bit. The inner details of pointer width for particular architectures
353234353Sdim  /// is not summed up in the triple, and so only a coarse grained predicate
354234353Sdim  /// system is provided.
355234353Sdim  bool isArch64Bit() const;
356234353Sdim
357296417Sdim  /// Test whether the architecture is 32-bit
358221345Sdim  ///
359234353Sdim  /// Note that this tests for 32-bit pointer width, and nothing else.
360234353Sdim  bool isArch32Bit() const;
361218893Sdim
362296417Sdim  /// Test whether the architecture is 16-bit
363234353Sdim  ///
364234353Sdim  /// Note that this tests for 16-bit pointer width, and nothing else.
365234353Sdim  bool isArch16Bit() const;
366218893Sdim
367221345Sdim  /// isOSVersionLT - Helper function for doing comparisons against version
368221345Sdim  /// numbers included in the target triple.
369221345Sdim  bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
370221345Sdim                     unsigned Micro = 0) const {
371221345Sdim    unsigned LHS[3];
372221345Sdim    getOSVersion(LHS[0], LHS[1], LHS[2]);
373221345Sdim
374221345Sdim    if (LHS[0] != Major)
375221345Sdim      return LHS[0] < Major;
376221345Sdim    if (LHS[1] != Minor)
377221345Sdim      return LHS[1] < Minor;
378221345Sdim    if (LHS[2] != Micro)
379221345Sdim      return LHS[1] < Micro;
380221345Sdim
381221345Sdim    return false;
382221345Sdim  }
383221345Sdim
384288943Sdim  bool isOSVersionLT(const Triple &Other) const {
385288943Sdim    unsigned RHS[3];
386288943Sdim    Other.getOSVersion(RHS[0], RHS[1], RHS[2]);
387288943Sdim    return isOSVersionLT(RHS[0], RHS[1], RHS[2]);
388288943Sdim  }
389288943Sdim
390234353Sdim  /// isMacOSXVersionLT - Comparison function for checking OS X version
391234353Sdim  /// compatibility, which handles supporting skewed version numbering schemes
392234353Sdim  /// used by the "darwin" triples.
393234353Sdim  unsigned isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
394239462Sdim                             unsigned Micro = 0) const {
395234353Sdim    assert(isMacOSX() && "Not an OS X triple!");
396234353Sdim
397234353Sdim    // If this is OS X, expect a sane version number.
398234353Sdim    if (getOS() == Triple::MacOSX)
399234353Sdim      return isOSVersionLT(Major, Minor, Micro);
400234353Sdim
401234353Sdim    // Otherwise, compare to the "Darwin" number.
402234353Sdim    assert(Major == 10 && "Unexpected major version");
403234353Sdim    return isOSVersionLT(Minor + 4, Micro, 0);
404234353Sdim  }
405234353Sdim
406221345Sdim  /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
407221345Sdim  /// "darwin" and "osx" as OS X triples.
408221345Sdim  bool isMacOSX() const {
409221345Sdim    return getOS() == Triple::Darwin || getOS() == Triple::MacOSX;
410221345Sdim  }
411221345Sdim
412249423Sdim  /// Is this an iOS triple.
413296417Sdim  /// Note: This identifies tvOS as a variant of iOS. If that ever
414296417Sdim  /// changes, i.e., if the two operating systems diverge or their version
415296417Sdim  /// numbers get out of sync, that will need to be changed.
416296417Sdim  /// watchOS has completely different version numbers so it is not included.
417249423Sdim  bool isiOS() const {
418296417Sdim    return getOS() == Triple::IOS || isTvOS();
419249423Sdim  }
420249423Sdim
421296417Sdim  /// Is this an Apple tvOS triple.
422296417Sdim  bool isTvOS() const {
423296417Sdim    return getOS() == Triple::TvOS;
424296417Sdim  }
425296417Sdim
426296417Sdim  /// Is this an Apple watchOS triple.
427296417Sdim  bool isWatchOS() const {
428296417Sdim    return getOS() == Triple::WatchOS;
429296417Sdim  }
430296417Sdim
431296417Sdim  /// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
432221345Sdim  bool isOSDarwin() const {
433296417Sdim    return isMacOSX() || isiOS() || isWatchOS();
434221345Sdim  }
435221345Sdim
436280031Sdim  bool isOSNetBSD() const {
437280031Sdim    return getOS() == Triple::NetBSD;
438280031Sdim  }
439280031Sdim
440280031Sdim  bool isOSOpenBSD() const {
441280031Sdim    return getOS() == Triple::OpenBSD;
442280031Sdim  }
443280031Sdim
444276479Sdim  bool isOSFreeBSD() const {
445276479Sdim    return getOS() == Triple::FreeBSD;
446276479Sdim  }
447276479Sdim
448280031Sdim  bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
449280031Sdim
450280031Sdim  bool isOSSolaris() const {
451280031Sdim    return getOS() == Triple::Solaris;
452280031Sdim  }
453280031Sdim
454280031Sdim  bool isOSBitrig() const {
455280031Sdim    return getOS() == Triple::Bitrig;
456280031Sdim  }
457280031Sdim
458296417Sdim  bool isOSIAMCU() const {
459296417Sdim    return getOS() == Triple::ELFIAMCU;
460296417Sdim  }
461296417Sdim
462296417Sdim  /// Checks if the environment could be MSVC.
463276479Sdim  bool isWindowsMSVCEnvironment() const {
464276479Sdim    return getOS() == Triple::Win32 &&
465276479Sdim           (getEnvironment() == Triple::UnknownEnvironment ||
466276479Sdim            getEnvironment() == Triple::MSVC);
467276479Sdim  }
468276479Sdim
469296417Sdim  /// Checks if the environment is MSVC.
470276479Sdim  bool isKnownWindowsMSVCEnvironment() const {
471276479Sdim    return getOS() == Triple::Win32 && getEnvironment() == Triple::MSVC;
472276479Sdim  }
473276479Sdim
474296417Sdim  bool isWindowsCoreCLREnvironment() const {
475296417Sdim    return getOS() == Triple::Win32 && getEnvironment() == Triple::CoreCLR;
476296417Sdim  }
477296417Sdim
478276479Sdim  bool isWindowsItaniumEnvironment() const {
479276479Sdim    return getOS() == Triple::Win32 && getEnvironment() == Triple::Itanium;
480276479Sdim  }
481276479Sdim
482276479Sdim  bool isWindowsCygwinEnvironment() const {
483280031Sdim    return getOS() == Triple::Win32 && getEnvironment() == Triple::Cygnus;
484276479Sdim  }
485276479Sdim
486276479Sdim  bool isWindowsGNUEnvironment() const {
487280031Sdim    return getOS() == Triple::Win32 && getEnvironment() == Triple::GNU;
488276479Sdim  }
489276479Sdim
490296417Sdim  /// Tests for either Cygwin or MinGW OS
491234353Sdim  bool isOSCygMing() const {
492276479Sdim    return isWindowsCygwinEnvironment() || isWindowsGNUEnvironment();
493234353Sdim  }
494234353Sdim
495296417Sdim  /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
496261991Sdim  bool isOSMSVCRT() const {
497280031Sdim    return isWindowsMSVCEnvironment() || isWindowsGNUEnvironment() ||
498280031Sdim           isWindowsItaniumEnvironment();
499261991Sdim  }
500261991Sdim
501296417Sdim  /// Tests whether the OS is Windows.
502221345Sdim  bool isOSWindows() const {
503288943Sdim    return getOS() == Triple::Win32;
504221345Sdim  }
505221345Sdim
506296417Sdim  /// Tests whether the OS is NaCl (Native Client)
507249423Sdim  bool isOSNaCl() const {
508249423Sdim    return getOS() == Triple::NaCl;
509249423Sdim  }
510249423Sdim
511296417Sdim  /// Tests whether the OS is Linux.
512261991Sdim  bool isOSLinux() const {
513261991Sdim    return getOS() == Triple::Linux;
514261991Sdim  }
515261991Sdim
516296417Sdim  /// Tests whether the OS uses the ELF binary format.
517234353Sdim  bool isOSBinFormatELF() const {
518276479Sdim    return getObjectFormat() == Triple::ELF;
519234353Sdim  }
520221345Sdim
521296417Sdim  /// Tests whether the OS uses the COFF binary format.
522234353Sdim  bool isOSBinFormatCOFF() const {
523276479Sdim    return getObjectFormat() == Triple::COFF;
524234353Sdim  }
525221345Sdim
526296417Sdim  /// Tests whether the environment is MachO.
527276479Sdim  bool isOSBinFormatMachO() const {
528276479Sdim    return getObjectFormat() == Triple::MachO;
529221345Sdim  }
530224145Sdim
531296417Sdim  /// Tests whether the target is the PS4 CPU
532288943Sdim  bool isPS4CPU() const {
533288943Sdim    return getArch() == Triple::x86_64 &&
534288943Sdim           getVendor() == Triple::SCEI &&
535288943Sdim           getOS() == Triple::PS4;
536288943Sdim  }
537288943Sdim
538296417Sdim  /// Tests whether the target is the PS4 platform
539288943Sdim  bool isPS4() const {
540288943Sdim    return getVendor() == Triple::SCEI &&
541288943Sdim           getOS() == Triple::PS4;
542288943Sdim  }
543288943Sdim
544296417Sdim  /// Tests whether the target is Android
545296417Sdim  bool isAndroid() const { return getEnvironment() == Triple::Android; }
546296417Sdim
547193323Sed  /// @}
548193323Sed  /// @name Mutators
549193323Sed  /// @{
550193323Sed
551193323Sed  /// setArch - Set the architecture (first) component of the triple
552193323Sed  /// to a known type.
553193323Sed  void setArch(ArchType Kind);
554193323Sed
555193323Sed  /// setVendor - Set the vendor (second) component of the triple to a
556193323Sed  /// known type.
557193323Sed  void setVendor(VendorType Kind);
558193323Sed
559193323Sed  /// setOS - Set the operating system (third) component of the triple
560193323Sed  /// to a known type.
561193323Sed  void setOS(OSType Kind);
562193323Sed
563218893Sdim  /// setEnvironment - Set the environment (fourth) component of the triple
564218893Sdim  /// to a known type.
565218893Sdim  void setEnvironment(EnvironmentType Kind);
566218893Sdim
567276479Sdim  /// setObjectFormat - Set the object file format
568276479Sdim  void setObjectFormat(ObjectFormatType Kind);
569276479Sdim
570243830Sdim  /// setTriple - Set all components to the new triple \p Str.
571198090Srdivacky  void setTriple(const Twine &Str);
572193323Sed
573193323Sed  /// setArchName - Set the architecture (first) component of the
574193323Sed  /// triple by name.
575199481Srdivacky  void setArchName(StringRef Str);
576193323Sed
577193323Sed  /// setVendorName - Set the vendor (second) component of the triple
578193323Sed  /// by name.
579199481Srdivacky  void setVendorName(StringRef Str);
580193323Sed
581193323Sed  /// setOSName - Set the operating system (third) component of the
582193323Sed  /// triple by name.
583199481Srdivacky  void setOSName(StringRef Str);
584193323Sed
585193323Sed  /// setEnvironmentName - Set the optional environment (fourth)
586193323Sed  /// component of the triple by name.
587199481Srdivacky  void setEnvironmentName(StringRef Str);
588193323Sed
589193323Sed  /// setOSAndEnvironmentName - Set the operating system and optional
590193323Sed  /// environment components with a single string.
591199481Srdivacky  void setOSAndEnvironmentName(StringRef Str);
592193323Sed
593193323Sed  /// @}
594234353Sdim  /// @name Helpers to build variants of a particular triple.
595234353Sdim  /// @{
596234353Sdim
597296417Sdim  /// Form a triple with a 32-bit variant of the current architecture.
598234353Sdim  ///
599234353Sdim  /// This can be used to move across "families" of architectures where useful.
600234353Sdim  ///
601234353Sdim  /// \returns A new triple with a 32-bit architecture or an unknown
602234353Sdim  ///          architecture if no such variant can be found.
603234353Sdim  llvm::Triple get32BitArchVariant() const;
604234353Sdim
605296417Sdim  /// Form a triple with a 64-bit variant of the current architecture.
606234353Sdim  ///
607234353Sdim  /// This can be used to move across "families" of architectures where useful.
608234353Sdim  ///
609234353Sdim  /// \returns A new triple with a 64-bit architecture or an unknown
610234353Sdim  ///          architecture if no such variant can be found.
611234353Sdim  llvm::Triple get64BitArchVariant() const;
612234353Sdim
613288943Sdim  /// Form a triple with a big endian variant of the current architecture.
614288943Sdim  ///
615288943Sdim  /// This can be used to move across "families" of architectures where useful.
616288943Sdim  ///
617288943Sdim  /// \returns A new triple with a big endian architecture or an unknown
618288943Sdim  ///          architecture if no such variant can be found.
619288943Sdim  llvm::Triple getBigEndianArchVariant() const;
620288943Sdim
621288943Sdim  /// Form a triple with a little endian variant of the current architecture.
622288943Sdim  ///
623288943Sdim  /// This can be used to move across "families" of architectures where useful.
624288943Sdim  ///
625288943Sdim  /// \returns A new triple with a little endian architecture or an unknown
626288943Sdim  ///          architecture if no such variant can be found.
627288943Sdim  llvm::Triple getLittleEndianArchVariant() const;
628288943Sdim
629276479Sdim  /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
630276479Sdim  ///
631276479Sdim  /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
632276479Sdim  /// string then the triple's arch name is used.
633296417Sdim  StringRef getARMCPUForArch(StringRef Arch = StringRef()) const;
634276479Sdim
635234353Sdim  /// @}
636193323Sed  /// @name Static helpers for IDs.
637193323Sed  /// @{
638193323Sed
639243830Sdim  /// getArchTypeName - Get the canonical name for the \p Kind architecture.
640193323Sed  static const char *getArchTypeName(ArchType Kind);
641193323Sed
642243830Sdim  /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
643198090Srdivacky  /// architecture. This is the prefix used by the architecture specific
644198090Srdivacky  /// builtins, and is suitable for passing to \see
645198090Srdivacky  /// Intrinsic::getIntrinsicForGCCBuiltin().
646198090Srdivacky  ///
647198090Srdivacky  /// \return - The architecture prefix, or 0 if none is defined.
648198090Srdivacky  static const char *getArchTypePrefix(ArchType Kind);
649198090Srdivacky
650243830Sdim  /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
651193323Sed  static const char *getVendorTypeName(VendorType Kind);
652193323Sed
653243830Sdim  /// getOSTypeName - Get the canonical name for the \p Kind operating system.
654193323Sed  static const char *getOSTypeName(OSType Kind);
655193323Sed
656243830Sdim  /// getEnvironmentTypeName - Get the canonical name for the \p Kind
657218893Sdim  /// environment.
658218893Sdim  static const char *getEnvironmentTypeName(EnvironmentType Kind);
659218893Sdim
660193323Sed  /// @}
661198090Srdivacky  /// @name Static helpers for converting alternate architecture names.
662198090Srdivacky  /// @{
663198090Srdivacky
664198090Srdivacky  /// getArchTypeForLLVMName - The canonical type for the given LLVM
665198090Srdivacky  /// architecture name (e.g., "x86").
666199481Srdivacky  static ArchType getArchTypeForLLVMName(StringRef Str);
667198090Srdivacky
668198090Srdivacky  /// @}
669193323Sed};
670193323Sed
671193323Sed} // End llvm namespace
672193323Sed
673193323Sed
674193323Sed#endif
675