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