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_be: return "aarch64_be";
25 case arm: return "arm";
26 case armeb: return "armeb";
27 case arc: return "arc";
28 case avr: return "avr";
29 case bpfel: return "bpfel";
30 case bpfeb: return "bpfeb";
31 case hexagon: return "hexagon";
32 case mips: return "mips";
33 case mipsel: return "mipsel";
34 case mips64: return "mips64";
35 case mips64el: return "mips64el";
36 case msp430: return "msp430";
37 case ppc64: return "powerpc64";
38 case ppc64le: return "powerpc64le";
39 case ppc: return "powerpc";
40 case r600: return "r600";
41 case amdgcn: return "amdgcn";
42 case riscv32: return "riscv32";
43 case riscv64: return "riscv64";
44 case sparc: return "sparc";
45 case sparcv9: return "sparcv9";
46 case sparcel: return "sparcel";
47 case systemz: return "s390x";
48 case tce: return "tce";
49 case tcele: return "tcele";
50 case thumb: return "thumb";
51 case thumbeb: return "thumbeb";
52 case x86: return "i386";
53 case x86_64: return "x86_64";
54 case xcore: return "xcore";
55 case nvptx: return "nvptx";
56 case nvptx64: return "nvptx64";
57 case le32: return "le32";
58 case le64: return "le64";
59 case amdil: return "amdil";
60 case amdil64: return "amdil64";
61 case hsail: return "hsail";
62 case hsail64: return "hsail64";
63 case spir: return "spir";
64 case spir64: return "spir64";
65 case kalimba: return "kalimba";
66 case lanai: return "lanai";
67 case shave: return "shave";
68 case wasm32: return "wasm32";
69 case wasm64: return "wasm64";
70 case renderscript32: return "renderscript32";
71 case renderscript64: return "renderscript64";
74 llvm_unreachable("Invalid ArchType!");
77 StringRef Triple::getArchTypePrefix(ArchType Kind) {
83 case aarch64_be: return "aarch64";
85 case arc: return "arc";
90 case thumbeb: return "arm";
92 case avr: return "avr";
96 case ppc: return "ppc";
101 case mips64el: return "mips";
103 case hexagon: return "hexagon";
105 case amdgcn: return "amdgcn";
106 case r600: return "r600";
109 case bpfeb: return "bpf";
113 case sparc: return "sparc";
115 case systemz: return "s390";
118 case x86_64: return "x86";
120 case xcore: return "xcore";
122 // NVPTX intrinsics are namespaced under nvvm.
123 case nvptx: return "nvvm";
124 case nvptx64: return "nvvm";
126 case le32: return "le32";
127 case le64: return "le64";
130 case amdil64: return "amdil";
133 case hsail64: return "hsail";
136 case spir64: return "spir";
137 case kalimba: return "kalimba";
138 case lanai: return "lanai";
139 case shave: return "shave";
141 case wasm64: return "wasm";
144 case riscv64: return "riscv";
148 StringRef Triple::getVendorTypeName(VendorType Kind) {
150 case UnknownVendor: return "unknown";
152 case Apple: return "apple";
153 case PC: return "pc";
154 case SCEI: return "scei";
155 case BGP: return "bgp";
156 case BGQ: return "bgq";
157 case Freescale: return "fsl";
158 case IBM: return "ibm";
159 case ImaginationTechnologies: return "img";
160 case MipsTechnologies: return "mti";
161 case NVIDIA: return "nvidia";
162 case CSR: return "csr";
163 case Myriad: return "myriad";
164 case AMD: return "amd";
165 case Mesa: return "mesa";
166 case SUSE: return "suse";
167 case OpenEmbedded: return "oe";
170 llvm_unreachable("Invalid VendorType!");
173 StringRef Triple::getOSTypeName(OSType Kind) {
175 case UnknownOS: return "unknown";
177 case Ananas: return "ananas";
178 case CloudABI: return "cloudabi";
179 case Darwin: return "darwin";
180 case DragonFly: return "dragonfly";
181 case FreeBSD: return "freebsd";
182 case Fuchsia: return "fuchsia";
183 case IOS: return "ios";
184 case KFreeBSD: return "kfreebsd";
185 case Linux: return "linux";
186 case Lv2: return "lv2";
187 case MacOSX: return "macosx";
188 case NetBSD: return "netbsd";
189 case OpenBSD: return "openbsd";
190 case Solaris: return "solaris";
191 case Win32: return "windows";
192 case Haiku: return "haiku";
193 case Minix: return "minix";
194 case RTEMS: return "rtems";
195 case NaCl: return "nacl";
196 case CNK: return "cnk";
197 case AIX: return "aix";
198 case CUDA: return "cuda";
199 case NVCL: return "nvcl";
200 case AMDHSA: return "amdhsa";
201 case PS4: return "ps4";
202 case ELFIAMCU: return "elfiamcu";
203 case TvOS: return "tvos";
204 case WatchOS: return "watchos";
205 case Mesa3D: return "mesa3d";
206 case Contiki: return "contiki";
207 case AMDPAL: return "amdpal";
208 case HermitCore: return "hermit";
209 case Hurd: return "hurd";
210 case WASI: return "wasi";
211 case Emscripten: return "emscripten";
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("ppc64", ppc64)
277 .Case("ppc64le", ppc64le)
279 .Case("amdgcn", amdgcn)
280 .Case("riscv32", riscv32)
281 .Case("riscv64", riscv64)
282 .Case("hexagon", hexagon)
283 .Case("sparc", sparc)
284 .Case("sparcel", sparcel)
285 .Case("sparcv9", sparcv9)
286 .Case("systemz", systemz)
288 .Case("tcele", tcele)
289 .Case("thumb", thumb)
290 .Case("thumbeb", thumbeb)
292 .Case("x86-64", x86_64)
293 .Case("xcore", xcore)
294 .Case("nvptx", nvptx)
295 .Case("nvptx64", nvptx64)
298 .Case("amdil", amdil)
299 .Case("amdil64", amdil64)
300 .Case("hsail", hsail)
301 .Case("hsail64", hsail64)
303 .Case("spir64", spir64)
304 .Case("kalimba", kalimba)
305 .Case("lanai", lanai)
306 .Case("shave", shave)
307 .Case("wasm32", wasm32)
308 .Case("wasm64", wasm64)
309 .Case("renderscript32", renderscript32)
310 .Case("renderscript64", renderscript64)
311 .Default(UnknownArch);
314 static Triple::ArchType parseARMArch(StringRef ArchName) {
315 ARM::ISAKind ISA = ARM::parseArchISA(ArchName);
316 ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName);
318 Triple::ArchType arch = Triple::UnknownArch;
320 case ARM::EndianKind::LITTLE: {
322 case ARM::ISAKind::ARM:
325 case ARM::ISAKind::THUMB:
326 arch = Triple::thumb;
328 case ARM::ISAKind::AARCH64:
329 arch = Triple::aarch64;
331 case ARM::ISAKind::INVALID:
336 case ARM::EndianKind::BIG: {
338 case ARM::ISAKind::ARM:
339 arch = Triple::armeb;
341 case ARM::ISAKind::THUMB:
342 arch = Triple::thumbeb;
344 case ARM::ISAKind::AARCH64:
345 arch = Triple::aarch64_be;
347 case ARM::ISAKind::INVALID:
352 case ARM::EndianKind::INVALID: {
357 ArchName = ARM::getCanonicalArchName(ArchName);
358 if (ArchName.empty())
359 return Triple::UnknownArch;
361 // Thumb only exists in v4+
362 if (ISA == ARM::ISAKind::THUMB &&
363 (ArchName.startswith("v2") || ArchName.startswith("v3")))
364 return Triple::UnknownArch;
366 // Thumb only for v6m
367 ARM::ProfileKind Profile = ARM::parseArchProfile(ArchName);
368 unsigned Version = ARM::parseArchVersion(ArchName);
369 if (Profile == ARM::ProfileKind::M && Version == 6) {
370 if (ENDIAN == ARM::EndianKind::BIG)
371 return Triple::thumbeb;
373 return Triple::thumb;
379 static Triple::ArchType parseArch(StringRef ArchName) {
380 auto AT = StringSwitch<Triple::ArchType>(ArchName)
381 .Cases("i386", "i486", "i586", "i686", Triple::x86)
382 // FIXME: Do we need to support these?
383 .Cases("i786", "i886", "i986", Triple::x86)
384 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
385 .Cases("powerpc", "ppc", "ppc32", Triple::ppc)
386 .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64)
387 .Cases("powerpc64le", "ppc64le", Triple::ppc64le)
388 .Case("xscale", Triple::arm)
389 .Case("xscaleeb", Triple::armeb)
390 .Case("aarch64", Triple::aarch64)
391 .Case("aarch64_be", Triple::aarch64_be)
392 .Case("arc", Triple::arc)
393 .Case("arm64", Triple::aarch64)
394 .Case("arm", Triple::arm)
395 .Case("armeb", Triple::armeb)
396 .Case("thumb", Triple::thumb)
397 .Case("thumbeb", Triple::thumbeb)
398 .Case("avr", Triple::avr)
399 .Case("msp430", Triple::msp430)
400 .Cases("mips", "mipseb", "mipsallegrex", "mipsisa32r6",
401 "mipsr6", Triple::mips)
402 .Cases("mipsel", "mipsallegrexel", "mipsisa32r6el", "mipsr6el",
404 .Cases("mips64", "mips64eb", "mipsn32", "mipsisa64r6",
405 "mips64r6", "mipsn32r6", Triple::mips64)
406 .Cases("mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el",
407 "mipsn32r6el", Triple::mips64el)
408 .Case("r600", Triple::r600)
409 .Case("amdgcn", Triple::amdgcn)
410 .Case("riscv32", Triple::riscv32)
411 .Case("riscv64", Triple::riscv64)
412 .Case("hexagon", Triple::hexagon)
413 .Cases("s390x", "systemz", Triple::systemz)
414 .Case("sparc", Triple::sparc)
415 .Case("sparcel", Triple::sparcel)
416 .Cases("sparcv9", "sparc64", Triple::sparcv9)
417 .Case("tce", Triple::tce)
418 .Case("tcele", Triple::tcele)
419 .Case("xcore", Triple::xcore)
420 .Case("nvptx", Triple::nvptx)
421 .Case("nvptx64", Triple::nvptx64)
422 .Case("le32", Triple::le32)
423 .Case("le64", Triple::le64)
424 .Case("amdil", Triple::amdil)
425 .Case("amdil64", Triple::amdil64)
426 .Case("hsail", Triple::hsail)
427 .Case("hsail64", Triple::hsail64)
428 .Case("spir", Triple::spir)
429 .Case("spir64", Triple::spir64)
430 .StartsWith("kalimba", Triple::kalimba)
431 .Case("lanai", Triple::lanai)
432 .Case("shave", Triple::shave)
433 .Case("wasm32", Triple::wasm32)
434 .Case("wasm64", Triple::wasm64)
435 .Case("renderscript32", Triple::renderscript32)
436 .Case("renderscript64", Triple::renderscript64)
437 .Default(Triple::UnknownArch);
439 // Some architectures require special parsing logic just to compute the
441 if (AT == Triple::UnknownArch) {
442 if (ArchName.startswith("arm") || ArchName.startswith("thumb") ||
443 ArchName.startswith("aarch64"))
444 return parseARMArch(ArchName);
445 if (ArchName.startswith("bpf"))
446 return parseBPFArch(ArchName);
452 static Triple::VendorType parseVendor(StringRef VendorName) {
453 return StringSwitch<Triple::VendorType>(VendorName)
454 .Case("apple", Triple::Apple)
455 .Case("pc", Triple::PC)
456 .Case("scei", Triple::SCEI)
457 .Case("bgp", Triple::BGP)
458 .Case("bgq", Triple::BGQ)
459 .Case("fsl", Triple::Freescale)
460 .Case("ibm", Triple::IBM)
461 .Case("img", Triple::ImaginationTechnologies)
462 .Case("mti", Triple::MipsTechnologies)
463 .Case("nvidia", Triple::NVIDIA)
464 .Case("csr", Triple::CSR)
465 .Case("myriad", Triple::Myriad)
466 .Case("amd", Triple::AMD)
467 .Case("mesa", Triple::Mesa)
468 .Case("suse", Triple::SUSE)
469 .Case("oe", Triple::OpenEmbedded)
470 .Default(Triple::UnknownVendor);
473 static Triple::OSType parseOS(StringRef OSName) {
474 return StringSwitch<Triple::OSType>(OSName)
475 .StartsWith("ananas", Triple::Ananas)
476 .StartsWith("cloudabi", Triple::CloudABI)
477 .StartsWith("darwin", Triple::Darwin)
478 .StartsWith("dragonfly", Triple::DragonFly)
479 .StartsWith("freebsd", Triple::FreeBSD)
480 .StartsWith("fuchsia", Triple::Fuchsia)
481 .StartsWith("ios", Triple::IOS)
482 .StartsWith("kfreebsd", Triple::KFreeBSD)
483 .StartsWith("linux", Triple::Linux)
484 .StartsWith("lv2", Triple::Lv2)
485 .StartsWith("macos", Triple::MacOSX)
486 .StartsWith("netbsd", Triple::NetBSD)
487 .StartsWith("openbsd", Triple::OpenBSD)
488 .StartsWith("solaris", Triple::Solaris)
489 .StartsWith("win32", Triple::Win32)
490 .StartsWith("windows", Triple::Win32)
491 .StartsWith("haiku", Triple::Haiku)
492 .StartsWith("minix", Triple::Minix)
493 .StartsWith("rtems", Triple::RTEMS)
494 .StartsWith("nacl", Triple::NaCl)
495 .StartsWith("cnk", Triple::CNK)
496 .StartsWith("aix", Triple::AIX)
497 .StartsWith("cuda", Triple::CUDA)
498 .StartsWith("nvcl", Triple::NVCL)
499 .StartsWith("amdhsa", Triple::AMDHSA)
500 .StartsWith("ps4", Triple::PS4)
501 .StartsWith("elfiamcu", Triple::ELFIAMCU)
502 .StartsWith("tvos", Triple::TvOS)
503 .StartsWith("watchos", Triple::WatchOS)
504 .StartsWith("mesa3d", Triple::Mesa3D)
505 .StartsWith("contiki", Triple::Contiki)
506 .StartsWith("amdpal", Triple::AMDPAL)
507 .StartsWith("hermit", Triple::HermitCore)
508 .StartsWith("hurd", Triple::Hurd)
509 .StartsWith("wasi", Triple::WASI)
510 .StartsWith("emscripten", Triple::Emscripten)
511 .Default(Triple::UnknownOS);
514 static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
515 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
516 .StartsWith("eabihf", Triple::EABIHF)
517 .StartsWith("eabi", Triple::EABI)
518 .StartsWith("gnuabin32", Triple::GNUABIN32)
519 .StartsWith("gnuabi64", Triple::GNUABI64)
520 .StartsWith("gnueabihf", Triple::GNUEABIHF)
521 .StartsWith("gnueabi", Triple::GNUEABI)
522 .StartsWith("gnux32", Triple::GNUX32)
523 .StartsWith("code16", Triple::CODE16)
524 .StartsWith("gnu", Triple::GNU)
525 .StartsWith("android", Triple::Android)
526 .StartsWith("musleabihf", Triple::MuslEABIHF)
527 .StartsWith("musleabi", Triple::MuslEABI)
528 .StartsWith("musl", Triple::Musl)
529 .StartsWith("msvc", Triple::MSVC)
530 .StartsWith("itanium", Triple::Itanium)
531 .StartsWith("cygnus", Triple::Cygnus)
532 .StartsWith("coreclr", Triple::CoreCLR)
533 .StartsWith("simulator", Triple::Simulator)
534 .Default(Triple::UnknownEnvironment);
537 static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
538 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
539 // "xcoff" must come before "coff" because of the order-dependendent
541 .EndsWith("xcoff", Triple::XCOFF)
542 .EndsWith("coff", Triple::COFF)
543 .EndsWith("elf", Triple::ELF)
544 .EndsWith("macho", Triple::MachO)
545 .EndsWith("wasm", Triple::Wasm)
546 .Default(Triple::UnknownObjectFormat);
549 static Triple::SubArchType parseSubArch(StringRef SubArchName) {
550 if (SubArchName.startswith("mips") &&
551 (SubArchName.endswith("r6el") || SubArchName.endswith("r6")))
552 return Triple::MipsSubArch_r6;
554 StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
556 // For now, this is the small part. Early return.
557 if (ARMSubArch.empty())
558 return StringSwitch<Triple::SubArchType>(SubArchName)
559 .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
560 .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
561 .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
562 .Default(Triple::NoSubArch);
565 switch(ARM::parseArch(ARMSubArch)) {
566 case ARM::ArchKind::ARMV4:
567 return Triple::NoSubArch;
568 case ARM::ArchKind::ARMV4T:
569 return Triple::ARMSubArch_v4t;
570 case ARM::ArchKind::ARMV5T:
571 return Triple::ARMSubArch_v5;
572 case ARM::ArchKind::ARMV5TE:
573 case ARM::ArchKind::IWMMXT:
574 case ARM::ArchKind::IWMMXT2:
575 case ARM::ArchKind::XSCALE:
576 case ARM::ArchKind::ARMV5TEJ:
577 return Triple::ARMSubArch_v5te;
578 case ARM::ArchKind::ARMV6:
579 return Triple::ARMSubArch_v6;
580 case ARM::ArchKind::ARMV6K:
581 case ARM::ArchKind::ARMV6KZ:
582 return Triple::ARMSubArch_v6k;
583 case ARM::ArchKind::ARMV6T2:
584 return Triple::ARMSubArch_v6t2;
585 case ARM::ArchKind::ARMV6M:
586 return Triple::ARMSubArch_v6m;
587 case ARM::ArchKind::ARMV7A:
588 case ARM::ArchKind::ARMV7R:
589 return Triple::ARMSubArch_v7;
590 case ARM::ArchKind::ARMV7VE:
591 return Triple::ARMSubArch_v7ve;
592 case ARM::ArchKind::ARMV7K:
593 return Triple::ARMSubArch_v7k;
594 case ARM::ArchKind::ARMV7M:
595 return Triple::ARMSubArch_v7m;
596 case ARM::ArchKind::ARMV7S:
597 return Triple::ARMSubArch_v7s;
598 case ARM::ArchKind::ARMV7EM:
599 return Triple::ARMSubArch_v7em;
600 case ARM::ArchKind::ARMV8A:
601 return Triple::ARMSubArch_v8;
602 case ARM::ArchKind::ARMV8_1A:
603 return Triple::ARMSubArch_v8_1a;
604 case ARM::ArchKind::ARMV8_2A:
605 return Triple::ARMSubArch_v8_2a;
606 case ARM::ArchKind::ARMV8_3A:
607 return Triple::ARMSubArch_v8_3a;
608 case ARM::ArchKind::ARMV8_4A:
609 return Triple::ARMSubArch_v8_4a;
610 case ARM::ArchKind::ARMV8_5A:
611 return Triple::ARMSubArch_v8_5a;
612 case ARM::ArchKind::ARMV8R:
613 return Triple::ARMSubArch_v8r;
614 case ARM::ArchKind::ARMV8MBaseline:
615 return Triple::ARMSubArch_v8m_baseline;
616 case ARM::ArchKind::ARMV8MMainline:
617 return Triple::ARMSubArch_v8m_mainline;
619 return Triple::NoSubArch;
623 static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
625 case Triple::UnknownObjectFormat: return "";
626 case Triple::COFF: return "coff";
627 case Triple::ELF: return "elf";
628 case Triple::MachO: return "macho";
629 case Triple::Wasm: return "wasm";
630 case Triple::XCOFF: return "xcoff";
632 llvm_unreachable("unknown object format type");
635 static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
636 switch (T.getArch()) {
637 case Triple::UnknownArch:
638 case Triple::aarch64:
644 return Triple::MachO;
645 else if (T.isOSWindows())
649 case Triple::aarch64_be:
653 case Triple::amdil64:
658 case Triple::hexagon:
661 case Triple::hsail64:
662 case Triple::kalimba:
667 case Triple::mips64el:
671 case Triple::nvptx64:
672 case Triple::ppc64le:
674 case Triple::renderscript32:
675 case Triple::renderscript64:
676 case Triple::riscv32:
677 case Triple::riscv64:
680 case Triple::sparcel:
681 case Triple::sparcv9:
684 case Triple::systemz:
687 case Triple::thumbeb:
694 return Triple::MachO;
695 else if (T.isOSAIX())
696 return Triple::XCOFF;
703 llvm_unreachable("unknown architecture");
706 /// Construct a triple from the string representation provided.
708 /// This stores the string representation and parses the various pieces into
710 Triple::Triple(const Twine &Str)
711 : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
712 Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
713 ObjectFormat(UnknownObjectFormat) {
714 // Do minimal parsing by hand here.
715 SmallVector<StringRef, 4> Components;
716 StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
717 if (Components.size() > 0) {
718 Arch = parseArch(Components[0]);
719 SubArch = parseSubArch(Components[0]);
720 if (Components.size() > 1) {
721 Vendor = parseVendor(Components[1]);
722 if (Components.size() > 2) {
723 OS = parseOS(Components[2]);
724 if (Components.size() > 3) {
725 Environment = parseEnvironment(Components[3]);
726 ObjectFormat = parseFormat(Components[3]);
731 StringSwitch<Triple::EnvironmentType>(Components[0])
732 .StartsWith("mipsn32", Triple::GNUABIN32)
733 .StartsWith("mips64", Triple::GNUABI64)
734 .StartsWith("mipsisa64", Triple::GNUABI64)
735 .StartsWith("mipsisa32", Triple::GNU)
736 .Cases("mips", "mipsel", "mipsr6", "mipsr6el", Triple::GNU)
737 .Default(UnknownEnvironment);
740 if (ObjectFormat == UnknownObjectFormat)
741 ObjectFormat = getDefaultFormat(*this);
744 /// Construct a triple from string representations of the architecture,
747 /// This joins each argument into a canonical string representation and parses
748 /// them into enum members. It leaves the environment unknown and omits it from
749 /// the string representation.
750 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
751 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
752 Arch(parseArch(ArchStr.str())),
753 SubArch(parseSubArch(ArchStr.str())),
754 Vendor(parseVendor(VendorStr.str())),
755 OS(parseOS(OSStr.str())),
756 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
757 ObjectFormat = getDefaultFormat(*this);
760 /// Construct a triple from string representations of the architecture,
761 /// vendor, OS, and environment.
763 /// This joins each argument into a canonical string representation and parses
764 /// them into enum members.
765 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
766 const Twine &EnvironmentStr)
767 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
768 EnvironmentStr).str()),
769 Arch(parseArch(ArchStr.str())),
770 SubArch(parseSubArch(ArchStr.str())),
771 Vendor(parseVendor(VendorStr.str())),
772 OS(parseOS(OSStr.str())),
773 Environment(parseEnvironment(EnvironmentStr.str())),
774 ObjectFormat(parseFormat(EnvironmentStr.str())) {
775 if (ObjectFormat == Triple::UnknownObjectFormat)
776 ObjectFormat = getDefaultFormat(*this);
779 std::string Triple::normalize(StringRef Str) {
780 bool IsMinGW32 = false;
781 bool IsCygwin = false;
783 // Parse into components.
784 SmallVector<StringRef, 4> Components;
785 Str.split(Components, '-');
787 // If the first component corresponds to a known architecture, preferentially
788 // use it for the architecture. If the second component corresponds to a
789 // known vendor, preferentially use it for the vendor, etc. This avoids silly
790 // component movement when a component parses as (eg) both a valid arch and a
792 ArchType Arch = UnknownArch;
793 if (Components.size() > 0)
794 Arch = parseArch(Components[0]);
795 VendorType Vendor = UnknownVendor;
796 if (Components.size() > 1)
797 Vendor = parseVendor(Components[1]);
798 OSType OS = UnknownOS;
799 if (Components.size() > 2) {
800 OS = parseOS(Components[2]);
801 IsCygwin = Components[2].startswith("cygwin");
802 IsMinGW32 = Components[2].startswith("mingw");
804 EnvironmentType Environment = UnknownEnvironment;
805 if (Components.size() > 3)
806 Environment = parseEnvironment(Components[3]);
807 ObjectFormatType ObjectFormat = UnknownObjectFormat;
808 if (Components.size() > 4)
809 ObjectFormat = parseFormat(Components[4]);
811 // Note which components are already in their final position. These will not
814 Found[0] = Arch != UnknownArch;
815 Found[1] = Vendor != UnknownVendor;
816 Found[2] = OS != UnknownOS;
817 Found[3] = Environment != UnknownEnvironment;
819 // If they are not there already, permute the components into their canonical
820 // positions by seeing if they parse as a valid architecture, and if so moving
821 // the component to the architecture position etc.
822 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
824 continue; // Already in the canonical position.
826 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
827 // Do not reparse any components that already matched.
828 if (Idx < array_lengthof(Found) && Found[Idx])
831 // Does this component parse as valid for the target position?
833 StringRef Comp = Components[Idx];
835 default: llvm_unreachable("unexpected component type!");
837 Arch = parseArch(Comp);
838 Valid = Arch != UnknownArch;
841 Vendor = parseVendor(Comp);
842 Valid = Vendor != UnknownVendor;
846 IsCygwin = Comp.startswith("cygwin");
847 IsMinGW32 = Comp.startswith("mingw");
848 Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
851 Environment = parseEnvironment(Comp);
852 Valid = Environment != UnknownEnvironment;
854 ObjectFormat = parseFormat(Comp);
855 Valid = ObjectFormat != UnknownObjectFormat;
860 continue; // Nope, try the next component.
862 // Move the component to the target position, pushing any non-fixed
863 // components that are in the way to the right. This tends to give
864 // good results in the common cases of a forgotten vendor component
865 // or a wrongly positioned environment.
867 // Insert left, pushing the existing components to the right. For
868 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
869 StringRef CurrentComponent(""); // The empty component.
870 // Replace the component we are moving with an empty component.
871 std::swap(CurrentComponent, Components[Idx]);
872 // Insert the component being moved at Pos, displacing any existing
873 // components to the right.
874 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
875 // Skip over any fixed components.
876 while (i < array_lengthof(Found) && Found[i])
878 // Place the component at the new position, getting the component
879 // that was at this position - it will be moved right.
880 std::swap(CurrentComponent, Components[i]);
882 } else if (Pos > Idx) {
883 // Push right by inserting empty components until the component at Idx
884 // reaches the target position Pos. For example, pc-a -> -pc-a when
885 // moving pc to the second position.
887 // Insert one empty component at Idx.
888 StringRef CurrentComponent(""); // The empty component.
889 for (unsigned i = Idx; i < Components.size();) {
890 // Place the component at the new position, getting the component
891 // that was at this position - it will be moved right.
892 std::swap(CurrentComponent, Components[i]);
893 // If it was placed on top of an empty component then we are done.
894 if (CurrentComponent.empty())
896 // Advance to the next component, skipping any fixed components.
897 while (++i < array_lengthof(Found) && Found[i])
900 // The last component was pushed off the end - append it.
901 if (!CurrentComponent.empty())
902 Components.push_back(CurrentComponent);
904 // Advance Idx to the component's new position.
905 while (++Idx < array_lengthof(Found) && Found[Idx])
907 } while (Idx < Pos); // Add more until the final position is reached.
909 assert(Pos < Components.size() && Components[Pos] == Comp &&
910 "Component moved wrong!");
916 // Replace empty components with "unknown" value.
917 for (unsigned i = 0, e = Components.size(); i < e; ++i) {
918 if (Components[i].empty())
919 Components[i] = "unknown";
922 // Special case logic goes here. At this point Arch, Vendor and OS have the
923 // correct values for the computed components.
924 std::string NormalizedEnvironment;
925 if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
926 StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
927 if (AndroidVersion.empty()) {
928 Components[3] = "android";
930 NormalizedEnvironment = Twine("android", AndroidVersion).str();
931 Components[3] = NormalizedEnvironment;
935 // SUSE uses "gnueabi" to mean "gnueabihf"
936 if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
937 Components[3] = "gnueabihf";
939 if (OS == Triple::Win32) {
940 Components.resize(4);
941 Components[2] = "windows";
942 if (Environment == UnknownEnvironment) {
943 if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
944 Components[3] = "msvc";
946 Components[3] = getObjectFormatTypeName(ObjectFormat);
948 } else if (IsMinGW32) {
949 Components.resize(4);
950 Components[2] = "windows";
951 Components[3] = "gnu";
952 } else if (IsCygwin) {
953 Components.resize(4);
954 Components[2] = "windows";
955 Components[3] = "cygnus";
957 if (IsMinGW32 || IsCygwin ||
958 (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
959 if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
960 Components.resize(5);
961 Components[4] = getObjectFormatTypeName(ObjectFormat);
965 // Stick the corrected components back together to form the normalized string.
966 std::string Normalized;
967 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
968 if (i) Normalized += '-';
969 Normalized += Components[i];
974 StringRef Triple::getArchName() const {
975 return StringRef(Data).split('-').first; // Isolate first component
978 StringRef Triple::getVendorName() const {
979 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
980 return Tmp.split('-').first; // Isolate second component
983 StringRef Triple::getOSName() const {
984 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
985 Tmp = Tmp.split('-').second; // Strip second component
986 return Tmp.split('-').first; // Isolate third component
989 StringRef Triple::getEnvironmentName() const {
990 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
991 Tmp = Tmp.split('-').second; // Strip second component
992 return Tmp.split('-').second; // Strip third component
995 StringRef Triple::getOSAndEnvironmentName() const {
996 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
997 return Tmp.split('-').second; // Strip second component
1000 static unsigned EatNumber(StringRef &Str) {
1001 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
1002 unsigned Result = 0;
1005 // Consume the leading digit.
1006 Result = Result*10 + (Str[0] - '0');
1009 Str = Str.substr(1);
1010 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
1015 static void parseVersionFromName(StringRef Name, unsigned &Major,
1016 unsigned &Minor, unsigned &Micro) {
1017 // Any unset version defaults to 0.
1018 Major = Minor = Micro = 0;
1020 // Parse up to three components.
1021 unsigned *Components[3] = {&Major, &Minor, &Micro};
1022 for (unsigned i = 0; i != 3; ++i) {
1023 if (Name.empty() || Name[0] < '0' || Name[0] > '9')
1026 // Consume the leading number.
1027 *Components[i] = EatNumber(Name);
1029 // Consume the separator, if present.
1030 if (Name.startswith("."))
1031 Name = Name.substr(1);
1035 void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
1036 unsigned &Micro) const {
1037 StringRef EnvironmentName = getEnvironmentName();
1038 StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
1039 if (EnvironmentName.startswith(EnvironmentTypeName))
1040 EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
1042 parseVersionFromName(EnvironmentName, Major, Minor, Micro);
1045 void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
1046 unsigned &Micro) const {
1047 StringRef OSName = getOSName();
1048 // Assume that the OS portion of the triple starts with the canonical name.
1049 StringRef OSTypeName = getOSTypeName(getOS());
1050 if (OSName.startswith(OSTypeName))
1051 OSName = OSName.substr(OSTypeName.size());
1052 else if (getOS() == MacOSX)
1053 OSName.consume_front("macos");
1055 parseVersionFromName(OSName, Major, Minor, Micro);
1058 bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
1059 unsigned &Micro) const {
1060 getOSVersion(Major, Minor, Micro);
1063 default: llvm_unreachable("unexpected OS for Darwin triple");
1065 // Default to darwin8, i.e., MacOSX 10.4.
1068 // Darwin version numbers are skewed from OS X versions.
1087 // Ignore the version from the triple. This is only handled because the
1088 // the clang driver combines OS X and IOS support into a common Darwin
1089 // toolchain that wants to know the OS X version number even when targeting
1099 void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
1100 unsigned &Micro) const {
1102 default: llvm_unreachable("unexpected OS for Darwin triple");
1105 // Ignore the version from the triple. This is only handled because the
1106 // the clang driver combines OS X and IOS support into a common Darwin
1107 // toolchain that wants to know the iOS version number even when targeting
1115 getOSVersion(Major, Minor, Micro);
1116 // Default to 5.0 (or 7.0 for arm64).
1118 Major = (getArch() == aarch64) ? 7 : 5;
1121 llvm_unreachable("conflicting triple info");
1125 void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
1126 unsigned &Micro) const {
1128 default: llvm_unreachable("unexpected OS for Darwin triple");
1131 // Ignore the version from the triple. This is only handled because the
1132 // the clang driver combines OS X and IOS support into a common Darwin
1133 // toolchain that wants to know the iOS version number even when targeting
1140 getOSVersion(Major, Minor, Micro);
1145 llvm_unreachable("conflicting triple info");
1149 void Triple::setTriple(const Twine &Str) {
1150 *this = Triple(Str);
1153 void Triple::setArch(ArchType Kind) {
1154 setArchName(getArchTypeName(Kind));
1157 void Triple::setVendor(VendorType Kind) {
1158 setVendorName(getVendorTypeName(Kind));
1161 void Triple::setOS(OSType Kind) {
1162 setOSName(getOSTypeName(Kind));
1165 void Triple::setEnvironment(EnvironmentType Kind) {
1166 if (ObjectFormat == getDefaultFormat(*this))
1167 return setEnvironmentName(getEnvironmentTypeName(Kind));
1169 setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
1170 getObjectFormatTypeName(ObjectFormat)).str());
1173 void Triple::setObjectFormat(ObjectFormatType Kind) {
1174 if (Environment == UnknownEnvironment)
1175 return setEnvironmentName(getObjectFormatTypeName(Kind));
1177 setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
1178 getObjectFormatTypeName(Kind)).str());
1181 void Triple::setArchName(StringRef Str) {
1182 // Work around a miscompilation bug for Twines in gcc 4.0.3.
1183 SmallString<64> Triple;
1186 Triple += getVendorName();
1188 Triple += getOSAndEnvironmentName();
1192 void Triple::setVendorName(StringRef Str) {
1193 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
1196 void Triple::setOSName(StringRef Str) {
1197 if (hasEnvironment())
1198 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
1199 "-" + getEnvironmentName());
1201 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1204 void Triple::setEnvironmentName(StringRef Str) {
1205 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1209 void Triple::setOSAndEnvironmentName(StringRef Str) {
1210 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1213 static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
1215 case llvm::Triple::UnknownArch:
1218 case llvm::Triple::avr:
1219 case llvm::Triple::msp430:
1222 case llvm::Triple::arc:
1223 case llvm::Triple::arm:
1224 case llvm::Triple::armeb:
1225 case llvm::Triple::hexagon:
1226 case llvm::Triple::le32:
1227 case llvm::Triple::mips:
1228 case llvm::Triple::mipsel:
1229 case llvm::Triple::nvptx:
1230 case llvm::Triple::ppc:
1231 case llvm::Triple::r600:
1232 case llvm::Triple::riscv32:
1233 case llvm::Triple::sparc:
1234 case llvm::Triple::sparcel:
1235 case llvm::Triple::tce:
1236 case llvm::Triple::tcele:
1237 case llvm::Triple::thumb:
1238 case llvm::Triple::thumbeb:
1239 case llvm::Triple::x86:
1240 case llvm::Triple::xcore:
1241 case llvm::Triple::amdil:
1242 case llvm::Triple::hsail:
1243 case llvm::Triple::spir:
1244 case llvm::Triple::kalimba:
1245 case llvm::Triple::lanai:
1246 case llvm::Triple::shave:
1247 case llvm::Triple::wasm32:
1248 case llvm::Triple::renderscript32:
1251 case llvm::Triple::aarch64:
1252 case llvm::Triple::aarch64_be:
1253 case llvm::Triple::amdgcn:
1254 case llvm::Triple::bpfel:
1255 case llvm::Triple::bpfeb:
1256 case llvm::Triple::le64:
1257 case llvm::Triple::mips64:
1258 case llvm::Triple::mips64el:
1259 case llvm::Triple::nvptx64:
1260 case llvm::Triple::ppc64:
1261 case llvm::Triple::ppc64le:
1262 case llvm::Triple::riscv64:
1263 case llvm::Triple::sparcv9:
1264 case llvm::Triple::systemz:
1265 case llvm::Triple::x86_64:
1266 case llvm::Triple::amdil64:
1267 case llvm::Triple::hsail64:
1268 case llvm::Triple::spir64:
1269 case llvm::Triple::wasm64:
1270 case llvm::Triple::renderscript64:
1273 llvm_unreachable("Invalid architecture value");
1276 bool Triple::isArch64Bit() const {
1277 return getArchPointerBitWidth(getArch()) == 64;
1280 bool Triple::isArch32Bit() const {
1281 return getArchPointerBitWidth(getArch()) == 32;
1284 bool Triple::isArch16Bit() const {
1285 return getArchPointerBitWidth(getArch()) == 16;
1288 Triple Triple::get32BitArchVariant() const {
1290 switch (getArch()) {
1291 case Triple::UnknownArch:
1292 case Triple::amdgcn:
1296 case Triple::msp430:
1297 case Triple::systemz:
1298 case Triple::ppc64le:
1299 T.setArch(UnknownArch);
1308 case Triple::hexagon:
1309 case Triple::kalimba:
1312 case Triple::mipsel:
1316 case Triple::riscv32:
1318 case Triple::sparcel:
1322 case Triple::thumbeb:
1327 case Triple::wasm32:
1328 case Triple::renderscript32:
1332 case Triple::aarch64: T.setArch(Triple::arm); break;
1333 case Triple::aarch64_be: T.setArch(Triple::armeb); break;
1334 case Triple::le64: T.setArch(Triple::le32); break;
1335 case Triple::mips64: T.setArch(Triple::mips); break;
1336 case Triple::mips64el: T.setArch(Triple::mipsel); break;
1337 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
1338 case Triple::ppc64: T.setArch(Triple::ppc); break;
1339 case Triple::sparcv9: T.setArch(Triple::sparc); break;
1340 case Triple::riscv64: T.setArch(Triple::riscv32); break;
1341 case Triple::x86_64: T.setArch(Triple::x86); break;
1342 case Triple::amdil64: T.setArch(Triple::amdil); break;
1343 case Triple::hsail64: T.setArch(Triple::hsail); break;
1344 case Triple::spir64: T.setArch(Triple::spir); break;
1345 case Triple::wasm64: T.setArch(Triple::wasm32); break;
1346 case Triple::renderscript64: T.setArch(Triple::renderscript32); break;
1351 Triple Triple::get64BitArchVariant() const {
1353 switch (getArch()) {
1354 case Triple::UnknownArch:
1357 case Triple::hexagon:
1358 case Triple::kalimba:
1360 case Triple::msp430:
1365 case Triple::sparcel:
1367 T.setArch(UnknownArch);
1370 case Triple::aarch64:
1371 case Triple::aarch64_be:
1375 case Triple::amdil64:
1376 case Triple::amdgcn:
1377 case Triple::hsail64:
1378 case Triple::spir64:
1379 case Triple::mips64:
1380 case Triple::mips64el:
1381 case Triple::nvptx64:
1383 case Triple::ppc64le:
1384 case Triple::riscv64:
1385 case Triple::sparcv9:
1386 case Triple::systemz:
1387 case Triple::x86_64:
1388 case Triple::wasm64:
1389 case Triple::renderscript64:
1393 case Triple::arm: T.setArch(Triple::aarch64); break;
1394 case Triple::armeb: T.setArch(Triple::aarch64_be); break;
1395 case Triple::le32: T.setArch(Triple::le64); break;
1396 case Triple::mips: T.setArch(Triple::mips64); break;
1397 case Triple::mipsel: T.setArch(Triple::mips64el); break;
1398 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
1399 case Triple::ppc: T.setArch(Triple::ppc64); break;
1400 case Triple::sparc: T.setArch(Triple::sparcv9); break;
1401 case Triple::riscv32: T.setArch(Triple::riscv64); break;
1402 case Triple::x86: T.setArch(Triple::x86_64); break;
1403 case Triple::amdil: T.setArch(Triple::amdil64); break;
1404 case Triple::hsail: T.setArch(Triple::hsail64); break;
1405 case Triple::spir: T.setArch(Triple::spir64); break;
1406 case Triple::thumb: T.setArch(Triple::aarch64); break;
1407 case Triple::thumbeb: T.setArch(Triple::aarch64_be); break;
1408 case Triple::wasm32: T.setArch(Triple::wasm64); break;
1409 case Triple::renderscript32: T.setArch(Triple::renderscript64); break;
1414 Triple Triple::getBigEndianArchVariant() const {
1416 // Already big endian.
1417 if (!isLittleEndian())
1419 switch (getArch()) {
1420 case Triple::UnknownArch:
1421 case Triple::amdgcn:
1422 case Triple::amdil64:
1425 case Triple::hexagon:
1426 case Triple::hsail64:
1428 case Triple::kalimba:
1431 case Triple::msp430:
1432 case Triple::nvptx64:
1435 case Triple::riscv32:
1436 case Triple::riscv64:
1438 case Triple::spir64:
1440 case Triple::wasm32:
1441 case Triple::wasm64:
1443 case Triple::x86_64:
1445 case Triple::renderscript32:
1446 case Triple::renderscript64:
1448 // ARM is intentionally unsupported here, changing the architecture would
1449 // drop any arch suffixes.
1452 T.setArch(UnknownArch);
1455 case Triple::tcele: T.setArch(Triple::tce); break;
1456 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1457 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1458 case Triple::mips64el:T.setArch(Triple::mips64); break;
1459 case Triple::mipsel: T.setArch(Triple::mips); break;
1460 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1461 case Triple::sparcel: T.setArch(Triple::sparc); break;
1463 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1468 Triple Triple::getLittleEndianArchVariant() const {
1470 if (isLittleEndian())
1473 switch (getArch()) {
1474 case Triple::UnknownArch:
1477 case Triple::sparcv9:
1478 case Triple::systemz:
1480 // ARM is intentionally unsupported here, changing the architecture would
1481 // drop any arch suffixes.
1483 case Triple::thumbeb:
1484 T.setArch(UnknownArch);
1487 case Triple::tce: T.setArch(Triple::tcele); break;
1488 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1489 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1490 case Triple::mips64: T.setArch(Triple::mips64el); break;
1491 case Triple::mips: T.setArch(Triple::mipsel); break;
1492 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1493 case Triple::sparc: T.setArch(Triple::sparcel); break;
1495 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1500 bool Triple::isLittleEndian() const {
1501 switch (getArch()) {
1502 case Triple::aarch64:
1503 case Triple::amdgcn:
1504 case Triple::amdil64:
1509 case Triple::hexagon:
1510 case Triple::hsail64:
1512 case Triple::kalimba:
1515 case Triple::mips64el:
1516 case Triple::mipsel:
1517 case Triple::msp430:
1518 case Triple::nvptx64:
1520 case Triple::ppc64le:
1522 case Triple::riscv32:
1523 case Triple::riscv64:
1525 case Triple::sparcel:
1526 case Triple::spir64:
1529 case Triple::wasm32:
1530 case Triple::wasm64:
1532 case Triple::x86_64:
1535 case Triple::renderscript32:
1536 case Triple::renderscript64:
1543 bool Triple::isCompatibleWith(const Triple &Other) const {
1544 // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
1545 if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
1546 (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
1547 (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) ||
1548 (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) {
1549 if (getVendor() == Triple::Apple)
1550 return getSubArch() == Other.getSubArch() &&
1551 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1553 return getSubArch() == Other.getSubArch() &&
1554 getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
1555 getEnvironment() == Other.getEnvironment() &&
1556 getObjectFormat() == Other.getObjectFormat();
1559 // If vendor is apple, ignore the version number.
1560 if (getVendor() == Triple::Apple)
1561 return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
1562 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1564 return *this == Other;
1567 std::string Triple::merge(const Triple &Other) const {
1568 // If vendor is apple, pick the triple with the larger version number.
1569 if (getVendor() == Triple::Apple)
1570 if (Other.isOSVersionLT(*this))
1576 StringRef Triple::getARMCPUForArch(StringRef MArch) const {
1578 MArch = getArchName();
1579 MArch = ARM::getCanonicalArchName(MArch);
1581 // Some defaults are forced.
1583 case llvm::Triple::FreeBSD:
1584 case llvm::Triple::NetBSD:
1585 if (!MArch.empty() && MArch == "v6")
1586 return "arm1176jzf-s";
1588 case llvm::Triple::Win32:
1589 // FIXME: this is invalid for WindowsCE
1591 case llvm::Triple::MacOSX:
1592 case llvm::Triple::IOS:
1593 case llvm::Triple::WatchOS:
1594 case llvm::Triple::TvOS:
1605 StringRef CPU = ARM::getDefaultCPU(MArch);
1606 if (!CPU.empty() && !CPU.equals("invalid"))
1609 // If no specific architecture version is requested, return the minimum CPU
1610 // required by the OS and environment.
1612 case llvm::Triple::NetBSD:
1613 switch (getEnvironment()) {
1614 case llvm::Triple::GNUEABIHF:
1615 case llvm::Triple::GNUEABI:
1616 case llvm::Triple::EABIHF:
1617 case llvm::Triple::EABI:
1618 return "arm926ej-s";
1622 case llvm::Triple::NaCl:
1623 case llvm::Triple::OpenBSD:
1626 switch (getEnvironment()) {
1627 case llvm::Triple::EABIHF:
1628 case llvm::Triple::GNUEABIHF:
1629 case llvm::Triple::MuslEABIHF:
1630 return "arm1176jzf-s";
1636 llvm_unreachable("invalid arch name");