Coverage Report

Created: 2018-07-19 03:59

/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, mipsallegrexel
60
    mips64,         // MIPS64: mips64
61
    mips64el,       // MIPS64EL: mips64el
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
    LastOSType = AMDPAL
186
  };
187
  enum EnvironmentType {
188
    UnknownEnvironment,
189
190
    GNU,
191
    GNUABIN32,
192
    GNUABI64,
193
    GNUEABI,
194
    GNUEABIHF,
195
    GNUX32,
196
    CODE16,
197
    EABI,
198
    EABIHF,
199
    Android,
200
    Musl,
201
    MuslEABI,
202
    MuslEABIHF,
203
204
    MSVC,
205
    Itanium,
206
    Cygnus,
207
    CoreCLR,
208
    Simulator,  // Simulator variants of other systems, e.g., Apple's iOS
209
    LastEnvironmentType = Simulator
210
  };
211
  enum ObjectFormatType {
212
    UnknownObjectFormat,
213
214
    COFF,
215
    ELF,
216
    MachO,
217
    Wasm,
218
  };
219
220
private:
221
  std::string Data;
222
223
  /// The parsed arch type.
224
  ArchType Arch;
225
226
  /// The parsed subarchitecture type.
227
  SubArchType SubArch;
228
229
  /// The parsed vendor type.
230
  VendorType Vendor;
231
232
  /// The parsed OS type.
233
  OSType OS;
234
235
  /// The parsed Environment type.
236
  EnvironmentType Environment;
237
238
  /// The object format type.
239
  ObjectFormatType ObjectFormat;
240
241
public:
242
  /// @name Constructors
243
  /// @{
244
245
  /// Default constructor is the same as an empty string and leaves all
246
  /// triple fields unknown.
247
  Triple()
248
      : Data(), Arch(), SubArch(), Vendor(), OS(), Environment(),
249
253k
        ObjectFormat() {}
250
251
  explicit Triple(const Twine &Str);
252
  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
253
  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
254
         const Twine &EnvironmentStr);
255
256
1.43k
  bool operator==(const Triple &Other) const {
257
1.43k
    return Arch == Other.Arch && 
SubArch == Other.SubArch1.38k
&&
258
1.43k
           
Vendor == Other.Vendor1.38k
&&
OS == Other.OS1.37k
&&
259
1.43k
           
Environment == Other.Environment1.37k
&&
260
1.43k
           
ObjectFormat == Other.ObjectFormat1.37k
;
261
1.43k
  }
262
263
964
  bool operator!=(const Triple &Other) const {
264
964
    return !(*this == Other);
265
964
  }
266
267
  /// @}
268
  /// @name Normalization
269
  /// @{
270
271
  /// normalize - Turn an arbitrary machine specification into the canonical
272
  /// triple form (or something sensible that the Triple class understands if
273
  /// nothing better can reasonably be done).  In particular, it handles the
274
  /// common case in which otherwise valid components are in the wrong order.
275
  static std::string normalize(StringRef Str);
276
277
  /// Return the normalized form of this triple's string.
278
127k
  std::string normalize() const { return normalize(Data); }
279
280
  /// @}
281
  /// @name Typed Component Access
282
  /// @{
283
284
  /// getArch - Get the parsed architecture type of this triple.
285
15.7M
  ArchType getArch() const { return Arch; }
286
287
  /// getSubArch - get the parsed subarchitecture type for this triple.
288
80.8k
  SubArchType getSubArch() const { return SubArch; }
289
290
  /// getVendor - Get the parsed vendor type of this triple.
291
272k
  VendorType getVendor() const { return Vendor; }
292
293
  /// getOS - Get the parsed operating system type of this triple.
294
97.7M
  OSType getOS() const { return OS; }
295
296
  /// hasEnvironment - Does this triple have the optional environment
297
  /// (fourth) component?
298
25.8k
  bool hasEnvironment() const {
299
25.8k
    return getEnvironmentName() != "";
300
25.8k
  }
301
302
  /// getEnvironment - Get the parsed environment type of this triple.
303
9.56M
  EnvironmentType getEnvironment() const { return Environment; }
304
305
  /// Parse the version number from the OS name component of the
306
  /// triple, if present.
307
  ///
