Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/Triple.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- Triple.cpp - Target triple helper class --------------------------===//
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
#include "llvm/ADT/Triple.h"
10
#include "llvm/ADT/STLExtras.h"
11
#include "llvm/ADT/SmallString.h"
12
#include "llvm/ADT/StringSwitch.h"
13
#include "llvm/Support/ErrorHandling.h"
14
#include "llvm/Support/Host.h"
15
#include "llvm/Support/TargetParser.h"
16
#include <cstring>
17
using namespace llvm;
18
19
86.0k
StringRef Triple::getArchTypeName(ArchType Kind) {
20
86.0k
  switch (Kind) {
21
86.0k
  
case UnknownArch: return "unknown"521
;
22
86.0k
23
86.0k
  
case aarch64: return "aarch64"30.3k
;
24
86.0k
  
case aarch64_be: return "aarch64_be"277
;
25
86.0k
  
case aarch64_32: return "aarch64_32"1
;
26
86.0k
  
case arm: return "arm"9.83k
;
27
86.0k
  
case armeb: return "armeb"137
;
28
86.0k
  
case arc: return "arc"1
;
29
86.0k
  
case avr: return "avr"9
;
30
86.0k
  
case bpfel: return "bpfel"146
;
31
86.0k
  
case bpfeb: return "bpfeb"89
;
32
86.0k
  
case hexagon: return "hexagon"1.18k
;
33
86.0k
  
case mips: return "mips"1.25k
;
34
86.0k
  
case mipsel: return "mipsel"953
;
35
86.0k
  
case mips64: return "mips64"809
;
36
86.0k
  
case mips64el: return "mips64el"443
;
37
86.0k
  
case msp430: return "msp430"75
;
38
86.0k
  
case ppc64: return "powerpc64"291
;
39
86.0k
  
case ppc64le: return "powerpc64le"277
;
40
86.0k
  
case ppc: return "powerpc"267
;
41
86.0k
  
case r600: return "r600"366
;
42
86.0k
  
case amdgcn: return "amdgcn"3.00k
;
43
86.0k
  
case riscv32: return "riscv32"311
;
44
86.0k
  
case riscv64: return "riscv64"278
;
45
86.0k
  
case sparc: return "sparc"264
;
46
86.0k
  
case sparcv9: return "sparcv9"179
;
47
86.0k
  
case sparcel: return "sparcel"35
;
48
86.0k
  
case systemz: return "s390x"58
;
49
86.0k
  
case tce: return "tce"3
;
50
86.0k
  
case tcele: return "tcele"3
;
51
86.0k
  
case thumb: return "thumb"89
;
52
86.0k
  
case thumbeb: return "thumbeb"22
;
53
86.0k
  
case x86: return "i386"6.07k
;
54
86.0k
  
case x86_64: return "x86_64"27.5k
;
55
86.0k
  
case xcore: return "xcore"79
;
56
86.0k
  
case nvptx: return "nvptx"186
;
57
86.0k
  
case nvptx64: return "nvptx64"377
;
58
86.0k
  
case le32: return "le32"9
;
59
86.0k
  
case le64: return "le64"6
;
60
86.0k
  
case amdil: return "amdil"4
;
61
86.0k
  
case amdil64: return "amdil64"4
;
62
86.0k
  
case hsail: return "hsail"4
;
63
86.0k
  
case hsail64: return "hsail64"4
;
64
86.0k
  
case spir: return "spir"4
;
65
86.0k
  
case spir64: return "spir64"4
;
66
86.0k
  
case kalimba: return "kalimba"1
;
67
86.0k
  
case lanai: return "lanai"23
;
68
86.0k
  
case shave: return "shave"8
;
69
86.0k
  
case wasm32: return "wasm32"91
;
70
86.0k
  
case wasm64: return "wasm64"29
;
71
86.0k
  
case renderscript32: return "renderscript32"3
;
72
86.0k
  
case renderscript64: return "renderscript64"3
;
73
0
  }
74
0
75
0
  llvm_unreachable("Invalid ArchType!");
76
0
}
77
78
35.4k
StringRef Triple::getArchTypePrefix(ArchType Kind) {
79
35.4k
  switch (Kind) {
80
35.4k
  default:
81
0
    return StringRef();
82
35.4k
83
35.4k
  case aarch64:
84
10.6k
  case aarch64_be:
85
10.6k
  case aarch64_32:  return "aarch64";
86
10.6k
87
10.6k
  
case arc: return "arc"0
;
88
10.6k
89
10.6k
  case arm:
90
1.91k
  case armeb:
91
1.91k
  case thumb:
92
1.91k
  case thumbeb:     return "arm";
93
1.91k
94
1.91k
  
case avr: return "avr"0
;
95
1.91k
96
4.61k
  case ppc64:
97
4.61k
  case ppc64le:
98
4.61k
  case ppc:         return "ppc";
99
4.61k
100
4.61k
  case mips:
101
755
  case mipsel:
102
755
  case mips64:
103
755
  case mips64el:    return "mips";
104
755
105
1.72k
  case hexagon:     return "hexagon";
106
755
107
755
  
case amdgcn: return "amdgcn"304
;
108
755
  
case r600: return "r600"8
;
109
755
110
755
  case bpfel:
111
0
  case bpfeb:       return "bpf";
112
0
113
0
  case sparcv9:
114
0
  case sparcel:
115
0
  case sparc:       return "sparc";
116
0
117
2.98k
  case systemz:     return "s390";
118
0
119
10.8k
  case x86:
120
10.8k
  case x86_64:      return "x86";
121
10.8k
122
10.8k
  
case xcore: return "xcore"4
;
123
10.8k
124
10.8k
  // NVPTX intrinsics are namespaced under nvvm.
125
10.8k
  
case nvptx: return "nvvm"784
;
126
10.8k
  
case nvptx64: return "nvvm"811
;
127
10.8k
128
10.8k
  
case le32: return "le32"0
;
129
10.8k
  
case le64: return "le64"0
;
130
10.8k
131
10.8k
  case amdil:
132
0
  case amdil64:     return "amdil";
133
0
134
0
  case hsail:
135
0
  case hsail64:     return "hsail";
136
0
137
0
  case spir:
138
0
  case spir64:      return "spir";
139
0
  case kalimba:     return "kalimba";
140
0
  case lanai:       return "lanai";
141
0
  case shave:       return "shave";
142
159
  case wasm32:
143
159
  case wasm64:      return "wasm";
144
159
145
159
  case riscv32:
146
0
  case riscv64:     return "riscv";
147
35.4k
  }
148
35.4k
}
149
150
1.33k
StringRef Triple::getVendorTypeName(VendorType Kind) {
151
1.33k
  switch (Kind) {
152
1.33k
  
case UnknownVendor: return "unknown"817
;
153
1.33k
154
1.33k
  
case Apple: return "apple"2
;
155
1.33k
  
case PC: return "pc"499
;
156
1.33k
  
case SCEI: return "scei"1
;
157
1.33k
  
case BGP: return "bgp"1
;
158
1.33k
  
case BGQ: return "bgq"1
;
159
1.33k
  
case Freescale: return "fsl"1
;
160
1.33k
  
case IBM: return "ibm"1
;
161
1.33k
  
case ImaginationTechnologies: return "img"1
;
162
1.33k
  
case MipsTechnologies: return "mti"1
;
163
1.33k
  
case NVIDIA: return "nvidia"1
;
164
1.33k
  
case CSR: return "csr"1
;
165
1.33k
  
case Myriad: return "myriad"1
;
166
1.33k
  
case AMD: return "amd"1
;
167
1.33k
  
case Mesa: return "mesa"1
;
168
1.33k
  
case SUSE: return "suse"1
;
169
1.33k
  
case OpenEmbedded: return "oe"1
;
170
0
  }
171
0
172
0
  llvm_unreachable("Invalid VendorType!");
173
0
}
174
175
334k
StringRef Triple::getOSTypeName(OSType Kind) {
176
334k
  switch (Kind) {
177
334k
  
case UnknownOS: return "unknown"4.01k
;
178
334k
179
334k
  
case Ananas: return "ananas"2
;
180
334k
  
case CloudABI: return "cloudabi"1
;
181
334k
  
case Darwin: return "darwin"86.2k
;
182
334k
  
case DragonFly: return "dragonfly"1
;
183
334k
  
case FreeBSD: return "freebsd"220
;
184
334k
  
case Fuchsia: return "fuchsia"1
;
185
334k
  
case IOS: return "ios"175k
;
186
334k
  
case KFreeBSD: return "kfreebsd"1
;
187
334k
  
case Linux: return "linux"14
;
188
334k
  
case Lv2: return "lv2"1
;
189
334k
  
case MacOSX: return "macosx"66.9k
;
190
334k
  
case NetBSD: return "netbsd"229
;
191
334k
  
case OpenBSD: return "openbsd"1
;
192
334k
  
case Solaris: return "solaris"1
;
193
334k
  
case Win32: return "windows"504
;
194
334k
  
case Haiku: return "haiku"1
;
195
334k
  
case Minix: return "minix"1
;
196
334k
  
case RTEMS: return "rtems"1
;
197
334k
  
case NaCl: return "nacl"1
;
198
334k
  
case CNK: return "cnk"1
;
199
334k
  
case AIX: return "aix"22
;
200
334k
  
case CUDA: return "cuda"1
;
201
334k
  
case NVCL: return "nvcl"1
;
202
334k
  
case AMDHSA: return "amdhsa"1
;
203
334k
  
case PS4: return "ps4"1
;
204
334k
  
case ELFIAMCU: return "elfiamcu"9
;
205
334k
  
case TvOS: return "tvos"245
;
206
334k
  
case WatchOS: return "watchos"234
;
207
334k
  
case Mesa3D: return "mesa3d"1
;
208
334k
  
case Contiki: return "contiki"1
;
209
334k
  
case AMDPAL: return "amdpal"1
;
210
334k
  
case HermitCore: return "hermit"1
;
211
334k
  
case Hurd: return "hurd"1
;
212
334k
  
case WASI: return "wasi"1
;
213
334k
  
case Emscripten: return "emscripten"1
;
214
0
  }
215
0
216
0
  llvm_unreachable("Invalid OSType");
217
0
}
218
219
6.59k
StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
220
6.59k
  switch (Kind) {
221
6.59k
  
case UnknownEnvironment: return "unknown"35
;
222
6.59k
  
case GNU: return "gnu"5
;
223
6.59k
  
case GNUABIN32: return "gnuabin32"39
;
224
6.59k
  
case GNUABI64: return "gnuabi64"40
;
225
6.59k
  
case GNUEABIHF: return "gnueabihf"4
;
226
6.59k
  
case GNUEABI: return "gnueabi"1
;
227
6.59k
  
case GNUX32: return "gnux32"3
;
228
6.59k
  
case CODE16: return "code16"2
;
229
6.59k
  
case EABI: return "eabi"1
;
230
6.59k
  
case EABIHF: return "eabihf"1
;
231
6.59k
  
case ELFv1: return "elfv1"1
;
232
6.59k
  
case ELFv2: return "elfv2"1
;
233
6.59k
  
case Android: return "android"1.40k
;
234
6.59k
  
case Musl: return "musl"1
;
235
6.59k
  
case MuslEABI: return "musleabi"1
;
236
6.59k
  
case MuslEABIHF: return "musleabihf"1
;
237
6.59k
  
case MSVC: return "msvc"4.11k
;
238
6.59k
  
case Itanium: return "itanium"1
;
239
6.59k
  
case Cygnus: return "cygnus"1
;
240
6.59k
  
case CoreCLR: return "coreclr"1
;
241
6.59k
  
case Simulator: return "simulator"934
;
242
6.59k
  
case MacABI: return "macabi"1
;
243
0
  }
