Coverage Report

Created: 2019-02-15 18: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
// 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
0
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
    arc,            // ARC: Synopsys ARC
53
    avr,            // AVR: Atmel AVR microcontroller
54
    bpfel,          // eBPF or extended BPF or 64-bit BPF (little endian)
55
    bpfeb,          // eBPF or extended BPF or 64-bit BPF (big endian)
56
    hexagon,        // Hexagon: hexagon
57
    mips,           // MIPS: mips, mipsallegrex, mipsr6
58
    mipsel,         // MIPSEL: mipsel, mipsallegrexe, mipsr6el
59
    mips64,         // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
60
    mips64el,       // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
61
    msp430,         // MSP430: msp430
62
    ppc,            // PPC: powerpc
63
    ppc64,          // PPC64: powerpc64, ppu
64
    ppc64le,        // PPC64LE: powerpc64le
65
    r600,           // R600: AMD GPUs HD2XXX - HD6XXX
66
    amdgcn,         // AMDGCN: AMD GCN GPUs
67
    riscv32,        // RISC-V (32-bit): riscv32
68
    riscv64,        // RISC-V (64-bit): riscv64
69
    sparc,          // Sparc: sparc
70
    sparcv9,        // Sparcv9: Sparcv9
71
    sparcel,        // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant
72
    systemz,        // SystemZ: s390x
73
    tce,            // TCE (http://tce.cs.tut.fi/): tce
74
    tcele,          // TCE little endian (http://tce.cs.tut.fi/): tcele
75
    thumb,          // Thumb (little endian): thumb, thumbv.*
76
    thumbeb,        // Thumb (big endian): thumbeb
77
    x86,            // X86: i[3-9]86
78
    x86_64,         // X86-64: amd64, x86_64
79
    xcore,          // XCore: xcore
80
    nvptx,          // NVPTX: 32-bit
81
    nvptx64,        // NVPTX: 64-bit
82
    le32,           // le32: generic little-endian 32-bit CPU (PNaCl)
83
    le64,           // le64: generic little-endian 64-bit CPU (PNaCl)
84
    amdil,          // AMDIL
85
    amdil64,        // AMDIL with 64-bit pointers
86
    hsail,          // AMD HSAIL
87
    hsail64,        // AMD HSAIL with 64-bit pointers
88
    spir,           // SPIR: standard portable IR for OpenCL 32-bit version
89
    spir64,         // SPIR: standard portable IR for OpenCL 64-bit version
90
    kalimba,        // Kalimba: generic kalimba
91
    shave,          // SHAVE: Movidius vector VLIW processors
92
    lanai,          // Lanai: Lanai 32-bit
93
    wasm32,         // WebAssembly with 32-bit pointers
94
    wasm64,         // WebAssembly with 64-bit pointers
95
    renderscript32, // 32-bit RenderScript
96
    renderscript64, // 64-bit RenderScript
97
    LastArchType = renderscript64
98
  };
99
  enum SubArchType {
100
    NoSubArch,
101
102
    ARMSubArch_v8_5a,
103
    ARMSubArch_v8_4a,
104
    ARMSubArch_v8_3a,
105
    ARMSubArch_v8_2a,
106
    ARMSubArch_v8_1a,
107
    ARMSubArch_v8,
108
    ARMSubArch_v8r,
109
    ARMSubArch_v8m_baseline,
110
    ARMSubArch_v8m_mainline,
111
    ARMSubArch_v7,
112
    ARMSubArch_v7em,
113
    ARMSubArch_v7m,
114
    ARMSubArch_v7s,
115
    ARMSubArch_v7k,
116
    ARMSubArch_v7ve,
117
    ARMSubArch_v6,
118
    ARMSubArch_v6m,
119
    ARMSubArch_v6k,
120
    ARMSubArch_v6t2,
121
    ARMSubArch_v5,
122
    ARMSubArch_v5te,
123
    ARMSubArch_v4t,
124
125
    KalimbaSubArch_v3,
126
    KalimbaSubArch_v4,
127
    KalimbaSubArch_v5,
128
129
    MipsSubArch_r6
130
  };