308
  /// For example, "fooos1.2.3" would return (1, 2, 3).
309
  ///
310
  /// If an entry is not defined, it will be returned as 0.
311
  void getEnvironmentVersion(unsigned &Major, unsigned &Minor,
312
                             unsigned &Micro) const;
313
314
  /// getFormat - Get the object format for this triple.
315
17.1M
  ObjectFormatType getObjectFormat() const { return ObjectFormat; }
316
317
  /// getOSVersion - 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 getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
324
325
  /// getOSMajorVersion - Return just the major version number, this is
326
  /// specialized because it is a common query.
327
19.6k
  unsigned getOSMajorVersion() const {
328
19.6k
    unsigned Maj, Min, Micro;
329
19.6k
    getOSVersion(Maj, Min, Micro);
330
19.6k
    return Maj;
331
19.6k
  }
332
333
  /// getMacOSXVersion - Parse the version number as with getOSVersion and then
334
  /// translate generic "darwin" versions to the corresponding OS X versions.
335
  /// This may also be called with IOS triples but the OS X version number is
336
  /// just set to a constant 10.4.0 in that case.  Returns true if successful.
337
  bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
338
                        unsigned &Micro) const;
339
340
  /// getiOSVersion - Parse the version number as with getOSVersion.  This should
341
  /// only be called with IOS or generic triples.
342
  void getiOSVersion(unsigned &Major, unsigned &Minor,
343
                     unsigned &Micro) const;
344
345
  /// getWatchOSVersion - Parse the version number as with getOSVersion.  This
346
  /// should only be called with WatchOS or generic triples.
347
  void getWatchOSVersion(unsigned &Major, unsigned &Minor,
348
                         unsigned &Micro) const;
349
350
  /// @}
351
  /// @name Direct Component Access
352
  /// @{
353
354
323k
  const std::string &str() const { return Data; }
355
356
192k
  const std::string &getTriple() const { return Data; }
357
358
  /// getArchName - Get the architecture (first) component of the
359
  /// triple.
360
  StringRef getArchName() const;
361
362
  /// getVendorName - Get the vendor (second) component of the triple.
363
  StringRef getVendorName() const;
364
365
  /// getOSName - Get the operating system (third) component of the
366
  /// triple.
367
  StringRef getOSName() const;
368
369
  /// getEnvironmentName - Get the optional environment (fourth)
370
  /// component of the triple, or "" if empty.
371
  StringRef getEnvironmentName() const;
372
373
  /// getOSAndEnvironmentName - Get the operating system and optional
374
  /// environment components as a single string (separated by a '-'
375
  /// if the environment component is present).
376
  StringRef getOSAndEnvironmentName() const;
377
378
  /// @}
379
  /// @name Convenience Predicates
380
  /// @{
381
382
  /// Test whether the architecture is 64-bit
383
  ///
384
  /// Note that this tests for 64-bit pointer width, and nothing else. Note
385
  /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
386
  /// 16-bit. The inner details of pointer width for particular architectures
387
  /// is not summed up in the triple, and so only a coarse grained predicate
388
  /// system is provided.
389
  bool isArch64Bit() const;
390
391
  /// Test whether the architecture is 32-bit
392
  ///
393
  /// Note that this tests for 32-bit pointer width, and nothing else.
394
  bool isArch32Bit() const;
395
396
  /// Test whether the architecture is 16-bit
397
  ///
398
  /// Note that this tests for 16-bit pointer width, and nothing else.
399
  bool isArch16Bit() const;
400
401
  /// isOSVersionLT - Helper function for doing comparisons against version
402
  /// numbers included in the target triple.
403
  bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
404
227k
                     unsigned Micro = 0) const {
405
227k
    unsigned LHS[3];
406
227k
    getOSVersion(LHS[0], LHS[1], LHS[2]);
407
227k
408
227k
    if (LHS[0] != Major)
409
176k
      return LHS[0] < Major;
410
50.4k
    if (LHS[1] != Minor)
411
38.6k
      return LHS[1] < Minor;
412
11.8k
    if (LHS[2] != Micro)
413
48
      return LHS[1] < Micro;
414
11.7k
415
11.7k
    return false;
416
11.7k
  }