244
0
245
0
  llvm_unreachable("Invalid EnvironmentType!");
246
0
}
247
248
8.07k
static Triple::ArchType parseBPFArch(StringRef ArchName) {
249
8.07k
  if (ArchName.equals("bpf")) {
250
33
    if (sys::IsLittleEndianHost)
251
33
      return Triple::bpfel;
252
0
    else
253
0
      return Triple::bpfeb;
254
8.04k
  } else if (ArchName.equals("bpf_be") || ArchName.equals("bpfeb")) {
255
599
    return Triple::bpfeb;
256
7.44k
  } else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) {
257
989
    return Triple::bpfel;
258
6.45k
  } else {
259
6.45k
    return Triple::UnknownArch;
260
6.45k
  }
261
8.07k
}
262
263
6.66k
Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
264
6.66k
  Triple::ArchType BPFArch(parseBPFArch(Name));
265
6.66k
  return StringSwitch<Triple::ArchType>(Name)
266
6.66k
    .Case("aarch64", aarch64)
267
6.66k
    .Case("aarch64_be", aarch64_be)
268
6.66k
    .Case("aarch64_32", aarch64_32)
269
6.66k
    .Case("arc", arc)
270
6.66k
    .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
271
6.66k
    .Case("arm64_32", aarch64_32)
272
6.66k
    .Case("arm", arm)
273
6.66k
    .Case("armeb", armeb)
274
6.66k
    .Case("avr", avr)
275
6.66k
    .StartsWith("bpf", BPFArch)
276
6.66k
    .Case("mips", mips)
277
6.66k
    .Case("mipsel", mipsel)
278
6.66k
    .Case("mips64", mips64)
279
6.66k
    .Case("mips64el", mips64el)
280
6.66k
    .Case("msp430", msp430)
281
6.66k
    .Case("ppc64", ppc64)
282
6.66k
    .Case("ppc32", ppc)
283
6.66k
    .Case("ppc", ppc)
284
6.66k
    .Case("ppc64le", ppc64le)
285
6.66k
    .Case("r600", r600)
286
6.66k
    .Case("amdgcn", amdgcn)
287
6.66k
    .Case("riscv32", riscv32)
288
6.66k
    .Case("riscv64", riscv64)
289
6.66k
    .Case("hexagon", hexagon)
290
6.66k
    .Case("sparc", sparc)
291
6.66k
    .Case("sparcel", sparcel)
292
6.66k
    .Case("sparcv9", sparcv9)
293
6.66k
    .Case("systemz", systemz)
294
6.66k
    .Case("tce", tce)
295
6.66k
    .Case("tcele", tcele)
296
6.66k
    .Case("thumb", thumb)
297
6.66k
    .Case("thumbeb", thumbeb)
298
6.66k
    .Case("x86", x86)
299
6.66k
    .Case("x86-64", x86_64)
300
6.66k
    .Case("xcore", xcore)
301
6.66k
    .Case("nvptx", nvptx)
302
6.66k
    .Case("nvptx64", nvptx64)
303
6.66k
    .Case("le32", le32)
304
6.66k
    .Case("le64", le64)
305
6.66k
    .Case("amdil", amdil)
306
6.66k
    .Case("amdil64", amdil64)
307
6.66k
    .Case("hsail", hsail)
308
6.66k
    .Case("hsail64", hsail64)
309
6.66k
    .Case("spir", spir)
310
6.66k
    .Case("spir64", spir64)
311
6.66k
    .Case("kalimba", kalimba)
312
6.66k
    .Case("lanai", lanai)
313
6.66k
    .Case("shave", shave)
314
6.66k
    .Case("wasm32", wasm32)
315
6.66k
    .Case("wasm64", wasm64)
316
6.66k
    .Case("renderscript32", renderscript32)
317
6.66k
    .Case("renderscript64", renderscript64)
318
6.66k
    .Default(UnknownArch);
319
6.66k
}
320
321
125k
static Triple::ArchType parseARMArch(StringRef ArchName) {
322
125k
  ARM::ISAKind ISA = ARM::parseArchISA(ArchName);
323
125k
  ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName);
324
125k
325
125k
  Triple::ArchType arch = Triple::UnknownArch;
326
125k
  switch (ENDIAN) {
327
125k
  case ARM::EndianKind::LITTLE: {
328
123k
    switch (ISA) {
329
123k
    case ARM::ISAKind::ARM:
330
30.7k
      arch = Triple::arm;
331
30.7k
      break;
332
123k
    case ARM::ISAKind::THUMB:
333
93.2k
      arch = Triple::thumb;
334
93.2k
      break;
335
123k
    case ARM::ISAKind::AARCH64:
336
8
      arch = Triple::aarch64;
337
8
      break;
338
123k
    case ARM::ISAKind::INVALID:
339
0
      break;
340
123k
    }
341
123k
    break;
342
123k
  }
343
123k
  case ARM::EndianKind::BIG: {
344
1.19k
    switch (ISA) {
345
1.19k
    case ARM::ISAKind::ARM:
346
778
      arch = Triple::armeb;
347
778
      break;
348
1.19k
    case ARM::ISAKind::THUMB:
349
398
      arch = Triple::thumbeb;
350
398
      break;
351
1.19k
    case ARM::ISAKind::AARCH64:
352
17
      arch = Triple::aarch64_be;
353
17
      break;
354
1.19k
    case ARM::ISAKind::INVALID:
355
0
      break;
356
1.19k
    }
357
1.19k
    break;
358
1.19k
  }
359
1.19k
  case ARM::EndianKind::INVALID: {
360
0
    break;
361
125k
  }
362
125k
  }
363
125k
364
125k
  ArchName = ARM::getCanonicalArchName(ArchName);
365
125k
  if (ArchName.empty())
366
35
    return Triple::UnknownArch;
367
125k
368
125k
  // Thumb only exists in v4+
369
125k
  if (ISA == ARM::ISAKind::THUMB &&
370
125k
      
(93.6k
ArchName.startswith("v2")93.6k
||
ArchName.startswith("v3")93.5k
))
371
8
    return Triple::UnknownArch;
372
125k
373
125k
  // Thumb only for v6m
374
125k
  ARM::ProfileKind Profile = ARM::parseArchProfile(ArchName);
375
125k
  unsigned Version = ARM::parseArchVersion(ArchName);
376
125k
  if (Profile == ARM::ProfileKind::M && 
Version == 621.1k
) {
377
4.66k
    if (ENDIAN == ARM::EndianKind::BIG)
378
4
      return Triple::thumbeb;
379
4.66k
    else
380
4.66k
      return Triple::thumb;
381
120k
  }
382
120k
383
120k
  return arch;
384
120k
}
385
386
2.07M
static Triple::ArchType parseArch(StringRef ArchName) {
387
2.07M
  auto AT = StringSwitch<Triple::ArchType>(ArchName)
388
2.07M
    .Cases("i386", "i486", "i586", "i686", Triple::x86)
389
2.07M
    // FIXME: Do we need to support these?
390
2.07M
    .Cases("i786", "i886", "i986", Triple::x86)
391
2.07M
    .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
392
2.07M
    .Cases("powerpc", "ppc", "ppc32", Triple::ppc)
393
2.07M
    .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64)
394
2.07M
    .Cases("powerpc64le", "ppc64le", Triple::ppc64le)
395
2.07M
    .Case("xscale", Triple::arm)
396
2.07M
    .Case("xscaleeb", Triple::armeb)
397
2.07M
    .Case("aarch64", Triple::aarch64)
398
2.07M
    .Case("aarch64_be", Triple::aarch64_be)
399
2.07M
    .Case("aarch64_32", Triple::aarch64_32)
400
2.07M
    .Case("arc", Triple::arc)
401
2.07M
    .Case("arm64", Triple::aarch64)
402
2.07M
    .Case("arm64_32", Triple::aarch64_32)
403
2.07M
    .Case("arm", Triple::arm)
404
2.07M
    .Case("armeb", Triple::armeb)
405
2.07M
    .Case("thumb", Triple::thumb)
406
2.07M
    .Case("thumbeb", Triple::thumbeb)
407
2.07M
    .Case("avr", Triple::avr)
408
2.07M
    .Case("msp430", Triple::msp430)
409
2.07M
    .Cases("mips", "mipseb", "mipsallegrex", "mipsisa32r6",
410
2.07M
           "mipsr6", Triple::mips)
411
2.07M
    .Cases("mipsel", "mipsallegrexel", "mipsisa32r6el", "mipsr6el",
412
2.07M
           Triple::mipsel)
413
2.07M
    .Cases("mips64", "mips64eb", "mipsn32", "mipsisa64r6",
414
2.07M
           "mips64r6", "mipsn32r6", Triple::mips64)