131
  enum VendorType {
132
    UnknownVendor,
133
134
    Apple,
135
    PC,
136
    SCEI,
137
    BGP,
138
    BGQ,
139
    Freescale,
140
    IBM,
141
    ImaginationTechnologies,
142
    MipsTechnologies,
143
    NVIDIA,
144
    CSR,
145
    Myriad,
146
    AMD,
147
    Mesa,
148
    SUSE,
149
    OpenEmbedded,
150
    LastVendorType = OpenEmbedded
151
  };
152
  enum OSType {
153
    UnknownOS,
154
155
    Ananas,
156
    CloudABI,
157
    Darwin,
158
    DragonFly,
159
    FreeBSD,
160
    Fuchsia,
161
    IOS,
162
    KFreeBSD,
163
    Linux,
164
    Lv2,        // PS3
165
    MacOSX,
166
    NetBSD,
167
    OpenBSD,
168
    Solaris,
169
    Win32,
170
    Haiku,
171
    Minix,
172
    RTEMS,
173
    NaCl,       // Native Client
174
    CNK,        // BG/P Compute-Node Kernel
175
    AIX,
176
    CUDA,       // NVIDIA CUDA
177
    NVCL,       // NVIDIA OpenCL
178
    AMDHSA,     // AMD HSA Runtime
179
    PS4,
180
    ELFIAMCU,
181
    TvOS,       // Apple tvOS
182
    WatchOS,    // Apple watchOS
183
    Mesa3D,
184
    Contiki,
185
    AMDPAL,     // AMD PAL Runtime
186
    HermitCore, // HermitCore Unikernel/Multikernel
187
    Hurd,       // GNU/Hurd
188
    WASI,       // Experimental WebAssembly OS
189
    LastOSType = WASI
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
273k
        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.58k
  bool operator==(const Triple &Other) const {
261
1.58k
    return Arch == Other.Arch && 
SubArch == Other.SubArch1.51k
&&
262
1.58k
           
Vendor == Other.Vendor1.51k
&&
OS == Other.OS1.49k
&&
263
1.58k
           
Environment == Other.Environment1.49k
&&
264
1.58k
           
ObjectFormat == Other.ObjectFormat1.49k
;
265
1.58k
  }
266
267
999
  bool operator!=(const Triple &Other) const {
268
999
    return !(*this == Other);
269
999
  }
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
136k
  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
20.6M
  ArchType getArch() const { return Arch; }
290
291
  /// getSubArch - get the parsed subarchitecture type for this triple.
292
106k
  SubArchType getSubArch() const { return SubArch; }
293
294
  /// getVendor - Get the parsed vendor type of this triple.
295
455k
  VendorType getVendor() const { return Vendor; }
296
297
  /// getOS - Get the parsed operating system type of this triple.
298
119M
  OSType getOS() const { return OS; }
299
300
  /// hasEnvironment - Does this triple have the optional environment
301
  /// (fourth) component?
302
27.5k
  bool hasEnvironment() const {
303
27.5k
    return getEnvironmentName() != "";
304
27.5k
  }
305
306
  /// getEnvironment - Get the parsed environment type of this triple.
307
10.5M
  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.7k
  unsigned getOSMajorVersion() const {
332
20.7k
    unsigned Maj, Min, Micro;
333
20.7k
    getOSVersion(Maj, Min, Micro);
334
20.7k
    return Maj;
335
20.7k
  }
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
383k
  const std::string &str() const { return Data; }
359
360
212k
  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
238k
                     unsigned Micro = 0) const {
409
238k
    unsigned LHS[3];
410
238k
    getOSVersion(LHS[0], LHS[1], LHS[2]);
411
238k
412
238k
    if (LHS[0] != Major)
413
186k
      return LHS[0] < Major;
414
51.4k
    if (LHS[1] != Minor)
415
40.0k
      return LHS[1] < Minor;
416
11.3k
    if (LHS[2] != Micro)
417
48
      return LHS[2] < Micro;
418
11.3k
419
11.3k
    return false;
420
11.3k
  }
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
90.2k
                         unsigned Micro = 0) const {
433
90.2k
    assert(isMacOSX() && "Not an OS X triple!");
434
90.2k
435
90.2k
    // If this is OS X, expect a sane version number.
436
90.2k
    if (getOS() == Triple::MacOSX)
437
39.1k
      return isOSVersionLT(Major, Minor, Micro);
438
51.0k
439
51.0k
    // Otherwise, compare to the "Darwin" number.
440
51.0k
    assert(Major == 10 && "Unexpected major version");
441
51.0k
    return isOSVersionLT(Minor + 4, Micro, 0);
442
51.0k
  }
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
14.6M
  bool isMacOSX() const {
447
14.6M
    return getOS() == Triple::Darwin || 
getOS() == Triple::MacOSX13.7M
;
448
14.6M
  }
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
12.8M
  bool isiOS() const {
456
12.8M
    return getOS() == Triple::IOS || 
isTvOS()3.02M
;
457
12.8M
  }