417
418
71
  bool isOSVersionLT(const Triple &Other) const {
419
71
    unsigned RHS[3];
420
71
    Other.getOSVersion(RHS[0], RHS[1], RHS[2]);
421
71
    return isOSVersionLT(RHS[0], RHS[1], RHS[2]);
422
71
  }
423
424
  /// isMacOSXVersionLT - Comparison function for checking OS X version
425
  /// compatibility, which handles supporting skewed version numbering schemes
426
  /// used by the "darwin" triples.
427
  bool isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
428
90.1k
                         unsigned Micro = 0) const {
429
90.1k
    assert(isMacOSX() && "Not an OS X triple!");
430
90.1k
431
90.1k
    // If this is OS X, expect a sane version number.
432
90.1k
    if (getOS() == Triple::MacOSX)
433
39.2k
      return isOSVersionLT(Major, Minor, Micro);
434
50.8k
435
50.8k
    // Otherwise, compare to the "Darwin" number.
436
50.8k
    assert(Major == 10 && "Unexpected major version");
437
50.8k
    return isOSVersionLT(Minor + 4, Micro, 0);
438
50.8k
  }
439
440
  /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
441
  /// "darwin" and "osx" as OS X triples.
442
13.6M
  bool isMacOSX() const {
443
13.6M
    return getOS() == Triple::Darwin || 
getOS() == Triple::MacOSX12.8M
;
444
13.6M
  }
445
446
  /// Is this an iOS triple.
447
  /// Note: This identifies tvOS as a variant of iOS. If that ever
448
  /// changes, i.e., if the two operating systems diverge or their version
449
  /// numbers get out of sync, that will need to be changed.
450
  /// watchOS has completely different version numbers so it is not included.
451
12.0M
  bool isiOS() const {
452
12.0M
    return getOS() == Triple::IOS || 
isTvOS()2.61M
;
453
12.0M
  }
454
455
  /// Is this an Apple tvOS triple.
456
3.25M
  bool isTvOS() const {
457
3.25M
    return getOS() == Triple::TvOS;
458
3.25M
  }
459
460
  /// Is this an Apple watchOS triple.
461
3.23M
  bool isWatchOS() const {
462
3.23M
    return getOS() == Triple::WatchOS;
463
3.23M
  }
464
465
78.4k
  bool isWatchABI() const {
466
78.4k
    return getSubArch() == Triple::ARMSubArch_v7k;
467
78.4k
  }
468
469
  /// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
470
12.8M
  bool isOSDarwin() const {
471
12.8M
    return isMacOSX() || 
isiOS()11.7M
||
isWatchOS()2.49M
;
472
12.8M
  }
473
474
30.0k
  bool isSimulatorEnvironment() const {
475
30.0k
    return getEnvironment() == Triple::Simulator;
476
30.0k
  }
477
478
3.82k
  bool isOSNetBSD() const {
479
3.82k
    return getOS() == Triple::NetBSD;
480
3.82k
  }
481
482
534k
  bool isOSOpenBSD() const {
483
534k
    return getOS() == Triple::OpenBSD;
484
534k
  }
485
486
110k
  bool isOSFreeBSD() const {
487
110k
    return getOS() == Triple::FreeBSD;
488
110k
  }
489
490
104k
  bool isOSFuchsia() const {
491
104k
    return getOS() == Triple::Fuchsia;
492
104k
  }
493
494
90
  bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
495
496
36.2k
  bool isOSSolaris() const {
497
36.2k
    return getOS() == Triple::Solaris;
498
36.2k
  }
499
500
479k
  bool isOSIAMCU() const {
501
479k
    return getOS() == Triple::ELFIAMCU;
502
479k
  }
503
504
7.84k
  bool isOSUnknown() const { return getOS() == Triple::UnknownOS; }
505
506
885k
  bool isGNUEnvironment() const {
507
885k
    EnvironmentType Env = getEnvironment();
508
885k
    return Env == Triple::GNU || 
Env == Triple::GNUABIN32836k
||
509
885k
           
Env == Triple::GNUABI64836k
||
Env == Triple::GNUEABI836k
||
510
885k
           
Env == Triple::GNUEABIHF833k
||
Env == Triple::GNUX32832k
;
511
885k
  }
512
513
149
  bool isOSContiki() const {
514
149
    return getOS() == Triple::Contiki;
515
149
  }