415
2.07M
    .Cases("mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el",
416
2.07M
           "mipsn32r6el", Triple::mips64el)
417
2.07M
    .Case("r600", Triple::r600)
418
2.07M
    .Case("amdgcn", Triple::amdgcn)
419
2.07M
    .Case("riscv32", Triple::riscv32)
420
2.07M
    .Case("riscv64", Triple::riscv64)
421
2.07M
    .Case("hexagon", Triple::hexagon)
422
2.07M
    .Cases("s390x", "systemz", Triple::systemz)
423
2.07M
    .Case("sparc", Triple::sparc)
424
2.07M
    .Case("sparcel", Triple::sparcel)
425
2.07M
    .Cases("sparcv9", "sparc64", Triple::sparcv9)
426
2.07M
    .Case("tce", Triple::tce)
427
2.07M
    .Case("tcele", Triple::tcele)
428
2.07M
    .Case("xcore", Triple::xcore)
429
2.07M
    .Case("nvptx", Triple::nvptx)
430
2.07M
    .Case("nvptx64", Triple::nvptx64)
431
2.07M
    .Case("le32", Triple::le32)
432
2.07M
    .Case("le64", Triple::le64)
433
2.07M
    .Case("amdil", Triple::amdil)
434
2.07M
    .Case("amdil64", Triple::amdil64)
435
2.07M
    .Case("hsail", Triple::hsail)
436
2.07M
    .Case("hsail64", Triple::hsail64)
437
2.07M
    .Case("spir", Triple::spir)
438
2.07M
    .Case("spir64", Triple::spir64)
439
2.07M
    .StartsWith("kalimba", Triple::kalimba)
440
2.07M
    .Case("lanai", Triple::lanai)
441
2.07M
    .Case("shave", Triple::shave)
442
2.07M
    .Case("wasm32", Triple::wasm32)
443
2.07M
    .Case("wasm64", Triple::wasm64)
444
2.07M
    .Case("renderscript32", Triple::renderscript32)
445
2.07M
    .Case("renderscript64", Triple::renderscript64)
446
2.07M
    .Default(Triple::UnknownArch);
447
2.07M
448
2.07M
  // Some architectures require special parsing logic just to compute the
449
2.07M
  // ArchType result.
450
2.07M
  if (AT == Triple::UnknownArch) {
451
173k
    if (ArchName.startswith("arm") || 
ArchName.startswith("thumb")141k
||
452
173k
        
ArchName.startswith("aarch64")48.1k
)
453
125k
      return parseARMArch(ArchName);
454
48.1k
    if (ArchName.startswith("bpf"))
455
1.41k
      return parseBPFArch(ArchName);
456
1.94M
  }
457
1.94M
458
1.94M
  return AT;
459
1.94M
}
460
461
2.08M
static Triple::VendorType parseVendor(StringRef VendorName) {
462
2.08M
  return StringSwitch<Triple::VendorType>(VendorName)
463
2.08M
    .Case("apple", Triple::Apple)
464
2.08M
    .Case("pc", Triple::PC)
465
2.08M
    .Case("scei", Triple::SCEI)
466
2.08M
    .Case("bgp", Triple::BGP)
467
2.08M
    .Case("bgq", Triple::BGQ)
468
2.08M
    .Case("fsl", Triple::Freescale)
469
2.08M
    .Case("ibm", Triple::IBM)
470
2.08M
    .Case("img", Triple::ImaginationTechnologies)
471
2.08M
    .Case("mti", Triple::MipsTechnologies)
472
2.08M
    .Case("nvidia", Triple::NVIDIA)
473
2.08M
    .Case("csr", Triple::CSR)
474
2.08M
    .Case("myriad", Triple::Myriad)
475
2.08M
    .Case("amd", Triple::AMD)
476
2.08M
    .Case("mesa", Triple::Mesa)
477
2.08M
    .Case("suse", Triple::SUSE)
478
2.08M
    .Case("oe", Triple::OpenEmbedded)
479
2.08M
    .Default(Triple::UnknownVendor);
480
2.08M
}
481
482
2.04M
static Triple::OSType parseOS(StringRef OSName) {
483
2.04M
  return StringSwitch<Triple::OSType>(OSName)
484
2.04M
    .StartsWith("ananas", Triple::Ananas)
485
2.04M
    .StartsWith("cloudabi", Triple::CloudABI)
486
2.04M
    .StartsWith("darwin", Triple::Darwin)
487
2.04M
    .StartsWith("dragonfly", Triple::DragonFly)
488
2.04M
    .StartsWith("freebsd", Triple::FreeBSD)
489
2.04M
    .StartsWith("fuchsia", Triple::Fuchsia)
490
2.04M
    .StartsWith("ios", Triple::IOS)
491
2.04M
    .StartsWith("kfreebsd", Triple::KFreeBSD)
492
2.04M
    .StartsWith("linux", Triple::Linux)
493
2.04M
    .StartsWith("lv2", Triple::Lv2)
494
2.04M
    .StartsWith("macos", Triple::MacOSX)
495
2.04M
    .StartsWith("netbsd", Triple::NetBSD)
496
2.04M
    .StartsWith("openbsd", Triple::OpenBSD)
497
2.04M
    .StartsWith("solaris", Triple::Solaris)
498
2.04M
    .StartsWith("win32", Triple::Win32)
499
2.04M
    .StartsWith("windows", Triple::Win32)
500
2.04M
    .StartsWith("haiku", Triple::Haiku)
501
2.04M
    .StartsWith("minix", Triple::Minix)
502
2.04M
    .StartsWith("rtems", Triple::RTEMS)
503
2.04M
    .StartsWith("nacl", Triple::NaCl)
504
2.04M
    .StartsWith("cnk", Triple::CNK)
505
2.04M
    .StartsWith("aix", Triple::AIX)
506
2.04M
    .StartsWith("cuda", Triple::CUDA)
507
2.04M
    .StartsWith("nvcl", Triple::NVCL)
508
2.04M
    .StartsWith("amdhsa", Triple::AMDHSA)
509
2.04M
    .StartsWith("ps4", Triple::PS4)
510
2.04M
    .StartsWith("elfiamcu", Triple::ELFIAMCU)
511
2.04M
    .StartsWith("tvos", Triple::TvOS)
512
2.04M
    .StartsWith("watchos", Triple::WatchOS)
513
2.04M
    .StartsWith("mesa3d", Triple::Mesa3D)
514
2.04M
    .StartsWith("contiki", Triple::Contiki)
515
2.04M
    .StartsWith("amdpal", Triple::AMDPAL)
516
2.04M
    .StartsWith("hermit", Triple::HermitCore)
517
2.04M
    .StartsWith("hurd", Triple::Hurd)
518
2.04M
    .StartsWith("wasi", Triple::WASI)
519
2.04M
    .StartsWith("emscripten", Triple::Emscripten)
520
2.04M
    .Default(Triple::UnknownOS);
521
2.04M
}
522
523
661k
static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
524
661k
  return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
525
661k
    .StartsWith("eabihf", Triple::EABIHF)
526
661k
    .StartsWith("eabi", Triple::EABI)
527
661k
    .StartsWith("elfv1", Triple::ELFv1)
528
661k
    .StartsWith("elfv2", Triple::ELFv2)
529
661k
    .StartsWith("gnuabin32", Triple::GNUABIN32)
530
661k
    .StartsWith("gnuabi64", Triple::GNUABI64)
531
661k
    .StartsWith("gnueabihf", Triple::GNUEABIHF)
532
661k
    .StartsWith("gnueabi", Triple::GNUEABI)
533
661k
    .StartsWith("gnux32", Triple::GNUX32)
534
661k
    .StartsWith("code16", Triple::CODE16)
535
661k
    .StartsWith("gnu", Triple::GNU)
536
661k
    .StartsWith("android", Triple::Android)
537
661k
    .StartsWith("musleabihf", Triple::MuslEABIHF)
538
661k
    .StartsWith("musleabi", Triple::MuslEABI)
539
661k
    .StartsWith("musl", Triple::Musl)
540
661k
    .StartsWith("msvc", Triple::MSVC)
541
661k
    .StartsWith("itanium", Triple::Itanium)
542
661k
    .StartsWith("cygnus", Triple::Cygnus)
543
661k
    .StartsWith("coreclr", Triple::CoreCLR)
544
661k
    .StartsWith("simulator", Triple::Simulator)
545
661k
    .StartsWith("macabi", Triple::MacABI)
546
661k
    .Default(Triple::UnknownEnvironment);
547
661k
}
548
549
612k
static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
550
612k
  return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
551
612k
    // "xcoff" must come before "coff" because of the order-dependendent
552
612k
    // pattern matching.
553
612k
    .EndsWith("xcoff", Triple::XCOFF)
554
612k
    .EndsWith("coff", Triple::COFF)
555
612k
    .EndsWith("elf", Triple::ELF)
556
612k
    .EndsWith("macho", Triple::MachO)
557
612k
    .EndsWith("wasm", Triple::Wasm)
558
612k
    .Default(Triple::UnknownObjectFormat);
