Coverage Report

Created: 2019-07-24 05:18

/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
class Triple {
44
public:
45
  enum ArchType {
46
    UnknownArch,
47
48
    arm,            // ARM (little endian): arm, armv.*, xscale
49
    armeb,          // ARM (big endian): armeb
50
    aarch64,        // AArch64 (little endian): aarch64
51
    aarch64_be,     // AArch64 (big endian): aarch64_be
52
    aarch64_32,     // AArch64 (little endian) ILP32: aarch64_32
53
    arc,            // ARC: Synopsys ARC
54
    avr,            // AVR: Atmel AVR microcontroller
55
    bpfel,          // eBPF or extended BPF or 64-bit BPF (little endian)
56
    bpfeb,          // eBPF or extended BPF or 64-bit BPF (big endian)
57
    hexagon,        // Hexagon: hexagon
58
    mips,           // MIPS: mips, mipsallegrex, mipsr6
59
    mipsel,         // MIPSEL: mipsel, mipsallegrexe, mipsr6el
60
    mips64,         // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
61
    mips64el,       // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
62
    msp430,         // MSP430: msp430
63
    ppc,            // PPC: powerpc
64
    ppc64,          // PPC64: powerpc64, ppu
65
    ppc64le,        // PPC64LE: powerpc64le
66
    r600,           // R600: AMD GPUs HD2XXX - HD6XXX
67
    amdgcn,         // AMDGCN: AMD GCN GPUs
68
    riscv32,        // RISC-V (32-bit): riscv32
69
    riscv64,        // RISC-V (64-bit): riscv64
70
    sparc,          // Sparc: sparc
71
    sparcv9,        // Sparcv9: Sparcv9
72
    sparcel,        // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant
73
    systemz,        // SystemZ: s390x
74
    tce,            // TCE (http://tce.cs.tut.fi/): tce
75
    tcele,          // TCE little endian (http://tce.cs.tut.fi/): tcele
76
    thumb,          // Thumb (little endian): thumb, thumbv.*
77
    thumbeb,        // Thumb (big endian): thumbeb
78
    x86,            // X86: i[3-9]86
79
    x86_64,         // X86-64: amd64, x86_64
80
    xcore,          // XCore: xcore
81
    nvptx,          // NVPTX: 32-bit
82
    nvptx64,        // NVPTX: 64-bit
83
    le32,           // le32: generic little-endian 32-bit CPU (PNaCl)
84
    le64,           // le64: generic little-endian 64-bit CPU (PNaCl)
85
    amdil,          // AMDIL
86
    amdil64,        // AMDIL with 64-bit pointers
87
    hsail,          // AMD HSAIL
88
    hsail64,        // AMD HSAIL with 64-bit pointers
89
    spir,           // SPIR: standard portable IR for OpenCL 32-bit version
90
    spir64,         // SPIR: standard portable IR for OpenCL 64-bit version
91
    kalimba,        // Kalimba: generic kalimba
92
    shave,          // SHAVE: Movidius vector VLIW processors
93
    lanai,          // Lanai: Lanai 32-bit
94
    wasm32,         // WebAssembly with 32-bit pointers
95
    wasm64,         // WebAssembly with 64-bit pointers
96
    renderscript32, // 32-bit RenderScript
97
    renderscript64, // 64-bit RenderScript
98
    LastArchType = renderscript64
99
  };
100
  enum SubArchType {
101
    NoSubArch,
102
103
    ARMSubArch_v8_5a,
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_v8_1m_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
    Hurd,       // GNU/Hurd
190
    WASI,       // Experimental WebAssembly OS
191
    Emscripten,
192
    LastOSType = Emscripten
193
  };
194
  enum EnvironmentType {
195
    UnknownEnvironment,
196
197
    GNU,
198
    GNUABIN32,
199
    GNUABI64,
200
    GNUEABI,
201
    GNUEABIHF,
202
    GNUX32,
203
    CODE16,
204
    EABI,
205
    EABIHF,
206
    ELFv1,
207
    ELFv2,
208
    Android,
209
    Musl,
210
    MuslEABI,
211
    MuslEABIHF,
212
213
    MSVC,
214
    Itanium,
215
    Cygnus,
216
    CoreCLR,
217
    Simulator, // Simulator variants of other systems, e.g., Apple's iOS
218
    MacABI, // Mac Catalyst variant of Apple's iOS deployment target.
219
    LastEnvironmentType = MacABI
220
  };
221
  enum ObjectFormatType {
222
    UnknownObjectFormat,
223
224
    COFF,
225
    ELF,
226
    MachO,
227
    Wasm,
228
    XCOFF,
229
  };
230
231
private:
232
  std::string Data;
233
234
  /// The parsed arch type.
235
  ArchType Arch;
236
237
  /// The parsed subarchitecture type.
238
  SubArchType SubArch;
239
240
  /// The parsed vendor type.
241
  VendorType Vendor;
242
243
  /// The parsed OS type.
244
  OSType OS;
245
246
  /// The parsed Environment type.
247
  EnvironmentType Environment;
248
249
  /// The object format type.
250
  ObjectFormatType ObjectFormat;
251
252
public:
253
  /// @name Constructors
254
  /// @{
255
256
  /// Default constructor is the same as an empty string and leaves all
257
  /// triple fields unknown.
258
  Triple()
259
      : Data(), Arch(), SubArch(), Vendor(), OS(), Environment(),
260
292k
        ObjectFormat() {}
261
262
  explicit Triple(const Twine &Str);
263
  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
264
  Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
265
         const Twine &EnvironmentStr);
