Coverage Report

Created: 2018-09-19 20:53

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/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
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLVM_ADT_TRIPLE_H
11
#define LLVM_ADT_TRIPLE_H
12
13
#include "llvm/ADT/Twine.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
21
namespace 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.
44
0
class Triple {
45
public:
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
    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
59
    mipsel,         // MIPSEL: mipsel, mipsallegrexe
60
    mips64,         // MIPS64: mips64, mipsn32
61
    mips64el,       // MIPS64EL: mips64el, mipsn32el
62
    msp430,         // MSP430: msp430
63
    nios2,          // NIOSII: nios2
64
    ppc,            // PPC: powerpc
65
    ppc64,          // PPC64: powerpc64, ppu
66
    ppc64le,        // PPC64LE: powerpc64le
67
    r600,           // R600: AMD GPUs HD2XXX - HD6XXX
68
    amdgcn,         // AMDGCN: AMD GCN GPUs
69
    riscv32,        // RISC-V (32-bit): riscv32
70
    riscv64,        // RISC-V (64-bit): riscv64
71
    sparc,          // Sparc: sparc
72
    sparcv9,        // Sparcv9: Sparcv9
73
    sparcel,        // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant
74
    systemz,        // SystemZ: s390x
75
    tce,            // TCE (http://tce.cs.tut.fi/): tce
76
    tcele,          // TCE little endian (http://tce.cs.tut.fi/): tcele
77
    thumb,          // Thumb (little endian): thumb, thumbv.*
78
    thumbeb,        // Thumb (big endian): thumbeb
79
    x86,            // X86: i[3-9]86
80
    x86_64,         // X86-64: amd64, x86_64
81
    xcore,          // XCore: xcore
82
    nvptx,          // NVPTX: 32-bit
83
    nvptx64,        // NVPTX: 64-bit
84
    le32,           // le32: generic little-endian 32-bit CPU (PNaCl)
85
    le64,           // le64: generic little-endian 64-bit CPU (PNaCl)
86
    amdil,          // AMDIL
87
    amdil64,        // AMDIL with 64-bit pointers
88
    hsail,          // AMD HSAIL
89
    hsail64,        // AMD HSAIL with 64-bit pointers
90
    spir,           // SPIR: standard portable IR for OpenCL 32-bit version
91
    spir64,         // SPIR: standard portable IR for OpenCL 64-bit version
92
    kalimba,        // Kalimba: generic kalimba
93
    shave,          // SHAVE: Movidius vector VLIW processors
94
    lanai,          // Lanai: Lanai 32-bit
95
    wasm32,         // WebAssembly with 32-bit pointers
96
    wasm64,         // WebAssembly with 64-bit pointers
97
    renderscript32, // 32-bit RenderScript
98
    renderscript64, // 64-bit RenderScript
99
    LastArchType = renderscript64
100
  };
101
  enum SubArchType {
102
    NoSubArch,
103
104
    ARMSubArch_v8_4a,
105
    ARMSubArch_v8_3a,
106
    ARMSubArch_v8_2a,
107
    ARMSubArch_v8_1a,
108
    ARMSubArch_v8,
109
    ARMSubArch_v8r,
110
    ARMSubArch_v8m_baseline,
111
    ARMSubArch_v8m_mainline,
112
    ARMSubArch_v7,
113
    ARMSubArch_v7em,
114
    ARMSubArch_v7m,
115
    ARMSubArch_v7s,
116
    ARMSubArch_v7k,
117
    ARMSubArch_v7ve,
118
    ARMSubArch_v6,
119
    ARMSubArch_v6m,
120
    ARMSubArch_v6k,
121
    ARMSubArch_v6t2,
122
    ARMSubArch_v5,
123
    ARMSubArch_v5te,
124
    ARMSubArch_v4t,
125
126
    KalimbaSubArch_v3,
127
    KalimbaSubArch_v4,
128
    KalimbaSubArch_v5
129
  };
130
  enum VendorType {
131
    UnknownVendor,
132
133
    Apple,
134
    PC,
135
    SCEI,
136
    BGP,
137
    BGQ,
138
    Freescale,
139
    IBM,
140
    ImaginationTechnologies,
141
    MipsTechnologies,
142
    NVIDIA,
143
    CSR,
144
    Myriad,
145
    AMD,
146
    Mesa,
147
    SUSE,
148
    OpenEmbedded,
149
    LastVendorType = OpenEmbedded
150
  };