559
612k
}
560
561
1.67M
static Triple::SubArchType parseSubArch(StringRef SubArchName) {
562
1.67M
  if (SubArchName.startswith("mips") &&
563
1.67M
      
(27.5k
SubArchName.endswith("r6el")27.5k
||
SubArchName.endswith("r6")27.3k
))
564
362
    return Triple::MipsSubArch_r6;
565
1.66M
566
1.66M
  StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
567
1.66M
568
1.66M
  // For now, this is the small part. Early return.
569
1.66M
  if (ARMSubArch.empty())
570
30.4k
    return StringSwitch<Triple::SubArchType>(SubArchName)
571
30.4k
      .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
572
30.4k
      .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
573
30.4k
      .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
574
30.4k
      .Default(Triple::NoSubArch);
575
1.63M
576
1.63M
  // ARM sub arch.
577
1.63M
  switch(ARM::parseArch(ARMSubArch)) {
578
1.63M
  case ARM::ArchKind::ARMV4:
579
171
    return Triple::NoSubArch;
580
1.63M
  case ARM::ArchKind::ARMV4T:
581
2.60k
    return Triple::ARMSubArch_v4t;
582
1.63M
  case ARM::ArchKind::ARMV5T:
583
543
    return Triple::ARMSubArch_v5;
584
1.63M
  case ARM::ArchKind::ARMV5TE:
585
304
  case ARM::ArchKind::IWMMXT:
586
304
  case ARM::ArchKind::IWMMXT2:
587
304
  case ARM::ArchKind::XSCALE:
588
304
  case ARM::ArchKind::ARMV5TEJ:
589
304
    return Triple::ARMSubArch_v5te;
590
1.69k
  case ARM::ArchKind::ARMV6:
591
1.69k
    return Triple::ARMSubArch_v6;
592
442
  case ARM::ArchKind::ARMV6K:
593
442
  case ARM::ArchKind::ARMV6KZ:
594
442
    return Triple::ARMSubArch_v6k;
595
442
  case ARM::ArchKind::ARMV6T2:
596
277
    return Triple::ARMSubArch_v6t2;
597
4.26k
  case ARM::ArchKind::ARMV6M:
598
4.26k
    return Triple::ARMSubArch_v6m;
599
48.2k
  case ARM::ArchKind::ARMV7A:
600
48.2k
  case ARM::ArchKind::ARMV7R:
601
48.2k
    return Triple::ARMSubArch_v7;
602
48.2k
  case ARM::ArchKind::ARMV7VE:
603
79
    return Triple::ARMSubArch_v7ve;
604
48.2k
  case ARM::ArchKind::ARMV7K:
605
19.8k
    return Triple::ARMSubArch_v7k;
606
48.2k
  case ARM::ArchKind::ARMV7M:
607
4.77k
    return Triple::ARMSubArch_v7m;
608
48.2k
  case ARM::ArchKind::ARMV7S:
609
15.0k
    return Triple::ARMSubArch_v7s;
610
48.2k
  case ARM::ArchKind::ARMV7EM:
611
7.24k
    return Triple::ARMSubArch_v7em;
612
588k
  case ARM::ArchKind::ARMV8A:
613
588k
    return Triple::ARMSubArch_v8;
614
48.2k
  case ARM::ArchKind::ARMV8_1A:
615
163
    return Triple::ARMSubArch_v8_1a;
616
48.2k
  case ARM::ArchKind::ARMV8_2A:
617
414
    return Triple::ARMSubArch_v8_2a;
618
48.2k
  case ARM::ArchKind::ARMV8_3A:
619
68
    return Triple::ARMSubArch_v8_3a;
620
48.2k
  case ARM::ArchKind::ARMV8_4A:
621
169
    return Triple::ARMSubArch_v8_4a;
622
48.2k
  case ARM::ArchKind::ARMV8_5A:
623
44
    return Triple::ARMSubArch_v8_5a;
624
48.2k
  case ARM::ArchKind::ARMV8R:
625
113
    return Triple::ARMSubArch_v8r;
626
48.2k
  case ARM::ArchKind::ARMV8MBaseline:
627
425
    return Triple::ARMSubArch_v8m_baseline;
628
48.2k
  case ARM::ArchKind::ARMV8MMainline:
629
704
    return Triple::ARMSubArch_v8m_mainline;
630
48.2k
  case ARM::ArchKind::ARMV8_1MMainline:
631
1.74k
    return Triple::ARMSubArch_v8_1m_mainline;
632
941k
  default:
633
941k
    return Triple::NoSubArch;
634
1.63M
  }
635
1.63M
}
636
637
2.20k
static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
638
2.20k
  switch (Kind) {
639
2.20k
  
case Triple::UnknownObjectFormat: return ""0
;
640
2.20k
  
case Triple::COFF: return "coff"498
;
641
2.20k
  
case Triple::ELF: return "elf"20
;
642
2.20k
  
case Triple::MachO: return "macho"1.68k
;
643
2.20k
  
case Triple::Wasm: return "wasm"0
;
644
2.20k
  
case Triple::XCOFF: return "xcoff"1
;
645
0
  }
646
0
  llvm_unreachable("unknown object format type");
647
0
}
648
649
1.65M
static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
650
1.65M
  switch (T.getArch()) {
651
1.65M
  case Triple::UnknownArch:
652
1.49M
  case Triple::aarch64:
653
1.49M
  case Triple::aarch64_32:
654
1.49M
  case Triple::arm:
655
1.49M
  case Triple::thumb:
656
1.49M
  case Triple::x86:
657
1.49M
  case Triple::x86_64:
658
1.49M
    if (T.isOSDarwin())
659
850k
      return Triple::MachO;
660
646k
    else if (T.isOSWindows())
661
29.5k
      return Triple::COFF;
662
616k
    return Triple::ELF;
663
616k
664
616k
  case Triple::aarch64_be:
665
137k
  case Triple::arc:
666
137k
  case Triple::amdgcn:
667
137k
  case Triple::amdil:
668
137k
  case Triple::amdil64:
669
137k
  case Triple::armeb:
670
137k
  case Triple::avr:
671
137k
  case Triple::bpfeb:
672
137k
  case Triple::bpfel:
673
137k
  case Triple::hexagon:
674
137k
  case Triple::lanai:
675
137k
  case Triple::hsail:
676
137k
  case Triple::hsail64:
677
137k
  case Triple::kalimba:
678
137k
  case Triple::le32:
679
137k
  case Triple::le64:
680
137k
  case Triple::mips:
681
137k
  case Triple::mips64:
682
137k
  case Triple::mips64el:
683
137k
  case Triple::mipsel:
684
137k
  case Triple::msp430:
685
137k
  case Triple::nvptx:
686
137k
  case Triple::nvptx64:
687
137k
  case Triple::ppc64le:
688
137k
  case Triple::r600:
689
137k
  case Triple::renderscript32:
690
137k
  case Triple::renderscript64:
691
137k
  case Triple::riscv32:
692
137k
  case Triple::riscv64:
693
137k
  case Triple::shave:
694
137k
  case Triple::sparc:
695
137k
  case Triple::sparcel:
696
137k
  case Triple::sparcv9:
697
137k
  case Triple::spir:
698
137k
  case Triple::spir64:
699
137k
  case Triple::systemz:
700
137k
  case Triple::tce:
701
137k
  case Triple::tcele:
702
137k
  case Triple::thumbeb:
703
137k
  case Triple::xcore:
704
137k
    return Triple::ELF;
705
137k
706
137k
  case Triple::ppc:
707
13.1k
  case Triple::ppc64:
708
13.1k
    if (T.isOSDarwin())
709
158
      return Triple::MachO;
710
12.9k
    else if (T.isOSAIX())
711
113
      return Triple::XCOFF;
712
12.8k
    return Triple::ELF;
713
12.8k
714
12.8k
  case Triple::wasm32:
715
4.26k
  case Triple::wasm64:
716
4.26k
    return Triple::Wasm;
717
0
  }
718
0
  llvm_unreachable("unknown architecture");
719
0
}
720
721
/// Construct a triple from the string representation provided.
722
///
723
/// This stores the string representation and parses the various pieces into
724
/// enum members.
725
Triple::Triple(const Twine &Str)
726
    : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
727
      Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
728
1.67M
      ObjectFormat(UnknownObjectFormat) {
729
1.67M
  // Do minimal parsing by hand here.
730
1.67M
  SmallVector<StringRef, 4> Components;
731
1.67M
  StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
732
1.67M
  if (
Components.size() > 01.67M
) {
733
1.67M
    Arch = parseArch(Components[0]);
734
1.67M
    SubArch = parseSubArch(Components[0]);
735
1.67M
    if (Components.size() > 1) {
736
1.60M
      Vendor = parseVendor(Components[1]);
737
1.60M
      if (Components.size() > 2) {
738
1.59M
        OS = parseOS(Components[2]);
739
1.59M
        if (Components.size() > 3) {
740
538k
          Environment = parseEnvironment(Components[3]);
741
538k
          ObjectFormat = parseFormat(Components[3]);
742
538k
        }
743
1.59M
      }
744
1.60M
    } else {
745
68.3k
      Environment =
746
68.3k
          StringSwitch<Triple::EnvironmentType>(Components[0])
747
68.3k
              .StartsWith("mipsn32", Triple::GNUABIN32)
748
68.3k
              .StartsWith("mips64", Triple::GNUABI64)
749
68.3k
              .StartsWith("mipsisa64", Triple::GNUABI64)
750
68.3k
              .StartsWith("mipsisa32", Triple::GNU)
751
68.3k
              .Cases("mips", "mipsel", "mipsr6", "mipsr6el", Triple::GNU)
752
68.3k
              .Default(UnknownEnvironment);
753
68.3k
    }
754
1.67M
  }
755
1.67M
  if (ObjectFormat == UnknownObjectFormat)
756
1.65M
    ObjectFormat = getDefaultFormat(*this);
757
1.67M
}
758
759
/// Construct a triple from string representations of the architecture,
760
/// vendor, and OS.
761
///
762
/// This joins each argument into a canonical string representation and parses
763
/// them into enum members. It leaves the environment unknown and omits it from
764
/// the string representation.
765
Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
766
    : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
767
      Arch(parseArch(ArchStr.str())),
768
      SubArch(parseSubArch(ArchStr.str())),
769
      Vendor(parseVendor(VendorStr.str())),
770
      OS(parseOS(OSStr.str())),
771
0
      Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
772
0
  ObjectFormat = getDefaultFormat(*this);
773
0
}
774
775
/// Construct a triple from string representations of the architecture,
776
/// vendor, OS, and environment.
777
///
778
/// This joins each argument into a canonical string representation and parses
779
/// them into enum members.
780
Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
781
               const Twine &EnvironmentStr)
782
    : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
783
            EnvironmentStr).str()),
784
      Arch(parseArch(ArchStr.str())),
785
      SubArch(parseSubArch(ArchStr.str())),
786
      Vendor(parseVendor(VendorStr.str())),
787
      OS(parseOS(OSStr.str())),
788
      Environment(parseEnvironment(EnvironmentStr.str())),