266
267
1.64k
  bool operator==(const Triple &Other) const {
268
1.64k
    return Arch == Other.Arch && 
SubArch == Other.SubArch1.56k
&&
269
1.64k
           
Vendor == Other.Vendor1.56k
&&
OS == Other.OS1.55k
&&
270
1.64k
           
Environment == Other.Environment1.55k
&&
271
1.64k
           
ObjectFormat == Other.ObjectFormat1.55k
;
272
1.64k
  }
273
274
1.01k
  bool operator!=(const Triple &Other) const {
275
1.01k
    return !(*this == Other);
276
1.01k
  }
277
278
  /// @}
279
  /// @name Normalization
280
  /// @{
281
282
  /// normalize - Turn an arbitrary machine specification into the canonical
283
  /// triple form (or something sensible that the Triple class understands if
284
  /// nothing better can reasonably be done).  In particular, it handles the
285
  /// common case in which otherwise valid components are in the wrong order.
286
  static std::string normalize(StringRef Str);
287
288
  /// Return the normalized form of this triple's string.
289
142k
  std::string normalize() const { return normalize(Data); }
290
291
  /// @}
292
  /// @name Typed Component Access
293
  /// @{
294
295
  /// getArch - Get the parsed architecture type of this triple.
296
23.1M
  ArchType getArch() const { return Arch; }
297
298
  /// getSubArch - get the parsed subarchitecture type for this triple.
299
109k
  SubArchType getSubArch() const { return SubArch; }
300
301
  /// getVendor - Get the parsed vendor type of this triple.
302
485k
  VendorType getVendor() const { return Vendor; }
303
304
  /// getOS - Get the parsed operating system type of this triple.
305
130M
  OSType getOS() const { return OS; }
306
307
  /// hasEnvironment - Does this triple have the optional environment
308
  /// (fourth) component?
309
29.0k
  bool hasEnvironment() const {
310
29.0k
    return getEnvironmentName() != "";
311
29.0k
  }
312
313
  /// getEnvironment - Get the parsed environment type of this triple.
314
10.2M
  EnvironmentType getEnvironment() const { return Environment; }
315
316
  /// Parse the version number from the OS name component of the
317
  /// triple, if present.
318
  ///
319
  /// For example, "fooos1.2.3" would return (1, 2, 3).
320
  ///
321
  /// If an entry is not defined, it will be returned as 0.
322
  void getEnvironmentVersion(unsigned &Major, unsigned &Minor,
323
                             unsigned &Micro) const;