458
459
  /// Is this an Apple tvOS triple.
460
3.73M
  bool isTvOS() const {
461
3.73M
    return getOS() == Triple::TvOS;
462
3.73M
  }
463
464
  /// Is this an Apple watchOS triple.
465
3.71M
  bool isWatchOS() const {
466
3.71M
    return getOS() == Triple::WatchOS;
467
3.71M
  }
468
469
79.8k
  bool isWatchABI() const {
470
79.8k
    return getSubArch() == Triple::ARMSubArch_v7k;
471
79.8k
  }
472
473
  /// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
474
13.7M
  bool isOSDarwin() const {
475
13.7M
    return isMacOSX() || 
isiOS()12.6M
||
isWatchOS()2.89M
;
476
13.7M
  }
477
478
31.9k
  bool isSimulatorEnvironment() const {
479
31.9k
    return getEnvironment() == Triple::Simulator;
480
31.9k
  }
481
482
73.9k
  bool isOSNetBSD() const {
483
73.9k
    return getOS() == Triple::NetBSD;
484
73.9k
  }
485
486
591k
  bool isOSOpenBSD() const {
487
591k
    return getOS() == Triple::OpenBSD;
488
591k
  }
489
490
121k
  bool isOSFreeBSD() const {
491
121k
    return getOS() == Triple::FreeBSD;
492
121k
  }
493
494
137k
  bool isOSFuchsia() const {
495
137k
    return getOS() == Triple::Fuchsia;
496
137k
  }
497
498
91
  bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
499
500
41.5k
  bool isOSSolaris() const {
501
41.5k
    return getOS() == Triple::Solaris;
502
41.5k
  }
503
504
428k
  bool isOSIAMCU() const {
505
428k
    return getOS() == Triple::ELFIAMCU;
506
428k
  }
507
508
8.85k
  bool isOSUnknown() const { return getOS() == Triple::UnknownOS; }
509
510
962k
  bool isGNUEnvironment() const {
511
962k
    EnvironmentType Env = getEnvironment();
512
962k
    return Env == Triple::GNU || 
Env == Triple::GNUABIN32902k
||
513
962k
           
Env == Triple::GNUABI64902k
||
Env == Triple::GNUEABI901k
||
514
962k
           
Env == Triple::GNUEABIHF898k
||
Env == Triple::GNUX32896k
;
515
962k
  }
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
  /// Tests whether the OS is Windows.
527
62.0M
  bool isOSWindows() const {
528
62.0M
    return getOS() == Triple::Win32;
529
62.0M
  }
530
531
  /// Checks if the environment is MSVC.
532
9.78M
  bool isKnownWindowsMSVCEnvironment() const {
533
9.78M
    return isOSWindows() && 
getEnvironment() == Triple::MSVC154k
;
534
9.78M
  }
535
536
  /// Checks if the environment could be MSVC.
537
9.38M
  bool isWindowsMSVCEnvironment() const {
538
9.38M
    return isKnownWindowsMSVCEnvironment() ||
539
9.38M
           
(9.24M
isOSWindows()9.24M
&&
getEnvironment() == Triple::UnknownEnvironment11.4k
);
540
9.38M
  }