789
2
      ObjectFormat(parseFormat(EnvironmentStr.str())) {
790
2
  if (ObjectFormat == Triple::UnknownObjectFormat)
791
2
    ObjectFormat = getDefaultFormat(*this);
792
2
}
793
794
395k
std::string Triple::normalize(StringRef Str) {
795
395k
  bool IsMinGW32 = false;
796
395k
  bool IsCygwin = false;
797
395k
798
395k
  // Parse into components.
799
395k
  SmallVector<StringRef, 4> Components;
800
395k
  Str.split(Components, '-');
801
395k
802
395k
  // If the first component corresponds to a known architecture, preferentially
803
395k
  // use it for the architecture.  If the second component corresponds to a
804
395k
  // known vendor, preferentially use it for the vendor, etc.  This avoids silly
805
395k
  // component movement when a component parses as (eg) both a valid arch and a
806
395k
  // valid os.
807
395k
  ArchType Arch = UnknownArch;
808
395k
  if (Components.size() > 0)
809
395k
    Arch = parseArch(Components[0]);
810
395k
  VendorType Vendor = UnknownVendor;
811
395k
  if (Components.size() > 1)
812
382k
    Vendor = parseVendor(Components[1]);
813
395k
  OSType OS = UnknownOS;
814
395k
  if (Components.size() > 2) {
815
378k
    OS = parseOS(Components[2]);
816
378k
    IsCygwin = Components[2].startswith("cygwin");
817
378k
    IsMinGW32 = Components[2].startswith("mingw");
818
378k
  }
819
395k
  EnvironmentType Environment = UnknownEnvironment;
820
395k
  if (Components.size() > 3)
821
38.5k
    Environment = parseEnvironment(Components[3]);
822
395k
  ObjectFormatType ObjectFormat = UnknownObjectFormat;
823
395k
  if (Components.size() > 4)
824
466
    ObjectFormat = parseFormat(Components[4]);
825
395k
826
395k
  // Note which components are already in their final position.  These will not
827
395k
  // be moved.
828
395k
  bool Found[4];
829
395k
  Found[0] = Arch != UnknownArch;
830
395k
  Found[1] = Vendor != UnknownVendor;
831
395k
  Found[2] = OS != UnknownOS;
832
395k
  Found[3] = Environment != UnknownEnvironment;
833
395k
834
395k
  // If they are not there already, permute the components into their canonical
835
395k
  // positions by seeing if they parse as a valid architecture, and if so moving
836
395k
  // the component to the architecture position etc.
837
1.97M
  for (unsigned Pos = 0; Pos != array_lengthof(Found); 
++Pos1.58M
) {
838
1.58M
    if (Found[Pos])
839
1.08M
      continue; // Already in the canonical position.
840
501k
841
1.91M
    
for (unsigned Idx = 0; 501k
Idx != Components.size();
++Idx1.41M
) {
842
1.44M
      // Do not reparse any components that already matched.
843
1.44M
      if (Idx < array_lengthof(Found) && 
Found[Idx]1.44M
)
844
1.17M
        continue;
845
269k
846
269k
      // Does this component parse as valid for the target position?
847
269k
      bool Valid = false;
848
269k
      StringRef Comp = Components[Idx];
849
269k
      switch (Pos) {
850
269k
      
default: 0
llvm_unreachable0
("unexpected component type!");
851
269k
      case 0:
852
9.96k
        Arch = parseArch(Comp);
853
9.96k
        Valid = Arch != UnknownArch;
854
9.96k
        break;
855
269k
      case 1:
856
99.2k
        Vendor = parseVendor(Comp);
857
99.2k
        Valid = Vendor != UnknownVendor;
858
99.2k
        break;
859
269k
      case 2:
860
76.0k
        OS = parseOS(Comp);
861
76.0k
        IsCygwin = Comp.startswith("cygwin");
862
76.0k
        IsMinGW32 = Comp.startswith("mingw");
863
76.0k
        Valid = OS != UnknownOS || 
IsCygwin65.6k
||
IsMinGW3265.6k
;
864
76.0k
        break;
865
269k
      case 3:
866
84.6k
        Environment = parseEnvironment(Comp);
867
84.6k
        Valid = Environment != UnknownEnvironment;
868
84.6k
        if (!Valid) {
869
74.2k
          ObjectFormat = parseFormat(Comp);
870
74.2k
          Valid = ObjectFormat != UnknownObjectFormat;
871
74.2k
        }
872
84.6k
        break;
873
269k
      }
874
269k
      if (!Valid)
875
237k
        continue; // Nope, try the next component.
876
31.9k
877
31.9k
      // Move the component to the target position, pushing any non-fixed
878
31.9k
      // components that are in the way to the right.  This tends to give
879
31.9k
      // good results in the common cases of a forgotten vendor component
880
31.9k
      // or a wrongly positioned environment.
881
31.9k
      if (Pos < Idx) {
882
5.31k
        // Insert left, pushing the existing components to the right.  For
883
5.31k
        // example, a-b-i386 -> i386-a-b when moving i386 to the front.
884
5.31k
        StringRef CurrentComponent(""); // The empty component.
885
5.31k
        // Replace the component we are moving with an empty component.
886
5.31k
        std::swap(CurrentComponent, Components[Idx]);
887
5.31k
        // Insert the component being moved at Pos, displacing any existing
888
5.31k
        // components to the right.
889
18.2k
        for (unsigned i = Pos; !CurrentComponent.empty(); 
++i12.9k
) {
890
12.9k
          // Skip over any fixed components.
891
13.9k
          while (i < array_lengthof(Found) && 
Found[i]13.9k
)
892
1.07k
            ++i;
893
12.9k
          // Place the component at the new position, getting the component
894
12.9k
          // that was at this position - it will be moved right.
895
12.9k
          std::swap(CurrentComponent, Components[i]);
896
12.9k
        }
897
26.6k
      } else if (Pos > Idx) {
898
10.2k
        // Push right by inserting empty components until the component at Idx
899
10.2k
        // reaches the target position Pos.  For example, pc-a -> -pc-a when
900
10.2k
        // moving pc to the second position.
901
11.5k
        do {
902
11.5k
          // Insert one empty component at Idx.
903
11.5k
          StringRef CurrentComponent(""); // The empty component.
904
29.5k
          for (unsigned i = Idx; i < Components.size();) {
905
17.9k
            // Place the component at the new position, getting the component
906
17.9k
            // that was at this position - it will be moved right.
907
17.9k
            std::swap(CurrentComponent, Components[i]);
908
17.9k
            // If it was placed on top of an empty component then we are done.
909
17.9k
            if (CurrentComponent.empty())
910
5
              break;
911
17.9k
            // Advance to the next component, skipping any fixed components.
912
17.9k
            
while (17.9k
++i < array_lengthof(Found) &&
Found[i]17.9k
)
913
43
              ;
914
17.9k
          }
915
11.5k
          // The last component was pushed off the end - append it.
916
11.5k
          if (!CurrentComponent.empty())
917
11.5k
            Components.push_back(CurrentComponent);
918
11.5k
919
11.5k
          // Advance Idx to the component's new position.
920
11.5k
          while (++Idx < array_lengthof(Found) && Found[Idx])
921
30
            ;
922
11.5k
        } while (Idx < Pos); // Add more until the final position is reached.
923
10.2k
      }
924
31.9k
      assert(Pos < Components.size() && Components[Pos] == Comp &&
925
31.9k
             "Component moved wrong!");
926
31.9k
      Found[Pos] = true;
927
31.9k
      break;
928
31.9k
    }
929
501k
  }
930
395k
931
395k
  // Replace empty components with "unknown" value.
932
1.60M
  
for (unsigned i = 0, e = Components.size(); 395k
i < e;
++i1.20M
) {
933
1.20M
    if (Components[i].empty())
934
19.4k
      Components[i] = "unknown";
935
1.20M
  }
936
395k
937
395k
  // Special case logic goes here.  At this point Arch, Vendor and OS have the
938
395k
  // correct values for the computed components.
939
395k
  std::string NormalizedEnvironment;
940
395k
  if (Environment == Triple::Android && 
Components[3].startswith("androideabi")1.39k
) {
941
126
    StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
942
126
    if (AndroidVersion.empty()) {
943
97
      Components[3] = "android";
944
97
    } else {
945
29
      NormalizedEnvironment = Twine("android", AndroidVersion).str();
946
29
      Components[3] = NormalizedEnvironment;
947
29
    }
948
126
  }
949
395k
950
395k
  // SUSE uses "gnueabi" to mean "gnueabihf"
951
395k
  if (Vendor == Triple::SUSE && 
Environment == llvm::Triple::GNUEABI61
)
952
5
    Components[3] = "gnueabihf";
953
395k
954
395k
  if (OS == Triple::Win32) {
955
6.33k
    Components.resize(4);
956
6.33k
    Components[2] = "windows";
957
6.33k
    if (Environment == UnknownEnvironment) {
958
1.31k
      if (ObjectFormat == UnknownObjectFormat || 
ObjectFormat == Triple::COFF67
)
959
1.26k
        Components[3] = "msvc";
960
55
      else
961
55
        Components[3] = getObjectFormatTypeName(ObjectFormat);
962
1.31k
    }
963
389k
  } else if (IsMinGW32) {
964
138
    Components.resize(4);
965
138
    Components[2] = "windows";
966
138
    Components[3] = "gnu";
967
389k
  } else if (IsCygwin) {
968
28
    Components.resize(4);
969
28
    Components[2] = "windows";
970
28
    Components[3] = "cygnus";
971
28
  }
972
395k
  if (IsMinGW32 || 
IsCygwin395k
||
973
395k
      
(395k
OS == Triple::Win32395k
&&
Environment != UnknownEnvironment6.33k
)) {
974
5.18k
    if (ObjectFormat != UnknownObjectFormat && 
ObjectFormat != Triple::COFF423
) {
975
12
      Components.resize(5);
976
12
      Components[4] = getObjectFormatTypeName(ObjectFormat);
977
12
    }
978
5.18k
  }
979
395k
980
395k
  // Stick the corrected components back together to form the normalized string.
981
395k
  std::string Normalized;
982
1.60M
  for (unsigned i = 0, e = Components.size(); i != e; 
++i1.20M
) {
983
1.20M
    if (i) 
Normalized += '-'812k
;
984
1.20M
    Normalized += Components[i];
985
1.20M
  }
986
395k
  return Normalized;
987
395k
}
988
989
174k
StringRef Triple::getArchName() const {
990
174k
  return StringRef(Data).split('-').first;           // Isolate first component
991
174k
}
992
993
105k
StringRef Triple::getVendorName() const {
994
105k
  StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
995
105k
  return Tmp.split('-').first;                       // Isolate second component
996
105k
}
997
998
379k
StringRef Triple::getOSName() const {
999
379k
  StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1000
379k
  Tmp = Tmp.split('-').second;                       // Strip second component
1001
379k
  return Tmp.split('-').first;                       // Isolate third component
1002
379k
}
1003
1004
47.5k
StringRef Triple::getEnvironmentName() const {
1005
47.5k
  StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1006
47.5k
  Tmp = Tmp.split('-').second;                       // Strip second component
1007
47.5k
  return Tmp.split('-').second;                      // Strip third component
1008
47.5k
}
1009
1010
81.0k
StringRef Triple::getOSAndEnvironmentName() const {
1011
81.0k
  StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1012
81.0k
  return Tmp.split('-').second;                      // Strip second component
1013
81.0k
}
1014
1015
893k
static unsigned EatNumber(StringRef &Str) {
1016
893k
  assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
1017
893k
  unsigned Result = 0;
1018
893k
1019
1.19M
  do {
1020
1.19M
    // Consume the leading digit.
1021
1.19M
    Result = Result*10 + (Str[0] - '0');
1022
1.19M
1023
1.19M
    // Eat the digit.
1024
1.19M
    Str = Str.substr(1);
1025
1.19M
  } while (!Str.empty() && 
Str[0] >= '0'883k
&&
Str[0] <= '9'296k
);
1026
893k
1027
893k
  return Result;
1028
893k
}
1029
1030
static void parseVersionFromName(StringRef Name, unsigned &Major,
1031
329k
                                 unsigned &Minor, unsigned &Micro) {
1032
329k
  // Any unset version defaults to 0.
1033
329k
  Major = Minor = Micro = 0;
1034
329k
1035
329k
  // Parse up to three components.
1036
329k
  unsigned *Components[3] = {&Major, &Minor, &Micro};
1037
1.22M
  for (unsigned i = 0; i != 3; 
++i893k
) {
1038
931k
    if (Name.empty() || 
Name[0] < '0'893k
||
Name[0] > '9'893k
)
1039
37.2k
      break;
1040
893k
1041
893k
    // Consume the leading number.
1042
893k
    *Components[i] = EatNumber(Name);
1043
893k
1044
893k
    // Consume the separator, if present.
1045
893k
    if (Name.startswith("."))
1046
586k
      Name = Name.substr(1);
1047
893k
  }
1048
329k
}
1049
1050
void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
1051
4.53k
                                   unsigned &Micro) const {
1052
4.53k
  StringRef EnvironmentName = getEnvironmentName();
1053
4.53k
  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
1054
4.53k
  if (EnvironmentName.startswith(EnvironmentTypeName))
1055
4.52k
    EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
1056
4.53k
1057
4.53k
  parseVersionFromName(EnvironmentName, Major, Minor, Micro);
1058
4.53k
}
1059
1060
void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
1061
324k
                          unsigned &Micro) const {
1062
324k
  StringRef OSName = getOSName();
1063
324k
  // Assume that the OS portion of the triple starts with the canonical name.
1064
324k
  StringRef OSTypeName = getOSTypeName(getOS());
1065
324k
  if (OSName.startswith(OSTypeName))
1066
324k
    OSName = OSName.substr(OSTypeName.size());
1067
232
  else if (getOS() == MacOSX)
1068
242
    OSName.consume_front("macos");
1069
324k
1070
324k
  parseVersionFromName(OSName, Major, Minor, Micro);
1071
324k
}
1072
1073
bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
1074
37.7k
                              unsigned &Micro) const {
1075
37.7k
  getOSVersion(Major, Minor, Micro);
1076
37.7k
1077
37.7k
  switch (getOS()) {
1078
37.7k
  
default: 0
llvm_unreachable0
("unexpected OS for Darwin triple");
1079
37.7k
  case Darwin:
1080
24.3k
    // Default to darwin8, i.e., MacOSX 10.4.
1081
24.3k
    if (Major == 0)
1082
472
      Major = 8;
1083
24.3k
    // Darwin version numbers are skewed from OS X versions.
1084
24.3k
    if (Major < 4)
1085
2
      return false;
1086
24.3k
    Micro = 0;
1087
24.3k
    Minor = Major - 4;
1088
24.3k
    Major = 10;
1089
24.3k
    break;
1090
24.3k
  case MacOSX:
1091
13.4k
    // Default to 10.4.
1092
13.4k
    if (Major == 0) {
1093
26
      Major = 10;
1094
26
      Minor = 4;
1095
26
    }
1096
13.4k
    if (Major != 10)
1097
3
      return false;
1098
13.4k
    break;
1099
13.4k
  case IOS:
1100
2
  case TvOS:
1101
2
  case WatchOS:
1102
2
    // Ignore the version from the triple.  This is only handled because the
1103
2
    // the clang driver combines OS X and IOS support into a common Darwin
1104
2
    // toolchain that wants to know the OS X version number even when targeting
1105
2
    // IOS.
1106
2
    Major = 10;
1107
2
    Minor = 4;
1108
2
    Micro = 0;
1109
2
    break;
1110
37.7k
  }
1111
37.7k
  return true;
1112
37.7k
}
1113
1114
void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
1115
10.0k
                           unsigned &Micro) const {
1116
10.0k
  switch (getOS()) {
1117
10.0k
  
default: 0
llvm_unreachable0
("unexpected OS for Darwin triple");
1118
10.0k
  case Darwin:
1119
29
  case MacOSX:
1120
29
    // Ignore the version from the triple.  This is only handled because the
1121
29
    // the clang driver combines OS X and IOS support into a common Darwin
1122
29
    // toolchain that wants to know the iOS version number even when targeting
1123
29
    // OS X.
1124
29
    Major = 5;
1125
29
    Minor = 0;
1126
29
    Micro = 0;
1127
29
    break;
1128
10.0k
  case IOS:
1129
10.0k
  case TvOS:
1130
10.0k
    getOSVersion(Major, Minor, Micro);
1131
10.0k
    // Default to 5.0 (or 7.0 for arm64).
1132
10.0k
    if (Major == 0)
1133
28
      Major = (getArch() == aarch64) ? 
78
:
520
;
1134
10.0k
    break;
1135
10.0k
  case WatchOS:
1136
0
    llvm_unreachable("conflicting triple info");
1137
10.0k
  }
1138
10.0k
}
1139
1140
void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
1141
36
                               unsigned &Micro) const {
1142
36
  switch (getOS()) {
1143
36
  
default: 0
llvm_unreachable0
("unexpected OS for Darwin triple");
1144
36
  case Darwin:
1145
1
  case MacOSX:
1146
1
    // Ignore the version from the triple.  This is only handled because the
1147
1
    // the clang driver combines OS X and IOS support into a common Darwin
1148
1
    // toolchain that wants to know the iOS version number even when targeting
1149
1
    // OS X.
1150
1
    Major = 2;
1151
1
    Minor = 0;
1152
1
    Micro = 0;
1153
1
    break;
1154
35
  case WatchOS:
1155
35
    getOSVersion(Major, Minor, Micro);
1156
35
    if (Major == 0)
1157
6
      Major = 2;
1158
35
    break;
1159
1
  case IOS:
1160
0
    llvm_unreachable("conflicting triple info");
1161
36
  }
1162
36
}
1163
1164
110k
void Triple::setTriple(const Twine &Str) {
1165
110k
  *this = Triple(Str);
1166
110k
}
1167
1168
50.0k
void Triple::setArch(ArchType Kind) {
1169
50.0k
  setArchName(getArchTypeName(Kind));
1170
50.0k
}
1171
1172
1.31k
void Triple::setVendor(VendorType Kind) {
1173
1.31k
  setVendorName(getVendorTypeName(Kind));
1174
1.31k
}
1175
1176
2.93k
void Triple::setOS(OSType Kind) {
1177
2.93k
  setOSName(getOSTypeName(Kind));
1178
2.93k
}
1179
1180
1.53k
void Triple::setEnvironment(EnvironmentType Kind) {
1181
1.53k
  if (ObjectFormat == getDefaultFormat(*this))
1182
1.53k
    return setEnvironmentName(getEnvironmentTypeName(Kind));
1183
0
1184
0
  setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
1185
0
                      getObjectFormatTypeName(ObjectFormat)).str());
