Coverage Report

Created: 2020-06-26 05:44

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