541
542
431
  bool isWindowsCoreCLREnvironment() const {
543
431
    return isOSWindows() && 
getEnvironment() == Triple::CoreCLR427
;
544
431
  }
545
546
9.04M
  bool isWindowsItaniumEnvironment() const {
547
9.04M
    return isOSWindows() && 
getEnvironment() == Triple::Itanium4.66k
;
548
9.04M
  }
549
550
653k
  bool isWindowsCygwinEnvironment() const {
551
653k
    return isOSWindows() && 
getEnvironment() == Triple::Cygnus14.1k
;
552
653k
  }
553
554
14.8M
  bool isWindowsGNUEnvironment() const {
555
14.8M
    return isOSWindows() && 
getEnvironment() == Triple::GNU89.4k
;
556
14.8M
  }
557
558
  /// Tests for either Cygwin or MinGW OS
559
143k
  bool isOSCygMing() const {
560
143k
    return isWindowsCygwinEnvironment() || 
isWindowsGNUEnvironment()143k
;
561
143k
  }
562
563
  /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
564
9.14M
  bool isOSMSVCRT() const {
565
9.14M
    return isWindowsMSVCEnvironment() || 
isWindowsGNUEnvironment()9.01M
||
566
9.14M
           
isWindowsItaniumEnvironment()9.00M
;
567
9.14M
  }
568
569
  /// Tests whether the OS is NaCl (Native Client)
570
1.83M
  bool isOSNaCl() const {
571
1.83M
    return getOS() == Triple::NaCl;
572
1.83M
  }
573
574
  /// Tests whether the OS is Linux.
575
311k
  bool isOSLinux() const {
576
311k
    return getOS() == Triple::Linux;
577
311k
  }
578
579
  /// Tests whether the OS is kFreeBSD.
580
5.14k
  bool isOSKFreeBSD() const {
581
5.14k
    return getOS() == Triple::KFreeBSD;
582
5.14k
  }
583
584
  /// Tests whether the OS is Hurd.
585
46.7k
  bool isOSHurd() const {
586
46.7k
    return getOS() == Triple::Hurd;
587
46.7k
  }
588
589
  /// Tests whether the OS is WASI.
590
0
  bool isOSWASI() const {
591
0
    return getOS() == Triple::WASI;
592
0
  }
593
594
  /// Tests whether the OS uses glibc.
595
1.41k
  bool isOSGlibc() const {
596
1.41k
    return (getOS() == Triple::Linux || 
getOS() == Triple::KFreeBSD808
||
597
1.41k
            
getOS() == Triple::Hurd804
) &&
598
1.41k
           
!isAndroid()613
;
599
1.41k
  }
600
601
  /// Tests whether the OS uses the ELF binary format.
602
2.17M
  bool isOSBinFormatELF() const {
603
2.17M
    return getObjectFormat() == Triple::ELF;
604
2.17M
  }
605
606
  /// Tests whether the OS uses the COFF binary format.
607
5.88M
  bool isOSBinFormatCOFF() const {
608
5.88M
    return getObjectFormat() == Triple::COFF;
609
5.88M
  }
610
611
  /// Tests whether the environment is MachO.
612
3.93M
  bool isOSBinFormatMachO() const {
613
3.93M
    return getObjectFormat() == Triple::MachO;
614
3.93M
  }
615
616
  /// Tests whether the OS uses the Wasm binary format.
617
723
  bool isOSBinFormatWasm() const {
618
723
    return getObjectFormat() == Triple::Wasm;
619
723
  }
620
621
  /// Tests whether the target is the PS4 CPU
622
140k
  bool isPS4CPU() const {
623
140k
    return getArch() == Triple::x86_64 &&
624
140k
           
getVendor() == Triple::SCEI64.5k
&&
625
140k
           
getOS() == Triple::PS4733
;
626
140k
  }
627
628
  /// Tests whether the target is the PS4 platform
629
97.1k
  bool isPS4() const {
630
97.1k
    return getVendor() == Triple::SCEI &&
631
97.1k
           
getOS() == Triple::PS4452
;
632
97.1k
  }
633
634
  /// Tests whether the target is Android