516
517
  /// Tests whether the OS is Haiku.
518
0
  bool isOSHaiku() const {
519
0
    return getOS() == Triple::Haiku;
520
0
  }
521
522
  /// Checks if the environment could be MSVC.
523
8.80M
  bool isWindowsMSVCEnvironment() const {
524
8.80M
    return getOS() == Triple::Win32 &&
525
8.80M
           
(82.1k
getEnvironment() == Triple::UnknownEnvironment82.1k
||
526
82.1k
            
getEnvironment() == Triple::MSVC82.0k
);
527
8.80M
  }
528
529
  /// Checks if the environment is MSVC.
530
106k
  bool isKnownWindowsMSVCEnvironment() const {
531
106k
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::MSVC4.53k
;
532
106k
  }
533
534
382
  bool isWindowsCoreCLREnvironment() const {
535
382
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::CoreCLR378
;
536
382
  }
537
538
8.55M
  bool isWindowsItaniumEnvironment() const {
539
8.55M
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::Itanium4.46k
;
540
8.55M
  }
541
542
644k
  bool isWindowsCygwinEnvironment() const {
543
644k
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::Cygnus13.2k
;
544
644k
  }
545
546
11.8M
  bool isWindowsGNUEnvironment() const {
547
11.8M
    return getOS() == Triple::Win32 && 
getEnvironment() == Triple::GNU29.1k
;
548
11.8M
  }
549
550
  /// Tests for either Cygwin or MinGW OS
551
137k
  bool isOSCygMing() const {
552
137k
    return isWindowsCygwinEnvironment() || 
isWindowsGNUEnvironment()137k
;
553
137k
  }
554
555
  /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
556
8.59M
  bool isOSMSVCRT() const {
557
8.59M
    return isWindowsMSVCEnvironment() || 
isWindowsGNUEnvironment()8.53M
||
558
8.59M
           
isWindowsItaniumEnvironment()8.52M
;
559
8.59M
  }
560
561
  /// Tests whether the OS is Windows.
562
15.6M
  bool isOSWindows() const {
563
15.6M
    return getOS() == Triple::Win32;
564
15.6M
  }
565
566
  /// Tests whether the OS is NaCl (Native Client)
567
1.66M
  bool isOSNaCl() const {
568
1.66M
    return getOS() == Triple::NaCl;
569
1.66M
  }
570
571
  /// Tests whether the OS is Linux.
572
296k
  bool isOSLinux() const {
573
296k
    return getOS() == Triple::Linux;
574
296k
  }
575
576
  /// Tests whether the OS is kFreeBSD.
577
4.63k
  bool isOSKFreeBSD() const {
578
4.63k
    return getOS() == Triple::KFreeBSD;
579
4.63k
  }
580
581
  /// Tests whether the OS uses glibc.
582
1.42k
  bool isOSGlibc() const {
583
1.42k
    return (getOS() == Triple::Linux || 
getOS() == Triple::KFreeBSD834
) &&
584
1.42k
           
!isAndroid()598
;
585
1.42k
  }
586
587
  /// Tests whether the OS uses the ELF binary format.
588
1.94M
  bool isOSBinFormatELF() const {
589
1.94M
    return getObjectFormat() == Triple::ELF;
590
1.94M
  }
591
592
  /// Tests whether the OS uses the COFF binary format.
593
5.72M
  bool isOSBinFormatCOFF() const {
594
5.72M
    return getObjectFormat() == Triple::COFF;
595
5.72M
  }
596
597
  /// Tests whether the environment is MachO.
598
9.37M
  bool isOSBinFormatMachO() const {
599
9.37M
    return getObjectFormat() == Triple::MachO;
600
9.37M
  }
601
602
  /// Tests whether the OS uses the Wasm binary format.
603
357
  bool isOSBinFormatWasm() const {
604
357
    return getObjectFormat() == Triple::Wasm;
605
357
  }
606
607
  /// Tests whether the target is the PS4 CPU
608
125k
  bool isPS4CPU() const {
609
125k
    return getArch() == Triple::x86_64 &&
610
125k
           
getVendor() == Triple::SCEI52.4k
&&
611
125k
           
getOS() == Triple::PS4716
;
612
125k
  }
