1 //===--- Triple.cpp - Target triple helper class --------------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
19 StringRef Triple::getArchTypeName(ArchType Kind) {
21 case UnknownArch: return "unknown";
23 case aarch64: return "aarch64";
24 case aarch64_32: return "aarch64_32";
25 case aarch64_be: return "aarch64_be";
26 case amdgcn: return "amdgcn";
27 case amdil64: return "amdil64";
28 case amdil: return "amdil";
29 case arc: return "arc";
30 case arm: return "arm";
31 case armeb: return "armeb";
32 case avr: return "avr";
33 case bpfeb: return "bpfeb";
34 case bpfel: return "bpfel";
35 case hexagon: return "hexagon";
36 case hsail64: return "hsail64";
37 case hsail: return "hsail";
38 case kalimba: return "kalimba";
39 case lanai: return "lanai";
40 case le32: return "le32";
41 case le64: return "le64";
42 case mips64: return "mips64";
43 case mips64el: return "mips64el";
44 case mips: return "mips";
45 case mipsel: return "mipsel";
46 case msp430: return "msp430";
47 case nvptx64: return "nvptx64";
48 case nvptx: return "nvptx";
49 case ppc64: return "powerpc64";
50 case ppc64le: return "powerpc64le";
51 case ppc: return "powerpc";
52 case r600: return "r600";
53 case renderscript32: return "renderscript32";
54 case renderscript64: return "renderscript64";
55 case riscv32: return "riscv32";
56 case riscv64: return "riscv64";
57 case shave: return "shave";
58 case sparc: return "sparc";
59 case sparcel: return "sparcel";
60 case sparcv9: return "sparcv9";
61 case spir64: return "spir64";
62 case spir: return "spir";
63 case systemz: return "s390x";
64 case tce: return "tce";
65 case tcele: return "tcele";
66 case thumb: return "thumb";
67 case thumbeb: return "thumbeb";
69 case wasm32: return "wasm32";
70 case wasm64: return "wasm64";
71 case x86: return "i386";
72 case x86_64: return "x86_64";
73 case xcore: return "xcore";
76 llvm_unreachable("Invalid ArchType!");
79 StringRef Triple::getArchTypePrefix(ArchType Kind) {
86 case aarch64_32: return "aarch64";
88 case arc: return "arc";
93 case thumbeb: return "arm";
95 case avr: return "avr";
99 case ppc: return "ppc";
104 case mips64el: return "mips";
106 case hexagon: return "hexagon";
108 case amdgcn: return "amdgcn";
109 case r600: return "r600";
112 case bpfeb: return "bpf";
116 case sparc: return "sparc";
118 case systemz: return "s390";
121 case x86_64: return "x86";
123 case xcore: return "xcore";
125 // NVPTX intrinsics are namespaced under nvvm.
126 case nvptx: return "nvvm";
127 case nvptx64: return "nvvm";
129 case le32: return "le32";
130 case le64: return "le64";
133 case amdil64: return "amdil";
136 case hsail64: return "hsail";
139 case spir64: return "spir";
140 case kalimba: return "kalimba";
141 case lanai: return "lanai";
142 case shave: return "shave";
144 case wasm64: return "wasm";
147 case riscv64: return "riscv";
149 case ve: return "ve";
153 StringRef Triple::getVendorTypeName(VendorType Kind) {
155 case UnknownVendor: return "unknown";
157 case AMD: return "amd";
158 case Apple: return "apple";
159 case BGP: return "bgp";
160 case BGQ: return "bgq";
161 case CSR: return "csr";
162 case Freescale: return "fsl";
163 case IBM: return "ibm";
164 case ImaginationTechnologies: return "img";
165 case Mesa: return "mesa";
166 case MipsTechnologies: return "mti";
167 case Myriad: return "myriad";
168 case NVIDIA: return "nvidia";
169 case OpenEmbedded: return "oe";
170 case PC: return "pc";
171 case SCEI: return "scei";
172 case SUSE: return "suse";
175 llvm_unreachable("Invalid VendorType!");
178 StringRef Triple::getOSTypeName(OSType Kind) {
180 case UnknownOS: return "unknown";
182 case AIX: return "aix";
183 case AMDHSA: return "amdhsa";
184 case AMDPAL: return "amdpal";
185 case Ananas: return "ananas";
186 case CNK: return "cnk";
187 case CUDA: return "cuda";
188 case CloudABI: return "cloudabi";
189 case Contiki: return "contiki";
190 case Darwin: return "darwin";
191 case DragonFly: return "dragonfly";
192 case ELFIAMCU: return "elfiamcu";
193 case Emscripten: return "emscripten";
194 case FreeBSD: return "freebsd";
195 case Fuchsia: return "fuchsia";
196 case Haiku: return "haiku";
197 case HermitCore: return "hermit";
198 case Hurd: return "hurd";
199 case IOS: return "ios";
200 case KFreeBSD: return "kfreebsd";
201 case Linux: return "linux";
202 case Lv2: return "lv2";
203 case MacOSX: return "macosx";
204 case Mesa3D: return "mesa3d";
205 case Minix: return "minix";
206 case NVCL: return "nvcl";
207 case NaCl: return "nacl";
208 case NetBSD: return "netbsd";
209 case OpenBSD: return "openbsd";
210 case PS4: return "ps4";
211 case RTEMS: return "rtems";
212 case Solaris: return "solaris";
213 case TvOS: return "tvos";
214 case WASI: return "wasi";
215 case WatchOS: return "watchos";
216 case Win32: return "windows";
219 llvm_unreachable("Invalid OSType");
222 StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
224 case UnknownEnvironment: return "unknown";
225 case Android: return "android";
226 case CODE16: return "code16";
227 case CoreCLR: return "coreclr";
228 case Cygnus: return "cygnus";
229 case EABI: return "eabi";
230 case EABIHF: return "eabihf";
231 case GNU: return "gnu";
232 case GNUABI64: return "gnuabi64";
233 case GNUABIN32: return "gnuabin32";
234 case GNUEABI: return "gnueabi";
235 case GNUEABIHF: return "gnueabihf";
236 case GNUX32: return "gnux32";
237 case Itanium: return "itanium";
238 case MSVC: return "msvc";
239 case MacABI: return "macabi";
240 case Musl: return "musl";
241 case MuslEABI: return "musleabi";
242 case MuslEABIHF: return "musleabihf";
243 case Simulator: return "simulator";
246 llvm_unreachable("Invalid EnvironmentType!");
249 static Triple::ArchType parseBPFArch(StringRef ArchName) {
250 if (ArchName.equals("bpf")) {
251 if (sys::IsLittleEndianHost)
252 return Triple::bpfel;
254 return Triple::bpfeb;
255 } else if (ArchName.equals("bpf_be") || ArchName.equals("bpfeb")) {
256 return Triple::bpfeb;
257 } else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) {
258 return Triple::bpfel;
260 return Triple::UnknownArch;
264 Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
265 Triple::ArchType BPFArch(parseBPFArch(Name));
266 return StringSwitch<Triple::ArchType>(Name)
267 .Case("aarch64", aarch64)
268 .Case("aarch64_be", aarch64_be)
269 .Case("aarch64_32", aarch64_32)
271 .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
272 .Case("arm64_32", aarch64_32)
274 .Case("armeb", armeb)
276 .StartsWith("bpf", BPFArch)
278 .Case("mipsel", mipsel)
279 .Case("mips64", mips64)
280 .Case("mips64el", mips64el)
281 .Case("msp430", msp430)
282 .Case("ppc64", ppc64)
285 .Case("ppc64le", ppc64le)
287 .Case("amdgcn", amdgcn)
288 .Case("riscv32", riscv32)
289 .Case("riscv64", riscv64)
290 .Case("hexagon", hexagon)
291 .Case("sparc", sparc)
292 .Case("sparcel", sparcel)
293 .Case("sparcv9", sparcv9)
294 .Case("systemz", systemz)
296 .Case("tcele", tcele)
297 .Case("thumb", thumb)
298 .Case("thumbeb", thumbeb)
300 .Case("x86-64", x86_64)
301 .Case("xcore", xcore)
302 .Case("nvptx", nvptx)
303 .Case("nvptx64", nvptx64)
306 .Case("amdil", amdil)
307 .Case("amdil64", amdil64)
308 .Case("hsail", hsail)
309 .Case("hsail64", hsail64)
311 .Case("spir64", spir64)
312 .Case("kalimba", kalimba)
313 .Case("lanai", lanai)
314 .Case("shave", shave)
315 .Case("wasm32", wasm32)
316 .Case("wasm64", wasm64)
317 .Case("renderscript32", renderscript32)
318 .Case("renderscript64", renderscript64)
320 .Default(UnknownArch);
323 static Triple::ArchType parseARMArch(StringRef ArchName) {
324 ARM::ISAKind ISA = ARM::parseArchISA(ArchName);
325 ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName);
327 Triple::ArchType arch = Triple::UnknownArch;
329 case ARM::EndianKind::LITTLE: {
331 case ARM::ISAKind::ARM:
334 case ARM::ISAKind::THUMB:
335 arch = Triple::thumb;
337 case ARM::ISAKind::AARCH64:
338 arch = Triple::aarch64;
340 case ARM::ISAKind::INVALID:
345 case ARM::EndianKind::BIG: {
347 case ARM::ISAKind::ARM:
348 arch = Triple::armeb;
350 case ARM::ISAKind::THUMB:
351 arch = Triple::thumbeb;
353 case ARM::ISAKind::AARCH64:
354 arch = Triple::aarch64_be;
356 case ARM::ISAKind::INVALID:
361 case ARM::EndianKind::INVALID: {
366 ArchName = ARM::getCanonicalArchName(ArchName);
367 if (ArchName.empty())
368 return Triple::UnknownArch;
370 // Thumb only exists in v4+
371 if (ISA == ARM::ISAKind::THUMB &&
372 (ArchName.startswith("v2") || ArchName.startswith("v3")))
373 return Triple::UnknownArch;
375 // Thumb only for v6m
376 ARM::ProfileKind Profile = ARM::parseArchProfile(ArchName);
377 unsigned Version = ARM::parseArchVersion(ArchName);
378 if (Profile == ARM::ProfileKind::M && Version == 6) {
379 if (ENDIAN == ARM::EndianKind::BIG)
380 return Triple::thumbeb;
382 return Triple::thumb;
388 static Triple::ArchType parseArch(StringRef ArchName) {
389 auto AT = StringSwitch<Triple::ArchType>(ArchName)
390 .Cases("i386", "i486", "i586", "i686", Triple::x86)
391 // FIXME: Do we need to support these?
392 .Cases("i786", "i886", "i986", Triple::x86)
393 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
394 .Cases("powerpc", "powerpcspe", "ppc", "ppc32", Triple::ppc)
395 .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64)
396 .Cases("powerpc64le", "ppc64le", Triple::ppc64le)
397 .Case("xscale", Triple::arm)
398 .Case("xscaleeb", Triple::armeb)
399 .Case("aarch64", Triple::aarch64)
400 .Case("aarch64_be", Triple::aarch64_be)
401 .Case("aarch64_32", Triple::aarch64_32)
402 .Case("arc", Triple::arc)
403 .Case("arm64", Triple::aarch64)
404 .Case("arm64_32", Triple::aarch64_32)
405 .Case("arm", Triple::arm)
406 .Case("armeb", Triple::armeb)
407 .Case("thumb", Triple::thumb)
408 .Case("thumbeb", Triple::thumbeb)
409 .Case("avr", Triple::avr)
410 .Case("msp430", Triple::msp430)
411 .Cases("mips", "mipseb", "mipsallegrex", "mipsisa32r6",
412 "mipsr6", Triple::mips)
413 .Cases("mipsel", "mipsallegrexel", "mipsisa32r6el", "mipsr6el",
415 .Cases("mips64", "mips64eb", "mipsn32", "mipsisa64r6",
416 "mips64r6", "mipsn32r6", Triple::mips64)
417 .Cases("mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el",
418 "mipsn32r6el", Triple::mips64el)
419 .Case("r600", Triple::r600)
420 .Case("amdgcn", Triple::amdgcn)
421 .Case("riscv32", Triple::riscv32)
422 .Case("riscv64", Triple::riscv64)
423 .Case("hexagon", Triple::hexagon)
424 .Cases("s390x", "systemz", Triple::systemz)
425 .Case("sparc", Triple::sparc)
426 .Case("sparcel", Triple::sparcel)
427 .Cases("sparcv9", "sparc64", Triple::sparcv9)
428 .Case("tce", Triple::tce)
429 .Case("tcele", Triple::tcele)
430 .Case("xcore", Triple::xcore)
431 .Case("nvptx", Triple::nvptx)
432 .Case("nvptx64", Triple::nvptx64)
433 .Case("le32", Triple::le32)
434 .Case("le64", Triple::le64)
435 .Case("amdil", Triple::amdil)
436 .Case("amdil64", Triple::amdil64)
437 .Case("hsail", Triple::hsail)
438 .Case("hsail64", Triple::hsail64)
439 .Case("spir", Triple::spir)
440 .Case("spir64", Triple::spir64)
441 .StartsWith("kalimba", Triple::kalimba)
442 .Case("lanai", Triple::lanai)
443 .Case("renderscript32", Triple::renderscript32)
444 .Case("renderscript64", Triple::renderscript64)
445 .Case("shave", Triple::shave)
446 .Case("ve", Triple::ve)
447 .Case("wasm32", Triple::wasm32)
448 .Case("wasm64", Triple::wasm64)
449 .Default(Triple::UnknownArch);
451 // Some architectures require special parsing logic just to compute the
453 if (AT == Triple::UnknownArch) {
454 if (ArchName.startswith("arm") || ArchName.startswith("thumb") ||
455 ArchName.startswith("aarch64"))
456 return parseARMArch(ArchName);
457 if (ArchName.startswith("bpf"))
458 return parseBPFArch(ArchName);
464 static Triple::VendorType parseVendor(StringRef VendorName) {
465 return StringSwitch<Triple::VendorType>(VendorName)
466 .Case("apple", Triple::Apple)
467 .Case("pc", Triple::PC)
468 .Case("scei", Triple::SCEI)
469 .Case("bgp", Triple::BGP)
470 .Case("bgq", Triple::BGQ)
471 .Case("fsl", Triple::Freescale)
472 .Case("ibm", Triple::IBM)
473 .Case("img", Triple::ImaginationTechnologies)
474 .Case("mti", Triple::MipsTechnologies)
475 .Case("nvidia", Triple::NVIDIA)
476 .Case("csr", Triple::CSR)
477 .Case("myriad", Triple::Myriad)
478 .Case("amd", Triple::AMD)
479 .Case("mesa", Triple::Mesa)
480 .Case("suse", Triple::SUSE)
481 .Case("oe", Triple::OpenEmbedded)
482 .Default(Triple::UnknownVendor);
485 static Triple::OSType parseOS(StringRef OSName) {
486 return StringSwitch<Triple::OSType>(OSName)
487 .StartsWith("ananas", Triple::Ananas)
488 .StartsWith("cloudabi", Triple::CloudABI)
489 .StartsWith("darwin", Triple::Darwin)
490 .StartsWith("dragonfly", Triple::DragonFly)
491 .StartsWith("freebsd", Triple::FreeBSD)
492 .StartsWith("fuchsia", Triple::Fuchsia)
493 .StartsWith("ios", Triple::IOS)
494 .StartsWith("kfreebsd", Triple::KFreeBSD)
495 .StartsWith("linux", Triple::Linux)
496 .StartsWith("lv2", Triple::Lv2)
497 .StartsWith("macos", Triple::MacOSX)
498 .StartsWith("netbsd", Triple::NetBSD)
499 .StartsWith("openbsd", Triple::OpenBSD)
500 .StartsWith("solaris", Triple::Solaris)
501 .StartsWith("win32", Triple::Win32)
502 .StartsWith("windows", Triple::Win32)
503 .StartsWith("haiku", Triple::Haiku)
504 .StartsWith("minix", Triple::Minix)
505 .StartsWith("rtems", Triple::RTEMS)
506 .StartsWith("nacl", Triple::NaCl)
507 .StartsWith("cnk", Triple::CNK)
508 .StartsWith("aix", Triple::AIX)
509 .StartsWith("cuda", Triple::CUDA)
510 .StartsWith("nvcl", Triple::NVCL)
511 .StartsWith("amdhsa", Triple::AMDHSA)
512 .StartsWith("ps4", Triple::PS4)
513 .StartsWith("elfiamcu", Triple::ELFIAMCU)
514 .StartsWith("tvos", Triple::TvOS)
515 .StartsWith("watchos", Triple::WatchOS)
516 .StartsWith("mesa3d", Triple::Mesa3D)
517 .StartsWith("contiki", Triple::Contiki)
518 .StartsWith("amdpal", Triple::AMDPAL)
519 .StartsWith("hermit", Triple::HermitCore)
520 .StartsWith("hurd", Triple::Hurd)
521 .StartsWith("wasi", Triple::WASI)
522 .StartsWith("emscripten", Triple::Emscripten)
523 .Default(Triple::UnknownOS);
526 static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
527 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
528 .StartsWith("eabihf", Triple::EABIHF)
529 .StartsWith("eabi", Triple::EABI)
530 .StartsWith("gnuabin32", Triple::GNUABIN32)
531 .StartsWith("gnuabi64", Triple::GNUABI64)
532 .StartsWith("gnueabihf", Triple::GNUEABIHF)
533 .StartsWith("gnueabi", Triple::GNUEABI)
534 .StartsWith("gnux32", Triple::GNUX32)
535 .StartsWith("code16", Triple::CODE16)
536 .StartsWith("gnu", Triple::GNU)
537 .StartsWith("android", Triple::Android)
538 .StartsWith("musleabihf", Triple::MuslEABIHF)
539 .StartsWith("musleabi", Triple::MuslEABI)
540 .StartsWith("musl", Triple::Musl)
541 .StartsWith("msvc", Triple::MSVC)
542 .StartsWith("itanium", Triple::Itanium)
543 .StartsWith("cygnus", Triple::Cygnus)
544 .StartsWith("coreclr", Triple::CoreCLR)
545 .StartsWith("simulator", Triple::Simulator)
546 .StartsWith("macabi", Triple::MacABI)
547 .Default(Triple::UnknownEnvironment);
550 static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
551 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
552 // "xcoff" must come before "coff" because of the order-dependendent
554 .EndsWith("xcoff", Triple::XCOFF)
555 .EndsWith("coff", Triple::COFF)
556 .EndsWith("elf", Triple::ELF)
557 .EndsWith("macho", Triple::MachO)
558 .EndsWith("wasm", Triple::Wasm)
559 .Default(Triple::UnknownObjectFormat);
562 static Triple::SubArchType parseSubArch(StringRef SubArchName) {
563 if (SubArchName.startswith("mips") &&
564 (SubArchName.endswith("r6el") || SubArchName.endswith("r6")))
565 return Triple::MipsSubArch_r6;
567 if (SubArchName == "powerpcspe")
568 return Triple::PPCSubArch_spe;
570 StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
572 // For now, this is the small part. Early return.
573 if (ARMSubArch.empty())
574 return StringSwitch<Triple::SubArchType>(SubArchName)
575 .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
576 .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
577 .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
578 .Default(Triple::NoSubArch);
581 switch(ARM::parseArch(ARMSubArch)) {
582 case ARM::ArchKind::ARMV4:
583 return Triple::NoSubArch;
584 case ARM::ArchKind::ARMV4T:
585 return Triple::ARMSubArch_v4t;
586 case ARM::ArchKind::ARMV5T:
587 return Triple::ARMSubArch_v5;
588 case ARM::ArchKind::ARMV5TE:
589 case ARM::ArchKind::IWMMXT:
590 case ARM::ArchKind::IWMMXT2:
591 case ARM::ArchKind::XSCALE:
592 case ARM::ArchKind::ARMV5TEJ:
593 return Triple::ARMSubArch_v5te;
594 case ARM::ArchKind::ARMV6:
595 return Triple::ARMSubArch_v6;
596 case ARM::ArchKind::ARMV6K:
597 case ARM::ArchKind::ARMV6KZ:
598 return Triple::ARMSubArch_v6k;
599 case ARM::ArchKind::ARMV6T2:
600 return Triple::ARMSubArch_v6t2;
601 case ARM::ArchKind::ARMV6M:
602 return Triple::ARMSubArch_v6m;
603 case ARM::ArchKind::ARMV7A:
604 case ARM::ArchKind::ARMV7R:
605 return Triple::ARMSubArch_v7;
606 case ARM::ArchKind::ARMV7VE:
607 return Triple::ARMSubArch_v7ve;
608 case ARM::ArchKind::ARMV7K:
609 return Triple::ARMSubArch_v7k;
610 case ARM::ArchKind::ARMV7M:
611 return Triple::ARMSubArch_v7m;
612 case ARM::ArchKind::ARMV7S:
613 return Triple::ARMSubArch_v7s;
614 case ARM::ArchKind::ARMV7EM:
615 return Triple::ARMSubArch_v7em;
616 case ARM::ArchKind::ARMV8A:
617 return Triple::ARMSubArch_v8;
618 case ARM::ArchKind::ARMV8_1A:
619 return Triple::ARMSubArch_v8_1a;
620 case ARM::ArchKind::ARMV8_2A:
621 return Triple::ARMSubArch_v8_2a;
622 case ARM::ArchKind::ARMV8_3A:
623 return Triple::ARMSubArch_v8_3a;
624 case ARM::ArchKind::ARMV8_4A:
625 return Triple::ARMSubArch_v8_4a;
626 case ARM::ArchKind::ARMV8_5A:
627 return Triple::ARMSubArch_v8_5a;
628 case ARM::ArchKind::ARMV8R:
629 return Triple::ARMSubArch_v8r;
630 case ARM::ArchKind::ARMV8MBaseline:
631 return Triple::ARMSubArch_v8m_baseline;
632 case ARM::ArchKind::ARMV8MMainline:
633 return Triple::ARMSubArch_v8m_mainline;
634 case ARM::ArchKind::ARMV8_1MMainline:
635 return Triple::ARMSubArch_v8_1m_mainline;
637 return Triple::NoSubArch;
641 static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
643 case Triple::UnknownObjectFormat: return "";
644 case Triple::COFF: return "coff";
645 case Triple::ELF: return "elf";
646 case Triple::MachO: return "macho";
647 case Triple::Wasm: return "wasm";
648 case Triple::XCOFF: return "xcoff";
650 llvm_unreachable("unknown object format type");
653 static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
654 switch (T.getArch()) {
655 case Triple::UnknownArch:
656 case Triple::aarch64:
657 case Triple::aarch64_32:
663 return Triple::MachO;
664 else if (T.isOSWindows())
668 case Triple::aarch64_be:
670 case Triple::amdil64:
677 case Triple::hexagon:
678 case Triple::hsail64:
680 case Triple::kalimba:
685 case Triple::mips64el:
689 case Triple::nvptx64:
691 case Triple::ppc64le:
693 case Triple::renderscript32:
694 case Triple::renderscript64:
695 case Triple::riscv32:
696 case Triple::riscv64:
699 case Triple::sparcel:
700 case Triple::sparcv9:
703 case Triple::systemz:
706 case Triple::thumbeb:
714 return Triple::MachO;
715 else if (T.isOSAIX())
716 return Triple::XCOFF;
723 llvm_unreachable("unknown architecture");
726 /// Construct a triple from the string representation provided.
728 /// This stores the string representation and parses the various pieces into
730 Triple::Triple(const Twine &Str)
731 : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
732 Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
733 ObjectFormat(UnknownObjectFormat) {
734 // Do minimal parsing by hand here.
735 SmallVector<StringRef, 4> Components;
736 StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
737 if (Components.size() > 0) {
738 Arch = parseArch(Components[0]);
739 SubArch = parseSubArch(Components[0]);
740 if (Components.size() > 1) {
741 Vendor = parseVendor(Components[1]);
742 if (Components.size() > 2) {
743 OS = parseOS(Components[2]);
744 if (Components.size() > 3) {
745 Environment = parseEnvironment(Components[3]);
746 ObjectFormat = parseFormat(Components[3]);
751 StringSwitch<Triple::EnvironmentType>(Components[0])
752 .StartsWith("mipsn32", Triple::GNUABIN32)
753 .StartsWith("mips64", Triple::GNUABI64)
754 .StartsWith("mipsisa64", Triple::GNUABI64)
755 .StartsWith("mipsisa32", Triple::GNU)
756 .Cases("mips", "mipsel", "mipsr6", "mipsr6el", Triple::GNU)
757 .Default(UnknownEnvironment);
760 if (ObjectFormat == UnknownObjectFormat)
761 ObjectFormat = getDefaultFormat(*this);
764 /// Construct a triple from string representations of the architecture,
767 /// This joins each argument into a canonical string representation and parses
768 /// them into enum members. It leaves the environment unknown and omits it from
769 /// the string representation.
770 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
771 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
772 Arch(parseArch(ArchStr.str())),
773 SubArch(parseSubArch(ArchStr.str())),
774 Vendor(parseVendor(VendorStr.str())),
775 OS(parseOS(OSStr.str())),
776 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
777 ObjectFormat = getDefaultFormat(*this);
780 /// Construct a triple from string representations of the architecture,
781 /// vendor, OS, and environment.
783 /// This joins each argument into a canonical string representation and parses
784 /// them into enum members.
785 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
786 const Twine &EnvironmentStr)
787 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
788 EnvironmentStr).str()),
789 Arch(parseArch(ArchStr.str())),
790 SubArch(parseSubArch(ArchStr.str())),
791 Vendor(parseVendor(VendorStr.str())),
792 OS(parseOS(OSStr.str())),
793 Environment(parseEnvironment(EnvironmentStr.str())),
794 ObjectFormat(parseFormat(EnvironmentStr.str())) {
795 if (ObjectFormat == Triple::UnknownObjectFormat)
796 ObjectFormat = getDefaultFormat(*this);
799 std::string Triple::normalize(StringRef Str) {
800 bool IsMinGW32 = false;
801 bool IsCygwin = false;
803 // Parse into components.
804 SmallVector<StringRef, 4> Components;
805 Str.split(Components, '-');
807 // If the first component corresponds to a known architecture, preferentially
808 // use it for the architecture. If the second component corresponds to a
809 // known vendor, preferentially use it for the vendor, etc. This avoids silly
810 // component movement when a component parses as (eg) both a valid arch and a
812 ArchType Arch = UnknownArch;
813 if (Components.size() > 0)
814 Arch = parseArch(Components[0]);
815 VendorType Vendor = UnknownVendor;
816 if (Components.size() > 1)
817 Vendor = parseVendor(Components[1]);
818 OSType OS = UnknownOS;
819 if (Components.size() > 2) {
820 OS = parseOS(Components[2]);
821 IsCygwin = Components[2].startswith("cygwin");
822 IsMinGW32 = Components[2].startswith("mingw");
824 EnvironmentType Environment = UnknownEnvironment;
825 if (Components.size() > 3)
826 Environment = parseEnvironment(Components[3]);
827 ObjectFormatType ObjectFormat = UnknownObjectFormat;
828 if (Components.size() > 4)
829 ObjectFormat = parseFormat(Components[4]);
831 // Note which components are already in their final position. These will not
834 Found[0] = Arch != UnknownArch;
835 Found[1] = Vendor != UnknownVendor;
836 Found[2] = OS != UnknownOS;
837 Found[3] = Environment != UnknownEnvironment;
839 // If they are not there already, permute the components into their canonical
840 // positions by seeing if they parse as a valid architecture, and if so moving
841 // the component to the architecture position etc.
842 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
844 continue; // Already in the canonical position.
846 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
847 // Do not reparse any components that already matched.
848 if (Idx < array_lengthof(Found) && Found[Idx])
851 // Does this component parse as valid for the target position?
853 StringRef Comp = Components[Idx];
855 default: llvm_unreachable("unexpected component type!");
857 Arch = parseArch(Comp);
858 Valid = Arch != UnknownArch;
861 Vendor = parseVendor(Comp);
862 Valid = Vendor != UnknownVendor;
866 IsCygwin = Comp.startswith("cygwin");
867 IsMinGW32 = Comp.startswith("mingw");
868 Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
871 Environment = parseEnvironment(Comp);
872 Valid = Environment != UnknownEnvironment;
874 ObjectFormat = parseFormat(Comp);
875 Valid = ObjectFormat != UnknownObjectFormat;
880 continue; // Nope, try the next component.
882 // Move the component to the target position, pushing any non-fixed
883 // components that are in the way to the right. This tends to give
884 // good results in the common cases of a forgotten vendor component
885 // or a wrongly positioned environment.
887 // Insert left, pushing the existing components to the right. For
888 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
889 StringRef CurrentComponent(""); // The empty component.
890 // Replace the component we are moving with an empty component.
891 std::swap(CurrentComponent, Components[Idx]);
892 // Insert the component being moved at Pos, displacing any existing
893 // components to the right.
894 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
895 // Skip over any fixed components.
896 while (i < array_lengthof(Found) && Found[i])
898 // Place the component at the new position, getting the component
899 // that was at this position - it will be moved right.
900 std::swap(CurrentComponent, Components[i]);
902 } else if (Pos > Idx) {
903 // Push right by inserting empty components until the component at Idx
904 // reaches the target position Pos. For example, pc-a -> -pc-a when
905 // moving pc to the second position.
907 // Insert one empty component at Idx.
908 StringRef CurrentComponent(""); // The empty component.
909 for (unsigned i = Idx; i < Components.size();) {
910 // Place the component at the new position, getting the component
911 // that was at this position - it will be moved right.
912 std::swap(CurrentComponent, Components[i]);
913 // If it was placed on top of an empty component then we are done.
914 if (CurrentComponent.empty())
916 // Advance to the next component, skipping any fixed components.
917 while (++i < array_lengthof(Found) && Found[i])
920 // The last component was pushed off the end - append it.
921 if (!CurrentComponent.empty())
922 Components.push_back(CurrentComponent);
924 // Advance Idx to the component's new position.
925 while (++Idx < array_lengthof(Found) && Found[Idx])
927 } while (Idx < Pos); // Add more until the final position is reached.
929 assert(Pos < Components.size() && Components[Pos] == Comp &&
930 "Component moved wrong!");
936 // Replace empty components with "unknown" value.
937 for (unsigned i = 0, e = Components.size(); i < e; ++i) {
938 if (Components[i].empty())
939 Components[i] = "unknown";
942 // Special case logic goes here. At this point Arch, Vendor and OS have the
943 // correct values for the computed components.
944 std::string NormalizedEnvironment;
945 if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
946 StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
947 if (AndroidVersion.empty()) {
948 Components[3] = "android";
950 NormalizedEnvironment = Twine("android", AndroidVersion).str();
951 Components[3] = NormalizedEnvironment;
955 // SUSE uses "gnueabi" to mean "gnueabihf"
956 if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
957 Components[3] = "gnueabihf";
959 if (OS == Triple::Win32) {
960 Components.resize(4);
961 Components[2] = "windows";
962 if (Environment == UnknownEnvironment) {
963 if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
964 Components[3] = "msvc";
966 Components[3] = getObjectFormatTypeName(ObjectFormat);
968 } else if (IsMinGW32) {
969 Components.resize(4);
970 Components[2] = "windows";
971 Components[3] = "gnu";
972 } else if (IsCygwin) {
973 Components.resize(4);
974 Components[2] = "windows";
975 Components[3] = "cygnus";
977 if (IsMinGW32 || IsCygwin ||
978 (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
979 if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
980 Components.resize(5);
981 Components[4] = getObjectFormatTypeName(ObjectFormat);
985 // Stick the corrected components back together to form the normalized string.
986 std::string Normalized;
987 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
988 if (i) Normalized += '-';
989 Normalized += Components[i];
994 StringRef Triple::getArchName() const {
995 return StringRef(Data).split('-').first; // Isolate first component
998 StringRef Triple::getVendorName() const {
999 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1000 return Tmp.split('-').first; // Isolate second component
1003 StringRef Triple::getOSName() const {
1004 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1005 Tmp = Tmp.split('-').second; // Strip second component
1006 return Tmp.split('-').first; // Isolate third component
1009 StringRef Triple::getEnvironmentName() const {
1010 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1011 Tmp = Tmp.split('-').second; // Strip second component
1012 return Tmp.split('-').second; // Strip third component
1015 StringRef Triple::getOSAndEnvironmentName() const {
1016 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1017 return Tmp.split('-').second; // Strip second component
1020 static unsigned EatNumber(StringRef &Str) {
1021 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
1022 unsigned Result = 0;
1025 // Consume the leading digit.
1026 Result = Result*10 + (Str[0] - '0');
1029 Str = Str.substr(1);
1030 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
1035 static void parseVersionFromName(StringRef Name, unsigned &Major,
1036 unsigned &Minor, unsigned &Micro) {
1037 // Any unset version defaults to 0.
1038 Major = Minor = Micro = 0;
1040 // Parse up to three components.
1041 unsigned *Components[3] = {&Major, &Minor, &Micro};
1042 for (unsigned i = 0; i != 3; ++i) {
1043 if (Name.empty() || Name[0] < '0' || Name[0] > '9')
1046 // Consume the leading number.
1047 *Components[i] = EatNumber(Name);
1049 // Consume the separator, if present.
1050 if (Name.startswith("."))
1051 Name = Name.substr(1);
1055 void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
1056 unsigned &Micro) const {
1057 StringRef EnvironmentName = getEnvironmentName();
1058 StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
1059 if (EnvironmentName.startswith(EnvironmentTypeName))
1060 EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
1062 parseVersionFromName(EnvironmentName, Major, Minor, Micro);
1065 void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
1066 unsigned &Micro) const {
1067 StringRef OSName = getOSName();
1068 // Assume that the OS portion of the triple starts with the canonical name.
1069 StringRef OSTypeName = getOSTypeName(getOS());
1070 if (OSName.startswith(OSTypeName))
1071 OSName = OSName.substr(OSTypeName.size());
1072 else if (getOS() == MacOSX)
1073 OSName.consume_front("macos");
1075 parseVersionFromName(OSName, Major, Minor, Micro);
1078 bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
1079 unsigned &Micro) const {
1080 getOSVersion(Major, Minor, Micro);
1083 default: llvm_unreachable("unexpected OS for Darwin triple");
1085 // Default to darwin8, i.e., MacOSX 10.4.
1088 // Darwin version numbers are skewed from OS X versions.
1107 // Ignore the version from the triple. This is only handled because the
1108 // the clang driver combines OS X and IOS support into a common Darwin
1109 // toolchain that wants to know the OS X version number even when targeting
1119 void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
1120 unsigned &Micro) const {
1122 default: llvm_unreachable("unexpected OS for Darwin triple");
1125 // Ignore the version from the triple. This is only handled because the
1126 // the clang driver combines OS X and IOS support into a common Darwin
1127 // toolchain that wants to know the iOS version number even when targeting
1135 getOSVersion(Major, Minor, Micro);
1136 // Default to 5.0 (or 7.0 for arm64).
1138 Major = (getArch() == aarch64) ? 7 : 5;
1141 llvm_unreachable("conflicting triple info");
1145 void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
1146 unsigned &Micro) const {
1148 default: llvm_unreachable("unexpected OS for Darwin triple");
1151 // Ignore the version from the triple. This is only handled because the
1152 // the clang driver combines OS X and IOS support into a common Darwin
1153 // toolchain that wants to know the iOS version number even when targeting
1160 getOSVersion(Major, Minor, Micro);
1165 llvm_unreachable("conflicting triple info");
1169 void Triple::setTriple(const Twine &Str) {
1170 *this = Triple(Str);
1173 void Triple::setArch(ArchType Kind) {
1174 setArchName(getArchTypeName(Kind));
1177 void Triple::setVendor(VendorType Kind) {
1178 setVendorName(getVendorTypeName(Kind));
1181 void Triple::setOS(OSType Kind) {
1182 setOSName(getOSTypeName(Kind));
1185 void Triple::setEnvironment(EnvironmentType Kind) {
1186 if (ObjectFormat == getDefaultFormat(*this))
1187 return setEnvironmentName(getEnvironmentTypeName(Kind));
1189 setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
1190 getObjectFormatTypeName(ObjectFormat)).str());
1193 void Triple::setObjectFormat(ObjectFormatType Kind) {
1194 if (Environment == UnknownEnvironment)
1195 return setEnvironmentName(getObjectFormatTypeName(Kind));
1197 setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
1198 getObjectFormatTypeName(Kind)).str());
1201 void Triple::setArchName(StringRef Str) {
1202 // Work around a miscompilation bug for Twines in gcc 4.0.3.
1203 SmallString<64> Triple;
1206 Triple += getVendorName();
1208 Triple += getOSAndEnvironmentName();
1212 void Triple::setVendorName(StringRef Str) {
1213 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
1216 void Triple::setOSName(StringRef Str) {
1217 if (hasEnvironment())
1218 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
1219 "-" + getEnvironmentName());
1221 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1224 void Triple::setEnvironmentName(StringRef Str) {
1225 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1229 void Triple::setOSAndEnvironmentName(StringRef Str) {
1230 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1233 static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
1235 case llvm::Triple::UnknownArch:
1238 case llvm::Triple::avr:
1239 case llvm::Triple::msp430:
1242 case llvm::Triple::aarch64_32:
1243 case llvm::Triple::amdil:
1244 case llvm::Triple::arc:
1245 case llvm::Triple::arm:
1246 case llvm::Triple::armeb:
1247 case llvm::Triple::hexagon:
1248 case llvm::Triple::hsail:
1249 case llvm::Triple::kalimba:
1250 case llvm::Triple::lanai:
1251 case llvm::Triple::le32:
1252 case llvm::Triple::mips:
1253 case llvm::Triple::mipsel:
1254 case llvm::Triple::nvptx:
1255 case llvm::Triple::ppc:
1256 case llvm::Triple::r600:
1257 case llvm::Triple::renderscript32:
1258 case llvm::Triple::riscv32:
1259 case llvm::Triple::shave:
1260 case llvm::Triple::sparc:
1261 case llvm::Triple::sparcel:
1262 case llvm::Triple::spir:
1263 case llvm::Triple::tce:
1264 case llvm::Triple::tcele:
1265 case llvm::Triple::thumb:
1266 case llvm::Triple::thumbeb:
1267 case llvm::Triple::wasm32:
1268 case llvm::Triple::x86:
1269 case llvm::Triple::xcore:
1272 case llvm::Triple::aarch64:
1273 case llvm::Triple::aarch64_be:
1274 case llvm::Triple::amdgcn:
1275 case llvm::Triple::amdil64:
1276 case llvm::Triple::bpfeb:
1277 case llvm::Triple::bpfel:
1278 case llvm::Triple::hsail64:
1279 case llvm::Triple::le64:
1280 case llvm::Triple::mips64:
1281 case llvm::Triple::mips64el:
1282 case llvm::Triple::nvptx64:
1283 case llvm::Triple::ppc64:
1284 case llvm::Triple::ppc64le:
1285 case llvm::Triple::renderscript64:
1286 case llvm::Triple::riscv64:
1287 case llvm::Triple::sparcv9:
1288 case llvm::Triple::spir64:
1289 case llvm::Triple::systemz:
1290 case llvm::Triple::ve:
1291 case llvm::Triple::wasm64:
1292 case llvm::Triple::x86_64:
1295 llvm_unreachable("Invalid architecture value");
1298 bool Triple::isArch64Bit() const {
1299 return getArchPointerBitWidth(getArch()) == 64;
1302 bool Triple::isArch32Bit() const {
1303 return getArchPointerBitWidth(getArch()) == 32;
1306 bool Triple::isArch16Bit() const {
1307 return getArchPointerBitWidth(getArch()) == 16;
1310 Triple Triple::get32BitArchVariant() const {
1312 switch (getArch()) {
1313 case Triple::UnknownArch:
1314 case Triple::amdgcn:
1318 case Triple::msp430:
1319 case Triple::ppc64le:
1320 case Triple::systemz:
1322 T.setArch(UnknownArch);
1325 case Triple::aarch64_32:
1330 case Triple::hexagon:
1332 case Triple::kalimba:
1336 case Triple::mipsel:
1340 case Triple::renderscript32:
1341 case Triple::riscv32:
1344 case Triple::sparcel:
1349 case Triple::thumbeb:
1350 case Triple::wasm32:
1356 case Triple::aarch64: T.setArch(Triple::arm); break;
1357 case Triple::aarch64_be: T.setArch(Triple::armeb); break;
1358 case Triple::amdil64: T.setArch(Triple::amdil); break;
1359 case Triple::hsail64: T.setArch(Triple::hsail); break;
1360 case Triple::le64: T.setArch(Triple::le32); break;
1361 case Triple::mips64: T.setArch(Triple::mips); break;
1362 case Triple::mips64el: T.setArch(Triple::mipsel); break;
1363 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
1364 case Triple::ppc64: T.setArch(Triple::ppc); break;
1365 case Triple::renderscript64: T.setArch(Triple::renderscript32); break;
1366 case Triple::riscv64: T.setArch(Triple::riscv32); break;
1367 case Triple::sparcv9: T.setArch(Triple::sparc); break;
1368 case Triple::spir64: T.setArch(Triple::spir); break;
1369 case Triple::wasm64: T.setArch(Triple::wasm32); break;
1370 case Triple::x86_64: T.setArch(Triple::x86); break;
1375 Triple Triple::get64BitArchVariant() const {
1377 switch (getArch()) {
1378 case Triple::UnknownArch:
1381 case Triple::hexagon:
1382 case Triple::kalimba:
1384 case Triple::msp430:
1387 case Triple::sparcel:
1391 T.setArch(UnknownArch);
1394 case Triple::aarch64:
1395 case Triple::aarch64_be:
1396 case Triple::amdgcn:
1397 case Triple::amdil64:
1400 case Triple::hsail64:
1402 case Triple::mips64:
1403 case Triple::mips64el:
1404 case Triple::nvptx64:
1406 case Triple::ppc64le:
1407 case Triple::renderscript64:
1408 case Triple::riscv64:
1409 case Triple::sparcv9:
1410 case Triple::spir64:
1411 case Triple::systemz:
1413 case Triple::wasm64:
1414 case Triple::x86_64:
1418 case Triple::aarch64_32: T.setArch(Triple::aarch64); break;
1419 case Triple::amdil: T.setArch(Triple::amdil64); break;
1420 case Triple::arm: T.setArch(Triple::aarch64); break;
1421 case Triple::armeb: T.setArch(Triple::aarch64_be); break;
1422 case Triple::hsail: T.setArch(Triple::hsail64); break;
1423 case Triple::le32: T.setArch(Triple::le64); break;
1424 case Triple::mips: T.setArch(Triple::mips64); break;
1425 case Triple::mipsel: T.setArch(Triple::mips64el); break;
1426 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
1427 case Triple::ppc: T.setArch(Triple::ppc64); break;
1428 case Triple::renderscript32: T.setArch(Triple::renderscript64); break;
1429 case Triple::riscv32: T.setArch(Triple::riscv64); break;
1430 case Triple::sparc: T.setArch(Triple::sparcv9); break;
1431 case Triple::spir: T.setArch(Triple::spir64); break;
1432 case Triple::thumb: T.setArch(Triple::aarch64); break;
1433 case Triple::thumbeb: T.setArch(Triple::aarch64_be); break;
1434 case Triple::wasm32: T.setArch(Triple::wasm64); break;
1435 case Triple::x86: T.setArch(Triple::x86_64); break;
1440 Triple Triple::getBigEndianArchVariant() const {
1442 // Already big endian.
1443 if (!isLittleEndian())
1445 switch (getArch()) {
1446 case Triple::UnknownArch:
1447 case Triple::amdgcn:
1448 case Triple::amdil64:
1451 case Triple::hexagon:
1452 case Triple::hsail64:
1454 case Triple::kalimba:
1457 case Triple::msp430:
1458 case Triple::nvptx64:
1461 case Triple::renderscript32:
1462 case Triple::renderscript64:
1463 case Triple::riscv32:
1464 case Triple::riscv64:
1466 case Triple::spir64:
1468 case Triple::wasm32:
1469 case Triple::wasm64:
1471 case Triple::x86_64:
1475 // ARM is intentionally unsupported here, changing the architecture would
1476 // drop any arch suffixes.
1479 T.setArch(UnknownArch);
1482 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1483 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1484 case Triple::mips64el:T.setArch(Triple::mips64); break;
1485 case Triple::mipsel: T.setArch(Triple::mips); break;
1486 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1487 case Triple::sparcel: T.setArch(Triple::sparc); break;
1488 case Triple::tcele: T.setArch(Triple::tce); break;
1490 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1495 Triple Triple::getLittleEndianArchVariant() const {
1497 if (isLittleEndian())
1500 switch (getArch()) {
1501 case Triple::UnknownArch:
1504 case Triple::sparcv9:
1505 case Triple::systemz:
1507 // ARM is intentionally unsupported here, changing the architecture would
1508 // drop any arch suffixes.
1510 case Triple::thumbeb:
1511 T.setArch(UnknownArch);
1514 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1515 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1516 case Triple::mips64: T.setArch(Triple::mips64el); break;
1517 case Triple::mips: T.setArch(Triple::mipsel); break;
1518 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1519 case Triple::sparc: T.setArch(Triple::sparcel); break;
1520 case Triple::tce: T.setArch(Triple::tcele); break;
1522 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1527 bool Triple::isLittleEndian() const {
1528 switch (getArch()) {
1529 case Triple::aarch64:
1530 case Triple::aarch64_32:
1531 case Triple::amdgcn:
1532 case Triple::amdil64:
1537 case Triple::hexagon:
1538 case Triple::hsail64:
1540 case Triple::kalimba:
1543 case Triple::mips64el:
1544 case Triple::mipsel:
1545 case Triple::msp430:
1546 case Triple::nvptx64:
1548 case Triple::ppc64le:
1550 case Triple::renderscript32:
1551 case Triple::renderscript64:
1552 case Triple::riscv32:
1553 case Triple::riscv64:
1555 case Triple::sparcel:
1556 case Triple::spir64:
1561 case Triple::wasm32:
1562 case Triple::wasm64:
1564 case Triple::x86_64:
1572 bool Triple::isCompatibleWith(const Triple &Other) const {
1573 // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
1574 if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
1575 (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
1576 (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) ||
1577 (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) {
1578 if (getVendor() == Triple::Apple)
1579 return getSubArch() == Other.getSubArch() &&
1580 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1582 return getSubArch() == Other.getSubArch() &&
1583 getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
1584 getEnvironment() == Other.getEnvironment() &&
1585 getObjectFormat() == Other.getObjectFormat();
1588 // If vendor is apple, ignore the version number.
1589 if (getVendor() == Triple::Apple)
1590 return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
1591 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1593 return *this == Other;
1596 std::string Triple::merge(const Triple &Other) const {
1597 // If vendor is apple, pick the triple with the larger version number.
1598 if (getVendor() == Triple::Apple)
1599 if (Other.isOSVersionLT(*this))
1605 StringRef Triple::getARMCPUForArch(StringRef MArch) const {
1607 MArch = getArchName();
1608 MArch = ARM::getCanonicalArchName(MArch);
1610 // Some defaults are forced.
1612 case llvm::Triple::FreeBSD:
1613 case llvm::Triple::NetBSD:
1614 if (!MArch.empty() && MArch == "v6")
1615 return "arm1176jzf-s";
1617 case llvm::Triple::Win32:
1618 // FIXME: this is invalid for WindowsCE
1620 case llvm::Triple::IOS:
1621 case llvm::Triple::MacOSX:
1622 case llvm::Triple::TvOS:
1623 case llvm::Triple::WatchOS:
1634 StringRef CPU = ARM::getDefaultCPU(MArch);
1635 if (!CPU.empty() && !CPU.equals("invalid"))
1638 // If no specific architecture version is requested, return the minimum CPU
1639 // required by the OS and environment.
1641 case llvm::Triple::NetBSD:
1642 switch (getEnvironment()) {
1643 case llvm::Triple::EABI:
1644 case llvm::Triple::EABIHF:
1645 case llvm::Triple::GNUEABI:
1646 case llvm::Triple::GNUEABIHF:
1647 return "arm926ej-s";
1651 case llvm::Triple::NaCl:
1652 case llvm::Triple::OpenBSD:
1655 switch (getEnvironment()) {
1656 case llvm::Triple::EABIHF:
1657 case llvm::Triple::GNUEABIHF:
1658 case llvm::Triple::MuslEABIHF:
1659 return "arm1176jzf-s";
1665 llvm_unreachable("invalid arch name");