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