324
325
  /// getFormat - Get the object format for this triple.
326
14.4M
  ObjectFormatType getObjectFormat() const { return ObjectFormat; }
327
328
  /// getOSVersion - Parse the version number from the OS name component of the
329
  /// triple, if present.
330
  ///
331
  /// For example, "fooos1.2.3" would return (1, 2, 3).
332
  ///
333
  /// If an entry is not defined, it will be returned as 0.
334
  void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
335
336
  /// getOSMajorVersion - Return just the major version number, this is
337
  /// specialized because it is a common query.
338
22.2k
  unsigned getOSMajorVersion() const {
339
22.2k
    unsigned Maj, Min, Micro;
340
22.2k
    getOSVersion(Maj, Min, Micro);
341
22.2k
    return Maj;
342
22.2k
  }
343
344
  /// getMacOSXVersion - Parse the version number as with getOSVersion and then
345
  /// translate generic "darwin" versions to the corresponding OS X versions.
346
  /// This may also be called with IOS triples but the OS X version number is
347
  /// just set to a constant 10.4.0 in that case.  Returns true if successful.
348
  bool getMacOSXVersion(unsigned &Major, unsigned &Minor,
349
                        unsigned &Micro) const;
350
351
  /// getiOSVersion - Parse the version number as with getOSVersion.  This should
352
  /// only be called with IOS or generic triples.
353
  void getiOSVersion(unsigned &Major, unsigned &Minor,
354
                     unsigned &Micro) const;
355
356
  /// getWatchOSVersion - Parse the version number as with getOSVersion.  This
357
  /// should only be called with WatchOS or generic triples.
358
  void getWatchOSVersion(unsigned &Major, unsigned &Minor,
359
                         unsigned &Micro) const;
360
361
  /// @}
362
  /// @name Direct Component Access
363
  /// @{
364
365
421k
  const std::string &str() const { return Data; }
366
367
231k
  const std::string &getTriple() const { return Data; }
368
369
  /// getArchName - Get the architecture (first) component of the
370
  /// triple.
371
  StringRef getArchName() const;
372
373
  /// getVendorName - Get the vendor (second) component of the triple.
374
  StringRef getVendorName() const;
375
376
  /// getOSName - Get the operating system (third) component of the
377
  /// triple.
378
  StringRef getOSName() const;
379
380
  /// getEnvironmentName - Get the optional environment (fourth)
381
  /// component of the triple, or "" if empty.
382
  StringRef getEnvironmentName() const;
383
384
  /// getOSAndEnvironmentName - Get the operating system and optional
385
  /// environment components as a single string (separated by a '-'
386
  /// if the environment component is present).
387
  StringRef getOSAndEnvironmentName() const;
388
389
  /// @}
390
  /// @name Convenience Predicates
391
  /// @{
392
393
  /// Test whether the architecture is 64-bit
394
  ///
395
  /// Note that this tests for 64-bit pointer width, and nothing else. Note
396
  /// that we intentionally expose only three predicates, 64-bit, 32-bit, and
397
  /// 16-bit. The inner details of pointer width for particular architectures
398
  /// is not summed up in the triple, and so only a coarse grained predicate
399
  /// system is provided.
400
  bool isArch64Bit() const;
401
402
  /// Test whether the architecture is 32-bit
403
  ///
404
  /// Note that this tests for 32-bit pointer width, and nothing else.
405
  bool isArch32Bit() const;
406
407
  /// Test whether the architecture is 16-bit
408
  ///
409
  /// Note that this tests for 16-bit pointer width, and nothing else.
410
  bool isArch16Bit() const;
411
412
  /// isOSVersionLT - Helper function for doing comparisons against version
413
  /// numbers included in the target triple.