1186
0
}
1187
1188
2.14k
void Triple::setObjectFormat(ObjectFormatType Kind) {
1189
2.14k
  if (Environment == UnknownEnvironment)
1190
1.64k
    return setEnvironmentName(getObjectFormatTypeName(Kind));
1191
498
1192
498
  setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
1193
498
                      getObjectFormatTypeName(Kind)).str());
1194
498
}
1195
1196
70.9k
void Triple::setArchName(StringRef Str) {
1197
70.9k
  // Work around a miscompilation bug for Twines in gcc 4.0.3.
1198
70.9k
  SmallString<64> Triple;
1199
70.9k
  Triple += Str;
1200
70.9k
  Triple += "-";
1201
70.9k
  Triple += getVendorName();
1202
70.9k
  Triple += "-";
1203
70.9k
  Triple += getOSAndEnvironmentName();
1204
70.9k
  setTriple(Triple);
1205
70.9k
}
1206
1207
1.32k
void Triple::setVendorName(StringRef Str) {
1208
1.32k
  setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
1209
1.32k
}
1210
1211
27.1k
void Triple::setOSName(StringRef Str) {
1212
27.1k
  if (hasEnvironment())
1213
1.80k
    setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
1214
1.80k
              "-" + getEnvironmentName());
1215
25.3k
  else
1216
25.3k
    setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1217
27.1k
}
1218
1219
4.69k
void Triple::setEnvironmentName(StringRef Str) {
1220
4.69k
  setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1221
4.69k
            "-" + Str);
