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

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