414
  bool isOSVersionLT(unsigned Major, unsigned Minor = 0,
415
244k
                     unsigned Micro = 0) const {
416
244k
    unsigned LHS[3];
417
244k
    getOSVersion(LHS[0], LHS[1], LHS[2]);
418
244k
419
244k
    if (LHS[0] != Major)
420
188k
      return LHS[0] < Major;
421
55.1k
    if (LHS[1] != Minor)
422
43.4k
      return LHS[1] < Minor;
423
11.6k
    if (LHS[2] != Micro)
424
48
      return LHS[2] < Micro;
425
11.6k
426
11.6k
    return false;
427
11.6k
  }
428
429
75
  bool isOSVersionLT(const Triple &Other) const {
430
75
    unsigned RHS[3];
431
75
    Other.getOSVersion(RHS[0], RHS[1], RHS[2]);
432
75
    return isOSVersionLT(RHS[0], RHS[1], RHS[2]);
433
75
  }
434
435
  /// isMacOSXVersionLT - Comparison function for checking OS X version
436
  /// compatibility, which handles supporting skewed version numbering schemes
437
  /// used by the "darwin" triples.
438
  bool isMacOSXVersionLT(unsigned Major, unsigned Minor = 0,
439
94.1k
                         unsigned Micro = 0) const {
440
94.1k
    assert(isMacOSX() && "Not an OS X triple!");
441
94.1k
442
94.1k
    // If this is OS X, expect a sane version number.
443
94.1k
    if (getOS() == Triple::MacOSX)
444
41.5k
      return isOSVersionLT(Major, Minor, Micro);
445
52.6k
446
52.6k
    // Otherwise, compare to the "Darwin" number.
447
52.6k
    assert(Major == 10 && "Unexpected major version");
448
52.6k
    return isOSVersionLT(Minor + 4, Micro, 0);
449
52.6k
  }
450
451
  /// isMacOSX - Is this a Mac OS X triple. For legacy reasons, we support both
452
  /// "darwin" and "osx" as OS X triples.
453
14.9M
  bool isMacOSX() const {
454
14.9M
    return getOS() == Triple::Darwin || 
getOS() == Triple::MacOSX13.8M
;
455
14.9M
  }
456
457
  /// Is this an iOS triple.
458
  /// Note: This identifies tvOS as a variant of iOS. If that ever
459
  /// changes, i.e., if the two operating systems diverge or their version
460
  /// numbers get out of sync, that will need to be changed.
461
  /// watchOS has completely different version numbers so it is not included.
462
12.9M
  bool isiOS() const {
463
12.9M
    return getOS() == Triple::IOS || 
isTvOS()3.42M
;
464
12.9M
  }
465
466
  /// Is this an Apple tvOS triple.
467
4.26M
  bool isTvOS() const {
468
4.26M
    return getOS() == Triple::TvOS;
469
4.26M
  }
470
471
  /// Is this an Apple watchOS triple.
472
4.24M
  bool isWatchOS() const {
473
4.24M
    return getOS() == Triple::WatchOS;
474
4.24M
  }
475
476
81.5k
  bool isWatchABI() const {
477
81.5k
    return getSubArch() == Triple::ARMSubArch_v7k;
478
81.5k
  }
479
480
  /// isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
481
13.9M
  bool isOSDarwin() const {
482
13.9M
    return isMacOSX() || 
isiOS()12.6M
||
isWatchOS()3.28M
;
483
13.9M
  }
484
485
33.7k
  bool isSimulatorEnvironment() const {
486
33.7k
    return getEnvironment() == Triple::Simulator;
487
33.7k
  }
488
489
13.8k
  bool isMacCatalystEnvironment() const {
490
13.8k
    return getEnvironment() == Triple::MacABI;
491
13.8k
  }
492
493
49.1k
  bool isOSNetBSD() const {
494
49.1k
    return getOS() == Triple::NetBSD;
495
49.1k
  }
496
497
604k
  bool isOSOpenBSD() const {
498
604k
    return getOS() == Triple::OpenBSD;
499
604k
  }
500
501
218k
  bool isOSFreeBSD() const {
502
218k
    return getOS() == Triple::FreeBSD;
503
218k
  }