151
  enum OSType {
152
    UnknownOS,
153
154
    Ananas,
155
    CloudABI,
156
    Darwin,
157
    DragonFly,
158
    FreeBSD,
159
    Fuchsia,
160
    IOS,
161
    KFreeBSD,
162
    Linux,
163
    Lv2,        // PS3
164
    MacOSX,
165
    NetBSD,
166
    OpenBSD,
167
    Solaris,
168
    Win32,
169
    Haiku,
170
    Minix,
171
    RTEMS,
172
    NaCl,       // Native Client
173
    CNK,        // BG/P Compute-Node Kernel
174
    AIX,
175
    CUDA,       // NVIDIA CUDA
176
    NVCL,       // NVIDIA OpenCL
177
    AMDHSA,     // AMD HSA Runtime
178
    PS4,
179
    ELFIAMCU,
180
    TvOS,       // Apple tvOS
181
    WatchOS,    // Apple watchOS
182
    Mesa3D,
183
    Contiki,
184
    AMDPAL,     // AMD PAL Runtime
185
    HermitCore, // HermitCore Unikernel/Multikernel
186
    LastOSType = HermitCore
187
  };
188
  enum EnvironmentType {
189
    UnknownEnvironment,
190
191
    GNU,
192
    GNUABIN32,
193
    GNUABI64,
194
    GNUEABI,
195
    GNUEABIHF,
196
    GNUX32,
197
    CODE16,
198
    EABI,
199
    EABIHF,
200
    Android,
201
    Musl,
202
    MuslEABI,
203
    MuslEABIHF,
204
205
    MSVC,
206
    Itanium,
207
    Cygnus,
208
    CoreCLR,
209
    Simulator,  // Simulator variants of other systems, e.g., Apple's iOS
210
    LastEnvironmentType = Simulator
211
  };
212
  enum ObjectFormatType {
213
    UnknownObjectFormat,
214
215
    COFF,
216
    ELF,
217
    MachO,
218
    Wasm,
219
  };
220
221
private:
222
  std::string Data;
223
224
  /// The parsed arch type.
225
  ArchType Arch;
226
227
  /// The parsed subarchitecture type.
228
  SubArchType SubArch;
229
230
  /// The parsed vendor type.
231
  VendorType Vendor;
232
233
  /// The parsed OS type.
234
  OSType OS;
235
236
  /// The parsed Environment type.
237
  EnvironmentType Environment;
238
239
  /// The object format type.
240
  ObjectFormatType ObjectFormat;
241
242
public:
243
  /// @name Constructors
244
  /// @{
245
246
  /// Default constructor is the same as an empty string and leaves all
247
  /// triple fields unknown.
248
  Triple()
249
      : Data(), Arch(), SubArch(), Vendor(), OS(), Environment(),
250
109k
        ObjectFormat() {}
251
252
  explicit Triple(const Twine &Str);
253
  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
254
  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
255
         const Twine &EnvironmentStr);
256
257
1.05k
  bool operator==(const Triple &Other) const {
258
1.05k
    return Arch == Other.Arch && SubArch == Other.SubArch &&
259
1.05k
           Vendor == Other.Vendor && OS == Other.OS &&
260
1.05k
           Environment == Other.Environment &&
261
1.05k
           ObjectFormat == Other.ObjectFormat;
262
1.05k
  }
263
264
824
  bool operator!=(const Triple &Other) const {
265
824
    return !(*this == Other);
266
824
  }
267
268
  /// @}
269
  /// @name Normalization
270
  /// @{
271
272
  /// normalize - Turn an arbitrary machine specification into the canonical
273
  /// triple form (or something sensible that the Triple class understands if
274
  /// nothing better can reasonably be done).  In particular, it handles the
275
  /// common case in which otherwise valid components are in the wrong order.
276
  static std::string normalize(StringRef Str);
277
278
  /// Return the normalized form of this triple's string.
279
77.9k
  std::string normalize() const { return normalize(Data); }
280
281
  /// @}
282
  /// @name Typed Component Access
283
  /// @{
284
285
  /// getArch - Get the parsed architecture type of this triple.
286
6.09M
  ArchType getArch() const { return Arch; }
287
288
  /// getSubArch - get the parsed subarchitecture type for this triple.