1222
4.69k
}
1223
1224
1
void Triple::setOSAndEnvironmentName(StringRef Str) {
1225
1
  setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1226
1
}
1227
1228
404k
static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
1229
404k
  switch (Arch) {
1230
404k
  case llvm::Triple::UnknownArch:
1231
40
    return 0;
1232
404k
1233
404k
  case llvm::Triple::avr:
1234
58
  case llvm::Triple::msp430:
1235
58
    return 16;
1236
58
1237
80.0k
  case llvm::Triple::aarch64_32:
1238
80.0k
  case llvm::Triple::arc:
1239
80.0k
  case llvm::Triple::arm:
1240
80.0k
  case llvm::Triple::armeb:
1241
80.0k
  case llvm::Triple::hexagon:
1242
80.0k
  case llvm::Triple::le32:
1243
80.0k
  case llvm::Triple::mips:
1244
80.0k
  case llvm::Triple::mipsel:
1245
80.0k
  case llvm::Triple::nvptx:
1246
80.0k
  case llvm::Triple::ppc:
1247
80.0k
  case llvm::Triple::r600:
1248
80.0k
  case llvm::Triple::riscv32:
1249
80.0k
  case llvm::Triple::sparc:
1250
80.0k
  case llvm::Triple::sparcel:
1251
80.0k
  case llvm::Triple::tce:
1252
80.0k
  case llvm::Triple::tcele:
1253
80.0k
  case llvm::Triple::thumb:
1254
80.0k
  case llvm::Triple::thumbeb:
1255
80.0k
  case llvm::Triple::x86:
1256
80.0k
  case llvm::Triple::xcore:
1257
80.0k
  case llvm::Triple::amdil:
1258
80.0k
  case llvm::Triple::hsail:
1259
80.0k
  case llvm::Triple::spir:
1260
80.0k
  case llvm::Triple::kalimba:
1261
80.0k
  case llvm::Triple::lanai:
1262
80.0k
  case llvm::Triple::shave:
1263
80.0k
  case llvm::Triple::wasm32:
1264
80.0k
  case llvm::Triple::renderscript32:
1265
80.0k
    return 32;
1266
80.0k
1267
324k
  case llvm::Triple::aarch64:
1268
324k
  case llvm::Triple::aarch64_be:
1269
324k
  case llvm::Triple::amdgcn:
1270
324k
  case llvm::Triple::bpfel:
1271
324k
  case llvm::Triple::bpfeb:
1272
324k
  case llvm::Triple::le64:
1273
324k
  case llvm::Triple::mips64:
1274
324k
  case llvm::Triple::mips64el:
1275
324k
  case llvm::Triple::nvptx64:
1276
324k
  case llvm::Triple::ppc64:
1277
324k
  case llvm::Triple::ppc64le:
1278
324k
  case llvm::Triple::riscv64:
1279
324k
  case llvm::Triple::sparcv9:
1280
324k
  case llvm::Triple::systemz:
1281
324k
  case llvm::Triple::x86_64:
1282
324k
  case llvm::Triple::amdil64:
1283
324k
  case llvm::Triple::hsail64:
1284
324k
  case llvm::Triple::spir64:
1285
324k
  case llvm::Triple::wasm64:
1286
324k
  case llvm::Triple::renderscript64:
1287
324k
    return 64;
1288
0
  }
1289
0
  llvm_unreachable("Invalid architecture value");