504
505
119k
  bool isOSFuchsia() const {
506
119k
    return getOS() == Triple::Fuchsia;
507
119k
  }
508
509
103
  bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
510
511
134k
  bool isOSSolaris() const {
512
134k
    return getOS() == Triple::Solaris;
513
134k
  }
514
515
424k
  bool isOSIAMCU() const {
516
424k
    return getOS() == Triple::ELFIAMCU;
517
424k
  }
518
519
8.95k
  bool isOSUnknown() const { return getOS() == Triple::UnknownOS; }
520
521
1.05M
  bool isGNUEnvironment() const {
522
1.05M
    EnvironmentType Env = getEnvironment();
523
1.05M
    return Env == Triple::GNU || 
Env == Triple::GNUABIN32977k
||
524
1.05M
           
Env == Triple::GNUABI64977k
||
Env == Triple::GNUEABI977k
||
525
1.05M
           
Env == Triple::GNUEABIHF972k
||
Env == Triple::GNUX32970k
;
526
1.05M
  }
527
528
151
  bool isOSContiki() const {
529
151
    return getOS() == Triple::Contiki;
530
151
  }
531
532
  /// Tests whether the OS is Haiku.
533
0
  bool isOSHaiku() const {
534
0
    return getOS() == Triple::Haiku;
535
0
  }
536
537
  /// Tests whether the OS is Windows.
538
70.8M
  bool isOSWindows() const {
539
70.8M
    return getOS() == Triple::Win32;
540
70.8M
  }
541
542
  /// Checks if the environment is MSVC.
543
11.4M
  bool isKnownWindowsMSVCEnvironment() const {
544
11.4M
    return isOSWindows() && 
getEnvironment() == Triple::MSVC184k
;
545
11.4M
  }
546
547
  /// Checks if the environment could be MSVC.
548
11.4M
  bool isWindowsMSVCEnvironment() const {
549
11.4M
    return isKnownWindowsMSVCEnvironment() ||
550
11.4M
           
(11.2M
isOSWindows()11.2M
&&
getEnvironment() == Triple::UnknownEnvironment12.9k
);
551
11.4M
  }
552
553
445
  bool isWindowsCoreCLREnvironment() const {
554
445
    return isOSWindows() && 
getEnvironment() == Triple::CoreCLR440
;
555
445
  }
556
557
10.7M
  bool isWindowsItaniumEnvironment() const {
558
10.7M
    return isOSWindows() && 
getEnvironment() == Triple::Itanium5.48k
;
559
10.7M
  }
560
561
639k
  bool isWindowsCygwinEnvironment() const {
562
639k
    return isOSWindows() && 
getEnvironment() == Triple::Cygnus14.4k
;
563
639k
  }
564
565
16.5M
  bool isWindowsGNUEnvironment() const {
566
16.5M
    return isOSWindows() && 
getEnvironment() == Triple::GNU91.0k
;
567
16.5M
  }
568
569
  /// Tests for either Cygwin or MinGW OS
570
153k
  bool isOSCygMing() const {
571
153k
    return isWindowsCygwinEnvironment() || 
isWindowsGNUEnvironment()153k
;
572
153k
  }
573
574
  /// Is this a "Windows" OS targeting a "MSVCRT.dll" environment.
575
10.7M
  bool isOSMSVCRT() const {
576
10.7M
    return isWindowsMSVCEnvironment() || 
isWindowsGNUEnvironment()10.6M
||
577
10.7M
           
isWindowsItaniumEnvironment()10.6M
;
578
10.7M
  }
579
580
  /// Tests whether the OS is NaCl (Native Client)
581
1.84M
  bool isOSNaCl() const {
582
1.84M
    return getOS() == Triple::NaCl;
583
1.84M
  }
584
585
  /// Tests whether the OS is Linux.
586
358k
  bool isOSLinux() const {
587
358k
    return getOS() == Triple::Linux;
588
358k
  }
589
590
  /// Tests whether the OS is kFreeBSD.
591
5.56k
  bool isOSKFreeBSD() const {
592
5.56k
    return getOS() == Triple::KFreeBSD;
593
5.56k
  }