289
55.7k
  SubArchType getSubArch() const { return SubArch; }
290
291
  /// getVendor - Get the parsed vendor type of this triple.
292
59.7k
  VendorType getVendor() const { return Vendor; }
293
294
  /// getOS - Get the parsed operating system type of this triple.
295
68.4M
  OSType getOS() const { return OS; }
296
297
  /// hasEnvironment - Does this triple have the optional environment
298
  /// (fourth) component?
299
17.2k
  bool hasEnvironment() const {
300
17.2k
    return getEnvironmentName() != "";
301
17.2k
  }
302
303
  /// getEnvironment - Get the parsed environment type of this triple.
304
7.33M
  EnvironmentType getEnvironment() const { return Environment; }
305
306
  /// Parse the version number from the OS name component of the
307
  /// triple, if present.
308
  ///
309
  /// For example, "fooos1.2.3" would return (1, 2, 3).
310
  ///
311
  /// If an entry is not defined, it will be returned as 0.
312
  void getEnvironmentVersion(unsigned &Major, unsigned &Minor,
313
                             unsigned &Micro) const;
314
315
  /// getFormat - Get the object format for this triple.
316
9.76M
  ObjectFormatType getObjectFormat() const { return ObjectFormat; }
317
318
  /// getOSVersion - 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 getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
325
326
  /// getOSMajorVersion - Return just the major version number, this is
327
  /// specialized because it is a common query.
328
12.2k
  unsigned getOSMajorVersion() const {
329
12.2k
    unsigned Maj, Min, Micro;
330
12.2k
    getOSVersion(Maj, Min, Micro);
331
12.2k
    return Maj;
332
12.2k
  }
333
334
  /// getMacOSXVersion - Parse the version number as with getOSVersion and then
335
  /// translate generic "darwin" versions to the corresponding OS X versions.
336
  /// This may also be called with IOS triples but the OS X version number is
337
  /// just set to a constant 10.4.0 in that case.  Returns true if successful.
338
  bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
339
                        unsigned &Micro) const;
340
341
  /// getiOSVersion - Parse the version number as with getOSVersion.  This should
342
  /// only be called with IOS or generic triples.
343
  void getiOSVersion(unsigned &Major, unsigned &Minor,
344
                     unsigned &Micro) const;
345
346
  /// getWatchOSVersion - Parse the version number as with getOSVersion.  This
347
  /// should only be called with WatchOS or generic triples.
348
  void getWatchOSVersion(unsigned &Major, unsigned &Minor,
349
                         unsigned &Micro) const;
350
351
  /// @}
352
  /// @name Direct Component Access
353
  /// @{
354
355
126k
  const std::string &str() const { return Data; }
356
357
62.8k
  const std::string &getTriple() const { return Data; }
358
359
  /// getArchName - Get the architecture (first) component of the
360
  /// triple.
361
  StringRef getArchName() const;
362
363
  /// getVendorName - Get the vendor (second) component of the triple.
364
  StringRef getVendorName() const;
365
366
  /// getOSName - Get the operating system (third) component of the
367
  /// triple.
368
  StringRef getOSName() const;
369
370
  /// getEnvironmentName - Get the optional environment (fourth)
371
  /// component of the triple, or "" if empty.
372
  StringRef getEnvironmentName() const;
373
374
  /// getOSAndEnvironmentName - Get the operating system and optional
375
  /// environment components as a single string (separated by a '-'
376
  /// if the environment component is present).
377
  StringRef getOSAndEnvironmentName() const;
378
379
  /// @}
380
  /// @name Convenience Predicates
381
  /// @{
382
383
  /// Test whether the architecture is 64-bit
384
  ///
385
  /// Note that this tests for 64-bit pointer width, and nothing else. Note
386
  /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
387
  /// 16-bit. The inner details of pointer width for particular architectures
388
  /// is not summed up in the triple, and so only a coarse grained predicate
389
  /// system is provided.
390
  bool isArch64Bit() const;
391
392
  /// Test whether the architecture is 32-bit
393
  ///
394
  /// Note that this tests for 32-bit pointer width, and nothing else.
395
  bool isArch32Bit() const;
396
397
  /// Test whether the architecture is 16-bit
398
  ///
399
  /// Note that this tests for 16-bit pointer width, and nothing else.
400
  bool isArch16Bit() const;
