Coverage Report

Created: 2018-11-16 02:38

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