594
595
  /// Tests whether the OS is Hurd.
596
21.6k
  bool isOSHurd() const {
597
21.6k
    return getOS() == Triple::Hurd;
598
21.6k
  }
599
600
  /// Tests whether the OS is WASI.
601
0
  bool isOSWASI() const {
602
0
    return getOS() == Triple::WASI;
603
0
  }
604
605
  /// Tests whether the OS is Emscripten.
606
1.16k
  bool isOSEmscripten() const {
607
1.16k
    return getOS() == Triple::Emscripten;
608
1.16k
  }
609
610
  /// Tests whether the OS uses glibc.
611
1.45k
  bool isOSGlibc() const {
612
1.45k
    return (getOS() == Triple::Linux || 
getOS() == Triple::KFreeBSD830
||
613
1.45k
            
getOS() == Triple::Hurd826
) &&
614
1.45k
           
!isAndroid()625
;
615
1.45k
  }
616
617
  /// Tests whether the OS is AIX.
618
273k
  bool isOSAIX() const {
619
273k
    return getOS() == Triple::AIX;
620
273k
  }
621
622
  /// Tests whether the OS uses the ELF binary format.
623
2.28M
  bool isOSBinFormatELF() const {
624
2.28M
    return getObjectFormat() == Triple::ELF;
625
2.28M
  }
626
627
  /// Tests whether the OS uses the COFF binary format.
628
7.96M
  bool isOSBinFormatCOFF() const {
629
7.96M
    return getObjectFormat() == Triple::COFF;
630
7.96M
  }
631
632
  /// Tests whether the environment is MachO.
633
3.99M
  bool isOSBinFormatMachO() const {
634
3.99M
    return getObjectFormat() == Triple::MachO;
635
3.99M
  }
636
637
  /// Tests whether the OS uses the Wasm binary format.
638
3.24k
  bool isOSBinFormatWasm() const {
639
3.24k
    return getObjectFormat() == Triple::Wasm;
640
3.24k
  }
641
642
  /// Tests whether the OS uses the XCOFF binary format.
643
55.2k
  bool isOSBinFormatXCOFF() const {
644
55.2k
    return getObjectFormat() == Triple::XCOFF;
645
55.2k
  }
646
647
  /// Tests whether the target is the PS4 CPU
648
146k
  bool isPS4CPU() const {
649
146k
    return getArch() == Triple::x86_64 &&
650
146k
           
getVendor() == Triple::SCEI69.8k
&&
651
146k
           
getOS() == Triple::PS4749
;
652
146k
  }
653
654
  /// Tests whether the target is the PS4 platform
655
102k
  bool isPS4() const {
656
102k
    return getVendor() == Triple::SCEI &&
657
102k
           
getOS() == Triple::PS4462
;
658
102k
  }
659
660
  /// Tests whether the target is Android
661
2.50M
  bool isAndroid() const { return getEnvironment() == Triple::Android; }
662
663
1.17k
  bool isAndroidVersionLT(unsigned Major) const {
664
1.17k
    assert(isAndroid() && "Not an Android triple!");
665
1.17k
666
1.17k
    unsigned Env[3];
667
1.17k
    getEnvironmentVersion(Env[0], Env[1], Env[2]);
668
1.17k
669
1.17k
    // 64-bit targets did not exist before API level 21 (Lollipop).
670
1.17k
    if (isArch64Bit() && 
Env[0] < 21434
)
671
389
      Env[0] = 21;
672
1.17k
673
1.17k
    return Env[0] < Major;
674
1.17k
  }
675
676
  /// Tests whether the environment is musl-libc
677
100k
  bool isMusl() const {
678
100k
    return getEnvironment() == Triple::Musl ||
679
100k
           
getEnvironment() == Triple::MuslEABI100k
||
680
100k
           
getEnvironment() == Triple::MuslEABIHF100k
;
681
100k
  }
682
683
  /// Tests whether the target is SPIR (32- or 64-bit).