401
402
  /// isOSVersionLT - Helper function for doing comparisons against version
403
  /// numbers included in the target triple.
404
  bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
405
163k
                     unsigned Micro = 0) const {
406
163k
    unsigned LHS[3];
407
163k
    getOSVersion(LHS[0], LHS[1], LHS[2]);
408
163k
409
163k
    if (LHS[0] != Major)
410
132k
      return LHS[0] < Major;
411
31.0k
    if (LHS[1] != Minor)
412
22.6k
      return LHS[1] < Minor;
413
8.41k
    if (LHS[2] != Micro)
414
0
      return LHS[1] < Micro;
415
8.41k
416
8.41k
    return false;
417
8.41k
  }
418
419
0
  bool isOSVersionLT(const Triple &Other) const {
420
0
    unsigned RHS[3];
421
0
    Other.getOSVersion(RHS[0], RHS[1], RHS[2]);
422
0
    return isOSVersionLT(RHS[0], RHS[1], RHS[2]);
423
0
  }
424
425
  /// isMacOSXVersionLT - Comparison function for checking OS X version
426
  /// compatibility, which handles supporting skewed version numbering schemes
427
  /// used by the "darwin" triples.
428
  bool isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
429
28.0k
                         unsigned Micro = 0) const {
430
28.0k
    assert(isMacOSX() && "Not an OS X triple!");
431
28.0k
432
28.0k
    // If this is OS X, expect a sane version number.
433
28.0k
    if (getOS() == Triple::MacOSX)
434
27.1k
      return isOSVersionLT(Major, Minor, Micro);
435
956
436
956
    // Otherwise, compare to the "Darwin" number.
437
956
    assert(Major == 10 && "Unexpected major version");
438
956
    return isOSVersionLT(Minor + 4, Micro, 0);
439
956
  }
440
441
  /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
442
  /// "darwin" and "osx" as OS X triples.
443
11.2M
  bool isMacOSX() const {
444
11.2M
    return getOS() == Triple::Darwin || 
getOS() == Triple::MacOSX11.0M
;
445
11.2M
  }
446
447
  /// Is this an iOS triple.
448
  /// Note: This identifies tvOS as a variant of iOS. If that ever
449
  /// changes, i.e., if the two operating systems diverge or their version
450
  /// numbers get out of sync, that will need to be changed.
451
  /// watchOS has completely different version numbers so it is not included.
452
10.7M
  bool isiOS() const {
453
10.7M
    return getOS() == Triple::IOS || 
isTvOS()534k
;
454
10.7M
  }
455
456
  /// Is this an Apple tvOS triple.
457
1.18M
  bool isTvOS() const {
458
1.18M
    return getOS() == Triple::TvOS;
459
1.18M
  }
460
461
  /// Is this an Apple watchOS triple.
462
1.19M
  bool isWatchOS() const {
463
1.19M
    return getOS() == Triple::WatchOS;
464
1.19M
  }
465
466
53.8k
  bool isWatchABI() const {
467
53.8k
    return getSubArch() == Triple::ARMSubArch_v7k;
468
53.8k
  }
469
470
  /// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
471
11.0M
  bool isOSDarwin() const {
472
11.0M
    return isMacOSX() || 
isiOS()10.6M
||
isWatchOS()494k
;
473
11.0M
  }
474
475
9.90k
  bool isSimulatorEnvironment() const {
476
9.90k
    return getEnvironment() == Triple::Simulator;
477
9.90k
  }
478
479
927
  bool isOSNetBSD() const {
480
927
    return getOS() == Triple::NetBSD;
481
927
  }
482
483
458k
  bool isOSOpenBSD() const {
484
458k
    return getOS() == Triple::OpenBSD;
485
458k
  }
486
487
51.4k
  bool isOSFreeBSD() const {
488
51.4k
    return getOS() == Triple::FreeBSD;
489
51.4k
  }
490
491
45.2k
  bool isOSFuchsia() const {
492
45.2k
    return getOS() == Triple::Fuchsia;
493
45.2k
  }
494
495
0
  bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
496
497
2.56k
  bool isOSSolaris() const {
498
2.56k
    return getOS() == Triple::Solaris;
499
2.56k
  }
500
501
305k
  bool isOSIAMCU() const {
502
305k
    return getOS() == Triple::ELFIAMCU;
503
305k
  }
