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

source code of include/llvm-20/llvm/TargetParser/Triple.h