OSDN Git Service

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