504
505
0
  bool isOSUnknown() const { return getOS() == Triple::UnknownOS; }
506
507
598k
  bool isGNUEnvironment() const {
508
598k
    EnvironmentType Env = getEnvironment();
509
598k
    return Env == Triple::GNU || 
Env == Triple::GNUABIN32598k
||
510
598k
           
Env == Triple::GNUABI64598k
||
Env == Triple::GNUEABI598k
||
511
598k
           
Env == Triple::GNUEABIHF598k
||
Env == Triple::GNUX32598k
;
512
598k
  }
513
514
0
  bool isOSContiki() const {
515
0
    return getOS() == Triple::Contiki;
516
0
  }
517
518
  /// Tests whether the OS is Haiku.
519
0
  bool isOSHaiku() const {
520
0
    return getOS() == Triple::Haiku;
521
0
  }
522
523
  /// Checks if the environment could be MSVC.
524
3.44M
  bool isWindowsMSVCEnvironment() const {
525
3.44M
    return getOS() == Triple::Win32 &&
526
3.44M
           
(170
getEnvironment() == Triple::UnknownEnvironment170
||
527
170
            getEnvironment() == Triple::MSVC);
528
3.44M
  }
529
530
  /// Checks if the environment is MSVC.
531
19.6k
  bool isKnownWindowsMSVCEnvironment() const {
532
19.6k
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::MSVC200
;
533
19.6k
  }
534
535
18
  bool isWindowsCoreCLREnvironment() const {
536
18
    return getOS() == Triple::Win32 && getEnvironment() == Triple::CoreCLR;
537
18
  }
538
539
3.31M
  bool isWindowsItaniumEnvironment() const {
540
3.31M
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::Itanium0
;
541
3.31M
  }
542
543
477k
  bool isWindowsCygwinEnvironment() const {
544
477k
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::Cygnus423
;
545
477k
  }
546
547
8.32M
  bool isWindowsGNUEnvironment() const {
548
8.32M
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::GNU494
;
549
8.32M
  }
550
551
  /// Tests for either Cygwin or MinGW OS
552
19.8k
  bool isOSCygMing() const {
553
19.8k
    return isWindowsCygwinEnvironment() || isWindowsGNUEnvironment();
554
19.8k
  }
555
556
  /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
557
3.29M
  bool isOSMSVCRT() const {
558
3.29M
    return isWindowsMSVCEnvironment() || 
isWindowsGNUEnvironment()3.29M
||
559
3.29M
           
isWindowsItaniumEnvironment()3.29M
;
560
3.29M
  }
561
562
  /// Tests whether the OS is Windows.
563
12.9M
  bool isOSWindows() const {
564
12.9M
    return getOS() == Triple::Win32;
565
12.9M
  }
566
567
  /// Tests whether the OS is NaCl (Native Client)
568
998k
  bool isOSNaCl() const {
569
998k
    return getOS() == Triple::NaCl;
570
998k
  }
571
572
  /// Tests whether the OS is Linux.
573
144k
  bool isOSLinux() const {
574
144k
    return getOS() == Triple::Linux;
575
144k
  }
576
577
  /// Tests whether the OS is kFreeBSD.
578
77
  bool isOSKFreeBSD() const {
579
77
    return getOS() == Triple::KFreeBSD;
580
77
  }
581
582
  /// Tests whether the OS uses glibc.
583
164
  bool isOSGlibc() const {
584
164
    return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD) &&
585
164
           
!isAndroid()0
;
586
164
  }
587
588
  /// Tests whether the OS uses the ELF binary format.
589
1.60M
  bool isOSBinFormatELF() const {
590
1.60M
    return getObjectFormat() == Triple::ELF;
591
1.60M
  }
592
593
  /// Tests whether the OS uses the COFF binary format.
594
5.18M
  bool isOSBinFormatCOFF() const {
595
5.18M
    return getObjectFormat() == Triple::COFF;
596
5.18M
  }
597
598
  /// Tests whether the environment is MachO.
599
2.86M
  bool isOSBinFormatMachO() const {
600
2.86M
    return getObjectFormat() == Triple::MachO;
601
2.86M
  }
602
603
  /// Tests whether the OS uses the Wasm binary format.
604
0
  bool isOSBinFormatWasm() const {
605
0
    return getObjectFormat() == Triple::Wasm;
606
0
  }