613
614
  /// Tests whether the target is the PS4 platform
615
82.3k
  bool isPS4() const {
616
82.3k
    return getVendor() == Triple::SCEI &&
617
82.3k
           
getOS() == Triple::PS4330
;
618
82.3k
  }
619
620
  /// Tests whether the target is Android
621
2.27M
  bool isAndroid() const { return getEnvironment() == Triple::Android; }
622
623
538
  bool isAndroidVersionLT(unsigned Major) const {
624
538
    assert(isAndroid() && "Not an Android triple!");
625
538
626
538
    unsigned Env[3];
627
538
    getEnvironmentVersion(Env[0], Env[1], Env[2]);
628
538
629
538
    // 64-bit targets did not exist before API level 21 (Lollipop).
630
538
    if (isArch64Bit() && 
Env[0] < 21220
)
631
200
      Env[0] = 21;
632
538
633
538
    return Env[0] < Major;
634
538
  }
635
636
  /// Tests whether the environment is musl-libc
637
5.54k
  bool isMusl() const {
638
5.54k
    return getEnvironment() == Triple::Musl ||
639
5.54k
           
getEnvironment() == Triple::MuslEABI5.50k
||
640
5.54k
           
getEnvironment() == Triple::MuslEABIHF5.47k
;
641
5.54k
  }
642
643
  /// Tests whether the target is NVPTX (32- or 64-bit).
644
512k
  bool isNVPTX() const {
645
512k
    return getArch() == Triple::nvptx || 
getArch() == Triple::nvptx64511k
;
646
512k
  }
647
648
  /// Tests whether the target is Thumb (little and big endian).
649
59.2k
  bool isThumb() const {
650
59.2k
    return getArch() == Triple::thumb || 
getArch() == Triple::thumbeb44.7k
;
651
59.2k
  }
652
653
  /// Tests whether the target is ARM (little and big endian).
654
37.0k
  bool isARM() const {
655
37.0k
    return getArch() == Triple::arm || 
getArch() == Triple::armeb35.4k
;
656
37.0k
  }
657
658
  /// Tests whether the target is AArch64 (little and big endian).
659
130
  bool isAArch64() const {
660
130
    return getArch() == Triple::aarch64 || 
getArch() == Triple::aarch64_be30
;
661
130
  }
662
663
  /// Tests whether the target is MIPS 32-bit (little and big endian).
664
168k
  bool isMIPS32() const {
665
168k
    return getArch() == Triple::mips || 
getArch() == Triple::mipsel159k
;
666
168k
  }
667
668
  /// Tests whether the target is MIPS 64-bit (little and big endian).
669
156k
  bool isMIPS64() const {
670
156k
    return getArch() == Triple::mips64 || 
getArch() == Triple::mips64el153k
;
671
156k
  }
672
673
  /// Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
674
149k
  bool isMIPS() const {
675
149k
    return isMIPS32() || 
isMIPS64()145k
;
676
149k
  }
677
678
  /// Tests whether the target supports comdat
679
398k
  bool supportsCOMDAT() const {
680
398k
    return !isOSBinFormatMachO();
681
398k
  }
682
683
  /// Tests whether the target uses emulated TLS as default.
684
481k
  bool hasDefaultEmulatedTLS() const {
685
481k
    return isAndroid() || 
isOSOpenBSD()480k
||
isWindowsCygwinEnvironment()480k
;
686
481k
  }
687
688
  /// @}
689
  /// @name Mutators
690
  /// @{
691
692
  /// setArch - Set the architecture (first) component of the triple
693
  /// to a known type.
694
  void setArch(ArchType Kind);
695
696
  /// setVendor - Set the vendor (second) component of the triple to a
697
  /// known type.
698
  void setVendor(VendorType Kind);
699
700
  /// setOS - Set the operating system (third) component of the triple
701
  /// to a known type.
702
  void setOS(OSType Kind);
703
704
  /// setEnvironment - Set the environment (fourth) component of the triple
705
  /// to a known type.
706
  void setEnvironment(EnvironmentType Kind);
707
708
  /// setObjectFormat - Set the object file format
709
  void setObjectFormat(ObjectFormatType Kind);
710
711
  /// setTriple - Set all components to the new triple \p Str.