635
2.47M
  bool isAndroid() const { return getEnvironment() == Triple::Android; }
636
637
1.15k
  bool isAndroidVersionLT(unsigned Major) const {
638
1.15k
    assert(isAndroid() && "Not an Android triple!");
639
1.15k
640
1.15k
    unsigned Env[3];
641
1.15k
    getEnvironmentVersion(Env[0], Env[1], Env[2]);
642
1.15k
643
1.15k
    // 64-bit targets did not exist before API level 21 (Lollipop).
644
1.15k
    if (isArch64Bit() && 
Env[0] < 21418
)
645
373
      Env[0] = 21;
646
1.15k
647
1.15k
    return Env[0] < Major;
648
1.15k
  }
649
650
  /// Tests whether the environment is musl-libc
651
91.1k
  bool isMusl() const {
652
91.1k
    return getEnvironment() == Triple::Musl ||
653
91.1k
           
getEnvironment() == Triple::MuslEABI91.0k
||
654
91.1k
           
getEnvironment() == Triple::MuslEABIHF91.0k
;
655
91.1k
  }
656
657
  /// Tests whether the target is NVPTX (32- or 64-bit).
658
508k
  bool isNVPTX() const {
659
508k
    return getArch() == Triple::nvptx || 
getArch() == Triple::nvptx64506k
;
660
508k
  }
661
662
  /// Tests whether the target is Thumb (little and big endian).
663
69.9k
  bool isThumb() const {
664
69.9k
    return getArch() == Triple::thumb || 
getArch() == Triple::thumbeb54.7k
;
665
69.9k
  }
666
667
  /// Tests whether the target is ARM (little and big endian).
668
386k
  bool isARM() const {
669
386k
    return getArch() == Triple::arm || 
getArch() == Triple::armeb384k
;
670
386k
  }
671
672
  /// Tests whether the target is AArch64 (little and big endian).
673
344k
  bool isAArch64() const {
674
344k
    return getArch() == Triple::aarch64 || 
getArch() == Triple::aarch64_be344k
;
675
344k
  }
676
677
  /// Tests whether the target is MIPS 32-bit (little and big endian).
678
516k
  bool isMIPS32() const {
679
516k
    return getArch() == Triple::mips || 
getArch() == Triple::mipsel508k
;
680
516k
  }
681
682
  /// Tests whether the target is MIPS 64-bit (little and big endian).
683
510k
  bool isMIPS64() const {
684
510k
    return getArch() == Triple::mips64 || 
getArch() == Triple::mips64el506k
;
685
510k
  }
686
687
  /// Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
688
499k
  bool isMIPS() const {
689
499k
    return isMIPS32() || 
isMIPS64()494k
;
690
499k
  }
691
692
  /// Tests whether the target supports comdat
693
434k
  bool supportsCOMDAT() const {
694
434k
    return !isOSBinFormatMachO();
695
434k
  }
696
697
  /// Tests whether the target uses emulated TLS as default.
698
482k
  bool hasDefaultEmulatedTLS() const {
699
482k
    return isAndroid() || 
isOSOpenBSD()481k
||
isWindowsCygwinEnvironment()481k
;
700
482k
  }
701
702
  /// @}
703
  /// @name Mutators
704
  /// @{
705
706
  /// setArch - Set the architecture (first) component of the triple
707
  /// to a known type.
708
  void setArch(ArchType Kind);
709
710
  /// setVendor - Set the vendor (second) component of the triple to a
711
  /// known type.
712
  void setVendor(VendorType Kind);
713
714
  /// setOS - Set the operating system (third) component of the triple
715
  /// to a known type.
716
  void setOS(OSType Kind);
717
718
  /// setEnvironment - Set the environment (fourth) component of the triple
719
  /// to a known type.
720
  void setEnvironment(EnvironmentType Kind);
721
722
  /// setObjectFormat - Set the object file format
723
  void setObjectFormat(ObjectFormatType Kind);
724
725
  /// setTriple - Set all components to the new triple \p Str.
726
  void setTriple(const Twine &Str);
727
728
  /// setArchName - Set the architecture (first) component of the
