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