712
  void setTriple(const Twine &Str);
713
714
  /// setArchName - Set the architecture (first) component of the
715
  /// triple by name.
716
  void setArchName(StringRef Str);
717
718
  /// setVendorName - Set the vendor (second) component of the triple
719
  /// by name.
720
  void setVendorName(StringRef Str);
721
722
  /// setOSName - Set the operating system (third) component of the
723
  /// triple by name.
724
  void setOSName(StringRef Str);
725
726
  /// setEnvironmentName - Set the optional environment (fourth)
727
  /// component of the triple by name.
728
  void setEnvironmentName(StringRef Str);
729
730
  /// setOSAndEnvironmentName - Set the operating system and optional
731
  /// environment components with a single string.
732
  void setOSAndEnvironmentName(StringRef Str);
733
734
  /// @}
735
  /// @name Helpers to build variants of a particular triple.
736
  /// @{
737
738
  /// Form a triple with a 32-bit variant of the current architecture.
739
  ///
740
  /// This can be used to move across "families" of architectures where useful.
741
  ///
742
  /// \returns A new triple with a 32-bit architecture or an unknown
743
  ///          architecture if no such variant can be found.
744
  llvm::Triple get32BitArchVariant() const;
745
746
  /// Form a triple with a 64-bit variant of the current architecture.
747
  ///
748
  /// This can be used to move across "families" of architectures where useful.
749
  ///
750
  /// \returns A new triple with a 64-bit architecture or an unknown
751
  ///          architecture if no such variant can be found.
752
  llvm::Triple get64BitArchVariant() const;
753
754
  /// Form a triple with a big endian variant of the current architecture.
755
  ///
756
  /// This can be used to move across "families" of architectures where useful.
757
  ///
758
  /// \returns A new triple with a big endian architecture or an unknown
759
  ///          architecture if no such variant can be found.
760
  llvm::Triple getBigEndianArchVariant() const;
761
762
  /// Form a triple with a little endian variant of the current architecture.
763
  ///
764
  /// This can be used to move across "families" of architectures where useful.
765
  ///
766
  /// \returns A new triple with a little endian architecture or an unknown
767
  ///          architecture if no such variant can be found.
768
  llvm::Triple getLittleEndianArchVariant() const;
769
770
  /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
771
  ///
772
  /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
773
  /// string then the triple's arch name is used.
774
  StringRef getARMCPUForArch(StringRef Arch = StringRef()) const;
775
776
  /// Tests whether the target triple is little endian.
777
  ///
778
  /// \returns true if the triple is little endian, false otherwise.
779
  bool isLittleEndian() const;
780
781
  /// Test whether target triples are compatible.
782
  bool isCompatibleWith(const Triple &Other) const;
783
784
  /// Merge target triples.
785
  std::string merge(const Triple &Other) const;
786
787
  /// @}
788
  /// @name Static helpers for IDs.
789
  /// @{
790
791
  /// getArchTypeName - Get the canonical name for the \p Kind architecture.
792
  static StringRef getArchTypeName(ArchType Kind);
793
794
  /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
795
  /// architecture. This is the prefix used by the architecture specific
796
  /// builtins, and is suitable for passing to \see
797
  /// Intrinsic::getIntrinsicForGCCBuiltin().
798
  ///
799
  /// \return - The architecture prefix, or 0 if none is defined.
800
  static StringRef getArchTypePrefix(ArchType Kind);
801
802
  /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
803
  static StringRef getVendorTypeName(VendorType Kind);
804
805
  /// getOSTypeName - Get the canonical name for the \p Kind operating system.
806
  static StringRef getOSTypeName(OSType Kind);
807
808
  /// getEnvironmentTypeName - Get the canonical name for the \p Kind
809
  /// environment.
810
  static StringRef getEnvironmentTypeName(EnvironmentType Kind);
811
812
  /// @}
813
  /// @name Static helpers for converting alternate architecture names.
814
  /// @{
815
816
  /// getArchTypeForLLVMName - The canonical type for the given LLVM
817
  /// architecture name (e.g., "x86").
818
  static ArchType getArchTypeForLLVMName(StringRef Str);
819
820
  /// @}
821
};
822
823
} // End llvm namespace
824
825
826
#endif