729
  /// triple by name.
730
  void setArchName(StringRef Str);
731
732
  /// setVendorName - Set the vendor (second) component of the triple
733
  /// by name.
734
  void setVendorName(StringRef Str);
735
736
  /// setOSName - Set the operating system (third) component of the
737
  /// triple by name.
738
  void setOSName(StringRef Str);
739
740
  /// setEnvironmentName - Set the optional environment (fourth)
741
  /// component of the triple by name.
742
  void setEnvironmentName(StringRef Str);
743
744
  /// setOSAndEnvironmentName - Set the operating system and optional
745
  /// environment components with a single string.
746
  void setOSAndEnvironmentName(StringRef Str);
747
748
  /// @}
749
  /// @name Helpers to build variants of a particular triple.
750
  /// @{
751
752
  /// Form a triple with a 32-bit variant of the current architecture.
753
  ///
754
  /// This can be used to move across "families" of architectures where useful.
755
  ///
756
  /// \returns A new triple with a 32-bit architecture or an unknown
757
  ///          architecture if no such variant can be found.
758
  llvm::Triple get32BitArchVariant() const;
759
760
  /// Form a triple with a 64-bit variant of the current architecture.
761
  ///
762
  /// This can be used to move across "families" of architectures where useful.
763
  ///
764
  /// \returns A new triple with a 64-bit architecture or an unknown
765
  ///          architecture if no such variant can be found.
766
  llvm::Triple get64BitArchVariant() const;
767
768
  /// Form a triple with a big endian variant of the current architecture.
769
  ///
770
  /// This can be used to move across "families" of architectures where useful.
771
  ///
772
  /// \returns A new triple with a big endian architecture or an unknown
773
  ///          architecture if no such variant can be found.
774
  llvm::Triple getBigEndianArchVariant() const;
775
776
  /// Form a triple with a little endian variant of the current architecture.
777
  ///
778
  /// This can be used to move across "families" of architectures where useful.
779
  ///
780
  /// \returns A new triple with a little endian architecture or an unknown
781
  ///          architecture if no such variant can be found.
782
  llvm::Triple getLittleEndianArchVariant() const;
783
784
  /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
785
  ///
786
  /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
787
  /// string then the triple's arch name is used.
788
  StringRef getARMCPUForArch(StringRef Arch = StringRef()) const;
789
790
  /// Tests whether the target triple is little endian.
791
  ///
792
  /// \returns true if the triple is little endian, false otherwise.
793
  bool isLittleEndian() const;
794
795
  /// Test whether target triples are compatible.
796
  bool isCompatibleWith(const Triple &Other) const;
797
798
  /// Merge target triples.
799
  std::string merge(const Triple &Other) const;
800
801
  /// @}
802
  /// @name Static helpers for IDs.
803
  /// @{
804
805
  /// getArchTypeName - Get the canonical name for the \p Kind architecture.
806
  static StringRef getArchTypeName(ArchType Kind);
807
808
  /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
809
  /// architecture. This is the prefix used by the architecture specific
810
  /// builtins, and is suitable for passing to \see
811
  /// Intrinsic::getIntrinsicForGCCBuiltin().
812
  ///
813
  /// \return - The architecture prefix, or 0 if none is defined.
814
  static StringRef getArchTypePrefix(ArchType Kind);
815
816
  /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
817
  static StringRef getVendorTypeName(VendorType Kind);
818
819
  /// getOSTypeName - Get the canonical name for the \p Kind operating system.
820
  static StringRef getOSTypeName(OSType Kind);
821
822
  /// getEnvironmentTypeName - Get the canonical name for the \p Kind
823
  /// environment.
824
  static StringRef getEnvironmentTypeName(EnvironmentType Kind);
825
826
  /// @}
827
  /// @name Static helpers for converting alternate architecture names.
828
  /// @{
829
830
  /// getArchTypeForLLVMName - The canonical type for the given LLVM
831
  /// architecture name (e.g., "x86").
832
  static ArchType getArchTypeForLLVMName(StringRef Str);
833
834
  /// @}
835
};
836
837
} // End llvm namespace
838
839
840
#endif