684
46.3k
  bool isSPIR() const {
685
46.3k
    return getArch() == Triple::spir || 
getArch() == Triple::spir6445.9k
;
686
46.3k
  }
687
688
  /// Tests whether the target is NVPTX (32- or 64-bit).
689
530k
  bool isNVPTX() const {
690
530k
    return getArch() == Triple::nvptx || 
getArch() == Triple::nvptx64528k
;
691
530k
  }
692
693
  /// Tests whether the target is Thumb (little and big endian).
694
76.5k
  bool isThumb() const {
695
76.5k
    return getArch() == Triple::thumb || 
getArch() == Triple::thumbeb60.0k
;
696
76.5k
  }
697
698
  /// Tests whether the target is ARM (little and big endian).
699
391k
  bool isARM() const {
700
391k
    return getArch() == Triple::arm || 
getArch() == Triple::armeb389k
;
701
391k
  }
702
703
  /// Tests whether the target is AArch64 (little and big endian).
704
346k
  bool isAArch64() const {
705
346k
    return getArch() == Triple::aarch64 || 
getArch() == Triple::aarch64_be345k
;
706
346k
  }
707
708
  /// Tests whether the target is MIPS 32-bit (little and big endian).
709
528k
  bool isMIPS32() const {
710
528k
    return getArch() == Triple::mips || 
getArch() == Triple::mipsel520k
;
711
528k
  }
712
713
  /// Tests whether the target is MIPS 64-bit (little and big endian).
714
522k
  bool isMIPS64() const {
715
522k
    return getArch() == Triple::mips64 || 
getArch() == Triple::mips64el518k
;
716
522k
  }
717
718
  /// Tests whether the target is MIPS (little and big endian, 32- or 64-bit).
719
510k
  bool isMIPS() const {
720
510k
    return isMIPS32() || 
isMIPS64()505k
;
721
510k
  }
722
723
  /// Tests whether the target is 64-bit PowerPC (little and big endian).
724
155k
  bool isPPC64() const {
725
155k
    return getArch() == Triple::ppc64 || 
getArch() == Triple::ppc64le152k
;
726
155k
  }
727
728
  /// Tests whether the target is RISC-V (32- and 64-bit).
729
3.44k
  bool isRISCV() const {
730
3.44k
    return getArch() == Triple::riscv32 || 
getArch() == Triple::riscv643.42k
;
731
3.44k
  }
732
733
  /// Tests whether the target supports comdat
734
450k
  bool supportsCOMDAT() const {
735
450k
    return !isOSBinFormatMachO();
736
450k
  }
737
738
  /// Tests whether the target uses emulated TLS as default.
739
486k
  bool hasDefaultEmulatedTLS() const {
740
486k
    return isAndroid() || 
isOSOpenBSD()486k
||
isWindowsCygwinEnvironment()486k
;
741
486k
  }
742
743
  /// @}
744
  /// @name Mutators
745
  /// @{
746
747
  /// setArch - Set the architecture (first) component of the triple
748
  /// to a known type.
749
  void setArch(ArchType Kind);
750
751
  /// setVendor - Set the vendor (second) component of the triple to a
752
  /// known type.
753
  void setVendor(VendorType Kind);
754
755
  /// setOS - Set the operating system (third) component of the triple
756
  /// to a known type.
757
  void setOS(OSType Kind);
758
759
  /// setEnvironment - Set the environment (fourth) component of the triple
760
  /// to a known type.
761
  void setEnvironment(EnvironmentType Kind);
762
763
  /// setObjectFormat - Set the object file format
764
  void setObjectFormat(ObjectFormatType Kind);
765
766
  /// setTriple - Set all components to the new triple \p Str.
767
  void setTriple(const Twine &Str);
768
769
  /// setArchName - Set the architecture (first) component of the
770
  /// triple by name.
771
  void setArchName(StringRef Str);
772
773
  /// setVendorName - Set the vendor (second) component of the triple
774
  /// by name.
775
  void setVendorName(StringRef Str);
776
777
  /// setOSName - Set the operating system (third) component of the
