1 //===--- Triple.cpp - Target triple helper class --------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/Triple.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/StringSwitch.h"
14 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/Host.h"
16 #include "llvm/Support/TargetParser.h"
20 StringRef
Triple::getArchTypeName(ArchType Kind
) {
22 case UnknownArch
: return "unknown";
24 case aarch64
: return "aarch64";
25 case aarch64_be
: return "aarch64_be";
26 case arm
: return "arm";
27 case armeb
: return "armeb";
28 case arc
: return "arc";
29 case avr
: return "avr";
30 case bpfel
: return "bpfel";
31 case bpfeb
: return "bpfeb";
32 case hexagon
: return "hexagon";
33 case mips
: return "mips";
34 case mipsel
: return "mipsel";
35 case mips64
: return "mips64";
36 case mips64el
: return "mips64el";
37 case msp430
: return "msp430";
38 case nios2
: return "nios2";
39 case ppc64
: return "powerpc64";
40 case ppc64le
: return "powerpc64le";
41 case ppc
: return "powerpc";
42 case r600
: return "r600";
43 case amdgcn
: return "amdgcn";
44 case riscv32
: return "riscv32";
45 case riscv64
: return "riscv64";
46 case sparc
: return "sparc";
47 case sparcv9
: return "sparcv9";
48 case sparcel
: return "sparcel";
49 case systemz
: return "s390x";
50 case tce
: return "tce";
51 case tcele
: return "tcele";
52 case thumb
: return "thumb";
53 case thumbeb
: return "thumbeb";
54 case x86
: return "i386";
55 case x86_64
: return "x86_64";
56 case xcore
: return "xcore";
57 case nvptx
: return "nvptx";
58 case nvptx64
: return "nvptx64";
59 case le32
: return "le32";
60 case le64
: return "le64";
61 case amdil
: return "amdil";
62 case amdil64
: return "amdil64";
63 case hsail
: return "hsail";
64 case hsail64
: return "hsail64";
65 case spir
: return "spir";
66 case spir64
: return "spir64";
67 case kalimba
: return "kalimba";
68 case lanai
: return "lanai";
69 case shave
: return "shave";
70 case wasm32
: return "wasm32";
71 case wasm64
: return "wasm64";
72 case renderscript32
: return "renderscript32";
73 case renderscript64
: return "renderscript64";
76 llvm_unreachable("Invalid ArchType!");
79 StringRef
Triple::getArchTypePrefix(ArchType Kind
) {
85 case aarch64_be
: return "aarch64";
87 case arc
: return "arc";
92 case thumbeb
: return "arm";
94 case avr
: return "avr";
98 case ppc
: return "ppc";
103 case mips64el
: return "mips";
105 case nios2
: return "nios2";
107 case hexagon
: return "hexagon";
109 case amdgcn
: return "amdgcn";
110 case r600
: return "r600";
113 case bpfeb
: return "bpf";
117 case sparc
: return "sparc";
119 case systemz
: return "s390";
122 case x86_64
: return "x86";
124 case xcore
: return "xcore";
126 // NVPTX intrinsics are namespaced under nvvm.
127 case nvptx
: return "nvvm";
128 case nvptx64
: return "nvvm";
130 case le32
: return "le32";
131 case le64
: return "le64";
134 case amdil64
: return "amdil";
137 case hsail64
: return "hsail";
140 case spir64
: return "spir";
141 case kalimba
: return "kalimba";
142 case lanai
: return "lanai";
143 case shave
: return "shave";
145 case wasm64
: return "wasm";
148 case riscv64
: return "riscv";
152 StringRef
Triple::getVendorTypeName(VendorType Kind
) {
154 case UnknownVendor
: return "unknown";
156 case Apple
: return "apple";
157 case PC
: return "pc";
158 case SCEI
: return "scei";
159 case BGP
: return "bgp";
160 case BGQ
: return "bgq";
161 case Freescale
: return "fsl";
162 case IBM
: return "ibm";
163 case ImaginationTechnologies
: return "img";
164 case MipsTechnologies
: return "mti";
165 case NVIDIA
: return "nvidia";
166 case CSR
: return "csr";
167 case Myriad
: return "myriad";
168 case AMD
: return "amd";
169 case Mesa
: return "mesa";
170 case SUSE
: return "suse";
171 case OpenEmbedded
: return "oe";
174 llvm_unreachable("Invalid VendorType!");
177 StringRef
Triple::getOSTypeName(OSType Kind
) {
179 case UnknownOS
: return "unknown";
181 case Ananas
: return "ananas";
182 case CloudABI
: return "cloudabi";
183 case Darwin
: return "darwin";
184 case DragonFly
: return "dragonfly";
185 case FreeBSD
: return "freebsd";
186 case Fuchsia
: return "fuchsia";
187 case IOS
: return "ios";
188 case KFreeBSD
: return "kfreebsd";
189 case Linux
: return "linux";
190 case Lv2
: return "lv2";
191 case MacOSX
: return "macosx";
192 case NetBSD
: return "netbsd";
193 case OpenBSD
: return "openbsd";
194 case Solaris
: return "solaris";
195 case Win32
: return "windows";
196 case Haiku
: return "haiku";
197 case Minix
: return "minix";
198 case RTEMS
: return "rtems";
199 case NaCl
: return "nacl";
200 case CNK
: return "cnk";
201 case AIX
: return "aix";
202 case CUDA
: return "cuda";
203 case NVCL
: return "nvcl";
204 case AMDHSA
: return "amdhsa";
205 case PS4
: return "ps4";
206 case ELFIAMCU
: return "elfiamcu";
207 case TvOS
: return "tvos";
208 case WatchOS
: return "watchos";
209 case Mesa3D
: return "mesa3d";
210 case Contiki
: return "contiki";
211 case AMDPAL
: return "amdpal";
214 llvm_unreachable("Invalid OSType");
217 StringRef
Triple::getEnvironmentTypeName(EnvironmentType Kind
) {
219 case UnknownEnvironment
: return "unknown";
220 case GNU
: return "gnu";
221 case GNUABIN32
: return "gnuabin32";
222 case GNUABI64
: return "gnuabi64";
223 case GNUEABIHF
: return "gnueabihf";
224 case GNUEABI
: return "gnueabi";
225 case GNUX32
: return "gnux32";
226 case CODE16
: return "code16";
227 case EABI
: return "eabi";
228 case EABIHF
: return "eabihf";
229 case Android
: return "android";
230 case Musl
: return "musl";
231 case MuslEABI
: return "musleabi";
232 case MuslEABIHF
: return "musleabihf";
233 case MSVC
: return "msvc";
234 case Itanium
: return "itanium";
235 case Cygnus
: return "cygnus";
236 case CoreCLR
: return "coreclr";
237 case Simulator
: return "simulator";
240 llvm_unreachable("Invalid EnvironmentType!");
243 static Triple::ArchType
parseBPFArch(StringRef ArchName
) {
244 if (ArchName
.equals("bpf")) {
245 if (sys::IsLittleEndianHost
)
246 return Triple::bpfel
;
248 return Triple::bpfeb
;
249 } else if (ArchName
.equals("bpf_be") || ArchName
.equals("bpfeb")) {
250 return Triple::bpfeb
;
251 } else if (ArchName
.equals("bpf_le") || ArchName
.equals("bpfel")) {
252 return Triple::bpfel
;
254 return Triple::UnknownArch
;
258 Triple::ArchType
Triple::getArchTypeForLLVMName(StringRef Name
) {
259 Triple::ArchType
BPFArch(parseBPFArch(Name
));
260 return StringSwitch
<Triple::ArchType
>(Name
)
261 .Case("aarch64", aarch64
)
262 .Case("aarch64_be", aarch64_be
)
264 .Case("arm64", aarch64
) // "arm64" is an alias for "aarch64"
266 .Case("armeb", armeb
)
268 .StartsWith("bpf", BPFArch
)
270 .Case("mipsel", mipsel
)
271 .Case("mips64", mips64
)
272 .Case("mips64el", mips64el
)
273 .Case("msp430", msp430
)
274 .Case("nios2", nios2
)
275 .Case("ppc64", ppc64
)
278 .Case("ppc64le", ppc64le
)
280 .Case("amdgcn", amdgcn
)
281 .Case("riscv32", riscv32
)
282 .Case("riscv64", riscv64
)
283 .Case("hexagon", hexagon
)
284 .Case("sparc", sparc
)
285 .Case("sparcel", sparcel
)
286 .Case("sparcv9", sparcv9
)
287 .Case("systemz", systemz
)
289 .Case("tcele", tcele
)
290 .Case("thumb", thumb
)
291 .Case("thumbeb", thumbeb
)
293 .Case("x86-64", x86_64
)
294 .Case("xcore", xcore
)
295 .Case("nvptx", nvptx
)
296 .Case("nvptx64", nvptx64
)
299 .Case("amdil", amdil
)
300 .Case("amdil64", amdil64
)
301 .Case("hsail", hsail
)
302 .Case("hsail64", hsail64
)
304 .Case("spir64", spir64
)
305 .Case("kalimba", kalimba
)
306 .Case("lanai", lanai
)
307 .Case("shave", shave
)
308 .Case("wasm32", wasm32
)
309 .Case("wasm64", wasm64
)
310 .Case("renderscript32", renderscript32
)
311 .Case("renderscript64", renderscript64
)
312 .Default(UnknownArch
);
315 static Triple::ArchType
parseARMArch(StringRef ArchName
) {
316 ARM::ISAKind ISA
= ARM::parseArchISA(ArchName
);
317 ARM::EndianKind ENDIAN
= ARM::parseArchEndian(ArchName
);
319 Triple::ArchType arch
= Triple::UnknownArch
;
321 case ARM::EndianKind::LITTLE
: {
323 case ARM::ISAKind::ARM
:
326 case ARM::ISAKind::THUMB
:
327 arch
= Triple::thumb
;
329 case ARM::ISAKind::AARCH64
:
330 arch
= Triple::aarch64
;
332 case ARM::ISAKind::INVALID
:
337 case ARM::EndianKind::BIG
: {
339 case ARM::ISAKind::ARM
:
340 arch
= Triple::armeb
;
342 case ARM::ISAKind::THUMB
:
343 arch
= Triple::thumbeb
;
345 case ARM::ISAKind::AARCH64
:
346 arch
= Triple::aarch64_be
;
348 case ARM::ISAKind::INVALID
:
353 case ARM::EndianKind::INVALID
: {
358 ArchName
= ARM::getCanonicalArchName(ArchName
);
359 if (ArchName
.empty())
360 return Triple::UnknownArch
;
362 // Thumb only exists in v4+
363 if (ISA
== ARM::ISAKind::THUMB
&&
364 (ArchName
.startswith("v2") || ArchName
.startswith("v3")))
365 return Triple::UnknownArch
;
367 // Thumb only for v6m
368 ARM::ProfileKind Profile
= ARM::parseArchProfile(ArchName
);
369 unsigned Version
= ARM::parseArchVersion(ArchName
);
370 if (Profile
== ARM::ProfileKind::M
&& Version
== 6) {
371 if (ENDIAN
== ARM::EndianKind::BIG
)
372 return Triple::thumbeb
;
374 return Triple::thumb
;
380 static Triple::ArchType
parseArch(StringRef ArchName
) {
381 auto AT
= StringSwitch
<Triple::ArchType
>(ArchName
)
382 .Cases("i386", "i486", "i586", "i686", Triple::x86
)
383 // FIXME: Do we need to support these?
384 .Cases("i786", "i886", "i986", Triple::x86
)
385 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64
)
386 .Cases("powerpc", "ppc", "ppc32", Triple::ppc
)
387 .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64
)
388 .Cases("powerpc64le", "ppc64le", Triple::ppc64le
)
389 .Case("xscale", Triple::arm
)
390 .Case("xscaleeb", Triple::armeb
)
391 .Case("aarch64", Triple::aarch64
)
392 .Case("aarch64_be", Triple::aarch64_be
)
393 .Case("arc", Triple::arc
)
394 .Case("arm64", Triple::aarch64
)
395 .Case("arm", Triple::arm
)
396 .Case("armeb", Triple::armeb
)
397 .Case("thumb", Triple::thumb
)
398 .Case("thumbeb", Triple::thumbeb
)
399 .Case("avr", Triple::avr
)
400 .Case("msp430", Triple::msp430
)
401 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips
)
402 .Cases("mipsel", "mipsallegrexel", Triple::mipsel
)
403 .Cases("mips64", "mips64eb", Triple::mips64
)
404 .Case("mips64el", Triple::mips64el
)
405 .Case("nios2", Triple::nios2
)
406 .Case("r600", Triple::r600
)
407 .Case("amdgcn", Triple::amdgcn
)
408 .Case("riscv32", Triple::riscv32
)
409 .Case("riscv64", Triple::riscv64
)
410 .Case("hexagon", Triple::hexagon
)
411 .Cases("s390x", "systemz", Triple::systemz
)
412 .Case("sparc", Triple::sparc
)
413 .Case("sparcel", Triple::sparcel
)
414 .Cases("sparcv9", "sparc64", Triple::sparcv9
)
415 .Case("tce", Triple::tce
)
416 .Case("tcele", Triple::tcele
)
417 .Case("xcore", Triple::xcore
)
418 .Case("nvptx", Triple::nvptx
)
419 .Case("nvptx64", Triple::nvptx64
)
420 .Case("le32", Triple::le32
)
421 .Case("le64", Triple::le64
)
422 .Case("amdil", Triple::amdil
)
423 .Case("amdil64", Triple::amdil64
)
424 .Case("hsail", Triple::hsail
)
425 .Case("hsail64", Triple::hsail64
)
426 .Case("spir", Triple::spir
)
427 .Case("spir64", Triple::spir64
)
428 .StartsWith("kalimba", Triple::kalimba
)
429 .Case("lanai", Triple::lanai
)
430 .Case("shave", Triple::shave
)
431 .Case("wasm32", Triple::wasm32
)
432 .Case("wasm64", Triple::wasm64
)
433 .Case("renderscript32", Triple::renderscript32
)
434 .Case("renderscript64", Triple::renderscript64
)
435 .Default(Triple::UnknownArch
);
437 // Some architectures require special parsing logic just to compute the
439 if (AT
== Triple::UnknownArch
) {
440 if (ArchName
.startswith("arm") || ArchName
.startswith("thumb") ||
441 ArchName
.startswith("aarch64"))
442 return parseARMArch(ArchName
);
443 if (ArchName
.startswith("bpf"))
444 return parseBPFArch(ArchName
);
450 static Triple::VendorType
parseVendor(StringRef VendorName
) {
451 return StringSwitch
<Triple::VendorType
>(VendorName
)
452 .Case("apple", Triple::Apple
)
453 .Case("pc", Triple::PC
)
454 .Case("scei", Triple::SCEI
)
455 .Case("bgp", Triple::BGP
)
456 .Case("bgq", Triple::BGQ
)
457 .Case("fsl", Triple::Freescale
)
458 .Case("ibm", Triple::IBM
)
459 .Case("img", Triple::ImaginationTechnologies
)
460 .Case("mti", Triple::MipsTechnologies
)
461 .Case("nvidia", Triple::NVIDIA
)
462 .Case("csr", Triple::CSR
)
463 .Case("myriad", Triple::Myriad
)
464 .Case("amd", Triple::AMD
)
465 .Case("mesa", Triple::Mesa
)
466 .Case("suse", Triple::SUSE
)
467 .Case("oe", Triple::OpenEmbedded
)
468 .Default(Triple::UnknownVendor
);
471 static Triple::OSType
parseOS(StringRef OSName
) {
472 return StringSwitch
<Triple::OSType
>(OSName
)
473 .StartsWith("ananas", Triple::Ananas
)
474 .StartsWith("cloudabi", Triple::CloudABI
)
475 .StartsWith("darwin", Triple::Darwin
)
476 .StartsWith("dragonfly", Triple::DragonFly
)
477 .StartsWith("freebsd", Triple::FreeBSD
)
478 .StartsWith("fuchsia", Triple::Fuchsia
)
479 .StartsWith("ios", Triple::IOS
)
480 .StartsWith("kfreebsd", Triple::KFreeBSD
)
481 .StartsWith("linux", Triple::Linux
)
482 .StartsWith("lv2", Triple::Lv2
)
483 .StartsWith("macos", Triple::MacOSX
)
484 .StartsWith("netbsd", Triple::NetBSD
)
485 .StartsWith("openbsd", Triple::OpenBSD
)
486 .StartsWith("solaris", Triple::Solaris
)
487 .StartsWith("win32", Triple::Win32
)
488 .StartsWith("windows", Triple::Win32
)
489 .StartsWith("haiku", Triple::Haiku
)
490 .StartsWith("minix", Triple::Minix
)
491 .StartsWith("rtems", Triple::RTEMS
)
492 .StartsWith("nacl", Triple::NaCl
)
493 .StartsWith("cnk", Triple::CNK
)
494 .StartsWith("aix", Triple::AIX
)
495 .StartsWith("cuda", Triple::CUDA
)
496 .StartsWith("nvcl", Triple::NVCL
)
497 .StartsWith("amdhsa", Triple::AMDHSA
)
498 .StartsWith("ps4", Triple::PS4
)
499 .StartsWith("elfiamcu", Triple::ELFIAMCU
)
500 .StartsWith("tvos", Triple::TvOS
)
501 .StartsWith("watchos", Triple::WatchOS
)
502 .StartsWith("mesa3d", Triple::Mesa3D
)
503 .StartsWith("contiki", Triple::Contiki
)
504 .StartsWith("amdpal", Triple::AMDPAL
)
505 .Default(Triple::UnknownOS
);
508 static Triple::EnvironmentType
parseEnvironment(StringRef EnvironmentName
) {
509 return StringSwitch
<Triple::EnvironmentType
>(EnvironmentName
)
510 .StartsWith("eabihf", Triple::EABIHF
)
511 .StartsWith("eabi", Triple::EABI
)
512 .StartsWith("gnuabin32", Triple::GNUABIN32
)
513 .StartsWith("gnuabi64", Triple::GNUABI64
)
514 .StartsWith("gnueabihf", Triple::GNUEABIHF
)
515 .StartsWith("gnueabi", Triple::GNUEABI
)
516 .StartsWith("gnux32", Triple::GNUX32
)
517 .StartsWith("code16", Triple::CODE16
)
518 .StartsWith("gnu", Triple::GNU
)
519 .StartsWith("android", Triple::Android
)
520 .StartsWith("musleabihf", Triple::MuslEABIHF
)
521 .StartsWith("musleabi", Triple::MuslEABI
)
522 .StartsWith("musl", Triple::Musl
)
523 .StartsWith("msvc", Triple::MSVC
)
524 .StartsWith("itanium", Triple::Itanium
)
525 .StartsWith("cygnus", Triple::Cygnus
)
526 .StartsWith("coreclr", Triple::CoreCLR
)
527 .StartsWith("simulator", Triple::Simulator
)
528 .Default(Triple::UnknownEnvironment
);
531 static Triple::ObjectFormatType
parseFormat(StringRef EnvironmentName
) {
532 return StringSwitch
<Triple::ObjectFormatType
>(EnvironmentName
)
533 .EndsWith("coff", Triple::COFF
)
534 .EndsWith("elf", Triple::ELF
)
535 .EndsWith("macho", Triple::MachO
)
536 .EndsWith("wasm", Triple::Wasm
)
537 .Default(Triple::UnknownObjectFormat
);
540 static Triple::SubArchType
parseSubArch(StringRef SubArchName
) {
541 StringRef ARMSubArch
= ARM::getCanonicalArchName(SubArchName
);
543 // For now, this is the small part. Early return.
544 if (ARMSubArch
.empty())
545 return StringSwitch
<Triple::SubArchType
>(SubArchName
)
546 .EndsWith("kalimba3", Triple::KalimbaSubArch_v3
)
547 .EndsWith("kalimba4", Triple::KalimbaSubArch_v4
)
548 .EndsWith("kalimba5", Triple::KalimbaSubArch_v5
)
549 .Default(Triple::NoSubArch
);
552 switch(ARM::parseArch(ARMSubArch
)) {
553 case ARM::ArchKind::ARMV4
:
554 return Triple::NoSubArch
;
555 case ARM::ArchKind::ARMV4T
:
556 return Triple::ARMSubArch_v4t
;
557 case ARM::ArchKind::ARMV5T
:
558 return Triple::ARMSubArch_v5
;
559 case ARM::ArchKind::ARMV5TE
:
560 case ARM::ArchKind::IWMMXT
:
561 case ARM::ArchKind::IWMMXT2
:
562 case ARM::ArchKind::XSCALE
:
563 case ARM::ArchKind::ARMV5TEJ
:
564 return Triple::ARMSubArch_v5te
;
565 case ARM::ArchKind::ARMV6
:
566 return Triple::ARMSubArch_v6
;
567 case ARM::ArchKind::ARMV6K
:
568 case ARM::ArchKind::ARMV6KZ
:
569 return Triple::ARMSubArch_v6k
;
570 case ARM::ArchKind::ARMV6T2
:
571 return Triple::ARMSubArch_v6t2
;
572 case ARM::ArchKind::ARMV6M
:
573 return Triple::ARMSubArch_v6m
;
574 case ARM::ArchKind::ARMV7A
:
575 case ARM::ArchKind::ARMV7R
:
576 return Triple::ARMSubArch_v7
;
577 case ARM::ArchKind::ARMV7VE
:
578 return Triple::ARMSubArch_v7ve
;
579 case ARM::ArchKind::ARMV7K
:
580 return Triple::ARMSubArch_v7k
;
581 case ARM::ArchKind::ARMV7M
:
582 return Triple::ARMSubArch_v7m
;
583 case ARM::ArchKind::ARMV7S
:
584 return Triple::ARMSubArch_v7s
;
585 case ARM::ArchKind::ARMV7EM
:
586 return Triple::ARMSubArch_v7em
;
587 case ARM::ArchKind::ARMV8A
:
588 return Triple::ARMSubArch_v8
;
589 case ARM::ArchKind::ARMV8_1A
:
590 return Triple::ARMSubArch_v8_1a
;
591 case ARM::ArchKind::ARMV8_2A
:
592 return Triple::ARMSubArch_v8_2a
;
593 case ARM::ArchKind::ARMV8_3A
:
594 return Triple::ARMSubArch_v8_3a
;
595 case ARM::ArchKind::ARMV8_4A
:
596 return Triple::ARMSubArch_v8_4a
;
597 case ARM::ArchKind::ARMV8R
:
598 return Triple::ARMSubArch_v8r
;
599 case ARM::ArchKind::ARMV8MBaseline
:
600 return Triple::ARMSubArch_v8m_baseline
;
601 case ARM::ArchKind::ARMV8MMainline
:
602 return Triple::ARMSubArch_v8m_mainline
;
604 return Triple::NoSubArch
;
608 static StringRef
getObjectFormatTypeName(Triple::ObjectFormatType Kind
) {
610 case Triple::UnknownObjectFormat
: return "";
611 case Triple::COFF
: return "coff";
612 case Triple::ELF
: return "elf";
613 case Triple::MachO
: return "macho";
614 case Triple::Wasm
: return "wasm";
616 llvm_unreachable("unknown object format type");
619 static Triple::ObjectFormatType
getDefaultFormat(const Triple
&T
) {
620 switch (T
.getArch()) {
621 case Triple::UnknownArch
:
622 case Triple::aarch64
:
628 return Triple::MachO
;
629 else if (T
.isOSWindows())
633 case Triple::aarch64_be
:
637 case Triple::amdil64
:
642 case Triple::hexagon
:
645 case Triple::hsail64
:
646 case Triple::kalimba
:
651 case Triple::mips64el
:
656 case Triple::nvptx64
:
657 case Triple::ppc64le
:
659 case Triple::renderscript32
:
660 case Triple::renderscript64
:
661 case Triple::riscv32
:
662 case Triple::riscv64
:
665 case Triple::sparcel
:
666 case Triple::sparcv9
:
669 case Triple::systemz
:
672 case Triple::thumbeb
:
679 return Triple::MachO
;
686 llvm_unreachable("unknown architecture");
689 /// Construct a triple from the string representation provided.
691 /// This stores the string representation and parses the various pieces into
693 Triple::Triple(const Twine
&Str
)
694 : Data(Str
.str()), Arch(UnknownArch
), SubArch(NoSubArch
),
695 Vendor(UnknownVendor
), OS(UnknownOS
), Environment(UnknownEnvironment
),
696 ObjectFormat(UnknownObjectFormat
) {
697 // Do minimal parsing by hand here.
698 SmallVector
<StringRef
, 4> Components
;
699 StringRef(Data
).split(Components
, '-', /*MaxSplit*/ 3);
700 if (Components
.size() > 0) {
701 Arch
= parseArch(Components
[0]);
702 SubArch
= parseSubArch(Components
[0]);
703 if (Components
.size() > 1) {
704 Vendor
= parseVendor(Components
[1]);
705 if (Components
.size() > 2) {
706 OS
= parseOS(Components
[2]);
707 if (Components
.size() > 3) {
708 Environment
= parseEnvironment(Components
[3]);
709 ObjectFormat
= parseFormat(Components
[3]);
714 if (ObjectFormat
== UnknownObjectFormat
)
715 ObjectFormat
= getDefaultFormat(*this);
718 /// Construct a triple from string representations of the architecture,
721 /// This joins each argument into a canonical string representation and parses
722 /// them into enum members. It leaves the environment unknown and omits it from
723 /// the string representation.
724 Triple::Triple(const Twine
&ArchStr
, const Twine
&VendorStr
, const Twine
&OSStr
)
725 : Data((ArchStr
+ Twine('-') + VendorStr
+ Twine('-') + OSStr
).str()),
726 Arch(parseArch(ArchStr
.str())),
727 SubArch(parseSubArch(ArchStr
.str())),
728 Vendor(parseVendor(VendorStr
.str())),
729 OS(parseOS(OSStr
.str())),
730 Environment(), ObjectFormat(Triple::UnknownObjectFormat
) {
731 ObjectFormat
= getDefaultFormat(*this);
734 /// Construct a triple from string representations of the architecture,
735 /// vendor, OS, and environment.
737 /// This joins each argument into a canonical string representation and parses
738 /// them into enum members.
739 Triple::Triple(const Twine
&ArchStr
, const Twine
&VendorStr
, const Twine
&OSStr
,
740 const Twine
&EnvironmentStr
)
741 : Data((ArchStr
+ Twine('-') + VendorStr
+ Twine('-') + OSStr
+ Twine('-') +
742 EnvironmentStr
).str()),
743 Arch(parseArch(ArchStr
.str())),
744 SubArch(parseSubArch(ArchStr
.str())),
745 Vendor(parseVendor(VendorStr
.str())),
746 OS(parseOS(OSStr
.str())),
747 Environment(parseEnvironment(EnvironmentStr
.str())),
748 ObjectFormat(parseFormat(EnvironmentStr
.str())) {
749 if (ObjectFormat
== Triple::UnknownObjectFormat
)
750 ObjectFormat
= getDefaultFormat(*this);
753 std::string
Triple::normalize(StringRef Str
) {
754 bool IsMinGW32
= false;
755 bool IsCygwin
= false;
757 // Parse into components.
758 SmallVector
<StringRef
, 4> Components
;
759 Str
.split(Components
, '-');
761 // If the first component corresponds to a known architecture, preferentially
762 // use it for the architecture. If the second component corresponds to a
763 // known vendor, preferentially use it for the vendor, etc. This avoids silly
764 // component movement when a component parses as (eg) both a valid arch and a
766 ArchType Arch
= UnknownArch
;
767 if (Components
.size() > 0)
768 Arch
= parseArch(Components
[0]);
769 VendorType Vendor
= UnknownVendor
;
770 if (Components
.size() > 1)
771 Vendor
= parseVendor(Components
[1]);
772 OSType OS
= UnknownOS
;
773 if (Components
.size() > 2) {
774 OS
= parseOS(Components
[2]);
775 IsCygwin
= Components
[2].startswith("cygwin");
776 IsMinGW32
= Components
[2].startswith("mingw");
778 EnvironmentType Environment
= UnknownEnvironment
;
779 if (Components
.size() > 3)
780 Environment
= parseEnvironment(Components
[3]);
781 ObjectFormatType ObjectFormat
= UnknownObjectFormat
;
782 if (Components
.size() > 4)
783 ObjectFormat
= parseFormat(Components
[4]);
785 // Note which components are already in their final position. These will not
788 Found
[0] = Arch
!= UnknownArch
;
789 Found
[1] = Vendor
!= UnknownVendor
;
790 Found
[2] = OS
!= UnknownOS
;
791 Found
[3] = Environment
!= UnknownEnvironment
;
793 // If they are not there already, permute the components into their canonical
794 // positions by seeing if they parse as a valid architecture, and if so moving
795 // the component to the architecture position etc.
796 for (unsigned Pos
= 0; Pos
!= array_lengthof(Found
); ++Pos
) {
798 continue; // Already in the canonical position.
800 for (unsigned Idx
= 0; Idx
!= Components
.size(); ++Idx
) {
801 // Do not reparse any components that already matched.
802 if (Idx
< array_lengthof(Found
) && Found
[Idx
])
805 // Does this component parse as valid for the target position?
807 StringRef Comp
= Components
[Idx
];
809 default: llvm_unreachable("unexpected component type!");
811 Arch
= parseArch(Comp
);
812 Valid
= Arch
!= UnknownArch
;
815 Vendor
= parseVendor(Comp
);
816 Valid
= Vendor
!= UnknownVendor
;
820 IsCygwin
= Comp
.startswith("cygwin");
821 IsMinGW32
= Comp
.startswith("mingw");
822 Valid
= OS
!= UnknownOS
|| IsCygwin
|| IsMinGW32
;
825 Environment
= parseEnvironment(Comp
);
826 Valid
= Environment
!= UnknownEnvironment
;
828 ObjectFormat
= parseFormat(Comp
);
829 Valid
= ObjectFormat
!= UnknownObjectFormat
;
834 continue; // Nope, try the next component.
836 // Move the component to the target position, pushing any non-fixed
837 // components that are in the way to the right. This tends to give
838 // good results in the common cases of a forgotten vendor component
839 // or a wrongly positioned environment.
841 // Insert left, pushing the existing components to the right. For
842 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
843 StringRef
CurrentComponent(""); // The empty component.
844 // Replace the component we are moving with an empty component.
845 std::swap(CurrentComponent
, Components
[Idx
]);
846 // Insert the component being moved at Pos, displacing any existing
847 // components to the right.
848 for (unsigned i
= Pos
; !CurrentComponent
.empty(); ++i
) {
849 // Skip over any fixed components.
850 while (i
< array_lengthof(Found
) && Found
[i
])
852 // Place the component at the new position, getting the component
853 // that was at this position - it will be moved right.
854 std::swap(CurrentComponent
, Components
[i
]);
856 } else if (Pos
> Idx
) {
857 // Push right by inserting empty components until the component at Idx
858 // reaches the target position Pos. For example, pc-a -> -pc-a when
859 // moving pc to the second position.
861 // Insert one empty component at Idx.
862 StringRef
CurrentComponent(""); // The empty component.
863 for (unsigned i
= Idx
; i
< Components
.size();) {
864 // Place the component at the new position, getting the component
865 // that was at this position - it will be moved right.
866 std::swap(CurrentComponent
, Components
[i
]);
867 // If it was placed on top of an empty component then we are done.
868 if (CurrentComponent
.empty())
870 // Advance to the next component, skipping any fixed components.
871 while (++i
< array_lengthof(Found
) && Found
[i
])
874 // The last component was pushed off the end - append it.
875 if (!CurrentComponent
.empty())
876 Components
.push_back(CurrentComponent
);
878 // Advance Idx to the component's new position.
879 while (++Idx
< array_lengthof(Found
) && Found
[Idx
])
881 } while (Idx
< Pos
); // Add more until the final position is reached.
883 assert(Pos
< Components
.size() && Components
[Pos
] == Comp
&&
884 "Component moved wrong!");
890 // Special case logic goes here. At this point Arch, Vendor and OS have the
891 // correct values for the computed components.
892 std::string NormalizedEnvironment
;
893 if (Environment
== Triple::Android
&& Components
[3].startswith("androideabi")) {
894 StringRef AndroidVersion
= Components
[3].drop_front(strlen("androideabi"));
895 if (AndroidVersion
.empty()) {
896 Components
[3] = "android";
898 NormalizedEnvironment
= Twine("android", AndroidVersion
).str();
899 Components
[3] = NormalizedEnvironment
;
903 // SUSE uses "gnueabi" to mean "gnueabihf"
904 if (Vendor
== Triple::SUSE
&& Environment
== llvm::Triple::GNUEABI
)
905 Components
[3] = "gnueabihf";
907 if (OS
== Triple::Win32
) {
908 Components
.resize(4);
909 Components
[2] = "windows";
910 if (Environment
== UnknownEnvironment
) {
911 if (ObjectFormat
== UnknownObjectFormat
|| ObjectFormat
== Triple::COFF
)
912 Components
[3] = "msvc";
914 Components
[3] = getObjectFormatTypeName(ObjectFormat
);
916 } else if (IsMinGW32
) {
917 Components
.resize(4);
918 Components
[2] = "windows";
919 Components
[3] = "gnu";
920 } else if (IsCygwin
) {
921 Components
.resize(4);
922 Components
[2] = "windows";
923 Components
[3] = "cygnus";
925 if (IsMinGW32
|| IsCygwin
||
926 (OS
== Triple::Win32
&& Environment
!= UnknownEnvironment
)) {
927 if (ObjectFormat
!= UnknownObjectFormat
&& ObjectFormat
!= Triple::COFF
) {
928 Components
.resize(5);
929 Components
[4] = getObjectFormatTypeName(ObjectFormat
);
933 // Stick the corrected components back together to form the normalized string.
934 std::string Normalized
;
935 for (unsigned i
= 0, e
= Components
.size(); i
!= e
; ++i
) {
936 if (i
) Normalized
+= '-';
937 Normalized
+= Components
[i
];
942 StringRef
Triple::getArchName() const {
943 return StringRef(Data
).split('-').first
; // Isolate first component
946 StringRef
Triple::getVendorName() const {
947 StringRef Tmp
= StringRef(Data
).split('-').second
; // Strip first component
948 return Tmp
.split('-').first
; // Isolate second component
951 StringRef
Triple::getOSName() const {
952 StringRef Tmp
= StringRef(Data
).split('-').second
; // Strip first component
953 Tmp
= Tmp
.split('-').second
; // Strip second component
954 return Tmp
.split('-').first
; // Isolate third component
957 StringRef
Triple::getEnvironmentName() const {
958 StringRef Tmp
= StringRef(Data
).split('-').second
; // Strip first component
959 Tmp
= Tmp
.split('-').second
; // Strip second component
960 return Tmp
.split('-').second
; // Strip third component
963 StringRef
Triple::getOSAndEnvironmentName() const {
964 StringRef Tmp
= StringRef(Data
).split('-').second
; // Strip first component
965 return Tmp
.split('-').second
; // Strip second component
968 static unsigned EatNumber(StringRef
&Str
) {
969 assert(!Str
.empty() && Str
[0] >= '0' && Str
[0] <= '9' && "Not a number");
973 // Consume the leading digit.
974 Result
= Result
*10 + (Str
[0] - '0');
978 } while (!Str
.empty() && Str
[0] >= '0' && Str
[0] <= '9');
983 static void parseVersionFromName(StringRef Name
, unsigned &Major
,
984 unsigned &Minor
, unsigned &Micro
) {
985 // Any unset version defaults to 0.
986 Major
= Minor
= Micro
= 0;
988 // Parse up to three components.
989 unsigned *Components
[3] = {&Major
, &Minor
, &Micro
};
990 for (unsigned i
= 0; i
!= 3; ++i
) {
991 if (Name
.empty() || Name
[0] < '0' || Name
[0] > '9')
994 // Consume the leading number.
995 *Components
[i
] = EatNumber(Name
);
997 // Consume the separator, if present.
998 if (Name
.startswith("."))
999 Name
= Name
.substr(1);
1003 void Triple::getEnvironmentVersion(unsigned &Major
, unsigned &Minor
,
1004 unsigned &Micro
) const {
1005 StringRef EnvironmentName
= getEnvironmentName();
1006 StringRef EnvironmentTypeName
= getEnvironmentTypeName(getEnvironment());
1007 if (EnvironmentName
.startswith(EnvironmentTypeName
))
1008 EnvironmentName
= EnvironmentName
.substr(EnvironmentTypeName
.size());
1010 parseVersionFromName(EnvironmentName
, Major
, Minor
, Micro
);
1013 void Triple::getOSVersion(unsigned &Major
, unsigned &Minor
,
1014 unsigned &Micro
) const {
1015 StringRef OSName
= getOSName();
1016 // Assume that the OS portion of the triple starts with the canonical name.
1017 StringRef OSTypeName
= getOSTypeName(getOS());
1018 if (OSName
.startswith(OSTypeName
))
1019 OSName
= OSName
.substr(OSTypeName
.size());
1020 else if (getOS() == MacOSX
)
1021 OSName
.consume_front("macos");
1023 parseVersionFromName(OSName
, Major
, Minor
, Micro
);
1026 bool Triple::getMacOSXVersion(unsigned &Major
, unsigned &Minor
,
1027 unsigned &Micro
) const {
1028 getOSVersion(Major
, Minor
, Micro
);
1031 default: llvm_unreachable("unexpected OS for Darwin triple");
1033 // Default to darwin8, i.e., MacOSX 10.4.
1036 // Darwin version numbers are skewed from OS X versions.
1055 // Ignore the version from the triple. This is only handled because the
1056 // the clang driver combines OS X and IOS support into a common Darwin
1057 // toolchain that wants to know the OS X version number even when targeting
1067 void Triple::getiOSVersion(unsigned &Major
, unsigned &Minor
,
1068 unsigned &Micro
) const {
1070 default: llvm_unreachable("unexpected OS for Darwin triple");
1073 // Ignore the version from the triple. This is only handled because the
1074 // the clang driver combines OS X and IOS support into a common Darwin
1075 // toolchain that wants to know the iOS version number even when targeting
1083 getOSVersion(Major
, Minor
, Micro
);
1084 // Default to 5.0 (or 7.0 for arm64).
1086 Major
= (getArch() == aarch64
) ? 7 : 5;
1089 llvm_unreachable("conflicting triple info");
1093 void Triple::getWatchOSVersion(unsigned &Major
, unsigned &Minor
,
1094 unsigned &Micro
) const {
1096 default: llvm_unreachable("unexpected OS for Darwin triple");
1099 // Ignore the version from the triple. This is only handled because the
1100 // the clang driver combines OS X and IOS support into a common Darwin
1101 // toolchain that wants to know the iOS version number even when targeting
1108 getOSVersion(Major
, Minor
, Micro
);
1113 llvm_unreachable("conflicting triple info");
1117 void Triple::setTriple(const Twine
&Str
) {
1118 *this = Triple(Str
);
1121 void Triple::setArch(ArchType Kind
) {
1122 setArchName(getArchTypeName(Kind
));
1125 void Triple::setVendor(VendorType Kind
) {
1126 setVendorName(getVendorTypeName(Kind
));
1129 void Triple::setOS(OSType Kind
) {
1130 setOSName(getOSTypeName(Kind
));
1133 void Triple::setEnvironment(EnvironmentType Kind
) {
1134 if (ObjectFormat
== getDefaultFormat(*this))
1135 return setEnvironmentName(getEnvironmentTypeName(Kind
));
1137 setEnvironmentName((getEnvironmentTypeName(Kind
) + Twine("-") +
1138 getObjectFormatTypeName(ObjectFormat
)).str());
1141 void Triple::setObjectFormat(ObjectFormatType Kind
) {
1142 if (Environment
== UnknownEnvironment
)
1143 return setEnvironmentName(getObjectFormatTypeName(Kind
));
1145 setEnvironmentName((getEnvironmentTypeName(Environment
) + Twine("-") +
1146 getObjectFormatTypeName(Kind
)).str());
1149 void Triple::setArchName(StringRef Str
) {
1150 // Work around a miscompilation bug for Twines in gcc 4.0.3.
1151 SmallString
<64> Triple
;
1154 Triple
+= getVendorName();
1156 Triple
+= getOSAndEnvironmentName();
1160 void Triple::setVendorName(StringRef Str
) {
1161 setTriple(getArchName() + "-" + Str
+ "-" + getOSAndEnvironmentName());
1164 void Triple::setOSName(StringRef Str
) {
1165 if (hasEnvironment())
1166 setTriple(getArchName() + "-" + getVendorName() + "-" + Str
+
1167 "-" + getEnvironmentName());
1169 setTriple(getArchName() + "-" + getVendorName() + "-" + Str
);
1172 void Triple::setEnvironmentName(StringRef Str
) {
1173 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1177 void Triple::setOSAndEnvironmentName(StringRef Str
) {
1178 setTriple(getArchName() + "-" + getVendorName() + "-" + Str
);
1181 static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch
) {
1183 case llvm::Triple::UnknownArch
:
1186 case llvm::Triple::avr
:
1187 case llvm::Triple::msp430
:
1190 case llvm::Triple::arc
:
1191 case llvm::Triple::arm
:
1192 case llvm::Triple::armeb
:
1193 case llvm::Triple::hexagon
:
1194 case llvm::Triple::le32
:
1195 case llvm::Triple::mips
:
1196 case llvm::Triple::mipsel
:
1197 case llvm::Triple::nios2
:
1198 case llvm::Triple::nvptx
:
1199 case llvm::Triple::ppc
:
1200 case llvm::Triple::r600
:
1201 case llvm::Triple::riscv32
:
1202 case llvm::Triple::sparc
:
1203 case llvm::Triple::sparcel
:
1204 case llvm::Triple::tce
:
1205 case llvm::Triple::tcele
:
1206 case llvm::Triple::thumb
:
1207 case llvm::Triple::thumbeb
:
1208 case llvm::Triple::x86
:
1209 case llvm::Triple::xcore
:
1210 case llvm::Triple::amdil
:
1211 case llvm::Triple::hsail
:
1212 case llvm::Triple::spir
:
1213 case llvm::Triple::kalimba
:
1214 case llvm::Triple::lanai
:
1215 case llvm::Triple::shave
:
1216 case llvm::Triple::wasm32
:
1217 case llvm::Triple::renderscript32
:
1220 case llvm::Triple::aarch64
:
1221 case llvm::Triple::aarch64_be
:
1222 case llvm::Triple::amdgcn
:
1223 case llvm::Triple::bpfel
:
1224 case llvm::Triple::bpfeb
:
1225 case llvm::Triple::le64
:
1226 case llvm::Triple::mips64
:
1227 case llvm::Triple::mips64el
:
1228 case llvm::Triple::nvptx64
:
1229 case llvm::Triple::ppc64
:
1230 case llvm::Triple::ppc64le
:
1231 case llvm::Triple::riscv64
:
1232 case llvm::Triple::sparcv9
:
1233 case llvm::Triple::systemz
:
1234 case llvm::Triple::x86_64
:
1235 case llvm::Triple::amdil64
:
1236 case llvm::Triple::hsail64
:
1237 case llvm::Triple::spir64
:
1238 case llvm::Triple::wasm64
:
1239 case llvm::Triple::renderscript64
:
1242 llvm_unreachable("Invalid architecture value");
1245 bool Triple::isArch64Bit() const {
1246 return getArchPointerBitWidth(getArch()) == 64;
1249 bool Triple::isArch32Bit() const {
1250 return getArchPointerBitWidth(getArch()) == 32;
1253 bool Triple::isArch16Bit() const {
1254 return getArchPointerBitWidth(getArch()) == 16;
1257 Triple
Triple::get32BitArchVariant() const {
1259 switch (getArch()) {
1260 case Triple::UnknownArch
:
1261 case Triple::amdgcn
:
1265 case Triple::msp430
:
1266 case Triple::systemz
:
1267 case Triple::ppc64le
:
1268 T
.setArch(UnknownArch
);
1277 case Triple::hexagon
:
1278 case Triple::kalimba
:
1281 case Triple::mipsel
:
1286 case Triple::riscv32
:
1288 case Triple::sparcel
:
1292 case Triple::thumbeb
:
1297 case Triple::wasm32
:
1298 case Triple::renderscript32
:
1302 case Triple::aarch64
: T
.setArch(Triple::arm
); break;
1303 case Triple::aarch64_be
: T
.setArch(Triple::armeb
); break;
1304 case Triple::le64
: T
.setArch(Triple::le32
); break;
1305 case Triple::mips64
: T
.setArch(Triple::mips
); break;
1306 case Triple::mips64el
: T
.setArch(Triple::mipsel
); break;
1307 case Triple::nvptx64
: T
.setArch(Triple::nvptx
); break;
1308 case Triple::ppc64
: T
.setArch(Triple::ppc
); break;
1309 case Triple::sparcv9
: T
.setArch(Triple::sparc
); break;
1310 case Triple::riscv64
: T
.setArch(Triple::riscv32
); break;
1311 case Triple::x86_64
: T
.setArch(Triple::x86
); break;
1312 case Triple::amdil64
: T
.setArch(Triple::amdil
); break;
1313 case Triple::hsail64
: T
.setArch(Triple::hsail
); break;
1314 case Triple::spir64
: T
.setArch(Triple::spir
); break;
1315 case Triple::wasm64
: T
.setArch(Triple::wasm32
); break;
1316 case Triple::renderscript64
: T
.setArch(Triple::renderscript32
); break;
1321 Triple
Triple::get64BitArchVariant() const {
1323 switch (getArch()) {
1324 case Triple::UnknownArch
:
1327 case Triple::hexagon
:
1328 case Triple::kalimba
:
1330 case Triple::msp430
:
1336 case Triple::sparcel
:
1338 T
.setArch(UnknownArch
);
1341 case Triple::aarch64
:
1342 case Triple::aarch64_be
:
1346 case Triple::amdil64
:
1347 case Triple::amdgcn
:
1348 case Triple::hsail64
:
1349 case Triple::spir64
:
1350 case Triple::mips64
:
1351 case Triple::mips64el
:
1352 case Triple::nvptx64
:
1354 case Triple::ppc64le
:
1355 case Triple::riscv64
:
1356 case Triple::sparcv9
:
1357 case Triple::systemz
:
1358 case Triple::x86_64
:
1359 case Triple::wasm64
:
1360 case Triple::renderscript64
:
1364 case Triple::arm
: T
.setArch(Triple::aarch64
); break;
1365 case Triple::armeb
: T
.setArch(Triple::aarch64_be
); break;
1366 case Triple::le32
: T
.setArch(Triple::le64
); break;
1367 case Triple::mips
: T
.setArch(Triple::mips64
); break;
1368 case Triple::mipsel
: T
.setArch(Triple::mips64el
); break;
1369 case Triple::nvptx
: T
.setArch(Triple::nvptx64
); break;
1370 case Triple::ppc
: T
.setArch(Triple::ppc64
); break;
1371 case Triple::sparc
: T
.setArch(Triple::sparcv9
); break;
1372 case Triple::riscv32
: T
.setArch(Triple::riscv64
); break;
1373 case Triple::x86
: T
.setArch(Triple::x86_64
); break;
1374 case Triple::amdil
: T
.setArch(Triple::amdil64
); break;
1375 case Triple::hsail
: T
.setArch(Triple::hsail64
); break;
1376 case Triple::spir
: T
.setArch(Triple::spir64
); break;
1377 case Triple::thumb
: T
.setArch(Triple::aarch64
); break;
1378 case Triple::thumbeb
: T
.setArch(Triple::aarch64_be
); break;
1379 case Triple::wasm32
: T
.setArch(Triple::wasm64
); break;
1380 case Triple::renderscript32
: T
.setArch(Triple::renderscript64
); break;
1385 Triple
Triple::getBigEndianArchVariant() const {
1387 // Already big endian.
1388 if (!isLittleEndian())
1390 switch (getArch()) {
1391 case Triple::UnknownArch
:
1392 case Triple::amdgcn
:
1393 case Triple::amdil64
:
1396 case Triple::hexagon
:
1397 case Triple::hsail64
:
1399 case Triple::kalimba
:
1402 case Triple::msp430
:
1404 case Triple::nvptx64
:
1407 case Triple::riscv32
:
1408 case Triple::riscv64
:
1410 case Triple::spir64
:
1412 case Triple::wasm32
:
1413 case Triple::wasm64
:
1415 case Triple::x86_64
:
1417 case Triple::renderscript32
:
1418 case Triple::renderscript64
:
1420 // ARM is intentionally unsupported here, changing the architecture would
1421 // drop any arch suffixes.
1424 T
.setArch(UnknownArch
);
1427 case Triple::tcele
: T
.setArch(Triple::tce
); break;
1428 case Triple::aarch64
: T
.setArch(Triple::aarch64_be
); break;
1429 case Triple::bpfel
: T
.setArch(Triple::bpfeb
); break;
1430 case Triple::mips64el
:T
.setArch(Triple::mips64
); break;
1431 case Triple::mipsel
: T
.setArch(Triple::mips
); break;
1432 case Triple::ppc64le
: T
.setArch(Triple::ppc64
); break;
1433 case Triple::sparcel
: T
.setArch(Triple::sparc
); break;
1435 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1440 Triple
Triple::getLittleEndianArchVariant() const {
1442 if (isLittleEndian())
1445 switch (getArch()) {
1446 case Triple::UnknownArch
:
1449 case Triple::sparcv9
:
1450 case Triple::systemz
:
1452 // ARM is intentionally unsupported here, changing the architecture would
1453 // drop any arch suffixes.
1455 case Triple::thumbeb
:
1456 T
.setArch(UnknownArch
);
1459 case Triple::tce
: T
.setArch(Triple::tcele
); break;
1460 case Triple::aarch64_be
: T
.setArch(Triple::aarch64
); break;
1461 case Triple::bpfeb
: T
.setArch(Triple::bpfel
); break;
1462 case Triple::mips64
: T
.setArch(Triple::mips64el
); break;
1463 case Triple::mips
: T
.setArch(Triple::mipsel
); break;
1464 case Triple::ppc64
: T
.setArch(Triple::ppc64le
); break;
1465 case Triple::sparc
: T
.setArch(Triple::sparcel
); break;
1467 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1472 bool Triple::isLittleEndian() const {
1473 switch (getArch()) {
1474 case Triple::aarch64
:
1475 case Triple::amdgcn
:
1476 case Triple::amdil64
:
1481 case Triple::hexagon
:
1482 case Triple::hsail64
:
1484 case Triple::kalimba
:
1487 case Triple::mips64el
:
1488 case Triple::mipsel
:
1489 case Triple::msp430
:
1491 case Triple::nvptx64
:
1493 case Triple::ppc64le
:
1495 case Triple::riscv32
:
1496 case Triple::riscv64
:
1498 case Triple::sparcel
:
1499 case Triple::spir64
:
1502 case Triple::wasm32
:
1503 case Triple::wasm64
:
1505 case Triple::x86_64
:
1508 case Triple::renderscript32
:
1509 case Triple::renderscript64
:
1516 bool Triple::isCompatibleWith(const Triple
&Other
) const {
1517 // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
1518 if ((getArch() == Triple::thumb
&& Other
.getArch() == Triple::arm
) ||
1519 (getArch() == Triple::arm
&& Other
.getArch() == Triple::thumb
) ||
1520 (getArch() == Triple::thumbeb
&& Other
.getArch() == Triple::armeb
) ||
1521 (getArch() == Triple::armeb
&& Other
.getArch() == Triple::thumbeb
)) {
1522 if (getVendor() == Triple::Apple
)
1523 return getSubArch() == Other
.getSubArch() &&
1524 getVendor() == Other
.getVendor() && getOS() == Other
.getOS();
1526 return getSubArch() == Other
.getSubArch() &&
1527 getVendor() == Other
.getVendor() && getOS() == Other
.getOS() &&
1528 getEnvironment() == Other
.getEnvironment() &&
1529 getObjectFormat() == Other
.getObjectFormat();
1532 // If vendor is apple, ignore the version number.
1533 if (getVendor() == Triple::Apple
)
1534 return getArch() == Other
.getArch() && getSubArch() == Other
.getSubArch() &&
1535 getVendor() == Other
.getVendor() && getOS() == Other
.getOS();
1537 return *this == Other
;
1540 std::string
Triple::merge(const Triple
&Other
) const {
1541 // If vendor is apple, pick the triple with the larger version number.
1542 if (getVendor() == Triple::Apple
)
1543 if (Other
.isOSVersionLT(*this))
1549 StringRef
Triple::getARMCPUForArch(StringRef MArch
) const {
1551 MArch
= getArchName();
1552 MArch
= ARM::getCanonicalArchName(MArch
);
1554 // Some defaults are forced.
1556 case llvm::Triple::FreeBSD
:
1557 case llvm::Triple::NetBSD
:
1558 if (!MArch
.empty() && MArch
== "v6")
1559 return "arm1176jzf-s";
1561 case llvm::Triple::Win32
:
1562 // FIXME: this is invalid for WindowsCE
1564 case llvm::Triple::MacOSX
:
1565 case llvm::Triple::IOS
:
1566 case llvm::Triple::WatchOS
:
1567 case llvm::Triple::TvOS
:
1578 StringRef CPU
= ARM::getDefaultCPU(MArch
);
1579 if (!CPU
.empty() && !CPU
.equals("invalid"))
1582 // If no specific architecture version is requested, return the minimum CPU
1583 // required by the OS and environment.
1585 case llvm::Triple::NetBSD
:
1586 switch (getEnvironment()) {
1587 case llvm::Triple::GNUEABIHF
:
1588 case llvm::Triple::GNUEABI
:
1589 case llvm::Triple::EABIHF
:
1590 case llvm::Triple::EABI
:
1591 return "arm926ej-s";
1595 case llvm::Triple::NaCl
:
1596 case llvm::Triple::OpenBSD
:
1599 switch (getEnvironment()) {
1600 case llvm::Triple::EABIHF
:
1601 case llvm::Triple::GNUEABIHF
:
1602 case llvm::Triple::MuslEABIHF
:
1603 return "arm1176jzf-s";
1609 llvm_unreachable("invalid arch name");