607
608
  /// Tests whether the target is the PS4 CPU
609
46.4k
  bool isPS4CPU() const {
610
46.4k
    return getArch() == Triple::x86_64 &&
611
46.4k
           
getVendor() == Triple::SCEI9.79k
&&
612
46.4k
           
getOS() == Triple::PS439
;
613
46.4k
  }
614
615
  /// Tests whether the target is the PS4 platform
616
34.7k
  bool isPS4() const {
617
34.7k
    return getVendor() == Triple::SCEI &&
618
34.7k
           
getOS() == Triple::PS419
;
619
34.7k
  }
620
621
  /// Tests whether the target is Android
622
1.84M
  bool isAndroid() const { return getEnvironment() == Triple::Android; }
623
624
15
  bool isAndroidVersionLT(unsigned Major) const {
625
15
    assert(isAndroid() && "Not an Android triple!");
626
15
627
15
    unsigned Env[3];
628
15
    getEnvironmentVersion(Env[0], Env[1], Env[2]);
629
15
630
15
    // 64-bit targets did not exist before API level 21 (Lollipop).
631
15
    if (isArch64Bit() && 
Env[0] < 2111
)
632
11
      Env[0] = 21;
633
15
634
15
    return Env[0] < Major;
635
15
  }
636
637
  /// Tests whether the environment is musl-libc
638
0
  bool isMusl() const {
639
0
    return getEnvironment() == Triple::Musl ||
640
0
           getEnvironment() == Triple::MuslEABI ||
641
0
           getEnvironment() == Triple::MuslEABIHF;
642
0
  }
643
644
  /// Tests whether the target is NVPTX (32- or 64-bit).
645
275k
  bool isNVPTX() const {
646
275k
    return 
getArch() == Triple::nvptx275k
|| getArch() == Triple::nvptx64;
647
275k
  }
648
649
  /// Tests whether the target is Thumb (little and big endian).
650
8.78k
  bool isThumb() const {
651
8.78k
    return getArch() == Triple::thumb || 
getArch() == Triple::thumbeb1.29k
;
652
8.78k
  }
653
654
  /// Tests whether the target is ARM (little and big endian).
655
0
  bool isARM() const {
656
0
    return getArch() == Triple::arm || getArch() == Triple::armeb;
657
0
  }
658
659
  /// Tests whether the target is AArch64 (little and big endian).
660
0
  bool isAArch64() const {
661
0
    return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be;
662
0
  }
663
664
  /// Tests whether the target is MIPS 32-bit (little and big endian).
665
67.5k
  bool isMIPS32() const {
666
67.5k
    return getArch() == Triple::mips || 
getArch() == Triple::mipsel67.0k
;
667
67.5k
  }
668
669
  /// Tests whether the target is MIPS 64-bit (little and big endian).
670
67.3k
  bool isMIPS64() const {
671
67.3k
    return getArch() == Triple::mips64 || 
getArch() == Triple::mips64el67.1k
;
672
67.3k
  }
673
674
  /// Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
675
66.9k
  bool isMIPS() const {
676
66.9k
    return isMIPS32() || 
isMIPS64()66.7k
;
677
66.9k
  }
678
679
  /// Tests whether the target supports comdat
680
306k
  bool supportsCOMDAT() const {
681
306k
    return !isOSBinFormatMachO();
682
306k
  }
683
684
  /// Tests whether the target uses emulated TLS as default.
685
444k
  bool hasDefaultEmulatedTLS() const {
686
444k
    return 
isAndroid()444k
||
isOSOpenBSD()444k
|| isWindowsCygwinEnvironment();
687
444k
  }
688
689
  /// @}
690
  /// @name Mutators
691
  /// @{
692
693
  /// setArch - Set the architecture (first) component of the triple
694
  /// to a known type.
695
  void setArch(ArchType Kind);
696
697
  /// setVendor - Set the vendor (second) component of the triple to a
698
  /// known type.
699
  void setVendor(VendorType Kind);
700
701
  /// setOS - Set the operating system (third) component of the triple
702
  /// to a known type.
703
  void setOS(OSType Kind);
704
705
  /// setEnvironment - Set the environment (fourth) component of the triple
706
  /// to a known type.
707
  void setEnvironment(EnvironmentType Kind);
708
709
  /// setObjectFormat - Set the object file format