778
  /// triple by name.
779
  void setOSName(StringRef Str);
780
781
  /// setEnvironmentName - Set the optional environment (fourth)
782
  /// component of the triple by name.
783
  void setEnvironmentName(StringRef Str);
784
785
  /// setOSAndEnvironmentName - Set the operating system and optional
786
  /// environment components with a single string.
787
  void setOSAndEnvironmentName(StringRef Str);
788
789
  /// @}
790
  /// @name Helpers to build variants of a particular triple.
791
  /// @{
792
793
  /// Form a triple with a 32-bit variant of the current architecture.
794
  ///
795
  /// This can be used to move across "families" of architectures where useful.
796
  ///
797
  /// \returns A new triple with a 32-bit architecture or an unknown
798
  ///          architecture if no such variant can be found.
799
  llvm::Triple get32BitArchVariant() const;
800
801
  /// Form a triple with a 64-bit variant of the current architecture.
802
  ///
803
  /// This can be used to move across "families" of architectures where useful.
804
  ///
805
  /// \returns A new triple with a 64-bit architecture or an unknown
806
  ///          architecture if no such variant can be found.
807
  llvm::Triple get64BitArchVariant() const;
808
809
  /// Form a triple with a big endian variant of the current architecture.
810
  ///
811
  /// This can be used to move across "families" of architectures where useful.
812
  ///
813
  /// \returns A new triple with a big endian architecture or an unknown
814
  ///          architecture if no such variant can be found.
815
  llvm::Triple getBigEndianArchVariant() const;
816
817
  /// Form a triple with a little endian variant of the current architecture.
818
  ///
819
  /// This can be used to move across "families" of architectures where useful.
820
  ///
821
  /// \returns A new triple with a little endian architecture or an unknown
822
  ///          architecture if no such variant can be found.
823
  llvm::Triple getLittleEndianArchVariant() const;
824
825
  /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
826
  ///
827
  /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
828
  /// string then the triple's arch name is used.
829
  StringRef getARMCPUForArch(StringRef Arch = StringRef()) const;
830
831
  /// Tests whether the target triple is little endian.
832
  ///
833
  /// \returns true if the triple is little endian, false otherwise.
834
  bool isLittleEndian() const;
835
836
  /// Test whether target triples are compatible.
837
  bool isCompatibleWith(const Triple &Other) const;
838
839
  /// Merge target triples.
840
  std::string merge(const Triple &Other) const;
841
842
  /// @}
843
  /// @name Static helpers for IDs.
844
  /// @{
845
846
  /// getArchTypeName - Get the canonical name for the \p Kind architecture.
847
  static StringRef getArchTypeName(ArchType Kind);
848
849
  /// getArchTypePrefix - Get the "prefix" canonical name for the \p Kind
850
  /// architecture. This is the prefix used by the architecture specific
851
  /// builtins, and is suitable for passing to \see
852
  /// Intrinsic::getIntrinsicForGCCBuiltin().
853
  ///
854
  /// \return - The architecture prefix, or 0 if none is defined.
855
  static StringRef getArchTypePrefix(ArchType Kind);
856
857
  /// getVendorTypeName - Get the canonical name for the \p Kind vendor.
858
  static StringRef getVendorTypeName(VendorType Kind);
859
860
  /// getOSTypeName - Get the canonical name for the \p Kind operating system.
861
  static StringRef getOSTypeName(OSType Kind);
862
863
  /// getEnvironmentTypeName - Get the canonical name for the \p Kind
864
  /// environment.
865
  static StringRef getEnvironmentTypeName(EnvironmentType Kind);
866
867
  /// @}
868
  /// @name Static helpers for converting alternate architecture names.
869
  /// @{
870
871
  /// getArchTypeForLLVMName - The canonical type for the given LLVM
872
  /// architecture name (e.g., "x86").
873
  static ArchType getArchTypeForLLVMName(StringRef Str);
874
875
  /// @}
876
};
877
878
} // End llvm namespace
879
880
881
#endif