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 ppc64: return "powerpc64";
39 case ppc64le: return "powerpc64le";
40 case ppc: return "powerpc";
41 case r600: return "r600";
42 case amdgcn: return "amdgcn";
43 case riscv32: return "riscv32";
44 case riscv64: return "riscv64";
45 case sparc: return "sparc";
46 case sparcv9: return "sparcv9";
47 case sparcel: return "sparcel";
48 case systemz: return "s390x";
49 case tce: return "tce";
50 case tcele: return "tcele";
51 case thumb: return "thumb";
52 case thumbeb: return "thumbeb";
53 case x86: return "i386";
54 case x86_64: return "x86_64";
55 case xcore: return "xcore";
56 case nvptx: return "nvptx";
57 case nvptx64: return "nvptx64";
58 case le32: return "le32";
59 case le64: return "le64";
60 case amdil: return "amdil";
61 case amdil64: return "amdil64";
62 case hsail: return "hsail";
63 case hsail64: return "hsail64";
64 case spir: return "spir";
65 case spir64: return "spir64";
66 case kalimba: return "kalimba";
67 case lanai: return "lanai";
68 case shave: return "shave";
69 case wasm32: return "wasm32";
70 case wasm64: return "wasm64";
71 case renderscript32: return "renderscript32";
72 case renderscript64: return "renderscript64";
75 llvm_unreachable("Invalid ArchType!");
78 StringRef Triple::getArchTypePrefix(ArchType Kind) {
84 case aarch64_be: return "aarch64";
86 case arc: return "arc";
91 case thumbeb: return "arm";
93 case avr: return "avr";
97 case ppc: return "ppc";
102 case mips64el: return "mips";
104 case hexagon: return "hexagon";
106 case amdgcn: return "amdgcn";
107 case r600: return "r600";
110 case bpfeb: return "bpf";
114 case sparc: return "sparc";
116 case systemz: return "s390";
119 case x86_64: return "x86";
121 case xcore: return "xcore";
123 // NVPTX intrinsics are namespaced under nvvm.
124 case nvptx: return "nvvm";
125 case nvptx64: return "nvvm";
127 case le32: return "le32";
128 case le64: return "le64";
131 case amdil64: return "amdil";
134 case hsail64: return "hsail";
137 case spir64: return "spir";
138 case kalimba: return "kalimba";
139 case lanai: return "lanai";
140 case shave: return "shave";
142 case wasm64: return "wasm";
145 case riscv64: return "riscv";
149 StringRef Triple::getVendorTypeName(VendorType Kind) {
151 case UnknownVendor: return "unknown";
153 case Apple: return "apple";
154 case PC: return "pc";
155 case SCEI: return "scei";
156 case BGP: return "bgp";
157 case BGQ: return "bgq";
158 case Freescale: return "fsl";
159 case IBM: return "ibm";
160 case ImaginationTechnologies: return "img";
161 case MipsTechnologies: return "mti";
162 case NVIDIA: return "nvidia";
163 case CSR: return "csr";
164 case Myriad: return "myriad";
165 case AMD: return "amd";
166 case Mesa: return "mesa";
167 case SUSE: return "suse";
168 case OpenEmbedded: return "oe";
171 llvm_unreachable("Invalid VendorType!");
174 StringRef Triple::getOSTypeName(OSType Kind) {
176 case UnknownOS: return "unknown";
178 case Ananas: return "ananas";
179 case CloudABI: return "cloudabi";
180 case Darwin: return "darwin";
181 case DragonFly: return "dragonfly";
182 case FreeBSD: return "freebsd";
183 case Fuchsia: return "fuchsia";
184 case IOS: return "ios";
185 case KFreeBSD: return "kfreebsd";
186 case Linux: return "linux";
187 case Lv2: return "lv2";
188 case MacOSX: return "macosx";
189 case NetBSD: return "netbsd";
190 case OpenBSD: return "openbsd";
191 case Solaris: return "solaris";
192 case Win32: return "windows";
193 case Haiku: return "haiku";
194 case Minix: return "minix";
195 case RTEMS: return "rtems";
196 case NaCl: return "nacl";
197 case CNK: return "cnk";
198 case AIX: return "aix";
199 case CUDA: return "cuda";
200 case NVCL: return "nvcl";
201 case AMDHSA: return "amdhsa";
202 case PS4: return "ps4";
203 case ELFIAMCU: return "elfiamcu";
204 case TvOS: return "tvos";
205 case WatchOS: return "watchos";
206 case Mesa3D: return "mesa3d";
207 case Contiki: return "contiki";
208 case AMDPAL: return "amdpal";
209 case HermitCore: return "hermit";
210 case Hurd: return "hurd";
211 case WASI: return "wasi";
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 .Default(Triple::UnknownOS);
513 static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
514 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
515 .StartsWith("eabihf", Triple::EABIHF)
516 .StartsWith("eabi", Triple::EABI)
517 .StartsWith("gnuabin32", Triple::GNUABIN32)
518 .StartsWith("gnuabi64", Triple::GNUABI64)
519 .StartsWith("gnueabihf", Triple::GNUEABIHF)
520 .StartsWith("gnueabi", Triple::GNUEABI)
521 .StartsWith("gnux32", Triple::GNUX32)
522 .StartsWith("code16", Triple::CODE16)
523 .StartsWith("gnu", Triple::GNU)
524 .StartsWith("android", Triple::Android)
525 .StartsWith("musleabihf", Triple::MuslEABIHF)
526 .StartsWith("musleabi", Triple::MuslEABI)
527 .StartsWith("musl", Triple::Musl)
528 .StartsWith("msvc", Triple::MSVC)
529 .StartsWith("itanium", Triple::Itanium)
530 .StartsWith("cygnus", Triple::Cygnus)
531 .StartsWith("coreclr", Triple::CoreCLR)
532 .StartsWith("simulator", Triple::Simulator)
533 .Default(Triple::UnknownEnvironment);
536 static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
537 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
538 .EndsWith("coff", Triple::COFF)
539 .EndsWith("elf", Triple::ELF)
540 .EndsWith("macho", Triple::MachO)
541 .EndsWith("wasm", Triple::Wasm)
542 .Default(Triple::UnknownObjectFormat);
545 static Triple::SubArchType parseSubArch(StringRef SubArchName) {
546 if (SubArchName.startswith("mips") &&
547 (SubArchName.endswith("r6el") || SubArchName.endswith("r6")))
548 return Triple::MipsSubArch_r6;
550 StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
552 // For now, this is the small part. Early return.
553 if (ARMSubArch.empty())
554 return StringSwitch<Triple::SubArchType>(SubArchName)
555 .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
556 .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
557 .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
558 .Default(Triple::NoSubArch);
561 switch(ARM::parseArch(ARMSubArch)) {
562 case ARM::ArchKind::ARMV4:
563 return Triple::NoSubArch;
564 case ARM::ArchKind::ARMV4T:
565 return Triple::ARMSubArch_v4t;
566 case ARM::ArchKind::ARMV5T:
567 return Triple::ARMSubArch_v5;
568 case ARM::ArchKind::ARMV5TE:
569 case ARM::ArchKind::IWMMXT:
570 case ARM::ArchKind::IWMMXT2:
571 case ARM::ArchKind::XSCALE:
572 case ARM::ArchKind::ARMV5TEJ:
573 return Triple::ARMSubArch_v5te;
574 case ARM::ArchKind::ARMV6:
575 return Triple::ARMSubArch_v6;
576 case ARM::ArchKind::ARMV6K:
577 case ARM::ArchKind::ARMV6KZ:
578 return Triple::ARMSubArch_v6k;
579 case ARM::ArchKind::ARMV6T2:
580 return Triple::ARMSubArch_v6t2;
581 case ARM::ArchKind::ARMV6M:
582 return Triple::ARMSubArch_v6m;
583 case ARM::ArchKind::ARMV7A:
584 case ARM::ArchKind::ARMV7R:
585 return Triple::ARMSubArch_v7;
586 case ARM::ArchKind::ARMV7VE:
587 return Triple::ARMSubArch_v7ve;
588 case ARM::ArchKind::ARMV7K:
589 return Triple::ARMSubArch_v7k;
590 case ARM::ArchKind::ARMV7M:
591 return Triple::ARMSubArch_v7m;
592 case ARM::ArchKind::ARMV7S:
593 return Triple::ARMSubArch_v7s;
594 case ARM::ArchKind::ARMV7EM:
595 return Triple::ARMSubArch_v7em;
596 case ARM::ArchKind::ARMV8A:
597 return Triple::ARMSubArch_v8;
598 case ARM::ArchKind::ARMV8_1A:
599 return Triple::ARMSubArch_v8_1a;
600 case ARM::ArchKind::ARMV8_2A:
601 return Triple::ARMSubArch_v8_2a;
602 case ARM::ArchKind::ARMV8_3A:
603 return Triple::ARMSubArch_v8_3a;
604 case ARM::ArchKind::ARMV8_4A:
605 return Triple::ARMSubArch_v8_4a;
606 case ARM::ArchKind::ARMV8_5A:
607 return Triple::ARMSubArch_v8_5a;
608 case ARM::ArchKind::ARMV8R:
609 return Triple::ARMSubArch_v8r;
610 case ARM::ArchKind::ARMV8MBaseline:
611 return Triple::ARMSubArch_v8m_baseline;
612 case ARM::ArchKind::ARMV8MMainline:
613 return Triple::ARMSubArch_v8m_mainline;
615 return Triple::NoSubArch;
619 static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
621 case Triple::UnknownObjectFormat: return "";
622 case Triple::COFF: return "coff";
623 case Triple::ELF: return "elf";
624 case Triple::MachO: return "macho";
625 case Triple::Wasm: return "wasm";
627 llvm_unreachable("unknown object format type");
630 static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
631 switch (T.getArch()) {
632 case Triple::UnknownArch:
633 case Triple::aarch64:
639 return Triple::MachO;
640 else if (T.isOSWindows())
644 case Triple::aarch64_be:
648 case Triple::amdil64:
653 case Triple::hexagon:
656 case Triple::hsail64:
657 case Triple::kalimba:
662 case Triple::mips64el:
666 case Triple::nvptx64:
667 case Triple::ppc64le:
669 case Triple::renderscript32:
670 case Triple::renderscript64:
671 case Triple::riscv32:
672 case Triple::riscv64:
675 case Triple::sparcel:
676 case Triple::sparcv9:
679 case Triple::systemz:
682 case Triple::thumbeb:
689 return Triple::MachO;
696 llvm_unreachable("unknown architecture");
699 /// Construct a triple from the string representation provided.
701 /// This stores the string representation and parses the various pieces into
703 Triple::Triple(const Twine &Str)
704 : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
705 Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
706 ObjectFormat(UnknownObjectFormat) {
707 // Do minimal parsing by hand here.
708 SmallVector<StringRef, 4> Components;
709 StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
710 if (Components.size() > 0) {
711 Arch = parseArch(Components[0]);
712 SubArch = parseSubArch(Components[0]);
713 if (Components.size() > 1) {
714 Vendor = parseVendor(Components[1]);
715 if (Components.size() > 2) {
716 OS = parseOS(Components[2]);
717 if (Components.size() > 3) {
718 Environment = parseEnvironment(Components[3]);
719 ObjectFormat = parseFormat(Components[3]);
724 StringSwitch<Triple::EnvironmentType>(Components[0])
725 .StartsWith("mipsn32", Triple::GNUABIN32)
726 .StartsWith("mips64", Triple::GNUABI64)
727 .StartsWith("mipsisa64", Triple::GNUABI64)
728 .StartsWith("mipsisa32", Triple::GNU)
729 .Cases("mips", "mipsel", "mipsr6", "mipsr6el", Triple::GNU)
730 .Default(UnknownEnvironment);
733 if (ObjectFormat == UnknownObjectFormat)
734 ObjectFormat = getDefaultFormat(*this);
737 /// Construct a triple from string representations of the architecture,
740 /// This joins each argument into a canonical string representation and parses
741 /// them into enum members. It leaves the environment unknown and omits it from
742 /// the string representation.
743 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
744 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
745 Arch(parseArch(ArchStr.str())),
746 SubArch(parseSubArch(ArchStr.str())),
747 Vendor(parseVendor(VendorStr.str())),
748 OS(parseOS(OSStr.str())),
749 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
750 ObjectFormat = getDefaultFormat(*this);
753 /// Construct a triple from string representations of the architecture,
754 /// vendor, OS, and environment.
756 /// This joins each argument into a canonical string representation and parses
757 /// them into enum members.
758 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
759 const Twine &EnvironmentStr)
760 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
761 EnvironmentStr).str()),
762 Arch(parseArch(ArchStr.str())),
763 SubArch(parseSubArch(ArchStr.str())),
764 Vendor(parseVendor(VendorStr.str())),
765 OS(parseOS(OSStr.str())),
766 Environment(parseEnvironment(EnvironmentStr.str())),
767 ObjectFormat(parseFormat(EnvironmentStr.str())) {
768 if (ObjectFormat == Triple::UnknownObjectFormat)
769 ObjectFormat = getDefaultFormat(*this);
772 std::string Triple::normalize(StringRef Str) {
773 bool IsMinGW32 = false;
774 bool IsCygwin = false;
776 // Parse into components.
777 SmallVector<StringRef, 4> Components;
778 Str.split(Components, '-');
780 // If the first component corresponds to a known architecture, preferentially
781 // use it for the architecture. If the second component corresponds to a
782 // known vendor, preferentially use it for the vendor, etc. This avoids silly
783 // component movement when a component parses as (eg) both a valid arch and a
785 ArchType Arch = UnknownArch;
786 if (Components.size() > 0)
787 Arch = parseArch(Components[0]);
788 VendorType Vendor = UnknownVendor;
789 if (Components.size() > 1)
790 Vendor = parseVendor(Components[1]);
791 OSType OS = UnknownOS;
792 if (Components.size() > 2) {
793 OS = parseOS(Components[2]);
794 IsCygwin = Components[2].startswith("cygwin");
795 IsMinGW32 = Components[2].startswith("mingw");
797 EnvironmentType Environment = UnknownEnvironment;
798 if (Components.size() > 3)
799 Environment = parseEnvironment(Components[3]);
800 ObjectFormatType ObjectFormat = UnknownObjectFormat;
801 if (Components.size() > 4)
802 ObjectFormat = parseFormat(Components[4]);
804 // Note which components are already in their final position. These will not
807 Found[0] = Arch != UnknownArch;
808 Found[1] = Vendor != UnknownVendor;
809 Found[2] = OS != UnknownOS;
810 Found[3] = Environment != UnknownEnvironment;
812 // If they are not there already, permute the components into their canonical
813 // positions by seeing if they parse as a valid architecture, and if so moving
814 // the component to the architecture position etc.
815 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
817 continue; // Already in the canonical position.
819 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
820 // Do not reparse any components that already matched.
821 if (Idx < array_lengthof(Found) && Found[Idx])
824 // Does this component parse as valid for the target position?
826 StringRef Comp = Components[Idx];
828 default: llvm_unreachable("unexpected component type!");
830 Arch = parseArch(Comp);
831 Valid = Arch != UnknownArch;
834 Vendor = parseVendor(Comp);
835 Valid = Vendor != UnknownVendor;
839 IsCygwin = Comp.startswith("cygwin");
840 IsMinGW32 = Comp.startswith("mingw");
841 Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
844 Environment = parseEnvironment(Comp);
845 Valid = Environment != UnknownEnvironment;
847 ObjectFormat = parseFormat(Comp);
848 Valid = ObjectFormat != UnknownObjectFormat;
853 continue; // Nope, try the next component.
855 // Move the component to the target position, pushing any non-fixed
856 // components that are in the way to the right. This tends to give
857 // good results in the common cases of a forgotten vendor component
858 // or a wrongly positioned environment.
860 // Insert left, pushing the existing components to the right. For
861 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
862 StringRef CurrentComponent(""); // The empty component.
863 // Replace the component we are moving with an empty component.
864 std::swap(CurrentComponent, Components[Idx]);
865 // Insert the component being moved at Pos, displacing any existing
866 // components to the right.
867 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
868 // Skip over any fixed components.
869 while (i < array_lengthof(Found) && Found[i])
871 // Place the component at the new position, getting the component
872 // that was at this position - it will be moved right.
873 std::swap(CurrentComponent, Components[i]);
875 } else if (Pos > Idx) {
876 // Push right by inserting empty components until the component at Idx
877 // reaches the target position Pos. For example, pc-a -> -pc-a when
878 // moving pc to the second position.
880 // Insert one empty component at Idx.
881 StringRef CurrentComponent(""); // The empty component.
882 for (unsigned i = Idx; i < Components.size();) {
883 // Place the component at the new position, getting the component
884 // that was at this position - it will be moved right.
885 std::swap(CurrentComponent, Components[i]);
886 // If it was placed on top of an empty component then we are done.
887 if (CurrentComponent.empty())
889 // Advance to the next component, skipping any fixed components.
890 while (++i < array_lengthof(Found) && Found[i])
893 // The last component was pushed off the end - append it.
894 if (!CurrentComponent.empty())
895 Components.push_back(CurrentComponent);
897 // Advance Idx to the component's new position.
898 while (++Idx < array_lengthof(Found) && Found[Idx])
900 } while (Idx < Pos); // Add more until the final position is reached.
902 assert(Pos < Components.size() && Components[Pos] == Comp &&
903 "Component moved wrong!");
909 // Replace empty components with "unknown" value.
910 for (unsigned i = 0, e = Components.size(); i < e; ++i) {
911 if (Components[i].empty())
912 Components[i] = "unknown";
915 // Special case logic goes here. At this point Arch, Vendor and OS have the
916 // correct values for the computed components.
917 std::string NormalizedEnvironment;
918 if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
919 StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
920 if (AndroidVersion.empty()) {
921 Components[3] = "android";
923 NormalizedEnvironment = Twine("android", AndroidVersion).str();
924 Components[3] = NormalizedEnvironment;
928 // SUSE uses "gnueabi" to mean "gnueabihf"
929 if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
930 Components[3] = "gnueabihf";
932 if (OS == Triple::Win32) {
933 Components.resize(4);
934 Components[2] = "windows";
935 if (Environment == UnknownEnvironment) {
936 if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
937 Components[3] = "msvc";
939 Components[3] = getObjectFormatTypeName(ObjectFormat);
941 } else if (IsMinGW32) {
942 Components.resize(4);
943 Components[2] = "windows";
944 Components[3] = "gnu";
945 } else if (IsCygwin) {
946 Components.resize(4);
947 Components[2] = "windows";
948 Components[3] = "cygnus";
950 if (IsMinGW32 || IsCygwin ||
951 (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
952 if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
953 Components.resize(5);
954 Components[4] = getObjectFormatTypeName(ObjectFormat);
958 // Stick the corrected components back together to form the normalized string.
959 std::string Normalized;
960 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
961 if (i) Normalized += '-';
962 Normalized += Components[i];
967 StringRef Triple::getArchName() const {
968 return StringRef(Data).split('-').first; // Isolate first component
971 StringRef Triple::getVendorName() const {
972 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
973 return Tmp.split('-').first; // Isolate second component
976 StringRef Triple::getOSName() const {
977 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
978 Tmp = Tmp.split('-').second; // Strip second component
979 return Tmp.split('-').first; // Isolate third component
982 StringRef Triple::getEnvironmentName() const {
983 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
984 Tmp = Tmp.split('-').second; // Strip second component
985 return Tmp.split('-').second; // Strip third component
988 StringRef Triple::getOSAndEnvironmentName() const {
989 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
990 return Tmp.split('-').second; // Strip second component
993 static unsigned EatNumber(StringRef &Str) {
994 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
998 // Consume the leading digit.
999 Result = Result*10 + (Str[0] - '0');
1002 Str = Str.substr(1);
1003 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
1008 static void parseVersionFromName(StringRef Name, unsigned &Major,
1009 unsigned &Minor, unsigned &Micro) {
1010 // Any unset version defaults to 0.
1011 Major = Minor = Micro = 0;
1013 // Parse up to three components.
1014 unsigned *Components[3] = {&Major, &Minor, &Micro};
1015 for (unsigned i = 0; i != 3; ++i) {
1016 if (Name.empty() || Name[0] < '0' || Name[0] > '9')
1019 // Consume the leading number.
1020 *Components[i] = EatNumber(Name);
1022 // Consume the separator, if present.
1023 if (Name.startswith("."))
1024 Name = Name.substr(1);
1028 void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
1029 unsigned &Micro) const {
1030 StringRef EnvironmentName = getEnvironmentName();
1031 StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
1032 if (EnvironmentName.startswith(EnvironmentTypeName))
1033 EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
1035 parseVersionFromName(EnvironmentName, Major, Minor, Micro);
1038 void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
1039 unsigned &Micro) const {
1040 StringRef OSName = getOSName();
1041 // Assume that the OS portion of the triple starts with the canonical name.
1042 StringRef OSTypeName = getOSTypeName(getOS());
1043 if (OSName.startswith(OSTypeName))
1044 OSName = OSName.substr(OSTypeName.size());
1045 else if (getOS() == MacOSX)
1046 OSName.consume_front("macos");
1048 parseVersionFromName(OSName, Major, Minor, Micro);
1051 bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
1052 unsigned &Micro) const {
1053 getOSVersion(Major, Minor, Micro);
1056 default: llvm_unreachable("unexpected OS for Darwin triple");
1058 // Default to darwin8, i.e., MacOSX 10.4.
1061 // Darwin version numbers are skewed from OS X versions.
1080 // Ignore the version from the triple. This is only handled because the
1081 // the clang driver combines OS X and IOS support into a common Darwin
1082 // toolchain that wants to know the OS X version number even when targeting
1092 void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
1093 unsigned &Micro) const {
1095 default: llvm_unreachable("unexpected OS for Darwin triple");
1098 // Ignore the version from the triple. This is only handled because the
1099 // the clang driver combines OS X and IOS support into a common Darwin
1100 // toolchain that wants to know the iOS version number even when targeting
1108 getOSVersion(Major, Minor, Micro);
1109 // Default to 5.0 (or 7.0 for arm64).
1111 Major = (getArch() == aarch64) ? 7 : 5;
1114 llvm_unreachable("conflicting triple info");
1118 void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
1119 unsigned &Micro) const {
1121 default: llvm_unreachable("unexpected OS for Darwin triple");
1124 // Ignore the version from the triple. This is only handled because the
1125 // the clang driver combines OS X and IOS support into a common Darwin
1126 // toolchain that wants to know the iOS version number even when targeting
1133 getOSVersion(Major, Minor, Micro);
1138 llvm_unreachable("conflicting triple info");
1142 void Triple::setTriple(const Twine &Str) {
1143 *this = Triple(Str);
1146 void Triple::setArch(ArchType Kind) {
1147 setArchName(getArchTypeName(Kind));
1150 void Triple::setVendor(VendorType Kind) {
1151 setVendorName(getVendorTypeName(Kind));
1154 void Triple::setOS(OSType Kind) {
1155 setOSName(getOSTypeName(Kind));
1158 void Triple::setEnvironment(EnvironmentType Kind) {
1159 if (ObjectFormat == getDefaultFormat(*this))
1160 return setEnvironmentName(getEnvironmentTypeName(Kind));
1162 setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
1163 getObjectFormatTypeName(ObjectFormat)).str());
1166 void Triple::setObjectFormat(ObjectFormatType Kind) {
1167 if (Environment == UnknownEnvironment)
1168 return setEnvironmentName(getObjectFormatTypeName(Kind));
1170 setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
1171 getObjectFormatTypeName(Kind)).str());
1174 void Triple::setArchName(StringRef Str) {
1175 // Work around a miscompilation bug for Twines in gcc 4.0.3.
1176 SmallString<64> Triple;
1179 Triple += getVendorName();
1181 Triple += getOSAndEnvironmentName();
1185 void Triple::setVendorName(StringRef Str) {
1186 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
1189 void Triple::setOSName(StringRef Str) {
1190 if (hasEnvironment())
1191 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
1192 "-" + getEnvironmentName());
1194 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1197 void Triple::setEnvironmentName(StringRef Str) {
1198 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1202 void Triple::setOSAndEnvironmentName(StringRef Str) {
1203 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1206 static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
1208 case llvm::Triple::UnknownArch:
1211 case llvm::Triple::avr:
1212 case llvm::Triple::msp430:
1215 case llvm::Triple::arc:
1216 case llvm::Triple::arm:
1217 case llvm::Triple::armeb:
1218 case llvm::Triple::hexagon:
1219 case llvm::Triple::le32:
1220 case llvm::Triple::mips:
1221 case llvm::Triple::mipsel:
1222 case llvm::Triple::nvptx:
1223 case llvm::Triple::ppc:
1224 case llvm::Triple::r600:
1225 case llvm::Triple::riscv32:
1226 case llvm::Triple::sparc:
1227 case llvm::Triple::sparcel:
1228 case llvm::Triple::tce:
1229 case llvm::Triple::tcele:
1230 case llvm::Triple::thumb:
1231 case llvm::Triple::thumbeb:
1232 case llvm::Triple::x86:
1233 case llvm::Triple::xcore:
1234 case llvm::Triple::amdil:
1235 case llvm::Triple::hsail:
1236 case llvm::Triple::spir:
1237 case llvm::Triple::kalimba:
1238 case llvm::Triple::lanai:
1239 case llvm::Triple::shave:
1240 case llvm::Triple::wasm32:
1241 case llvm::Triple::renderscript32:
1244 case llvm::Triple::aarch64:
1245 case llvm::Triple::aarch64_be:
1246 case llvm::Triple::amdgcn:
1247 case llvm::Triple::bpfel:
1248 case llvm::Triple::bpfeb:
1249 case llvm::Triple::le64:
1250 case llvm::Triple::mips64:
1251 case llvm::Triple::mips64el:
1252 case llvm::Triple::nvptx64:
1253 case llvm::Triple::ppc64:
1254 case llvm::Triple::ppc64le:
1255 case llvm::Triple::riscv64:
1256 case llvm::Triple::sparcv9:
1257 case llvm::Triple::systemz:
1258 case llvm::Triple::x86_64:
1259 case llvm::Triple::amdil64:
1260 case llvm::Triple::hsail64:
1261 case llvm::Triple::spir64:
1262 case llvm::Triple::wasm64:
1263 case llvm::Triple::renderscript64:
1266 llvm_unreachable("Invalid architecture value");
1269 bool Triple::isArch64Bit() const {
1270 return getArchPointerBitWidth(getArch()) == 64;
1273 bool Triple::isArch32Bit() const {
1274 return getArchPointerBitWidth(getArch()) == 32;
1277 bool Triple::isArch16Bit() const {
1278 return getArchPointerBitWidth(getArch()) == 16;
1281 Triple Triple::get32BitArchVariant() const {
1283 switch (getArch()) {
1284 case Triple::UnknownArch:
1285 case Triple::amdgcn:
1289 case Triple::msp430:
1290 case Triple::systemz:
1291 case Triple::ppc64le:
1292 T.setArch(UnknownArch);
1301 case Triple::hexagon:
1302 case Triple::kalimba:
1305 case Triple::mipsel:
1309 case Triple::riscv32:
1311 case Triple::sparcel:
1315 case Triple::thumbeb:
1320 case Triple::wasm32:
1321 case Triple::renderscript32:
1325 case Triple::aarch64: T.setArch(Triple::arm); break;
1326 case Triple::aarch64_be: T.setArch(Triple::armeb); break;
1327 case Triple::le64: T.setArch(Triple::le32); break;
1328 case Triple::mips64: T.setArch(Triple::mips); break;
1329 case Triple::mips64el: T.setArch(Triple::mipsel); break;
1330 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
1331 case Triple::ppc64: T.setArch(Triple::ppc); break;
1332 case Triple::sparcv9: T.setArch(Triple::sparc); break;
1333 case Triple::riscv64: T.setArch(Triple::riscv32); break;
1334 case Triple::x86_64: T.setArch(Triple::x86); break;
1335 case Triple::amdil64: T.setArch(Triple::amdil); break;
1336 case Triple::hsail64: T.setArch(Triple::hsail); break;
1337 case Triple::spir64: T.setArch(Triple::spir); break;
1338 case Triple::wasm64: T.setArch(Triple::wasm32); break;
1339 case Triple::renderscript64: T.setArch(Triple::renderscript32); break;
1344 Triple Triple::get64BitArchVariant() const {
1346 switch (getArch()) {
1347 case Triple::UnknownArch:
1350 case Triple::hexagon:
1351 case Triple::kalimba:
1353 case Triple::msp430:
1358 case Triple::sparcel:
1360 T.setArch(UnknownArch);
1363 case Triple::aarch64:
1364 case Triple::aarch64_be:
1368 case Triple::amdil64:
1369 case Triple::amdgcn:
1370 case Triple::hsail64:
1371 case Triple::spir64:
1372 case Triple::mips64:
1373 case Triple::mips64el:
1374 case Triple::nvptx64:
1376 case Triple::ppc64le:
1377 case Triple::riscv64:
1378 case Triple::sparcv9:
1379 case Triple::systemz:
1380 case Triple::x86_64:
1381 case Triple::wasm64:
1382 case Triple::renderscript64:
1386 case Triple::arm: T.setArch(Triple::aarch64); break;
1387 case Triple::armeb: T.setArch(Triple::aarch64_be); break;
1388 case Triple::le32: T.setArch(Triple::le64); break;
1389 case Triple::mips: T.setArch(Triple::mips64); break;
1390 case Triple::mipsel: T.setArch(Triple::mips64el); break;
1391 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
1392 case Triple::ppc: T.setArch(Triple::ppc64); break;
1393 case Triple::sparc: T.setArch(Triple::sparcv9); break;
1394 case Triple::riscv32: T.setArch(Triple::riscv64); break;
1395 case Triple::x86: T.setArch(Triple::x86_64); break;
1396 case Triple::amdil: T.setArch(Triple::amdil64); break;
1397 case Triple::hsail: T.setArch(Triple::hsail64); break;
1398 case Triple::spir: T.setArch(Triple::spir64); break;
1399 case Triple::thumb: T.setArch(Triple::aarch64); break;
1400 case Triple::thumbeb: T.setArch(Triple::aarch64_be); break;
1401 case Triple::wasm32: T.setArch(Triple::wasm64); break;
1402 case Triple::renderscript32: T.setArch(Triple::renderscript64); break;
1407 Triple Triple::getBigEndianArchVariant() const {
1409 // Already big endian.
1410 if (!isLittleEndian())
1412 switch (getArch()) {
1413 case Triple::UnknownArch:
1414 case Triple::amdgcn:
1415 case Triple::amdil64:
1418 case Triple::hexagon:
1419 case Triple::hsail64:
1421 case Triple::kalimba:
1424 case Triple::msp430:
1425 case Triple::nvptx64:
1428 case Triple::riscv32:
1429 case Triple::riscv64:
1431 case Triple::spir64:
1433 case Triple::wasm32:
1434 case Triple::wasm64:
1436 case Triple::x86_64:
1438 case Triple::renderscript32:
1439 case Triple::renderscript64:
1441 // ARM is intentionally unsupported here, changing the architecture would
1442 // drop any arch suffixes.
1445 T.setArch(UnknownArch);
1448 case Triple::tcele: T.setArch(Triple::tce); break;
1449 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1450 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1451 case Triple::mips64el:T.setArch(Triple::mips64); break;
1452 case Triple::mipsel: T.setArch(Triple::mips); break;
1453 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1454 case Triple::sparcel: T.setArch(Triple::sparc); break;
1456 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1461 Triple Triple::getLittleEndianArchVariant() const {
1463 if (isLittleEndian())
1466 switch (getArch()) {
1467 case Triple::UnknownArch:
1470 case Triple::sparcv9:
1471 case Triple::systemz:
1473 // ARM is intentionally unsupported here, changing the architecture would
1474 // drop any arch suffixes.
1476 case Triple::thumbeb:
1477 T.setArch(UnknownArch);
1480 case Triple::tce: T.setArch(Triple::tcele); break;
1481 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1482 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1483 case Triple::mips64: T.setArch(Triple::mips64el); break;
1484 case Triple::mips: T.setArch(Triple::mipsel); break;
1485 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1486 case Triple::sparc: T.setArch(Triple::sparcel); break;
1488 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1493 bool Triple::isLittleEndian() const {
1494 switch (getArch()) {
1495 case Triple::aarch64:
1496 case Triple::amdgcn:
1497 case Triple::amdil64:
1502 case Triple::hexagon:
1503 case Triple::hsail64:
1505 case Triple::kalimba:
1508 case Triple::mips64el:
1509 case Triple::mipsel:
1510 case Triple::msp430:
1511 case Triple::nvptx64:
1513 case Triple::ppc64le:
1515 case Triple::riscv32:
1516 case Triple::riscv64:
1518 case Triple::sparcel:
1519 case Triple::spir64:
1522 case Triple::wasm32:
1523 case Triple::wasm64:
1525 case Triple::x86_64:
1528 case Triple::renderscript32:
1529 case Triple::renderscript64:
1536 bool Triple::isCompatibleWith(const Triple &Other) const {
1537 // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
1538 if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
1539 (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
1540 (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) ||
1541 (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) {
1542 if (getVendor() == Triple::Apple)
1543 return getSubArch() == Other.getSubArch() &&
1544 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1546 return getSubArch() == Other.getSubArch() &&
1547 getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
1548 getEnvironment() == Other.getEnvironment() &&
1549 getObjectFormat() == Other.getObjectFormat();
1552 // If vendor is apple, ignore the version number.
1553 if (getVendor() == Triple::Apple)
1554 return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
1555 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1557 return *this == Other;
1560 std::string Triple::merge(const Triple &Other) const {
1561 // If vendor is apple, pick the triple with the larger version number.
1562 if (getVendor() == Triple::Apple)
1563 if (Other.isOSVersionLT(*this))
1569 StringRef Triple::getARMCPUForArch(StringRef MArch) const {
1571 MArch = getArchName();
1572 MArch = ARM::getCanonicalArchName(MArch);
1574 // Some defaults are forced.
1576 case llvm::Triple::FreeBSD:
1577 case llvm::Triple::NetBSD:
1578 if (!MArch.empty() && MArch == "v6")
1579 return "arm1176jzf-s";
1581 case llvm::Triple::Win32:
1582 // FIXME: this is invalid for WindowsCE
1584 case llvm::Triple::MacOSX:
1585 case llvm::Triple::IOS:
1586 case llvm::Triple::WatchOS:
1587 case llvm::Triple::TvOS:
1598 StringRef CPU = ARM::getDefaultCPU(MArch);
1599 if (!CPU.empty() && !CPU.equals("invalid"))
1602 // If no specific architecture version is requested, return the minimum CPU
1603 // required by the OS and environment.
1605 case llvm::Triple::NetBSD:
1606 switch (getEnvironment()) {
1607 case llvm::Triple::GNUEABIHF:
1608 case llvm::Triple::GNUEABI:
1609 case llvm::Triple::EABIHF:
1610 case llvm::Triple::EABI:
1611 return "arm926ej-s";
1615 case llvm::Triple::NaCl:
1616 case llvm::Triple::OpenBSD:
1619 switch (getEnvironment()) {
1620 case llvm::Triple::EABIHF:
1621 case llvm::Triple::GNUEABIHF:
1622 case llvm::Triple::MuslEABIHF:
1623 return "arm1176jzf-s";
1629 llvm_unreachable("invalid arch name");