710
  void setObjectFormat(ObjectFormatType Kind);
711
712
  /// setTriple - Set all components to the new triple \p Str.
713
  void setTriple(const Twine &Str);
714
715
  /// setArchName - Set the architecture (first) component of the
716
  /// triple by name.
717
  void setArchName(StringRef Str);
718
719
  /// setVendorName - Set the vendor (second) component of the triple
720
  /// by name.
721
  void setVendorName(StringRef Str);
722
723
  /// setOSName - Set the operating system (third) component of the
724
  /// triple by name.
725
  void setOSName(StringRef Str);
726
727
  /// setEnvironmentName - Set the optional environment (fourth)
728
  /// component of the triple by name.
729
  void setEnvironmentName(StringRef Str);
730
731
  /// setOSAndEnvironmentName - Set the operating system and optional
732
  /// environment components with a single string.
733
  void setOSAndEnvironmentName(StringRef Str);
734
735
  /// @}
736
  /// @name Helpers to build variants of a particular triple.
737
  /// @{
738
739
  /// Form a triple with a 32-bit variant of the current architecture.
740
  ///
741
  /// This can be used to move across "families" of architectures where useful.
742
  ///
743
  /// \returns A new triple with a 32-bit architecture or an unknown
744
  ///          architecture if no such variant can be found.
745
  llvm::Triple get32BitArchVariant() const;
746
747
  /// Form a triple with a 64-bit variant of the current architecture.
748
  ///
749
  /// This can be used to move across "families" of architectures where useful.
750
  ///
751
  /// \returns A new triple with a 64-bit architecture or an unknown
752
  ///          architecture if no such variant can be found.
753
  llvm::Triple get64BitArchVariant() const;
754
755
  /// Form a triple with a big endian variant of the current architecture.
756
  ///
757
  /// This can be used to move across "families" of architectures where useful.
758
  ///
759
  /// \returns A new triple with a big endian architecture or an unknown
760
  ///          architecture if no such variant can be found.
761
  llvm::Triple getBigEndianArchVariant() const;
762
763
  /// Form a triple with a little endian variant of the current architecture.
764
  ///
765
  /// This can be used to move across "families" of architectures where useful.
766
  ///
767
  /// \returns A new triple with a little endian architecture or an unknown
768
  ///          architecture if no such variant can be found.
769
  llvm::Triple getLittleEndianArchVariant() const;
770
771
  /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
772
  ///
773
  /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
774
  /// string then the triple's arch name is used.
775
  StringRef getARMCPUForArch(StringRef Arch = StringRef()) const;
776
777
  /// Tests whether the target triple is little endian.
778
  ///
779
  /// \returns true if the triple is little endian, false otherwise.
780
  bool isLittleEndian() const;
781
782
  /// Test whether target triples are compatible.
783
  bool isCompatibleWith(const Triple &Other) const;
784
785
  /// Merge target triples.
786
  std::string merge(const Triple &Other) const;
787
788
  /// @}
789
  /// @name Static helpers for IDs.
790
  /// @{
791
792
  /// getArchTypeName - Get the canonical name for the \p Kind architecture.
793
  static StringRef getArchTypeName(ArchType Kind);
794
795
  /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
796
  /// architecture. This is the prefix used by the architecture specific
797
  /// builtins, and is suitable for passing to \see
798
  /// Intrinsic::getIntrinsicForGCCBuiltin().
799
  ///
800
  /// \return - The architecture prefix, or 0 if none is defined.
801
  static StringRef getArchTypePrefix(ArchType Kind);
802
803
  /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
804
  static StringRef getVendorTypeName(VendorType Kind);
805
806
  /// getOSTypeName - Get the canonical name for the \p Kind operating system.
807
  static StringRef getOSTypeName(OSType Kind);
808
809
  /// getEnvironmentTypeName - Get the canonical name for the \p Kind
810
  /// environment.
811
  static StringRef getEnvironmentTypeName(EnvironmentType Kind);
812
813
  /// @}
814
  /// @name Static helpers for converting alternate architecture names.
815
  /// @{
816
817
  /// getArchTypeForLLVMName - The canonical type for the given LLVM
818
  /// architecture name (e.g., "x86").
819
  static ArchType getArchTypeForLLVMName(StringRef Str);
820
821
  /// @}
822
};
823
824
} // End llvm namespace
825
826
827
#endif