1290
0
}
1291
1292
255k
bool Triple::isArch64Bit() const {
1293
255k
  return getArchPointerBitWidth(getArch()) == 64;
1294
255k
}
1295
1296
148k
bool Triple::isArch32Bit() const {
1297
148k
  return getArchPointerBitWidth(getArch()) == 32;
1298
148k
}
1299
1300
73
bool Triple::isArch16Bit() const {
1301
73
  return getArchPointerBitWidth(getArch()) == 16;
1302
73
}
1303
1304
1.95k
Triple Triple::get32BitArchVariant() const {
1305
1.95k
  Triple T(*this);
1306
1.95k
  switch (getArch()) {
1307
1.95k
  case Triple::UnknownArch:
1308
236
  case Triple::amdgcn:
1309
236
  case Triple::avr:
1310
236
  case Triple::bpfel:
1311
236
  case Triple::bpfeb:
1312
236
  case Triple::msp430:
1313
236
  case Triple::systemz:
1314
236
  case Triple::ppc64le:
1315
236
    T.setArch(UnknownArch);
1316
236
    break;
1317
236
1318
236
  case Triple::aarch64_32:
1319
140
  case Triple::amdil:
1320
140
  case Triple::hsail:
1321
140
  case Triple::spir:
1322
140
  case Triple::arc:
1323
140
  case Triple::arm:
1324
140
  case Triple::armeb:
1325
140
  case Triple::hexagon:
1326
140
  case Triple::kalimba:
1327
140
  case Triple::le32:
1328
140
  case Triple::mips:
1329
140
  case Triple::mipsel:
1330
140
  case Triple::nvptx:
1331
140
  case Triple::ppc:
1332
140
  case Triple::r600:
1333
140
  case Triple::riscv32:
1334
140
  case Triple::sparc:
1335
140
  case Triple::sparcel:
1336
140
  case Triple::tce:
1337
140
  case Triple::tcele:
1338
140
  case Triple::thumb:
1339
140
  case Triple::thumbeb:
1340
140
  case Triple::x86:
1341
140
  case Triple::xcore:
1342
140
  case Triple::lanai:
1343
140
  case Triple::shave:
1344
140
  case Triple::wasm32:
1345
140
  case Triple::renderscript32:
1346
140
    // Already 32-bit.
1347
140
    break;
1348
140
1349
155
  case Triple::aarch64:        T.setArch(Triple::arm);     break;
1350
140
  
case Triple::aarch64_be: T.setArch(Triple::armeb); break9
;
1351
140
  
case Triple::le64: T.setArch(Triple::le32); break1
;
1352
140
  
case Triple::mips64: T.setArch(Triple::mips); break107
;
1353
140
  
case Triple::mips64el: T.setArch(Triple::mipsel); break77
;
1354
140
  
case Triple::nvptx64: T.setArch(Triple::nvptx); break1
;
1355
140
  
case Triple::ppc64: T.setArch(Triple::ppc); break129
;
1356
140
  
case Triple::sparcv9: T.setArch(Triple::sparc); break22
;
1357
140
  
case Triple::riscv64: T.setArch(Triple::riscv32); break64
;
1358
1.00k
  case Triple::x86_64:         T.setArch(Triple::x86);     break;
1359
140
  
case Triple::amdil64: T.setArch(Triple::amdil); break1
;
1360
140
  
case Triple::hsail64: T.setArch(Triple::hsail); break1
;
1361
140
  
case Triple::spir64: T.setArch(Triple::spir); break1
;
1362
140
  
case Triple::wasm64: T.setArch(Triple::wasm32); break5
;
1363
140
  
case Triple::renderscript64: T.setArch(Triple::renderscript32); break1
;
1364
1.95k
  }
1365
1.95k
  return T;
1366
1.95k
}
1367
1368
1.90k
Triple Triple::get64BitArchVariant() const {
1369
1.90k
  Triple T(*this);
1370
1.90k
  switch (getArch()) {
1371
1.90k
  case Triple::UnknownArch:
1372
103
  case Triple::arc:
1373
103
  case Triple::avr:
1374
103
  case Triple::hexagon:
1375
103
  case Triple::kalimba:
1376
103
  case Triple::lanai:
1377
103
  case Triple::msp430:
1378
103
  case Triple::r600:
1379
103
  case Triple::tce:
1380
103
  case Triple::tcele:
1381
103
  case Triple::xcore:
1382
103
  case Triple::sparcel:
1383
103
  case Triple::shave:
1384
103
    T.setArch(UnknownArch);
1385
103
    break;
1386
103
1387
108
  case Triple::aarch64:
1388
108
  case Triple::aarch64_be:
1389
108
  case Triple::bpfel:
1390
108
  case Triple::bpfeb:
1391
108
  case Triple::le64:
1392
108
  case Triple::amdil64:
1393
108
  case Triple::amdgcn:
1394
108
  case Triple::hsail64:
1395
108
  case Triple::spir64:
1396
108
  case Triple::mips64:
1397
108
  case Triple::mips64el:
1398
108
  case Triple::nvptx64:
1399
108
  case Triple::ppc64:
1400
108
  case Triple::ppc64le:
1401
108
  case Triple::riscv64:
1402
108
  case Triple::sparcv9:
1403
108
  case Triple::systemz:
1404
108
  case Triple::x86_64:
1405
108
  case Triple::wasm64:
1406
108
  case Triple::renderscript64:
1407
108
    // Already 64-bit.
1408
108
    break;
1409
108
1410
108
  
case Triple::aarch64_32: T.setArch(Triple::aarch64); break0
;
1411
513
  case Triple::arm:             T.setArch(Triple::aarch64);    break;
1412
108
  
case Triple::armeb: T.setArch(Triple::aarch64_be); break44
;
1413
108
  
case Triple::le32: T.setArch(Triple::le64); break1
;
1414
323
  case Triple::mips:            T.setArch(Triple::mips64);     break;
1415
108
  
case Triple::mipsel: T.setArch(Triple::mips64el); break104
;
1416
108
  
case Triple::nvptx: T.setArch(Triple::nvptx64); break1
;
1417
108
  
case Triple::ppc: T.setArch(Triple::ppc64); break29
;
1418
108
  
case Triple::sparc: T.setArch(Triple::sparcv9); break36
;
1419
108
  
case Triple::riscv32: T.setArch(Triple::riscv64); break104
;
1420
503
  case Triple::x86:             T.setArch(Triple::x86_64);     break;
1421
108
  
case Triple::amdil: T.setArch(Triple::amdil64); break1
;
1422
108
  
case Triple::hsail: T.setArch(Triple::hsail64); break1
;
1423
108
  
case Triple::spir: T.setArch(Triple::spir64); break1
;
1424
108
  
case Triple::thumb: T.setArch(Triple::aarch64); break15
;
1425
108
  
case Triple::thumbeb: T.setArch(Triple::aarch64_be); break12
;
1426
108
  
case Triple::wasm32: T.setArch(Triple::wasm64); break5
;
1427
108
  
case Triple::renderscript32: T.setArch(Triple::renderscript64); break1
;
1428
1.90k
  }
1429
1.90k
  return T;
1430
1.90k
}
1431
1432
238
Triple Triple::getBigEndianArchVariant() const {
1433
238
  Triple T(*this);
1434
238
  // Already big endian.
1435
238
  if (!isLittleEndian())
1436
73
    return T;
1437
165
  switch (getArch()) {
1438
165
  case Triple::UnknownArch:
1439
109
  case Triple::amdgcn:
1440
109
  case Triple::amdil64:
1441
109
  case Triple::amdil:
1442
109
  case Triple::avr:
1443
109
  case Triple::hexagon:
1444
109
  case Triple::hsail64:
1445
109
  case Triple::hsail:
1446
109
  case Triple::kalimba:
1447
109
  case Triple::le32:
1448
109
  case Triple::le64:
1449
109
  case Triple::msp430:
1450
109
  case Triple::nvptx64:
1451
109
  case Triple::nvptx:
1452
109
  case Triple::r600:
1453
109
  case Triple::riscv32:
1454
109
  case Triple::riscv64:
1455
109
  case Triple::shave:
1456
109
  case Triple::spir64:
1457
109
  case Triple::spir:
1458
109
  case Triple::wasm32:
1459
109
  case Triple::wasm64:
1460
109
  case Triple::x86:
1461
109
  case Triple::x86_64:
1462
109
  case Triple::xcore:
1463
109
  case Triple::renderscript32:
1464
109
  case Triple::renderscript64:
1465
109
1466
109
  // ARM is intentionally unsupported here, changing the architecture would
1467
109
  // drop any arch suffixes.
1468
109
  case Triple::arm:
1469
109
  case Triple::thumb:
1470
109
    T.setArch(UnknownArch);
1471
109
    break;
1472
109
1473
109
  
case Triple::tcele: T.setArch(Triple::tce); break1
;
1474
109
  
case Triple::aarch64: T.setArch(Triple::aarch64_be); break46
;
1475
109
  
case Triple::bpfel: T.setArch(Triple::bpfeb); break1
;
1476
109
  
case Triple::mips64el:T.setArch(Triple::mips64); break2
;
1477
109
  
case Triple::mipsel: T.setArch(Triple::mips); break3
;
1478
109
  
case Triple::ppc64le: T.setArch(Triple::ppc64); break2
;
1479
109
  
case Triple::sparcel: T.setArch(Triple::sparc); break1
;
1480
109
  default:
1481
0
    llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1482
165
  }
1483
165
  return T;
1484
165
}
1485
1486
263
Triple Triple::getLittleEndianArchVariant() const {
1487
263
  Triple T(*this);
1488
263
  if (isLittleEndian())
1489
187
    return T;
1490
76
1491
76
  switch (getArch()) {
1492
76
  case Triple::UnknownArch:
1493
10
  case Triple::lanai:
1494
10
  case Triple::ppc:
1495
10
  case Triple::sparcv9:
1496
10
  case Triple::systemz:
1497
10
1498
10
  // ARM is intentionally unsupported here, changing the architecture would
1499
10
  // drop any arch suffixes.
1500
10
  case Triple::armeb:
1501
10
  case Triple::thumbeb:
1502
10
    T.setArch(UnknownArch);
1503
10
    break;
1504
10
1505
10
  
case Triple::tce: T.setArch(Triple::tcele); break1
;
1506
37
  case Triple::aarch64_be: T.setArch(Triple::aarch64);  break;
1507
10
  
case Triple::bpfeb: T.setArch(Triple::bpfel); break1
;
1508
10
  
case Triple::mips64: T.setArch(Triple::mips64el); break6
;
1509
18
  case Triple::mips:       T.setArch(Triple::mipsel);   break;
1510
10
  
case Triple::ppc64: T.setArch(Triple::ppc64le); break2
;
1511
10
  
case Triple::sparc: T.setArch(Triple::sparcel); break1
;
1512
10
  default:
1513
0
    llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1514
76
  }
1515
76
  return T;
1516
76
}
1517
1518
60.3k
bool Triple::isLittleEndian() const {
1519
60.3k
  switch (getArch()) {
1520
60.3k
  case Triple::aarch64:
1521
52.9k
  case Triple::aarch64_32:
1522
52.9k
  case Triple::amdgcn:
1523
52.9k
  case Triple::amdil64:
1524
52.9k
  case Triple::amdil:
1525
52.9k
  case Triple::arm:
1526
52.9k
  case Triple::avr:
1527
52.9k
  case Triple::bpfel:
1528
52.9k
  case Triple::hexagon:
1529
52.9k
  case Triple::hsail64:
1530
52.9k
  case Triple::hsail:
1531
52.9k
  case Triple::kalimba:
1532
52.9k
  case Triple::le32:
1533
52.9k
  case Triple::le64:
1534
52.9k
  case Triple::mips64el:
1535
52.9k
  case Triple::mipsel:
1536
52.9k
  case Triple::msp430:
1537
52.9k
  case Triple::nvptx64:
1538
52.9k
  case Triple::nvptx:
1539
52.9k
  case Triple::ppc64le:
1540
52.9k
  case Triple::r600:
1541
52.9k
  case Triple::riscv32:
1542
52.9k
  case Triple::riscv64:
1543
52.9k
  case Triple::shave:
1544
52.9k
  case Triple::sparcel:
1545
52.9k
  case Triple::spir64:
1546
52.9k
  case Triple::spir:
1547
52.9k
  case Triple::thumb:
1548
52.9k
  case Triple::wasm32:
1549
52.9k
  case Triple::wasm64:
1550
52.9k
  case Triple::x86:
1551
52.9k
  case Triple::x86_64:
1552
52.9k
  case Triple::xcore:
1553
52.9k
  case Triple::tcele:
1554
52.9k
  case Triple::renderscript32:
1555
52.9k
  case Triple::renderscript64:
1556
52.9k
    return true;
1557
52.9k
  default:
1558
7.40k
    return false;
1559
60.3k
  }
1560
60.3k
}
1561
1562
616
bool Triple::isCompatibleWith(const Triple &Other) const {
1563
616
  // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
1564
616
  if ((getArch() == Triple::thumb && 
Other.getArch() == Triple::arm4
) ||
1565
616
      
(613
getArch() == Triple::arm613
&&
Other.getArch() == Triple::thumb4
) ||
1566
616
      
(613
getArch() == Triple::thumbeb613
&&
Other.getArch() == Triple::armeb0
) ||
1567
616
      
(613
getArch() == Triple::armeb613
&&
Other.getArch() == Triple::thumbeb0
)) {
1568
3
    if (getVendor() == Triple::Apple)
1569
0
      return getSubArch() == Other.getSubArch() &&
1570
0
             getVendor() == Other.getVendor() && getOS() == Other.getOS();
1571
3
    else
1572
3
      return getSubArch() == Other.getSubArch() &&
1573
3
             getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
1574
3
             getEnvironment() == Other.getEnvironment() &&
1575
3
             getObjectFormat() == Other.getObjectFormat();
1576
613
  }
1577
613
1578
613
  // If vendor is apple, ignore the version number.
1579
613
  if (getVendor() == Triple::Apple)
1580
75
    return getArch() == Other.getArch() && 
getSubArch() == Other.getSubArch()74
&&
1581
75
           
getVendor() == Other.getVendor()74
&&
getOS() == Other.getOS()74
;
1582
538
1583
538
  return *this == Other;
1584
538
}
1585
1586
1.07k
std::string Triple::merge(const Triple &Other) const {
1587
1.07k
  // If vendor is apple, pick the triple with the larger version number.
1588
1.07k
  if (getVendor() == Triple::Apple)
1589
75
    if (Other.isOSVersionLT(*this))
1590
1
      return str();
1591
1.07k
1592
1.07k
  return Other.str();
1593
1.07k
}
1594
1595
18.0k
StringRef Triple::getARMCPUForArch(StringRef MArch) const {
1596
18.0k
  if (MArch.empty())
1597
14
    MArch = getArchName();
1598
18.0k
  MArch = ARM::getCanonicalArchName(MArch);
1599
18.0k
1600
18.0k
  // Some defaults are forced.
1601
18.0k
  switch (getOS()) {
1602
18.0k
  case llvm::Triple::FreeBSD:
1603
182
  case llvm::Triple::NetBSD:
1604
182
    if (!MArch.empty() && MArch == "v6")
1605
7
      return "arm1176jzf-s";
1606
175
    break;
1607
195
  case llvm::Triple::Win32:
1608
195
    // FIXME: this is invalid for WindowsCE
1609
195
    return "cortex-a9";
1610
4.93k
  case llvm::Triple::MacOSX:
1611
4.93k
  case llvm::Triple::IOS:
1612
4.93k
  case llvm::Triple::WatchOS:
1613
4.93k
  case llvm::Triple::TvOS:
1614
4.93k
    if (MArch == "v7k")
1615
1.60k
      return "cortex-a7";
1616
3.32k
    break;
1617
12.7k
  default:
1618
12.7k
    break;
1619
16.2k
  }
1620
16.2k
1621
16.2k
  if (MArch.empty())
1622
10
    return StringRef();
1623
16.2k
1624
16.2k
  StringRef CPU = ARM::getDefaultCPU(MArch);
1625
16.2k
  if (!CPU.empty() && 
!CPU.equals("invalid")15.4k
)
1626
15.4k
    return CPU;
1627
826
1628
826
  // If no specific architecture version is requested, return the minimum CPU
1629
826
  // required by the OS and environment.
1630
826
  switch (getOS()) {
1631
826
  case llvm::Triple::NetBSD:
1632
56
    switch (getEnvironment()) {
1633
56
    case llvm::Triple::GNUEABIHF:
1634
50
    case llvm::Triple::GNUEABI:
1635
50
    case llvm::Triple::EABIHF:
1636
50
    case llvm::Triple::EABI:
1637
50
      return "arm926ej-s";
1638
50
    default:
1639
6
      return "strongarm";
1640
0
    }
1641
13
  case llvm::Triple::NaCl:
1642
13
  case llvm::Triple::OpenBSD:
1643
13
    return "cortex-a8";
1644
757
  default:
1645
757
    switch (getEnvironment()) {
1646
757
    case llvm::Triple::EABIHF:
1647
41
    case llvm::Triple::GNUEABIHF:
1648
41
    case llvm::Triple::MuslEABIHF:
1649
41
      return "arm1176jzf-s";
1650
716
    default:
1651
716
      return "arm7tdmi";
1652
0
    }
1653
0
  }
1654
0
1655
0
  llvm_unreachable("invalid arch name");
1656
0
}