xref: /freebsd/contrib/llvm-project/llvm/include/llvm/TargetParser/Triple.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- llvm/TargetParser/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_TARGETPARSER_TRIPLE_H
10 #define LLVM_TARGETPARSER_TRIPLE_H
11 
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Support/Compiler.h"
14 #include "llvm/Support/VersionTuple.h"
15 
16 // Some system headers or GCC predefined macros conflict with identifiers in
17 // this file.  Undefine them here.
18 #undef NetBSD
19 #undef mips
20 #undef sparc
21 
22 namespace llvm {
23 enum class ExceptionHandling;
24 class Twine;
25 
26 /// Triple - Helper class for working with autoconf configuration names. For
27 /// historical reasons, we also call these 'triples' (they used to contain
28 /// exactly three fields).
29 ///
30 /// Configuration names are strings in the canonical form:
31 ///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM
32 /// or
33 ///   ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
34 ///
35 /// This class is used for clients which want to support arbitrary
36 /// configuration names, but also want to implement certain special
37 /// behavior for particular configurations. This class isolates the mapping
38 /// from the components of the configuration name to well known IDs.
39 ///
40 /// At its core the Triple class is designed to be a wrapper for a triple
41 /// string; the constructor does not change or normalize the triple string.
42 /// Clients that need to handle the non-canonical triples that users often
43 /// specify should use the normalize method.
44 ///
45 /// See autoconf/config.guess for a glimpse into what configuration names
46 /// look like in practice.
47 class Triple {
48 public:
49   enum ArchType {
50     UnknownArch,
51 
52     arm,            // ARM (little endian): arm, armv.*, xscale
53     armeb,          // ARM (big endian): armeb
54     aarch64,        // AArch64 (little endian): aarch64
55     aarch64_be,     // AArch64 (big endian): aarch64_be
56     aarch64_32,     // AArch64 (little endian) ILP32: aarch64_32
57     arc,            // ARC: Synopsys ARC
58     avr,            // AVR: Atmel AVR microcontroller
59     bpfel,          // eBPF or extended BPF or 64-bit BPF (little endian)
60     bpfeb,          // eBPF or extended BPF or 64-bit BPF (big endian)
61     csky,           // CSKY: csky
62     dxil,           // DXIL 32-bit DirectX bytecode
63     hexagon,        // Hexagon: hexagon
64     loongarch32,    // LoongArch (32-bit): loongarch32
65     loongarch64,    // LoongArch (64-bit): loongarch64
66     m68k,           // M68k: Motorola 680x0 family
67     mips,           // MIPS: mips, mipsallegrex, mipsr6
68     mipsel,         // MIPSEL: mipsel, mipsallegrexe, mipsr6el
69     mips64,         // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
70     mips64el,       // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
71     msp430,         // MSP430: msp430
72     ppc,            // PPC: powerpc
73     ppcle,          // PPCLE: powerpc (little endian)
74     ppc64,          // PPC64: powerpc64, ppu
75     ppc64le,        // PPC64LE: powerpc64le
76     r600,           // R600: AMD GPUs HD2XXX - HD6XXX
77     amdgcn,         // AMDGCN: AMD GCN GPUs
78     riscv32,        // RISC-V (32-bit): riscv32
79     riscv64,        // RISC-V (64-bit): riscv64
80     sparc,          // Sparc: sparc
81     sparcv9,        // Sparcv9: Sparcv9
82     sparcel,        // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant
83     systemz,        // SystemZ: s390x
84     tce,            // TCE (http://tce.cs.tut.fi/): tce
85     tcele,          // TCE little endian (http://tce.cs.tut.fi/): tcele
86     thumb,          // Thumb (little endian): thumb, thumbv.*
87     thumbeb,        // Thumb (big endian): thumbeb
88     x86,            // X86: i[3-9]86
89     x86_64,         // X86-64: amd64, x86_64
90     xcore,          // XCore: xcore
91     xtensa,         // Tensilica: Xtensa
92     nvptx,          // NVPTX: 32-bit
93     nvptx64,        // NVPTX: 64-bit
94     amdil,          // AMDIL
95     amdil64,        // AMDIL with 64-bit pointers
96     hsail,          // AMD HSAIL
97     hsail64,        // AMD HSAIL with 64-bit pointers
98     spir,           // SPIR: standard portable IR for OpenCL 32-bit version
99     spir64,         // SPIR: standard portable IR for OpenCL 64-bit version
100     spirv,          // SPIR-V with logical memory layout.
101     spirv32,        // SPIR-V with 32-bit pointers
102     spirv64,        // SPIR-V with 64-bit pointers
103     kalimba,        // Kalimba: generic kalimba
104     shave,          // SHAVE: Movidius vector VLIW processors
105     lanai,          // Lanai: Lanai 32-bit
106     wasm32,         // WebAssembly with 32-bit pointers
107     wasm64,         // WebAssembly with 64-bit pointers
108     renderscript32, // 32-bit RenderScript
109     renderscript64, // 64-bit RenderScript
110     ve,             // NEC SX-Aurora Vector Engine
111     LastArchType = ve
112   };
113   enum SubArchType {
114     NoSubArch,
115 
116     ARMSubArch_v9_6a,
117     ARMSubArch_v9_5a,
118     ARMSubArch_v9_4a,
119     ARMSubArch_v9_3a,
120     ARMSubArch_v9_2a,
121     ARMSubArch_v9_1a,
122     ARMSubArch_v9,
123     ARMSubArch_v8_9a,
124     ARMSubArch_v8_8a,
125     ARMSubArch_v8_7a,
126     ARMSubArch_v8_6a,
127     ARMSubArch_v8_5a,
128     ARMSubArch_v8_4a,
129     ARMSubArch_v8_3a,
130     ARMSubArch_v8_2a,
131     ARMSubArch_v8_1a,
132     ARMSubArch_v8,
133     ARMSubArch_v8r,
134     ARMSubArch_v8m_baseline,
135     ARMSubArch_v8m_mainline,
136     ARMSubArch_v8_1m_mainline,
137     ARMSubArch_v7,
138     ARMSubArch_v7em,
139     ARMSubArch_v7m,
140     ARMSubArch_v7s,
141     ARMSubArch_v7k,
142     ARMSubArch_v7ve,
143     ARMSubArch_v6,
144     ARMSubArch_v6m,
145     ARMSubArch_v6k,
146     ARMSubArch_v6t2,
147     ARMSubArch_v5,
148     ARMSubArch_v5te,
149     ARMSubArch_v4t,
150 
151     AArch64SubArch_arm64e,
152     AArch64SubArch_arm64ec,
153 
154     KalimbaSubArch_v3,
155     KalimbaSubArch_v4,
156     KalimbaSubArch_v5,
157 
158     MipsSubArch_r6,
159 
160     PPCSubArch_spe,
161 
162     // SPIR-V sub-arch corresponds to its version.
163     SPIRVSubArch_v10,
164     SPIRVSubArch_v11,
165     SPIRVSubArch_v12,
166     SPIRVSubArch_v13,
167     SPIRVSubArch_v14,
168     SPIRVSubArch_v15,
169     SPIRVSubArch_v16,
170 
171     // DXIL sub-arch corresponds to its version.
172     DXILSubArch_v1_0,
173     DXILSubArch_v1_1,
174     DXILSubArch_v1_2,
175     DXILSubArch_v1_3,
176     DXILSubArch_v1_4,
177     DXILSubArch_v1_5,
178     DXILSubArch_v1_6,
179     DXILSubArch_v1_7,
180     DXILSubArch_v1_8,
181     LatestDXILSubArch = DXILSubArch_v1_8,
182   };
183   enum VendorType {
184     UnknownVendor,
185 
186     Apple,
187     PC,
188     SCEI,
189     Freescale,
190     IBM,
191     ImaginationTechnologies,
192     MipsTechnologies,
193     NVIDIA,
194     CSR,
195     AMD,
196     Mesa,
197     SUSE,
198     OpenEmbedded,
199     Intel,
200     LastVendorType = Intel
201   };
202   enum OSType {
203     UnknownOS,
204 
205     Darwin,
206     DragonFly,
207     FreeBSD,
208     Fuchsia,
209     IOS,
210     KFreeBSD,
211     Linux,
212     Lv2, // PS3
213     MacOSX,
214     Managarm,
215     NetBSD,
216     OpenBSD,
217     Solaris,
218     UEFI,
219     Win32,
220     ZOS,
221     Haiku,
222     RTEMS,
223     NaCl, // Native Client
224     AIX,
225     CUDA,   // NVIDIA CUDA
226     NVCL,   // NVIDIA OpenCL
227     AMDHSA, // AMD HSA Runtime
228     PS4,
229     PS5,
230     ELFIAMCU,
231     TvOS,      // Apple tvOS
232     WatchOS,   // Apple watchOS
233     BridgeOS,  // Apple bridgeOS
234     DriverKit, // Apple DriverKit
235     XROS,      // Apple XROS
236     Mesa3D,
237     AMDPAL,     // AMD PAL Runtime
238     HermitCore, // HermitCore Unikernel/Multikernel
239     Hurd,       // GNU/Hurd
240     WASI,       // Experimental WebAssembly OS
241     Emscripten,
242     ShaderModel, // DirectX ShaderModel
243     LiteOS,
244     Serenity,
245     Vulkan, // Vulkan SPIR-V
246     LastOSType = Vulkan
247   };
248   enum EnvironmentType {
249     UnknownEnvironment,
250 
251     GNU,
252     GNUT64,
253     GNUABIN32,
254     GNUABI64,
255     GNUEABI,
256     GNUEABIT64,
257     GNUEABIHF,
258     GNUEABIHFT64,
259     GNUF32,
260     GNUF64,
261     GNUSF,
262     GNUX32,
263     GNUILP32,
264     CODE16,
265     EABI,
266     EABIHF,
267     Android,
268     Musl,
269     MuslABIN32,
270     MuslABI64,
271     MuslEABI,
272     MuslEABIHF,
273     MuslF32,
274     MuslSF,
275     MuslX32,
276     LLVM,
277 
278     MSVC,
279     Itanium,
280     Cygnus,
281     CoreCLR,
282     Simulator, // Simulator variants of other systems, e.g., Apple's iOS
283     MacABI,    // Mac Catalyst variant of Apple's iOS deployment target.
284 
285     // Shader Stages
286     // The order of these values matters, and must be kept in sync with the
287     // language options enum in Clang. The ordering is enforced in
288     // static_asserts in Triple.cpp and in Clang.
289     Pixel,
290     Vertex,
291     Geometry,
292     Hull,
293     Domain,
294     Compute,
295     Library,
296     RayGeneration,
297     Intersection,
298     AnyHit,
299     ClosestHit,
300     Miss,
301     Callable,
302     Mesh,
303     Amplification,
304     OpenCL,
305     OpenHOS,
306     Mlibc,
307 
308     PAuthTest,
309 
310     LastEnvironmentType = PAuthTest
311   };
312   enum ObjectFormatType {
313     UnknownObjectFormat,
314 
315     COFF,
316     DXContainer,
317     ELF,
318     GOFF,
319     MachO,
320     SPIRV,
321     Wasm,
322     XCOFF,
323   };
324 
325 private:
326   std::string Data;
327 
328   /// The parsed arch type.
329   ArchType Arch{};
330 
331   /// The parsed subarchitecture type.
332   SubArchType SubArch{};
333 
334   /// The parsed vendor type.
335   VendorType Vendor{};
336 
337   /// The parsed OS type.
338   OSType OS{};
339 
340   /// The parsed Environment type.
341   EnvironmentType Environment{};
342 
343   /// The object format type.
344   ObjectFormatType ObjectFormat{};
345 
346 public:
347   /// @name Constructors
348   /// @{
349 
350   /// Default constructor is the same as an empty string and leaves all
351   /// triple fields unknown.
352   Triple() = default;
353 
354   LLVM_ABI explicit Triple(std::string &&Str);
Triple(StringRef Str)355   explicit Triple(StringRef Str) : Triple(Str.str()) {}
Triple(const char * Str)356   explicit Triple(const char *Str) : Triple(std::string(Str)) {}
Triple(const std::string & Str)357   explicit Triple(const std::string &Str) : Triple(std::string(Str)) {}
358   LLVM_ABI explicit Triple(const Twine &Str);
359 
360   LLVM_ABI Triple(const Twine &ArchStr, const Twine &VendorStr,
361                   const Twine &OSStr);
362   LLVM_ABI Triple(const Twine &ArchStr, const Twine &VendorStr,
363                   const Twine &OSStr, const Twine &EnvironmentStr);
364 
365   bool operator==(const Triple &Other) const {
366     return Arch == Other.Arch && SubArch == Other.SubArch &&
367            Vendor == Other.Vendor && OS == Other.OS &&
368            Environment == Other.Environment &&
369            ObjectFormat == Other.ObjectFormat;
370   }
371 
372   bool operator!=(const Triple &Other) const {
373     return !(*this == Other);
374   }
375 
376   /// @}
377   /// @name Normalization
378   /// @{
379 
380   /// Canonical form
381   enum class CanonicalForm {
382     ANY = 0,
383     THREE_IDENT = 3, // ARCHITECTURE-VENDOR-OPERATING_SYSTEM
384     FOUR_IDENT = 4,  // ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
385     FIVE_IDENT = 5,  // ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT-FORMAT
386   };
387 
388   /// Turn an arbitrary machine specification into the canonical triple form (or
389   /// something sensible that the Triple class understands if nothing better can
390   /// reasonably be done).  In particular, it handles the common case in which
391   /// otherwise valid components are in the wrong order. \p Form is used to
392   /// specify the output canonical form.
393   LLVM_ABI static std::string
394   normalize(StringRef Str, CanonicalForm Form = CanonicalForm::ANY);
395 
396   /// Return the normalized form of this triple's string.
397   std::string normalize(CanonicalForm Form = CanonicalForm::ANY) const {
398     return normalize(Data, Form);
399   }
400 
401   /// @}
402   /// @name Typed Component Access
403   /// @{
404 
405   /// Get the parsed architecture type of this triple.
getArch()406   ArchType getArch() const { return Arch; }
407 
408   /// get the parsed subarchitecture type for this triple.
getSubArch()409   SubArchType getSubArch() const { return SubArch; }
410 
411   /// Get the parsed vendor type of this triple.
getVendor()412   VendorType getVendor() const { return Vendor; }
413 
414   /// Get the parsed operating system type of this triple.
getOS()415   OSType getOS() const { return OS; }
416 
417   /// Does this triple have the optional environment (fourth) component?
hasEnvironment()418   bool hasEnvironment() const {
419     return getEnvironmentName() != "";
420   }
421 
422   /// Get the parsed environment type of this triple.
getEnvironment()423   EnvironmentType getEnvironment() const { return Environment; }
424 
425   /// Parse the version number from the OS name component of the
426   /// triple, if present.
427   ///
428   /// For example, "fooos1.2.3" would return (1, 2, 3).
429   LLVM_ABI VersionTuple getEnvironmentVersion() const;
430 
431   /// Get the object format for this triple.
getObjectFormat()432   ObjectFormatType getObjectFormat() const { return ObjectFormat; }
433 
434   /// Parse the version number from the OS name component of the triple, if
435   /// present.
436   ///
437   /// For example, "fooos1.2.3" would return (1, 2, 3).
438   LLVM_ABI VersionTuple getOSVersion() const;
439 
440   /// Return just the major version number, this is specialized because it is a
441   /// common query.
getOSMajorVersion()442   unsigned getOSMajorVersion() const { return getOSVersion().getMajor(); }
443 
444   /// Parse the version number as with getOSVersion and then translate generic
445   /// "darwin" versions to the corresponding OS X versions.  This may also be
446   /// called with IOS triples but the OS X version number is just set to a
447   /// constant 10.4.0 in that case.  Returns true if successful.
448   LLVM_ABI bool getMacOSXVersion(VersionTuple &Version) const;
449 
450   /// Parse the version number as with getOSVersion.  This should only be called
451   /// with IOS or generic triples.
452   LLVM_ABI VersionTuple getiOSVersion() const;
453 
454   /// Parse the version number as with getOSVersion.  This should only be called
455   /// with WatchOS or generic triples.
456   LLVM_ABI VersionTuple getWatchOSVersion() const;
457 
458   /// Parse the version number as with getOSVersion.
459   LLVM_ABI VersionTuple getDriverKitVersion() const;
460 
461   /// Parse the Vulkan version number from the OSVersion and SPIR-V version
462   /// (SubArch).  This should only be called with Vulkan SPIR-V triples.
463   LLVM_ABI VersionTuple getVulkanVersion() const;
464 
465   /// Parse the DXIL version number from the OSVersion and DXIL version
466   /// (SubArch).  This should only be called with DXIL triples.
467   LLVM_ABI VersionTuple getDXILVersion() const;
468 
469   /// @}
470   /// @name Direct Component Access
471   /// @{
472 
str()473   const std::string &str() const { return Data; }
474 
getTriple()475   const std::string &getTriple() const { return Data; }
476 
477   /// Whether the triple is empty / default constructed.
empty()478   bool empty() const { return Data.empty(); }
479 
480   /// Get the architecture (first) component of the triple.
481   LLVM_ABI StringRef getArchName() const;
482 
483   /// Get the vendor (second) component of the triple.
484   LLVM_ABI StringRef getVendorName() const;
485 
486   /// Get the operating system (third) component of the triple.
487   LLVM_ABI StringRef getOSName() const;
488 
489   /// Get the optional environment (fourth) component of the triple, or "" if
490   /// empty.
491   LLVM_ABI StringRef getEnvironmentName() const;
492 
493   /// Get the operating system and optional environment components as a single
494   /// string (separated by a '-' if the environment component is present).
495   LLVM_ABI StringRef getOSAndEnvironmentName() const;
496 
497   /// Get the version component of the environment component as a single
498   /// string (the version after the environment).
499   ///
500   /// For example, "fooos1.2.3" would return "1.2.3".
501   LLVM_ABI StringRef getEnvironmentVersionString() const;
502 
503   /// @}
504   /// @name Convenience Predicates
505   /// @{
506 
507   /// Returns the pointer width of this architecture.
508   LLVM_ABI static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch);
509 
510   /// Returns the pointer width of this architecture.
getArchPointerBitWidth()511   unsigned getArchPointerBitWidth() const {
512     return getArchPointerBitWidth(getArch());
513   }
514 
515   /// Returns the trampoline size in bytes for this configuration.
516   LLVM_ABI unsigned getTrampolineSize() const;
517 
518   /// Test whether the architecture is 64-bit
519   ///
520   /// Note that this tests for 64-bit pointer width, and nothing else. Note
521   /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
522   /// 16-bit. The inner details of pointer width for particular architectures
523   /// is not summed up in the triple, and so only a coarse grained predicate
524   /// system is provided.
525   LLVM_ABI bool isArch64Bit() const;
526 
527   /// Test whether the architecture is 32-bit
528   ///
529   /// Note that this tests for 32-bit pointer width, and nothing else.
530   LLVM_ABI bool isArch32Bit() const;
531 
532   /// Test whether the architecture is 16-bit
533   ///
534   /// Note that this tests for 16-bit pointer width, and nothing else.
535   LLVM_ABI bool isArch16Bit() const;
536 
537   /// Helper function for doing comparisons against version numbers included in
538   /// the target triple.
539   bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
540                      unsigned Micro = 0) const {
541     if (Minor == 0) {
542       return getOSVersion() < VersionTuple(Major);
543     }
544     if (Micro == 0) {
545       return getOSVersion() < VersionTuple(Major, Minor);
546     }
547     return getOSVersion() < VersionTuple(Major, Minor, Micro);
548   }
549 
isOSVersionLT(const Triple & Other)550   bool isOSVersionLT(const Triple &Other) const {
551     return getOSVersion() < Other.getOSVersion();
552   }
553 
554   /// Comparison function for checking OS X version compatibility, which handles
555   /// supporting skewed version numbering schemes used by the "darwin" triples.
556   LLVM_ABI bool isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
557                                   unsigned Micro = 0) const;
558 
559   /// Is this a Mac OS X triple. For legacy reasons, we support both "darwin"
560   /// and "osx" as OS X triples.
isMacOSX()561   bool isMacOSX() const {
562     return getOS() == Triple::Darwin || getOS() == Triple::MacOSX;
563   }
564 
565   /// Is this an iOS triple.
566   /// Note: This identifies tvOS as a variant of iOS. If that ever
567   /// changes, i.e., if the two operating systems diverge or their version
568   /// numbers get out of sync, that will need to be changed.
569   /// watchOS has completely different version numbers so it is not included.
isiOS()570   bool isiOS() const {
571     return getOS() == Triple::IOS || isTvOS();
572   }
573 
574   /// Is this an Apple tvOS triple.
isTvOS()575   bool isTvOS() const {
576     return getOS() == Triple::TvOS;
577   }
578 
579   /// Is this an Apple watchOS triple.
isWatchOS()580   bool isWatchOS() const {
581     return getOS() == Triple::WatchOS;
582   }
583 
isWatchABI()584   bool isWatchABI() const {
585     return getSubArch() == Triple::ARMSubArch_v7k;
586   }
587 
588   /// Is this an Apple XROS triple.
isXROS()589   bool isXROS() const { return getOS() == Triple::XROS; }
590 
591   /// Is this an Apple BridgeOS triple.
isBridgeOS()592   bool isBridgeOS() const { return getOS() == Triple::BridgeOS; }
593 
594   /// Is this an Apple DriverKit triple.
isDriverKit()595   bool isDriverKit() const { return getOS() == Triple::DriverKit; }
596 
isOSzOS()597   bool isOSzOS() const { return getOS() == Triple::ZOS; }
598 
599   /// Is this an Apple MachO triple.
isAppleMachO()600   bool isAppleMachO() const {
601     return (getVendor() == Triple::Apple) && isOSBinFormatMachO();
602   }
603 
604   /// Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, DriverKit, XROS, or
605   /// bridgeOS).
isOSDarwin()606   bool isOSDarwin() const {
607     return isMacOSX() || isiOS() || isWatchOS() || isDriverKit() || isXROS() ||
608            isBridgeOS();
609   }
610 
isSimulatorEnvironment()611   bool isSimulatorEnvironment() const {
612     return getEnvironment() == Triple::Simulator;
613   }
614 
isMacCatalystEnvironment()615   bool isMacCatalystEnvironment() const {
616     return getEnvironment() == Triple::MacABI;
617   }
618 
619   /// Returns true for targets that run on a macOS machine.
isTargetMachineMac()620   bool isTargetMachineMac() const {
621     return isMacOSX() || (isOSDarwin() && (isSimulatorEnvironment() ||
622                                            isMacCatalystEnvironment()));
623   }
624 
isOSNetBSD()625   bool isOSNetBSD() const {
626     return getOS() == Triple::NetBSD;
627   }
628 
isOSOpenBSD()629   bool isOSOpenBSD() const {
630     return getOS() == Triple::OpenBSD;
631   }
632 
isOSFreeBSD()633   bool isOSFreeBSD() const {
634     return getOS() == Triple::FreeBSD;
635   }
636 
isOSFuchsia()637   bool isOSFuchsia() const {
638     return getOS() == Triple::Fuchsia;
639   }
640 
isOSDragonFly()641   bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
642 
isOSSolaris()643   bool isOSSolaris() const {
644     return getOS() == Triple::Solaris;
645   }
646 
isOSIAMCU()647   bool isOSIAMCU() const {
648     return getOS() == Triple::ELFIAMCU;
649   }
650 
isOSUnknown()651   bool isOSUnknown() const { return getOS() == Triple::UnknownOS; }
652 
isGNUEnvironment()653   bool isGNUEnvironment() const {
654     EnvironmentType Env = getEnvironment();
655     return Env == Triple::GNU || Env == Triple::GNUT64 ||
656            Env == Triple::GNUABIN32 || Env == Triple::GNUABI64 ||
657            Env == Triple::GNUEABI || Env == Triple::GNUEABIT64 ||
658            Env == Triple::GNUEABIHF || Env == Triple::GNUEABIHFT64 ||
659            Env == Triple::GNUF32 || Env == Triple::GNUF64 ||
660            Env == Triple::GNUSF || Env == Triple::GNUX32;
661   }
662 
663   /// Tests whether the OS is Haiku.
isOSHaiku()664   bool isOSHaiku() const {
665     return getOS() == Triple::Haiku;
666   }
667 
668   /// Tests whether the OS is UEFI.
isUEFI()669   bool isUEFI() const {
670     return getOS() == Triple::UEFI;
671   }
672 
673   /// Tests whether the OS is Windows.
isOSWindows()674   bool isOSWindows() const {
675     return getOS() == Triple::Win32;
676   }
677 
678   /// Checks if the environment is MSVC.
isKnownWindowsMSVCEnvironment()679   bool isKnownWindowsMSVCEnvironment() const {
680     return isOSWindows() && getEnvironment() == Triple::MSVC;
681   }
682 
683   /// Checks if the environment could be MSVC.
isWindowsMSVCEnvironment()684   bool isWindowsMSVCEnvironment() const {
685     return isKnownWindowsMSVCEnvironment() ||
686            (isOSWindows() && getEnvironment() == Triple::UnknownEnvironment);
687   }
688 
689   // Checks if we're using the Windows Arm64EC ABI.
isWindowsArm64EC()690   bool isWindowsArm64EC() const {
691     return getArch() == Triple::aarch64 &&
692            getSubArch() == Triple::AArch64SubArch_arm64ec;
693   }
694 
isWindowsCoreCLREnvironment()695   bool isWindowsCoreCLREnvironment() const {
696     return isOSWindows() && getEnvironment() == Triple::CoreCLR;
697   }
698 
isWindowsItaniumEnvironment()699   bool isWindowsItaniumEnvironment() const {
700     return isOSWindows() && getEnvironment() == Triple::Itanium;
701   }
702 
isWindowsCygwinEnvironment()703   bool isWindowsCygwinEnvironment() const {
704     return isOSWindows() && getEnvironment() == Triple::Cygnus;
705   }
706 
isWindowsGNUEnvironment()707   bool isWindowsGNUEnvironment() const {
708     return isOSWindows() && getEnvironment() == Triple::GNU;
709   }
710 
711   /// Tests for either Cygwin or MinGW OS
isOSCygMing()712   bool isOSCygMing() const {
713     return isWindowsCygwinEnvironment() || isWindowsGNUEnvironment();
714   }
715 
716   /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
isOSMSVCRT()717   bool isOSMSVCRT() const {
718     return isWindowsMSVCEnvironment() || isWindowsGNUEnvironment() ||
719            isWindowsItaniumEnvironment();
720   }
721 
722   /// Tests whether the OS is NaCl (Native Client)
isOSNaCl()723   bool isOSNaCl() const {
724     return getOS() == Triple::NaCl;
725   }
726 
727   /// Tests whether the OS is Linux.
isOSLinux()728   bool isOSLinux() const {
729     return getOS() == Triple::Linux;
730   }
731 
732   /// Tests whether the OS is kFreeBSD.
isOSKFreeBSD()733   bool isOSKFreeBSD() const {
734     return getOS() == Triple::KFreeBSD;
735   }
736 
737   /// Tests whether the OS is Hurd.
isOSHurd()738   bool isOSHurd() const {
739     return getOS() == Triple::Hurd;
740   }
741 
742   /// Tests whether the OS is WASI.
isOSWASI()743   bool isOSWASI() const {
744     return getOS() == Triple::WASI;
745   }
746 
747   /// Tests whether the OS is Emscripten.
isOSEmscripten()748   bool isOSEmscripten() const {
749     return getOS() == Triple::Emscripten;
750   }
751 
752   /// Tests whether the OS uses glibc.
isOSGlibc()753   bool isOSGlibc() const {
754     return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD ||
755             getOS() == Triple::Hurd) &&
756            !isAndroid();
757   }
758 
759   /// Tests whether the OS is AIX.
isOSAIX()760   bool isOSAIX() const {
761     return getOS() == Triple::AIX;
762   }
763 
isOSSerenity()764   bool isOSSerenity() const {
765     return getOS() == Triple::Serenity;
766   }
767 
768   /// Tests whether the OS uses the ELF binary format.
isOSBinFormatELF()769   bool isOSBinFormatELF() const {
770     return getObjectFormat() == Triple::ELF;
771   }
772 
773   /// Tests whether the OS uses the COFF binary format.
isOSBinFormatCOFF()774   bool isOSBinFormatCOFF() const {
775     return getObjectFormat() == Triple::COFF;
776   }
777 
778   /// Tests whether the OS uses the GOFF binary format.
isOSBinFormatGOFF()779   bool isOSBinFormatGOFF() const { return getObjectFormat() == Triple::GOFF; }
780 
781   /// Tests whether the environment is MachO.
isOSBinFormatMachO()782   bool isOSBinFormatMachO() const {
783     return getObjectFormat() == Triple::MachO;
784   }
785 
786   /// Tests whether the OS uses the Wasm binary format.
isOSBinFormatWasm()787   bool isOSBinFormatWasm() const {
788     return getObjectFormat() == Triple::Wasm;
789   }
790 
791   /// Tests whether the OS uses the XCOFF binary format.
isOSBinFormatXCOFF()792   bool isOSBinFormatXCOFF() const {
793     return getObjectFormat() == Triple::XCOFF;
794   }
795 
796   /// Tests whether the OS uses the DXContainer binary format.
isOSBinFormatDXContainer()797   bool isOSBinFormatDXContainer() const {
798     return getObjectFormat() == Triple::DXContainer;
799   }
800 
801   /// Tests whether the target is the PS4 platform.
isPS4()802   bool isPS4() const {
803     return getArch() == Triple::x86_64 &&
804            getVendor() == Triple::SCEI &&
805            getOS() == Triple::PS4;
806   }
807 
808   /// Tests whether the target is the PS5 platform.
isPS5()809   bool isPS5() const {
810     return getArch() == Triple::x86_64 &&
811       getVendor() == Triple::SCEI &&
812       getOS() == Triple::PS5;
813   }
814 
815   /// Tests whether the target is the PS4 or PS5 platform.
isPS()816   bool isPS() const { return isPS4() || isPS5(); }
817 
818   /// Tests whether the target is Android
isAndroid()819   bool isAndroid() const { return getEnvironment() == Triple::Android; }
820 
isAndroidVersionLT(unsigned Major)821   bool isAndroidVersionLT(unsigned Major) const {
822     assert(isAndroid() && "Not an Android triple!");
823 
824     VersionTuple Version = getEnvironmentVersion();
825 
826     // 64-bit targets did not exist before API level 21 (Lollipop).
827     if (isArch64Bit() && Version.getMajor() < 21)
828       return VersionTuple(21) < VersionTuple(Major);
829 
830     return Version < VersionTuple(Major);
831   }
832 
833   /// Tests whether the environment is musl-libc
isMusl()834   bool isMusl() const {
835     return getEnvironment() == Triple::Musl ||
836            getEnvironment() == Triple::MuslABIN32 ||
837            getEnvironment() == Triple::MuslABI64 ||
838            getEnvironment() == Triple::MuslEABI ||
839            getEnvironment() == Triple::MuslEABIHF ||
840            getEnvironment() == Triple::MuslF32 ||
841            getEnvironment() == Triple::MuslSF ||
842            getEnvironment() == Triple::MuslX32 ||
843            getEnvironment() == Triple::OpenHOS || isOSLiteOS();
844   }
845 
846   /// Tests whether the target is OHOS
847   /// LiteOS default enviroment is also OHOS, but omited on triple.
isOHOSFamily()848   bool isOHOSFamily() const { return isOpenHOS() || isOSLiteOS(); }
849 
isOpenHOS()850   bool isOpenHOS() const { return getEnvironment() == Triple::OpenHOS; }
851 
isOSLiteOS()852   bool isOSLiteOS() const { return getOS() == Triple::LiteOS; }
853 
854   /// Tests whether the target is DXIL.
isDXIL()855   bool isDXIL() const {
856     return getArch() == Triple::dxil;
857   }
858 
isShaderModelOS()859   bool isShaderModelOS() const {
860     return getOS() == Triple::ShaderModel;
861   }
862 
isVulkanOS()863   bool isVulkanOS() const { return getOS() == Triple::Vulkan; }
864 
isOSManagarm()865   bool isOSManagarm() const { return getOS() == Triple::Managarm; }
866 
isShaderStageEnvironment()867   bool isShaderStageEnvironment() const {
868     EnvironmentType Env = getEnvironment();
869     return Env == Triple::Pixel || Env == Triple::Vertex ||
870            Env == Triple::Geometry || Env == Triple::Hull ||
871            Env == Triple::Domain || Env == Triple::Compute ||
872            Env == Triple::Library || Env == Triple::RayGeneration ||
873            Env == Triple::Intersection || Env == Triple::AnyHit ||
874            Env == Triple::ClosestHit || Env == Triple::Miss ||
875            Env == Triple::Callable || Env == Triple::Mesh ||
876            Env == Triple::Amplification;
877   }
878 
879   /// Tests whether the target is SPIR (32- or 64-bit).
isSPIR()880   bool isSPIR() const {
881     return getArch() == Triple::spir || getArch() == Triple::spir64;
882   }
883 
884   /// Tests whether the target is SPIR-V (32/64-bit/Logical).
isSPIRV()885   bool isSPIRV() const {
886     return getArch() == Triple::spirv32 || getArch() == Triple::spirv64 ||
887            getArch() == Triple::spirv;
888   }
889 
890   // Tests whether the target is SPIR-V or SPIR.
isSPIROrSPIRV()891   bool isSPIROrSPIRV() const { return isSPIR() || isSPIRV(); }
892 
893   /// Tests whether the target is SPIR-V Logical
isSPIRVLogical()894   bool isSPIRVLogical() const {
895     return getArch() == Triple::spirv;
896   }
897 
898   /// Tests whether the target is NVPTX (32- or 64-bit).
isNVPTX()899   bool isNVPTX() const {
900     return getArch() == Triple::nvptx || getArch() == Triple::nvptx64;
901   }
902 
903   /// Tests whether the target is AMDGCN
isAMDGCN()904   bool isAMDGCN() const { return getArch() == Triple::amdgcn; }
905 
isAMDGPU()906   bool isAMDGPU() const { return getArch() == Triple::r600 || isAMDGCN(); }
907 
908   /// Tests whether the target is Thumb (little and big endian).
isThumb()909   bool isThumb() const {
910     return getArch() == Triple::thumb || getArch() == Triple::thumbeb;
911   }
912 
913   /// Tests whether the target is ARM (little and big endian).
isARM()914   bool isARM() const {
915     return getArch() == Triple::arm || getArch() == Triple::armeb;
916   }
917 
918   /// Tests whether the target supports the EHABI exception
919   /// handling standard.
isTargetEHABICompatible()920   bool isTargetEHABICompatible() const {
921     return (isARM() || isThumb()) &&
922            (getEnvironment() == Triple::EABI ||
923             getEnvironment() == Triple::GNUEABI ||
924             getEnvironment() == Triple::GNUEABIT64 ||
925             getEnvironment() == Triple::MuslEABI ||
926             getEnvironment() == Triple::EABIHF ||
927             getEnvironment() == Triple::GNUEABIHF ||
928             getEnvironment() == Triple::GNUEABIHFT64 ||
929             getEnvironment() == Triple::OpenHOS ||
930             getEnvironment() == Triple::MuslEABIHF || isAndroid()) &&
931            isOSBinFormatELF() && !isOSNetBSD();
932   }
933 
934   // ARM EABI is the bare-metal EABI described in ARM ABI documents and
935   // can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
936   // FIXME: Add a flag for bare-metal for that target and set Triple::EABI
937   // even for GNUEABI, so we can make a distinction here and still conform to
938   // the EABI on GNU (and Android) mode. This requires change in Clang, too.
939   // FIXME: The Darwin exception is temporary, while we move users to
940   // "*-*-*-macho" triples as quickly as possible.
isTargetAEABI()941   bool isTargetAEABI() const {
942     return (getEnvironment() == Triple::EABI ||
943             getEnvironment() == Triple::EABIHF) &&
944            !isOSDarwin() && !isOSWindows();
945   }
946 
isTargetGNUAEABI()947   bool isTargetGNUAEABI() const {
948     return (getEnvironment() == Triple::GNUEABI ||
949             getEnvironment() == Triple::GNUEABIT64 ||
950             getEnvironment() == Triple::GNUEABIHF ||
951             getEnvironment() == Triple::GNUEABIHFT64) &&
952            !isOSDarwin() && !isOSWindows();
953   }
954 
isTargetMuslAEABI()955   bool isTargetMuslAEABI() const {
956     return (getEnvironment() == Triple::MuslEABI ||
957             getEnvironment() == Triple::MuslEABIHF ||
958             getEnvironment() == Triple::OpenHOS) &&
959            !isOSDarwin() && !isOSWindows();
960   }
961 
962   /// Tests whether the target is T32.
isArmT32()963   bool isArmT32() const {
964     switch (getSubArch()) {
965     case Triple::ARMSubArch_v8m_baseline:
966     case Triple::ARMSubArch_v7s:
967     case Triple::ARMSubArch_v7k:
968     case Triple::ARMSubArch_v7ve:
969     case Triple::ARMSubArch_v6:
970     case Triple::ARMSubArch_v6m:
971     case Triple::ARMSubArch_v6k:
972     case Triple::ARMSubArch_v6t2:
973     case Triple::ARMSubArch_v5:
974     case Triple::ARMSubArch_v5te:
975     case Triple::ARMSubArch_v4t:
976       return false;
977     default:
978       return true;
979     }
980   }
981 
982   /// Tests whether the target is an M-class.
isArmMClass()983   bool isArmMClass() const {
984     switch (getSubArch()) {
985     case Triple::ARMSubArch_v6m:
986     case Triple::ARMSubArch_v7m:
987     case Triple::ARMSubArch_v7em:
988     case Triple::ARMSubArch_v8m_mainline:
989     case Triple::ARMSubArch_v8m_baseline:
990     case Triple::ARMSubArch_v8_1m_mainline:
991       return true;
992     default:
993       return false;
994     }
995   }
996 
997   /// Tests whether the target is AArch64 (little and big endian).
isAArch64()998   bool isAArch64() const {
999     return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be ||
1000            getArch() == Triple::aarch64_32;
1001   }
1002 
1003   /// Tests whether the target is AArch64 and pointers are the size specified by
1004   /// \p PointerWidth.
isAArch64(int PointerWidth)1005   bool isAArch64(int PointerWidth) const {
1006     assert(PointerWidth == 64 || PointerWidth == 32);
1007     if (!isAArch64())
1008       return false;
1009     return getArch() == Triple::aarch64_32 ||
1010                    getEnvironment() == Triple::GNUILP32
1011                ? PointerWidth == 32
1012                : PointerWidth == 64;
1013   }
1014 
1015   /// Tests whether the target is 32-bit LoongArch.
isLoongArch32()1016   bool isLoongArch32() const { return getArch() == Triple::loongarch32; }
1017 
1018   /// Tests whether the target is 64-bit LoongArch.
isLoongArch64()1019   bool isLoongArch64() const { return getArch() == Triple::loongarch64; }
1020 
1021   /// Tests whether the target is LoongArch (32- and 64-bit).
isLoongArch()1022   bool isLoongArch() const { return isLoongArch32() || isLoongArch64(); }
1023 
1024   /// Tests whether the target is MIPS 32-bit (little and big endian).
isMIPS32()1025   bool isMIPS32() const {
1026     return getArch() == Triple::mips || getArch() == Triple::mipsel;
1027   }
1028 
1029   /// Tests whether the target is MIPS 64-bit (little and big endian).
isMIPS64()1030   bool isMIPS64() const {
1031     return getArch() == Triple::mips64 || getArch() == Triple::mips64el;
1032   }
1033 
1034   /// Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
isMIPS()1035   bool isMIPS() const {
1036     return isMIPS32() || isMIPS64();
1037   }
1038 
1039   /// Tests whether the target is PowerPC (32- or 64-bit LE or BE).
isPPC()1040   bool isPPC() const {
1041     return getArch() == Triple::ppc || getArch() == Triple::ppc64 ||
1042            getArch() == Triple::ppcle || getArch() == Triple::ppc64le;
1043   }
1044 
1045   /// Tests whether the target is 32-bit PowerPC (little and big endian).
isPPC32()1046   bool isPPC32() const {
1047     return getArch() == Triple::ppc || getArch() == Triple::ppcle;
1048   }
1049 
1050   /// Tests whether the target is 64-bit PowerPC (little and big endian).
isPPC64()1051   bool isPPC64() const {
1052     return getArch() == Triple::ppc64 || getArch() == Triple::ppc64le;
1053   }
1054 
1055   /// Tests whether the target 64-bit PowerPC big endian ABI is ELFv2.
isPPC64ELFv2ABI()1056   bool isPPC64ELFv2ABI() const {
1057     return (getArch() == Triple::ppc64 &&
1058             ((getOS() == Triple::FreeBSD &&
1059               (getOSMajorVersion() >= 13 || getOSVersion().empty())) ||
1060              getOS() == Triple::OpenBSD || isMusl()));
1061   }
1062 
1063   /// Tests whether the target 32-bit PowerPC uses Secure PLT.
isPPC32SecurePlt()1064   bool isPPC32SecurePlt() const {
1065     return ((getArch() == Triple::ppc || getArch() == Triple::ppcle) &&
1066             ((getOS() == Triple::FreeBSD &&
1067               (getOSMajorVersion() >= 13 || getOSVersion().empty())) ||
1068              getOS() == Triple::NetBSD || getOS() == Triple::OpenBSD ||
1069              isMusl()));
1070   }
1071 
1072   /// Tests whether the target is 32-bit RISC-V.
isRISCV32()1073   bool isRISCV32() const { return getArch() == Triple::riscv32; }
1074 
1075   /// Tests whether the target is 64-bit RISC-V.
isRISCV64()1076   bool isRISCV64() const { return getArch() == Triple::riscv64; }
1077 
1078   /// Tests whether the target is RISC-V (32- and 64-bit).
isRISCV()1079   bool isRISCV() const { return isRISCV32() || isRISCV64(); }
1080 
1081   /// Tests whether the target is 32-bit SPARC (little and big endian).
isSPARC32()1082   bool isSPARC32() const {
1083     return getArch() == Triple::sparc || getArch() == Triple::sparcel;
1084   }
1085 
1086   /// Tests whether the target is 64-bit SPARC (big endian).
isSPARC64()1087   bool isSPARC64() const { return getArch() == Triple::sparcv9; }
1088 
1089   /// Tests whether the target is SPARC.
isSPARC()1090   bool isSPARC() const { return isSPARC32() || isSPARC64(); }
1091 
1092   /// Tests whether the target is SystemZ.
isSystemZ()1093   bool isSystemZ() const {
1094     return getArch() == Triple::systemz;
1095   }
1096 
1097   /// Tests whether the target is x86 (32- or 64-bit).
isX86()1098   bool isX86() const {
1099     return getArch() == Triple::x86 || getArch() == Triple::x86_64;
1100   }
1101 
1102   /// Tests whether the target is VE
isVE()1103   bool isVE() const {
1104     return getArch() == Triple::ve;
1105   }
1106 
1107   /// Tests whether the target is wasm (32- and 64-bit).
isWasm()1108   bool isWasm() const {
1109     return getArch() == Triple::wasm32 || getArch() == Triple::wasm64;
1110   }
1111 
1112   // Tests whether the target is CSKY
isCSKY()1113   bool isCSKY() const {
1114     return getArch() == Triple::csky;
1115   }
1116 
1117   /// Tests whether the target is the Apple "arm64e" AArch64 subarch.
isArm64e()1118   bool isArm64e() const {
1119     return getArch() == Triple::aarch64 &&
1120            getSubArch() == Triple::AArch64SubArch_arm64e;
1121   }
1122 
1123   // Tests whether the target is N32.
isABIN32()1124   bool isABIN32() const {
1125     EnvironmentType Env = getEnvironment();
1126     return Env == Triple::GNUABIN32 || Env == Triple::MuslABIN32;
1127   }
1128 
1129   /// Tests whether the target is X32.
isX32()1130   bool isX32() const {
1131     EnvironmentType Env = getEnvironment();
1132     return Env == Triple::GNUX32 || Env == Triple::MuslX32;
1133   }
1134 
1135   /// Tests whether the target is eBPF.
isBPF()1136   bool isBPF() const {
1137     return getArch() == Triple::bpfel || getArch() == Triple::bpfeb;
1138   }
1139 
1140   /// Tests if the target forces 64-bit time_t on a 32-bit architecture.
isTime64ABI()1141   bool isTime64ABI() const {
1142     EnvironmentType Env = getEnvironment();
1143     return Env == Triple::GNUT64 || Env == Triple::GNUEABIT64 ||
1144            Env == Triple::GNUEABIHFT64;
1145   }
1146 
1147   /// Tests if the target forces hardfloat.
isHardFloatABI()1148   bool isHardFloatABI() const {
1149     EnvironmentType Env = getEnvironment();
1150     return Env == llvm::Triple::GNUEABIHF ||
1151            Env == llvm::Triple::GNUEABIHFT64 ||
1152            Env == llvm::Triple::MuslEABIHF ||
1153            Env == llvm::Triple::EABIHF;
1154   }
1155 
1156   /// Tests whether the target supports comdat
supportsCOMDAT()1157   bool supportsCOMDAT() const {
1158     return !(isOSBinFormatMachO() || isOSBinFormatXCOFF() ||
1159              isOSBinFormatDXContainer());
1160   }
1161 
1162   /// Tests whether the target uses emulated TLS as default.
1163   ///
1164   /// Note: Android API level 29 (10) introduced ELF TLS.
hasDefaultEmulatedTLS()1165   bool hasDefaultEmulatedTLS() const {
1166     return (isAndroid() && isAndroidVersionLT(29)) || isOSOpenBSD() ||
1167            isWindowsCygwinEnvironment() || isOHOSFamily();
1168   }
1169 
1170   /// True if the target uses TLSDESC by default.
hasDefaultTLSDESC()1171   bool hasDefaultTLSDESC() const {
1172     return isAArch64() || (isAndroid() && isRISCV64()) || isOSFuchsia();
1173   }
1174 
1175   /// Tests whether the target uses -data-sections as default.
hasDefaultDataSections()1176   bool hasDefaultDataSections() const {
1177     return isOSBinFormatXCOFF() || isWasm();
1178   }
1179 
1180   /// Tests if the environment supports dllimport/export annotations.
hasDLLImportExport()1181   bool hasDLLImportExport() const { return isOSWindows() || isPS(); }
1182 
1183   /// @}
1184   /// @name Mutators
1185   /// @{
1186 
1187   /// Set the architecture (first) component of the triple to a known type.
1188   LLVM_ABI void setArch(ArchType Kind, SubArchType SubArch = NoSubArch);
1189 
1190   /// Set the vendor (second) component of the triple to a known type.
1191   LLVM_ABI void setVendor(VendorType Kind);
1192 
1193   /// Set the operating system (third) component of the triple to a known type.
1194   LLVM_ABI void setOS(OSType Kind);
1195 
1196   /// Set the environment (fourth) component of the triple to a known type.
1197   LLVM_ABI void setEnvironment(EnvironmentType Kind);
1198 
1199   /// Set the object file format.
1200   LLVM_ABI void setObjectFormat(ObjectFormatType Kind);
1201 
1202   /// Set all components to the new triple \p Str.
1203   LLVM_ABI void setTriple(const Twine &Str);
1204 
1205   /// Set the architecture (first) component of the triple by name.
1206   LLVM_ABI void setArchName(StringRef Str);
1207 
1208   /// Set the vendor (second) component of the triple by name.
1209   LLVM_ABI void setVendorName(StringRef Str);
1210 
1211   /// Set the operating system (third) component of the triple by name.
1212   LLVM_ABI void setOSName(StringRef Str);
1213 
1214   /// Set the optional environment (fourth) component of the triple by name.
1215   LLVM_ABI void setEnvironmentName(StringRef Str);
1216 
1217   /// Set the operating system and optional environment components with a single
1218   /// string.
1219   LLVM_ABI void setOSAndEnvironmentName(StringRef Str);
1220 
1221   /// @}
1222   /// @name Helpers to build variants of a particular triple.
1223   /// @{
1224 
1225   /// Form a triple with a 32-bit variant of the current architecture.
1226   ///
1227   /// This can be used to move across "families" of architectures where useful.
1228   ///
1229   /// \returns A new triple with a 32-bit architecture or an unknown
1230   ///          architecture if no such variant can be found.
1231   LLVM_ABI llvm::Triple get32BitArchVariant() const;
1232 
1233   /// Form a triple with a 64-bit variant of the current architecture.
1234   ///
1235   /// This can be used to move across "families" of architectures where useful.
1236   ///
1237   /// \returns A new triple with a 64-bit architecture or an unknown
1238   ///          architecture if no such variant can be found.
1239   LLVM_ABI llvm::Triple get64BitArchVariant() const;
1240 
1241   /// Form a triple with a big endian variant of the current architecture.
1242   ///
1243   /// This can be used to move across "families" of architectures where useful.
1244   ///
1245   /// \returns A new triple with a big endian architecture or an unknown
1246   ///          architecture if no such variant can be found.
1247   LLVM_ABI llvm::Triple getBigEndianArchVariant() const;
1248 
1249   /// Form a triple with a little endian variant of the current architecture.
1250   ///
1251   /// This can be used to move across "families" of architectures where useful.
1252   ///
1253   /// \returns A new triple with a little endian architecture or an unknown
1254   ///          architecture if no such variant can be found.
1255   LLVM_ABI llvm::Triple getLittleEndianArchVariant() const;
1256 
1257   /// Tests whether the target triple is little endian.
1258   ///
1259   /// \returns true if the triple is little endian, false otherwise.
1260   LLVM_ABI bool isLittleEndian() const;
1261 
1262   /// Test whether target triples are compatible.
1263   LLVM_ABI bool isCompatibleWith(const Triple &Other) const;
1264 
1265   /// Test whether the target triple is for a GPU.
isGPU()1266   bool isGPU() const { return isSPIRV() || isNVPTX() || isAMDGPU(); }
1267 
1268   /// Merge target triples.
1269   LLVM_ABI std::string merge(const Triple &Other) const;
1270 
1271   /// Some platforms have different minimum supported OS versions that
1272   /// varies by the architecture specified in the triple. This function
1273   /// returns the minimum supported OS version for this triple if one an exists,
1274   /// or an invalid version tuple if this triple doesn't have one.
1275   LLVM_ABI VersionTuple getMinimumSupportedOSVersion() const;
1276 
1277   /// @}
1278   /// @name Static helpers for IDs.
1279   /// @{
1280 
1281   /// Get the canonical name for the \p Kind architecture.
1282   LLVM_ABI static StringRef getArchTypeName(ArchType Kind);
1283 
1284   /// Get the architecture name based on \p Kind and \p SubArch.
1285   LLVM_ABI static StringRef getArchName(ArchType Kind,
1286                                         SubArchType SubArch = NoSubArch);
1287 
1288   /// Get the "prefix" canonical name for the \p Kind architecture. This is the
1289   /// prefix used by the architecture specific builtins, and is suitable for
1290   /// passing to \see Intrinsic::getIntrinsicForClangBuiltin().
1291   ///
1292   /// \return - The architecture prefix, or 0 if none is defined.
1293   LLVM_ABI static StringRef getArchTypePrefix(ArchType Kind);
1294 
1295   /// Get the canonical name for the \p Kind vendor.
1296   LLVM_ABI static StringRef getVendorTypeName(VendorType Kind);
1297 
1298   /// Get the canonical name for the \p Kind operating system.
1299   LLVM_ABI static StringRef getOSTypeName(OSType Kind);
1300 
1301   /// Get the canonical name for the \p Kind environment.
1302   LLVM_ABI static StringRef getEnvironmentTypeName(EnvironmentType Kind);
1303 
1304   /// Get the name for the \p Object format.
1305   LLVM_ABI static StringRef
1306   getObjectFormatTypeName(ObjectFormatType ObjectFormat);
1307 
1308   /// @}
1309   /// @name Static helpers for converting alternate architecture names.
1310   /// @{
1311 
1312   /// The canonical type for the given LLVM architecture name (e.g., "x86").
1313   LLVM_ABI static ArchType getArchTypeForLLVMName(StringRef Str);
1314 
1315   /// @}
1316 
1317   /// Returns a canonicalized OS version number for the specified OS.
1318   LLVM_ABI static VersionTuple
1319   getCanonicalVersionForOS(OSType OSKind, const VersionTuple &Version,
1320                            bool IsInValidRange);
1321 
1322   /// Returns whether an OS version is invalid and would not map to an Apple OS.
1323   LLVM_ABI static bool isValidVersionForOS(OSType OSKind,
1324                                            const VersionTuple &Version);
1325 
1326   LLVM_ABI ExceptionHandling getDefaultExceptionHandling() const;
1327 };
1328 
1329 } // End llvm namespace
1330 
1331 
1332 #endif
1333