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