LLVM  10.0.0
Triple.h
Go to the documentation of this file.
1 //===-- llvm/ADT/Triple.h - Target triple helper class ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_ADT_TRIPLE_H
10 #define LLVM_ADT_TRIPLE_H
11 
12 #include "llvm/ADT/Twine.h"
13 
14 // Some system headers or GCC predefined macros conflict with identifiers in
15 // this file. Undefine them here.
16 #undef NetBSD
17 #undef mips
18 #undef sparc
19 
20 namespace llvm {
21 
22 /// Triple - Helper class for working with autoconf configuration names. For
23 /// historical reasons, we also call these 'triples' (they used to contain
24 /// exactly three fields).
25 ///
26 /// Configuration names are strings in the canonical form:
27 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM
28 /// or
29 /// ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT
30 ///
31 /// This class is used for clients which want to support arbitrary
32 /// configuration names, but also want to implement certain special
33 /// behavior for particular configurations. This class isolates the mapping
34 /// from the components of the configuration name to well known IDs.
35 ///
36 /// At its core the Triple class is designed to be a wrapper for a triple
37 /// string; the constructor does not change or normalize the triple string.
38 /// Clients that need to handle the non-canonical triples that users often
39 /// specify should use the normalize method.
40 ///
41 /// See autoconf/config.guess for a glimpse into what configuration names
42 /// look like in practice.
43 class Triple {
44 public:
45  enum ArchType {
47 
48  arm, // ARM (little endian): arm, armv.*, xscale
49  armeb, // ARM (big endian): armeb
50  aarch64, // AArch64 (little endian): aarch64
51  aarch64_be, // AArch64 (big endian): aarch64_be
52  aarch64_32, // AArch64 (little endian) ILP32: aarch64_32
53  arc, // ARC: Synopsys ARC
54  avr, // AVR: Atmel AVR microcontroller
55  bpfel, // eBPF or extended BPF or 64-bit BPF (little endian)
56  bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian)
57  hexagon, // Hexagon: hexagon
58  mips, // MIPS: mips, mipsallegrex, mipsr6
59  mipsel, // MIPSEL: mipsel, mipsallegrexe, mipsr6el
60  mips64, // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
61  mips64el, // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
62  msp430, // MSP430: msp430
63  ppc, // PPC: powerpc
64  ppc64, // PPC64: powerpc64, ppu
65  ppc64le, // PPC64LE: powerpc64le
66  r600, // R600: AMD GPUs HD2XXX - HD6XXX
67  amdgcn, // AMDGCN: AMD GCN GPUs
68  riscv32, // RISC-V (32-bit): riscv32
69  riscv64, // RISC-V (64-bit): riscv64
70  sparc, // Sparc: sparc
71  sparcv9, // Sparcv9: Sparcv9
72  sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant
73  systemz, // SystemZ: s390x
74  tce, // TCE (http://tce.cs.tut.fi/): tce
75  tcele, // TCE little endian (http://tce.cs.tut.fi/): tcele
76  thumb, // Thumb (little endian): thumb, thumbv.*
77  thumbeb, // Thumb (big endian): thumbeb
78  x86, // X86: i[3-9]86
79  x86_64, // X86-64: amd64, x86_64
80  xcore, // XCore: xcore
81  nvptx, // NVPTX: 32-bit
82  nvptx64, // NVPTX: 64-bit
83  le32, // le32: generic little-endian 32-bit CPU (PNaCl)
84  le64, // le64: generic little-endian 64-bit CPU (PNaCl)
85  amdil, // AMDIL
86  amdil64, // AMDIL with 64-bit pointers
87  hsail, // AMD HSAIL
88  hsail64, // AMD HSAIL with 64-bit pointers
89  spir, // SPIR: standard portable IR for OpenCL 32-bit version
90  spir64, // SPIR: standard portable IR for OpenCL 64-bit version
91  kalimba, // Kalimba: generic kalimba
92  shave, // SHAVE: Movidius vector VLIW processors
93  lanai, // Lanai: Lanai 32-bit
94  wasm32, // WebAssembly with 32-bit pointers
95  wasm64, // WebAssembly with 64-bit pointers
96  renderscript32, // 32-bit RenderScript
97  renderscript64, // 64-bit RenderScript
98  ve, // NEC SX-Aurora Vector Engine
100  };
101  enum SubArchType {
103 
127 
131 
133 
135  };
136  enum VendorType {
138 
140  PC,
156  };
157  enum OSType {
159 
169  Lv2, // PS3
178  NaCl, // Native Client
179  CNK, // BG/P Compute-Node Kernel
181  CUDA, // NVIDIA CUDA
182  NVCL, // NVIDIA OpenCL
183  AMDHSA, // AMD HSA Runtime
186  TvOS, // Apple tvOS
187  WatchOS, // Apple watchOS
190  AMDPAL, // AMD PAL Runtime
191  HermitCore, // HermitCore Unikernel/Multikernel
192  Hurd, // GNU/Hurd
193  WASI, // Experimental WebAssembly OS
196  };
199 
213 
218  Simulator, // Simulator variants of other systems, e.g., Apple's iOS
219  MacABI, // Mac Catalyst variant of Apple's iOS deployment target.
221  };
224 
230  };
231 
232 private:
233  std::string Data;
234 
235  /// The parsed arch type.
236  ArchType Arch;
237 
238  /// The parsed subarchitecture type.
239  SubArchType SubArch;
240 
241  /// The parsed vendor type.
242  VendorType Vendor;
243 
244  /// The parsed OS type.
245  OSType OS;
246 
247  /// The parsed Environment type.
248  EnvironmentType Environment;
249 
250  /// The object format type.
251  ObjectFormatType ObjectFormat;
252 
253 public:
254  /// @name Constructors
255  /// @{
256 
257  /// Default constructor is the same as an empty string and leaves all
258  /// triple fields unknown.
260  : Data(), Arch(), SubArch(), Vendor(), OS(), Environment(),
261  ObjectFormat() {}
262 
263  explicit Triple(const Twine &Str);
264  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
265  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
266  const Twine &EnvironmentStr);
267 
268  bool operator==(const Triple &Other) const {
269  return Arch == Other.Arch && SubArch == Other.SubArch &&
270  Vendor == Other.Vendor && OS == Other.OS &&
271  Environment == Other.Environment &&
272  ObjectFormat == Other.ObjectFormat;
273  }
274 
275  bool operator!=(const Triple &Other) const {
276  return !(*this == Other);
277  }
278 
279  /// @}
280  /// @name Normalization
281  /// @{
282 
283  /// normalize - Turn an arbitrary machine specification into the canonical
284  /// triple form (or something sensible that the Triple class understands if
285  /// nothing better can reasonably be done). In particular, it handles the
286  /// common case in which otherwise valid components are in the wrong order.
287  static std::string normalize(StringRef Str);
288 
289  /// Return the normalized form of this triple's string.
290  std::string normalize() const { return normalize(Data); }
291 
292  /// @}
293  /// @name Typed Component Access
294  /// @{
295 
296  /// getArch - Get the parsed architecture type of this triple.
297  ArchType getArch() const { return Arch; }
298 
299  /// getSubArch - get the parsed subarchitecture type for this triple.
300  SubArchType getSubArch() const { return SubArch; }
301 
302  /// getVendor - Get the parsed vendor type of this triple.
303  VendorType getVendor() const { return Vendor; }
304 
305  /// getOS - Get the parsed operating system type of this triple.
306  OSType getOS() const { return OS; }
307 
308  /// hasEnvironment - Does this triple have the optional environment
309  /// (fourth) component?
310  bool hasEnvironment() const {
311  return getEnvironmentName() != "";
312  }
313 
314  /// getEnvironment - Get the parsed environment type of this triple.
315  EnvironmentType getEnvironment() const { return Environment; }
316 
317  /// Parse the version number from the OS name component of the
318  /// triple, if present.
319  ///
320  /// For example, "fooos1.2.3" would return (1, 2, 3).
321  ///
322  /// If an entry is not defined, it will be returned as 0.
323  void getEnvironmentVersion(unsigned &Major, unsigned &Minor,
324  unsigned &Micro) const;
325 
326  /// getFormat - Get the object format for this triple.
327  ObjectFormatType getObjectFormat() const { return ObjectFormat; }
328 
329  /// getOSVersion - Parse the version number from the OS name component of the
330  /// triple, if present.
331  ///
332  /// For example, "fooos1.2.3" would return (1, 2, 3).
333  ///
334  /// If an entry is not defined, it will be returned as 0.
335  void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
336 
337  /// getOSMajorVersion - Return just the major version number, this is
338  /// specialized because it is a common query.
339  unsigned getOSMajorVersion() const {
340  unsigned Maj, Min, Micro;
341  getOSVersion(Maj, Min, Micro);
342  return Maj;
343  }
344 
345  /// getMacOSXVersion - Parse the version number as with getOSVersion and then
346  /// translate generic "darwin" versions to the corresponding OS X versions.
347  /// This may also be called with IOS triples but the OS X version number is
348  /// just set to a constant 10.4.0 in that case. Returns true if successful.
349  bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
350  unsigned &Micro) const;
351 
352  /// getiOSVersion - Parse the version number as with getOSVersion. This should
353  /// only be called with IOS or generic triples.
354  void getiOSVersion(unsigned &Major, unsigned &Minor,
355  unsigned &Micro) const;
356 
357  /// getWatchOSVersion - Parse the version number as with getOSVersion. This
358  /// should only be called with WatchOS or generic triples.
359  void getWatchOSVersion(unsigned &Major, unsigned &Minor,
360  unsigned &Micro) const;
361 
362  /// @}
363  /// @name Direct Component Access
364  /// @{
365 
366  const std::string &str() const { return Data; }
367 
368  const std::string &getTriple() const { return Data; }
369 
370  /// getArchName - Get the architecture (first) component of the
371  /// triple.
372  StringRef getArchName() const;
373 
374  /// getVendorName - Get the vendor (second) component of the triple.
375  StringRef getVendorName() const;
376 
377  /// getOSName - Get the operating system (third) component of the
378  /// triple.
379  StringRef getOSName() const;
380 
381  /// getEnvironmentName - Get the optional environment (fourth)
382  /// component of the triple, or "" if empty.
384 
385  /// getOSAndEnvironmentName - Get the operating system and optional
386  /// environment components as a single string (separated by a '-'
387  /// if the environment component is present).
389 
390  /// @}
391  /// @name Convenience Predicates
392  /// @{
393 
394  /// Test whether the architecture is 64-bit
395  ///
396  /// Note that this tests for 64-bit pointer width, and nothing else. Note
397  /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
398  /// 16-bit. The inner details of pointer width for particular architectures
399  /// is not summed up in the triple, and so only a coarse grained predicate
400  /// system is provided.
401  bool isArch64Bit() const;
402 
403  /// Test whether the architecture is 32-bit
404  ///
405  /// Note that this tests for 32-bit pointer width, and nothing else.
406  bool isArch32Bit() const;
407 
408  /// Test whether the architecture is 16-bit
409  ///
410  /// Note that this tests for 16-bit pointer width, and nothing else.
411  bool isArch16Bit() const;
412 
413  /// isOSVersionLT - Helper function for doing comparisons against version
414  /// numbers included in the target triple.
415  bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
416  unsigned Micro = 0) const {
417  unsigned LHS[3];
418  getOSVersion(LHS[0], LHS[1], LHS[2]);
419 
420  if (LHS[0] != Major)
421  return LHS[0] < Major;
422  if (LHS[1] != Minor)
423  return LHS[1] < Minor;
424  if (LHS[2] != Micro)
425  return LHS[2] < Micro;
426 
427  return false;
428  }
429 
430  bool isOSVersionLT(const Triple &Other) const {
431  unsigned RHS[3];
432  Other.getOSVersion(RHS[0], RHS[1], RHS[2]);
433  return isOSVersionLT(RHS[0], RHS[1], RHS[2]);
434  }
435 
436  /// isMacOSXVersionLT - Comparison function for checking OS X version
437  /// compatibility, which handles supporting skewed version numbering schemes
438  /// used by the "darwin" triples.
439  bool isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
440  unsigned Micro = 0) const {
441  assert(isMacOSX() && "Not an OS X triple!");
442 
443  // If this is OS X, expect a sane version number.
444  if (getOS() == Triple::MacOSX)
445  return isOSVersionLT(Major, Minor, Micro);
446 
447  // Otherwise, compare to the "Darwin" number.
448  assert(Major == 10 && "Unexpected major version");
449  return isOSVersionLT(Minor + 4, Micro, 0);
450  }
451 
452  /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
453  /// "darwin" and "osx" as OS X triples.
454  bool isMacOSX() const {
455  return getOS() == Triple::Darwin || getOS() == Triple::MacOSX;
456  }
457 
458  /// Is this an iOS triple.
459  /// Note: This identifies tvOS as a variant of iOS. If that ever
460  /// changes, i.e., if the two operating systems diverge or their version
461  /// numbers get out of sync, that will need to be changed.
462  /// watchOS has completely different version numbers so it is not included.
463  bool isiOS() const {
464  return getOS() == Triple::IOS || isTvOS();
465  }
466 
467  /// Is this an Apple tvOS triple.
468  bool isTvOS() const {
469  return getOS() == Triple::TvOS;
470  }
471 
472  /// Is this an Apple watchOS triple.
473  bool isWatchOS() const {
474  return getOS() == Triple::WatchOS;
475  }
476 
477  bool isWatchABI() const {
479  }
480 
481  /// isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
482  bool isOSDarwin() const {
483  return isMacOSX() || isiOS() || isWatchOS();
484  }
485 
486  bool isSimulatorEnvironment() const {
487  return getEnvironment() == Triple::Simulator;
488  }
489 
491  return getEnvironment() == Triple::MacABI;
492  }
493 
494  bool isOSNetBSD() const {
495  return getOS() == Triple::NetBSD;
496  }
497 
498  bool isOSOpenBSD() const {
499  return getOS() == Triple::OpenBSD;
500  }
501 
502  bool isOSFreeBSD() const {
503  return getOS() == Triple::FreeBSD;
504  }
505 
506  bool isOSFuchsia() const {
507  return getOS() == Triple::Fuchsia;
508  }
509 
510  bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
511 
512  bool isOSSolaris() const {
513  return getOS() == Triple::Solaris;
514  }
515 
516  bool isOSIAMCU() const {
517  return getOS() == Triple::ELFIAMCU;
518  }
519 
520  bool isOSUnknown() const { return getOS() == Triple::UnknownOS; }
521 
522  bool isGNUEnvironment() const {
524  return Env == Triple::GNU || Env == Triple::GNUABIN32 ||
525  Env == Triple::GNUABI64 || Env == Triple::GNUEABI ||
526  Env == Triple::GNUEABIHF || Env == Triple::GNUX32;
527  }
528 
529  bool isOSContiki() const {
530  return getOS() == Triple::Contiki;
531  }
532 
533  /// Tests whether the OS is Haiku.
534  bool isOSHaiku() const {
535  return getOS() == Triple::Haiku;
536  }
537 
538  /// Tests whether the OS is Windows.
539  bool isOSWindows() const {
540  return getOS() == Triple::Win32;
541  }
542 
543  /// Checks if the environment is MSVC.
545  return isOSWindows() && getEnvironment() == Triple::MSVC;
546  }
547 
548  /// Checks if the environment could be MSVC.
552  }
553 
555  return isOSWindows() && getEnvironment() == Triple::CoreCLR;
556  }
557 
559  return isOSWindows() && getEnvironment() == Triple::Itanium;
560  }
561 
563  return isOSWindows() && getEnvironment() == Triple::Cygnus;
564  }
565 
566  bool isWindowsGNUEnvironment() const {
567  return isOSWindows() && getEnvironment() == Triple::GNU;
568  }
569 
570  /// Tests for either Cygwin or MinGW OS
571  bool isOSCygMing() const {
573  }
574 
575  /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
576  bool isOSMSVCRT() const {
579  }
580 
581  /// Tests whether the OS is NaCl (Native Client)
582  bool isOSNaCl() const {
583  return getOS() == Triple::NaCl;
584  }
585 
586  /// Tests whether the OS is Linux.
587  bool isOSLinux() const {
588  return getOS() == Triple::Linux;
589  }
590 
591  /// Tests whether the OS is kFreeBSD.
592  bool isOSKFreeBSD() const {
593  return getOS() == Triple::KFreeBSD;
594  }
595 
596  /// Tests whether the OS is Hurd.
597  bool isOSHurd() const {
598  return getOS() == Triple::Hurd;
599  }
600 
601  /// Tests whether the OS is WASI.
602  bool isOSWASI() const {
603  return getOS() == Triple::WASI;
604  }
605 
606  /// Tests whether the OS is Emscripten.
607  bool isOSEmscripten() const {
608  return getOS() == Triple::Emscripten;
609  }
610 
611  /// Tests whether the OS uses glibc.
612  bool isOSGlibc() const {
613  return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD ||
614  getOS() == Triple::Hurd) &&
615  !isAndroid();
616  }
617 
618  /// Tests whether the OS is AIX.
619  bool isOSAIX() const {
620  return getOS() == Triple::AIX;
621  }
622 
623  /// Tests whether the OS uses the ELF binary format.
624  bool isOSBinFormatELF() const {
625  return getObjectFormat() == Triple::ELF;
626  }
627 
628  /// Tests whether the OS uses the COFF binary format.
629  bool isOSBinFormatCOFF() const {
630  return getObjectFormat() == Triple::COFF;
631  }
632 
633  /// Tests whether the environment is MachO.
634  bool isOSBinFormatMachO() const {
635  return getObjectFormat() == Triple::MachO;
636  }
637 
638  /// Tests whether the OS uses the Wasm binary format.
639  bool isOSBinFormatWasm() const {
640  return getObjectFormat() == Triple::Wasm;
641  }
642 
643  /// Tests whether the OS uses the XCOFF binary format.
644  bool isOSBinFormatXCOFF() const {
645  return getObjectFormat() == Triple::XCOFF;
646  }
647 
648  /// Tests whether the target is the PS4 CPU
649  bool isPS4CPU() const {
650  return getArch() == Triple::x86_64 &&
651  getVendor() == Triple::SCEI &&
652  getOS() == Triple::PS4;
653  }
654 
655  /// Tests whether the target is the PS4 platform
656  bool isPS4() const {
657  return getVendor() == Triple::SCEI &&
658  getOS() == Triple::PS4;
659  }
660 
661  /// Tests whether the target is Android
662  bool isAndroid() const { return getEnvironment() == Triple::Android; }
663 
664  bool isAndroidVersionLT(unsigned Major) const {
665  assert(isAndroid() && "Not an Android triple!");
666 
667  unsigned Env[3];
668  getEnvironmentVersion(Env[0], Env[1], Env[2]);
669 
670  // 64-bit targets did not exist before API level 21 (Lollipop).
671  if (isArch64Bit() && Env[0] < 21)
672  Env[0] = 21;
673 
674  return Env[0] < Major;
675  }
676 
677  /// Tests whether the environment is musl-libc
678  bool isMusl() const {
679  return getEnvironment() == Triple::Musl ||
682  }
683 
684  /// Tests whether the target is SPIR (32- or 64-bit).
685  bool isSPIR() const {
686  return getArch() == Triple::spir || getArch() == Triple::spir64;
687  }
688 
689  /// Tests whether the target is NVPTX (32- or 64-bit).
690  bool isNVPTX() const {
691  return getArch() == Triple::nvptx || getArch() == Triple::nvptx64;
692  }
693 
694  /// Tests whether the target is Thumb (little and big endian).
695  bool isThumb() const {
696  return getArch() == Triple::thumb || getArch() == Triple::thumbeb;
697  }
698 
699  /// Tests whether the target is ARM (little and big endian).
700  bool isARM() const {
701  return getArch() == Triple::arm || getArch() == Triple::armeb;
702  }
703 
704  /// Tests whether the target is AArch64 (little and big endian).
705  bool isAArch64() const {
707  }
708 
709  /// Tests whether the target is MIPS 32-bit (little and big endian).
710  bool isMIPS32() const {
711  return getArch() == Triple::mips || getArch() == Triple::mipsel;
712  }
713 
714  /// Tests whether the target is MIPS 64-bit (little and big endian).
715  bool isMIPS64() const {
716  return getArch() == Triple::mips64 || getArch() == Triple::mips64el;
717  }
718 
719  /// Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
720  bool isMIPS() const {
721  return isMIPS32() || isMIPS64();
722  }
723 
724  /// Tests whether the target is 64-bit PowerPC (little and big endian).
725  bool isPPC64() const {
726  return getArch() == Triple::ppc64 || getArch() == Triple::ppc64le;
727  }
728 
729  /// Tests whether the target is RISC-V (32- and 64-bit).
730  bool isRISCV() const {
731  return getArch() == Triple::riscv32 || getArch() == Triple::riscv64;
732  }
733 
734  /// Tests whether the target is x86 (32- or 64-bit).
735  bool isX86() const {
736  return getArch() == Triple::x86 || getArch() == Triple::x86_64;
737  }
738 
739  /// Tests whether the target is VE
740  bool isVE() const {
741  return getArch() == Triple::ve;
742  }
743 
744  /// Tests whether the target supports comdat
745  bool supportsCOMDAT() const {
746  return !isOSBinFormatMachO();
747  }
748 
749  /// Tests whether the target uses emulated TLS as default.
750  bool hasDefaultEmulatedTLS() const {
752  }
753 
754  /// @}
755  /// @name Mutators
756  /// @{
757 
758  /// setArch - Set the architecture (first) component of the triple
759  /// to a known type.
760  void setArch(ArchType Kind);
761 
762  /// setVendor - Set the vendor (second) component of the triple to a
763  /// known type.
764  void setVendor(VendorType Kind);
765 
766  /// setOS - Set the operating system (third) component of the triple
767  /// to a known type.
768  void setOS(OSType Kind);
769 
770  /// setEnvironment - Set the environment (fourth) component of the triple
771  /// to a known type.
772  void setEnvironment(EnvironmentType Kind);
773 
774  /// setObjectFormat - Set the object file format
776 
777  /// setTriple - Set all components to the new triple \p Str.
778  void setTriple(const Twine &Str);
779 
780  /// setArchName - Set the architecture (first) component of the
781  /// triple by name.
782  void setArchName(StringRef Str);
783 
784  /// setVendorName - Set the vendor (second) component of the triple
785  /// by name.
786  void setVendorName(StringRef Str);
787 
788  /// setOSName - Set the operating system (third) component of the
789  /// triple by name.
790  void setOSName(StringRef Str);
791 
792  /// setEnvironmentName - Set the optional environment (fourth)
793  /// component of the triple by name.
794  void setEnvironmentName(StringRef Str);
795 
796  /// setOSAndEnvironmentName - Set the operating system and optional
797  /// environment components with a single string.
799 
800  /// @}
801  /// @name Helpers to build variants of a particular triple.
802  /// @{
803 
804  /// Form a triple with a 32-bit variant of the current architecture.
805  ///
806  /// This can be used to move across "families" of architectures where useful.
807  ///
808  /// \returns A new triple with a 32-bit architecture or an unknown
809  /// architecture if no such variant can be found.
811 
812  /// Form a triple with a 64-bit variant of the current architecture.
813  ///
814  /// This can be used to move across "families" of architectures where useful.
815  ///
816  /// \returns A new triple with a 64-bit architecture or an unknown
817  /// architecture if no such variant can be found.
819 
820  /// Form a triple with a big endian variant of the current architecture.
821  ///
822  /// This can be used to move across "families" of architectures where useful.
823  ///
824  /// \returns A new triple with a big endian architecture or an unknown
825  /// architecture if no such variant can be found.
827 
828  /// Form a triple with a little endian variant of the current architecture.
829  ///
830  /// This can be used to move across "families" of architectures where useful.
831  ///
832  /// \returns A new triple with a little endian architecture or an unknown
833  /// architecture if no such variant can be found.
835 
836  /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
837  ///
838  /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
839  /// string then the triple's arch name is used.
841 
842  /// Tests whether the target triple is little endian.
843  ///
844  /// \returns true if the triple is little endian, false otherwise.
845  bool isLittleEndian() const;
846 
847  /// Test whether target triples are compatible.
848  bool isCompatibleWith(const Triple &Other) const;
849 
850  /// Merge target triples.
851  std::string merge(const Triple &Other) const;
852 
853  /// @}
854  /// @name Static helpers for IDs.
855  /// @{
856 
857  /// getArchTypeName - Get the canonical name for the \p Kind architecture.
858  static StringRef getArchTypeName(ArchType Kind);
859 
860  /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
861  /// architecture. This is the prefix used by the architecture specific
862  /// builtins, and is suitable for passing to \see
863  /// Intrinsic::getIntrinsicForGCCBuiltin().
864  ///
865  /// \return - The architecture prefix, or 0 if none is defined.
866  static StringRef getArchTypePrefix(ArchType Kind);
867 
868  /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
870 
871  /// getOSTypeName - Get the canonical name for the \p Kind operating system.
872  static StringRef getOSTypeName(OSType Kind);
873 
874  /// getEnvironmentTypeName - Get the canonical name for the \p Kind
875  /// environment.
877 
878  /// @}
879  /// @name Static helpers for converting alternate architecture names.
880  /// @{
881 
882  /// getArchTypeForLLVMName - The canonical type for the given LLVM
883  /// architecture name (e.g., "x86").
885 
886  /// @}
887 };
888 
889 } // End llvm namespace
890 
891 
892 #endif
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
Definition: Triple.h:482
bool isOSHaiku() const
Tests whether the OS is Haiku.
Definition: Triple.h:534
bool isOSEmscripten() const
Tests whether the OS is Emscripten.
Definition: Triple.h:607
void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getiOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1119
bool isMIPS64() const
Tests whether the target is MIPS 64-bit (little and big endian).
Definition: Triple.h:715
bool isOSMSVCRT() const
Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
Definition: Triple.h:576
bool supportsCOMDAT() const
Tests whether the target supports comdat.
Definition: Triple.h:745
static StringRef getVendorTypeName(VendorType Kind)
getVendorTypeName - Get the canonical name for the Kind vendor.
Definition: Triple.cpp:153
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:454
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:624
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:306
void setVendor(VendorType Kind)
setVendor - Set the vendor (second) component of the triple to a known type.
Definition: Triple.cpp:1177
bool isX86() const
Tests whether the target is x86 (32- or 64-bit).
Definition: Triple.h:735
bool isArch16Bit() const
Test whether the architecture is 16-bit.
Definition: Triple.cpp:1306
bool isOSNaCl() const
Tests whether the OS is NaCl (Native Client)
Definition: Triple.h:582
bool isWatchOS() const
Is this an Apple watchOS triple.
Definition: Triple.h:473
bool isVE() const
Tests whether the target is VE.
Definition: Triple.h:740
bool hasEnvironment() const
hasEnvironment - Does this triple have the optional environment (fourth) component?
Definition: Triple.h:310
void setOS(OSType Kind)
setOS - Set the operating system (third) component of the triple to a known type. ...
Definition: Triple.cpp:1181
bool isOSFuchsia() const
Definition: Triple.h:506
void setEnvironment(EnvironmentType Kind)
setEnvironment - Set the environment (fourth) component of the triple to a known type.
Definition: Triple.cpp:1185
void getEnvironmentVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
Parse the version number from the OS name component of the triple, if present.
Definition: Triple.cpp:1055
bool isWindowsCygwinEnvironment() const
Definition: Triple.h:562
StringRef getARMCPUForArch(StringRef Arch=StringRef()) const
Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
Definition: Triple.cpp:1605
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
bool isAArch64() const
Tests whether the target is AArch64 (little and big endian).
Definition: Triple.h:705
static StringRef getArchTypeName(ArchType Kind)
getArchTypeName - Get the canonical name for the Kind architecture.
Definition: Triple.cpp:19
bool isKnownWindowsMSVCEnvironment() const
Checks if the environment is MSVC.
Definition: Triple.h:544
bool isMacCatalystEnvironment() const
Definition: Triple.h:490
bool isOSHurd() const
Tests whether the OS is Hurd.
Definition: Triple.h:597
bool hasDefaultEmulatedTLS() const
Tests whether the target uses emulated TLS as default.
Definition: Triple.h:750
void setVendorName(StringRef Str)
setVendorName - Set the vendor (second) component of the triple by name.
Definition: Triple.cpp:1212
bool isOSSolaris() const
Definition: Triple.h:512
Triple()
Default constructor is the same as an empty string and leaves all triple fields unknown.
Definition: Triple.h:259
SubArchType getSubArch() const
getSubArch - get the parsed subarchitecture type for this triple.
Definition: Triple.h:300
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:297
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition: Triple.cpp:1302
bool isiOS() const
Is this an iOS triple.
Definition: Triple.h:463
bool isPS4() const
Tests whether the target is the PS4 platform.
Definition: Triple.h:656
bool isOSWASI() const
Tests whether the OS is WASI.
Definition: Triple.h:602
bool isOSNetBSD() const
Definition: Triple.h:494
bool isWindowsItaniumEnvironment() const
Definition: Triple.h:558
bool isWindowsGNUEnvironment() const
Definition: Triple.h:566
static StringRef getOSTypeName(OSType Kind)
getOSTypeName - Get the canonical name for the Kind operating system.
Definition: Triple.cpp:178
bool isWindowsCoreCLREnvironment() const
Definition: Triple.h:554
const std::string & str() const
Definition: Triple.h:366
bool isOSDragonFly() const
Definition: Triple.h:510
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:539
void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getOSVersion - Parse the version number from the OS name component of the triple, if present...
Definition: Triple.cpp:1065
bool isMusl() const
Tests whether the environment is musl-libc.
Definition: Triple.h:678
void setObjectFormat(ObjectFormatType Kind)
setObjectFormat - Set the object file format
Definition: Triple.cpp:1193
StringRef getOSAndEnvironmentName() const
getOSAndEnvironmentName - Get the operating system and optional environment components as a single st...
Definition: Triple.cpp:1015
llvm::Triple get32BitArchVariant() const
Form a triple with a 32-bit variant of the current architecture.
Definition: Triple.cpp:1310
bool isLittleEndian() const
Tests whether the target triple is little endian.
Definition: Triple.cpp:1527
VendorType getVendor() const
getVendor - Get the parsed vendor type of this triple.
Definition: Triple.h:303
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:629
void setEnvironmentName(StringRef Str)
setEnvironmentName - Set the optional environment (fourth) component of the triple by name...
Definition: Triple.cpp:1224
bool isOSOpenBSD() const
Definition: Triple.h:498
llvm::Triple getBigEndianArchVariant() const
Form a triple with a big endian variant of the current architecture.
Definition: Triple.cpp:1440
bool isWatchABI() const
Definition: Triple.h:477
void setTriple(const Twine &Str)
setTriple - Set all components to the new triple Str.
Definition: Triple.cpp:1169
bool operator==(const Triple &Other) const
Definition: Triple.h:268
bool isCompatibleWith(const Triple &Other) const
Test whether target triples are compatible.
Definition: Triple.cpp:1572
static StringRef getArchTypePrefix(ArchType Kind)
getArchTypePrefix - Get the "prefix" canonical name for the Kind architecture.
Definition: Triple.cpp:79
bool operator!=(const Triple &Other) const
Definition: Triple.h:275
bool isAndroidVersionLT(unsigned Major) const
Definition: Triple.h:664
bool isPS4CPU() const
Tests whether the target is the PS4 CPU.
Definition: Triple.h:649
void getWatchOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getWatchOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1145
bool isOSKFreeBSD() const
Tests whether the OS is kFreeBSD.
Definition: Triple.h:592
void setArchName(StringRef Str)
setArchName - Set the architecture (first) component of the triple by name.
Definition: Triple.cpp:1201
bool isPPC64() const
Tests whether the target is 64-bit PowerPC (little and big endian).
Definition: Triple.h:725
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:634
void setOSName(StringRef Str)
setOSName - Set the operating system (third) component of the triple by name.
Definition: Triple.cpp:1216
unsigned getOSMajorVersion() const
getOSMajorVersion - Return just the major version number, this is specialized because it is a common ...
Definition: Triple.h:339
bool isOSUnknown() const
Definition: Triple.h:520
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
bool isOSAIX() const
Tests whether the OS is AIX.
Definition: Triple.h:619
bool isOSIAMCU() const
Definition: Triple.h:516
StringRef getArchName() const
getArchName - Get the architecture (first) component of the triple.
Definition: Triple.cpp:994
bool getMacOSXVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getMacOSXVersion - Parse the version number as with getOSVersion and then translate generic "darwin" ...
Definition: Triple.cpp:1078
bool isOSContiki() const
Definition: Triple.h:529
static ArchType getArchTypeForLLVMName(StringRef Str)
getArchTypeForLLVMName - The canonical type for the given LLVM architecture name (e.g., "x86").
Definition: Triple.cpp:264
StringRef getOSName() const
getOSName - Get the operating system (third) component of the triple.
Definition: Triple.cpp:1003
bool isOSLinux() const
Tests whether the OS is Linux.
Definition: Triple.h:587
EnvironmentType getEnvironment() const
getEnvironment - Get the parsed environment type of this triple.
Definition: Triple.h:315
std::string merge(const Triple &Other) const
Merge target triples.
Definition: Triple.cpp:1596
bool isOSVersionLT(const Triple &Other) const
Definition: Triple.h:430
bool isOSFreeBSD() const
Definition: Triple.h:502
std::string normalize() const
Return the normalized form of this triple&#39;s string.
Definition: Triple.h:290
StringRef getEnvironmentName() const
getEnvironmentName - Get the optional environment (fourth) component of the triple, or "" if empty.
Definition: Triple.cpp:1009
bool isMIPS() const
Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
Definition: Triple.h:720
bool isOSBinFormatXCOFF() const
Tests whether the OS uses the XCOFF binary format.
Definition: Triple.h:644
bool isOSCygMing() const
Tests for either Cygwin or MinGW OS.
Definition: Triple.h:571
const std::string & getTriple() const
Definition: Triple.h:368
bool isMIPS32() const
Tests whether the target is MIPS 32-bit (little and big endian).
Definition: Triple.h:710
bool isOSGlibc() const
Tests whether the OS uses glibc.
Definition: Triple.h:612
llvm::Triple getLittleEndianArchVariant() const
Form a triple with a little endian variant of the current architecture.
Definition: Triple.cpp:1495
bool isThumb() const
Tests whether the target is Thumb (little and big endian).
Definition: Triple.h:695
ObjectFormatType getObjectFormat() const
getFormat - Get the object format for this triple.
Definition: Triple.h:327
void setOSAndEnvironmentName(StringRef Str)
setOSAndEnvironmentName - Set the operating system and optional environment components with a single ...
Definition: Triple.cpp:1229
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1298
bool isGNUEnvironment() const
Definition: Triple.h:522
bool isRISCV() const
Tests whether the target is RISC-V (32- and 64-bit).
Definition: Triple.h:730
bool isMacOSXVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
isMacOSXVersionLT - Comparison function for checking OS X version compatibility, which handles suppor...
Definition: Triple.h:439
StringRef getVendorName() const
getVendorName - Get the vendor (second) component of the triple.
Definition: Triple.cpp:998
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSimulatorEnvironment() const
Definition: Triple.h:486
ObjectFormatType
Definition: Triple.h:222
bool isTvOS() const
Is this an Apple tvOS triple.
Definition: Triple.h:468
bool isAndroid() const
Tests whether the target is Android.
Definition: Triple.h:662
llvm::Triple get64BitArchVariant() const
Form a triple with a 64-bit variant of the current architecture.
Definition: Triple.cpp:1375
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
Definition: Triple.h:690
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
bool isOSVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
isOSVersionLT - Helper function for doing comparisons against version numbers included in the target ...
Definition: Triple.h:415
bool isOSBinFormatWasm() const
Tests whether the OS uses the Wasm binary format.
Definition: Triple.h:639
bool isWindowsMSVCEnvironment() const
Checks if the environment could be MSVC.
Definition: Triple.h:549
bool isSPIR() const
Tests whether the target is SPIR (32- or 64-bit).
Definition: Triple.h:685
bool isARM() const
Tests whether the target is ARM (little and big endian).
Definition: Triple.h:700
void setArch(ArchType Kind)
setArch - Set the architecture (first) component of the triple to a known type.
Definition: Triple.cpp:1173
static StringRef getEnvironmentTypeName(EnvironmentType Kind)
getEnvironmentTypeName - Get the canonical name for the Kind environment.
Definition: Triple.cpp:222