1 //===--- Triple.cpp - Target triple helper class --------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/Triple.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/StringSwitch.h"
14 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/Host.h"
16 #include "llvm/Support/TargetParser.h"
20 StringRef Triple::getArchTypeName(ArchType Kind) {
22 case UnknownArch: return "unknown";
24 case aarch64: return "aarch64";
25 case aarch64_be: return "aarch64_be";
26 case arm: return "arm";
27 case armeb: return "armeb";
28 case arc: return "arc";
29 case avr: return "avr";
30 case bpfel: return "bpfel";
31 case bpfeb: return "bpfeb";
32 case hexagon: return "hexagon";
33 case mips: return "mips";
34 case mipsel: return "mipsel";
35 case mips64: return "mips64";
36 case mips64el: return "mips64el";
37 case msp430: return "msp430";
38 case nios2: return "nios2";
39 case ppc64: return "powerpc64";
40 case ppc64le: return "powerpc64le";
41 case ppc: return "powerpc";
42 case r600: return "r600";
43 case amdgcn: return "amdgcn";
44 case riscv32: return "riscv32";
45 case riscv64: return "riscv64";
46 case sparc: return "sparc";
47 case sparcv9: return "sparcv9";
48 case sparcel: return "sparcel";
49 case systemz: return "s390x";
50 case tce: return "tce";
51 case tcele: return "tcele";
52 case thumb: return "thumb";
53 case thumbeb: return "thumbeb";
54 case x86: return "i386";
55 case x86_64: return "x86_64";
56 case xcore: return "xcore";
57 case nvptx: return "nvptx";
58 case nvptx64: return "nvptx64";
59 case le32: return "le32";
60 case le64: return "le64";
61 case amdil: return "amdil";
62 case amdil64: return "amdil64";
63 case hsail: return "hsail";
64 case hsail64: return "hsail64";
65 case spir: return "spir";
66 case spir64: return "spir64";
67 case kalimba: return "kalimba";
68 case lanai: return "lanai";
69 case shave: return "shave";
70 case wasm32: return "wasm32";
71 case wasm64: return "wasm64";
72 case renderscript32: return "renderscript32";
73 case renderscript64: return "renderscript64";
76 llvm_unreachable("Invalid ArchType!");
79 StringRef Triple::getArchTypePrefix(ArchType Kind) {
85 case aarch64_be: return "aarch64";
87 case arc: return "arc";
92 case thumbeb: return "arm";
94 case avr: return "avr";
98 case ppc: return "ppc";
103 case mips64el: return "mips";
105 case nios2: return "nios2";
107 case hexagon: return "hexagon";
109 case amdgcn: return "amdgcn";
110 case r600: return "r600";
113 case bpfeb: return "bpf";
117 case sparc: return "sparc";
119 case systemz: return "s390";
122 case x86_64: return "x86";
124 case xcore: return "xcore";
126 // NVPTX intrinsics are namespaced under nvvm.
127 case nvptx: return "nvvm";
128 case nvptx64: return "nvvm";
130 case le32: return "le32";
131 case le64: return "le64";
134 case amdil64: return "amdil";
137 case hsail64: return "hsail";
140 case spir64: return "spir";
141 case kalimba: return "kalimba";
142 case lanai: return "lanai";
143 case shave: return "shave";
145 case wasm64: return "wasm";
148 case riscv64: return "riscv";
152 StringRef Triple::getVendorTypeName(VendorType Kind) {
154 case UnknownVendor: return "unknown";
156 case Apple: return "apple";
157 case PC: return "pc";
158 case SCEI: return "scei";
159 case BGP: return "bgp";
160 case BGQ: return "bgq";
161 case Freescale: return "fsl";
162 case IBM: return "ibm";
163 case ImaginationTechnologies: return "img";
164 case MipsTechnologies: return "mti";
165 case NVIDIA: return "nvidia";
166 case CSR: return "csr";
167 case Myriad: return "myriad";
168 case AMD: return "amd";
169 case Mesa: return "mesa";
170 case SUSE: return "suse";
173 llvm_unreachable("Invalid VendorType!");
176 StringRef Triple::getOSTypeName(OSType Kind) {
178 case UnknownOS: return "unknown";
180 case Ananas: return "ananas";
181 case CloudABI: return "cloudabi";
182 case Darwin: return "darwin";
183 case DragonFly: return "dragonfly";
184 case FreeBSD: return "freebsd";
185 case Fuchsia: return "fuchsia";
186 case IOS: return "ios";
187 case KFreeBSD: return "kfreebsd";
188 case Linux: return "linux";
189 case Lv2: return "lv2";
190 case MacOSX: return "macosx";
191 case NetBSD: return "netbsd";
192 case OpenBSD: return "openbsd";
193 case Solaris: return "solaris";
194 case Win32: return "windows";
195 case Haiku: return "haiku";
196 case Minix: return "minix";
197 case RTEMS: return "rtems";
198 case NaCl: return "nacl";
199 case CNK: return "cnk";
200 case AIX: return "aix";
201 case CUDA: return "cuda";
202 case NVCL: return "nvcl";
203 case AMDHSA: return "amdhsa";
204 case PS4: return "ps4";
205 case ELFIAMCU: return "elfiamcu";
206 case TvOS: return "tvos";
207 case WatchOS: return "watchos";
208 case Mesa3D: return "mesa3d";
209 case Contiki: return "contiki";
212 llvm_unreachable("Invalid OSType");
215 StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
217 case UnknownEnvironment: return "unknown";
218 case GNU: return "gnu";
219 case GNUABI64: return "gnuabi64";
220 case GNUEABIHF: return "gnueabihf";
221 case GNUEABI: return "gnueabi";
222 case GNUX32: return "gnux32";
223 case CODE16: return "code16";
224 case EABI: return "eabi";
225 case EABIHF: return "eabihf";
226 case Android: return "android";
227 case Musl: return "musl";
228 case MuslEABI: return "musleabi";
229 case MuslEABIHF: return "musleabihf";
230 case MSVC: return "msvc";
231 case Itanium: return "itanium";
232 case Cygnus: return "cygnus";
233 case AMDOpenCL: return "amdopencl";
234 case CoreCLR: return "coreclr";
235 case OpenCL: return "opencl";
238 llvm_unreachable("Invalid EnvironmentType!");
241 static Triple::ArchType parseBPFArch(StringRef ArchName) {
242 if (ArchName.equals("bpf")) {
243 if (sys::IsLittleEndianHost)
244 return Triple::bpfel;
246 return Triple::bpfeb;
247 } else if (ArchName.equals("bpf_be") || ArchName.equals("bpfeb")) {
248 return Triple::bpfeb;
249 } else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) {
250 return Triple::bpfel;
252 return Triple::UnknownArch;
256 Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
257 Triple::ArchType BPFArch(parseBPFArch(Name));
258 return StringSwitch<Triple::ArchType>(Name)
259 .Case("aarch64", aarch64)
260 .Case("aarch64_be", aarch64_be)
262 .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
264 .Case("armeb", armeb)
266 .StartsWith("bpf", BPFArch)
268 .Case("mipsel", mipsel)
269 .Case("mips64", mips64)
270 .Case("mips64el", mips64el)
271 .Case("msp430", msp430)
272 .Case("nios2", nios2)
273 .Case("ppc64", ppc64)
276 .Case("ppc64le", ppc64le)
278 .Case("amdgcn", amdgcn)
279 .Case("riscv32", riscv32)
280 .Case("riscv64", riscv64)
281 .Case("hexagon", hexagon)
282 .Case("sparc", sparc)
283 .Case("sparcel", sparcel)
284 .Case("sparcv9", sparcv9)
285 .Case("systemz", systemz)
287 .Case("tcele", tcele)
288 .Case("thumb", thumb)
289 .Case("thumbeb", thumbeb)
291 .Case("x86-64", x86_64)
292 .Case("xcore", xcore)
293 .Case("nvptx", nvptx)
294 .Case("nvptx64", nvptx64)
297 .Case("amdil", amdil)
298 .Case("amdil64", amdil64)
299 .Case("hsail", hsail)
300 .Case("hsail64", hsail64)
302 .Case("spir64", spir64)
303 .Case("kalimba", kalimba)
304 .Case("lanai", lanai)
305 .Case("shave", shave)
306 .Case("wasm32", wasm32)
307 .Case("wasm64", wasm64)
308 .Case("renderscript32", renderscript32)
309 .Case("renderscript64", renderscript64)
310 .Default(UnknownArch);
313 static Triple::ArchType parseARMArch(StringRef ArchName) {
314 ARM::ISAKind ISA = ARM::parseArchISA(ArchName);
315 ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName);
317 Triple::ArchType arch = Triple::UnknownArch;
319 case ARM::EndianKind::LITTLE: {
321 case ARM::ISAKind::ARM:
324 case ARM::ISAKind::THUMB:
325 arch = Triple::thumb;
327 case ARM::ISAKind::AARCH64:
328 arch = Triple::aarch64;
330 case ARM::ISAKind::INVALID:
335 case ARM::EndianKind::BIG: {
337 case ARM::ISAKind::ARM:
338 arch = Triple::armeb;
340 case ARM::ISAKind::THUMB:
341 arch = Triple::thumbeb;
343 case ARM::ISAKind::AARCH64:
344 arch = Triple::aarch64_be;
346 case ARM::ISAKind::INVALID:
351 case ARM::EndianKind::INVALID: {
356 ArchName = ARM::getCanonicalArchName(ArchName);
357 if (ArchName.empty())
358 return Triple::UnknownArch;
360 // Thumb only exists in v4+
361 if (ISA == ARM::ISAKind::THUMB &&
362 (ArchName.startswith("v2") || ArchName.startswith("v3")))
363 return Triple::UnknownArch;
365 // Thumb only for v6m
366 ARM::ProfileKind Profile = ARM::parseArchProfile(ArchName);
367 unsigned Version = ARM::parseArchVersion(ArchName);
368 if (Profile == ARM::ProfileKind::M && Version == 6) {
369 if (ENDIAN == ARM::EndianKind::BIG)
370 return Triple::thumbeb;
372 return Triple::thumb;
378 static Triple::ArchType parseArch(StringRef ArchName) {
379 auto AT = StringSwitch<Triple::ArchType>(ArchName)
380 .Cases("i386", "i486", "i586", "i686", Triple::x86)
381 // FIXME: Do we need to support these?
382 .Cases("i786", "i886", "i986", Triple::x86)
383 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
384 .Cases("powerpc", "ppc32", Triple::ppc)
385 .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64)
386 .Cases("powerpc64le", "ppc64le", Triple::ppc64le)
387 .Case("xscale", Triple::arm)
388 .Case("xscaleeb", Triple::armeb)
389 .Case("aarch64", Triple::aarch64)
390 .Case("aarch64_be", Triple::aarch64_be)
391 .Case("arc", Triple::arc)
392 .Case("arm64", Triple::aarch64)
393 .Case("arm", Triple::arm)
394 .Case("armeb", Triple::armeb)
395 .Case("thumb", Triple::thumb)
396 .Case("thumbeb", Triple::thumbeb)
397 .Case("avr", Triple::avr)
398 .Case("msp430", Triple::msp430)
399 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
400 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
401 .Cases("mips64", "mips64eb", Triple::mips64)
402 .Case("mips64el", Triple::mips64el)
403 .Case("nios2", Triple::nios2)
404 .Case("r600", Triple::r600)
405 .Case("amdgcn", Triple::amdgcn)
406 .Case("riscv32", Triple::riscv32)
407 .Case("riscv64", Triple::riscv64)
408 .Case("hexagon", Triple::hexagon)
409 .Cases("s390x", "systemz", Triple::systemz)
410 .Case("sparc", Triple::sparc)
411 .Case("sparcel", Triple::sparcel)
412 .Cases("sparcv9", "sparc64", Triple::sparcv9)
413 .Case("tce", Triple::tce)
414 .Case("tcele", Triple::tcele)
415 .Case("xcore", Triple::xcore)
416 .Case("nvptx", Triple::nvptx)
417 .Case("nvptx64", Triple::nvptx64)
418 .Case("le32", Triple::le32)
419 .Case("le64", Triple::le64)
420 .Case("amdil", Triple::amdil)
421 .Case("amdil64", Triple::amdil64)
422 .Case("hsail", Triple::hsail)
423 .Case("hsail64", Triple::hsail64)
424 .Case("spir", Triple::spir)
425 .Case("spir64", Triple::spir64)
426 .StartsWith("kalimba", Triple::kalimba)
427 .Case("lanai", Triple::lanai)
428 .Case("shave", Triple::shave)
429 .Case("wasm32", Triple::wasm32)
430 .Case("wasm64", Triple::wasm64)
431 .Case("renderscript32", Triple::renderscript32)
432 .Case("renderscript64", Triple::renderscript64)
433 .Default(Triple::UnknownArch);
435 // Some architectures require special parsing logic just to compute the
437 if (AT == Triple::UnknownArch) {
438 if (ArchName.startswith("arm") || ArchName.startswith("thumb") ||
439 ArchName.startswith("aarch64"))
440 return parseARMArch(ArchName);
441 if (ArchName.startswith("bpf"))
442 return parseBPFArch(ArchName);
448 static Triple::VendorType parseVendor(StringRef VendorName) {
449 return StringSwitch<Triple::VendorType>(VendorName)
450 .Case("apple", Triple::Apple)
451 .Case("pc", Triple::PC)
452 .Case("scei", Triple::SCEI)
453 .Case("bgp", Triple::BGP)
454 .Case("bgq", Triple::BGQ)
455 .Case("fsl", Triple::Freescale)
456 .Case("ibm", Triple::IBM)
457 .Case("img", Triple::ImaginationTechnologies)
458 .Case("mti", Triple::MipsTechnologies)
459 .Case("nvidia", Triple::NVIDIA)
460 .Case("csr", Triple::CSR)
461 .Case("myriad", Triple::Myriad)
462 .Case("amd", Triple::AMD)
463 .Case("mesa", Triple::Mesa)
464 .Case("suse", Triple::SUSE)
465 .Default(Triple::UnknownVendor);
468 static Triple::OSType parseOS(StringRef OSName) {
469 return StringSwitch<Triple::OSType>(OSName)
470 .StartsWith("ananas", Triple::Ananas)
471 .StartsWith("cloudabi", Triple::CloudABI)
472 .StartsWith("darwin", Triple::Darwin)
473 .StartsWith("dragonfly", Triple::DragonFly)
474 .StartsWith("freebsd", Triple::FreeBSD)
475 .StartsWith("fuchsia", Triple::Fuchsia)
476 .StartsWith("ios", Triple::IOS)
477 .StartsWith("kfreebsd", Triple::KFreeBSD)
478 .StartsWith("linux", Triple::Linux)
479 .StartsWith("lv2", Triple::Lv2)
480 .StartsWith("macos", Triple::MacOSX)
481 .StartsWith("netbsd", Triple::NetBSD)
482 .StartsWith("openbsd", Triple::OpenBSD)
483 .StartsWith("solaris", Triple::Solaris)
484 .StartsWith("win32", Triple::Win32)
485 .StartsWith("windows", Triple::Win32)
486 .StartsWith("haiku", Triple::Haiku)
487 .StartsWith("minix", Triple::Minix)
488 .StartsWith("rtems", Triple::RTEMS)
489 .StartsWith("nacl", Triple::NaCl)
490 .StartsWith("cnk", Triple::CNK)
491 .StartsWith("aix", Triple::AIX)
492 .StartsWith("cuda", Triple::CUDA)
493 .StartsWith("nvcl", Triple::NVCL)
494 .StartsWith("amdhsa", Triple::AMDHSA)
495 .StartsWith("ps4", Triple::PS4)
496 .StartsWith("elfiamcu", Triple::ELFIAMCU)
497 .StartsWith("tvos", Triple::TvOS)
498 .StartsWith("watchos", Triple::WatchOS)
499 .StartsWith("mesa3d", Triple::Mesa3D)
500 .StartsWith("contiki", Triple::Contiki)
501 .Default(Triple::UnknownOS);
504 static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
505 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
506 .StartsWith("eabihf", Triple::EABIHF)
507 .StartsWith("eabi", Triple::EABI)
508 .StartsWith("gnuabi64", Triple::GNUABI64)
509 .StartsWith("gnueabihf", Triple::GNUEABIHF)
510 .StartsWith("gnueabi", Triple::GNUEABI)
511 .StartsWith("gnux32", Triple::GNUX32)
512 .StartsWith("code16", Triple::CODE16)
513 .StartsWith("gnu", Triple::GNU)
514 .StartsWith("android", Triple::Android)
515 .StartsWith("musleabihf", Triple::MuslEABIHF)
516 .StartsWith("musleabi", Triple::MuslEABI)
517 .StartsWith("musl", Triple::Musl)
518 .StartsWith("msvc", Triple::MSVC)
519 .StartsWith("itanium", Triple::Itanium)
520 .StartsWith("cygnus", Triple::Cygnus)
521 .StartsWith("amdopencl", Triple::AMDOpenCL)
522 .StartsWith("coreclr", Triple::CoreCLR)
523 .StartsWith("opencl", Triple::OpenCL)
524 .Default(Triple::UnknownEnvironment);
527 static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
528 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
529 .EndsWith("coff", Triple::COFF)
530 .EndsWith("elf", Triple::ELF)
531 .EndsWith("macho", Triple::MachO)
532 .EndsWith("wasm", Triple::Wasm)
533 .Default(Triple::UnknownObjectFormat);
536 static Triple::SubArchType parseSubArch(StringRef SubArchName) {
537 StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
539 // For now, this is the small part. Early return.
540 if (ARMSubArch.empty())
541 return StringSwitch<Triple::SubArchType>(SubArchName)
542 .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
543 .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
544 .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
545 .Default(Triple::NoSubArch);
548 switch(ARM::parseArch(ARMSubArch)) {
549 case ARM::ArchKind::ARMV4:
550 return Triple::NoSubArch;
551 case ARM::ArchKind::ARMV4T:
552 return Triple::ARMSubArch_v4t;
553 case ARM::ArchKind::ARMV5T:
554 return Triple::ARMSubArch_v5;
555 case ARM::ArchKind::ARMV5TE:
556 case ARM::ArchKind::IWMMXT:
557 case ARM::ArchKind::IWMMXT2:
558 case ARM::ArchKind::XSCALE:
559 case ARM::ArchKind::ARMV5TEJ:
560 return Triple::ARMSubArch_v5te;
561 case ARM::ArchKind::ARMV6:
562 return Triple::ARMSubArch_v6;
563 case ARM::ArchKind::ARMV6K:
564 case ARM::ArchKind::ARMV6KZ:
565 return Triple::ARMSubArch_v6k;
566 case ARM::ArchKind::ARMV6T2:
567 return Triple::ARMSubArch_v6t2;
568 case ARM::ArchKind::ARMV6M:
569 return Triple::ARMSubArch_v6m;
570 case ARM::ArchKind::ARMV7A:
571 case ARM::ArchKind::ARMV7R:
572 return Triple::ARMSubArch_v7;
573 case ARM::ArchKind::ARMV7VE:
574 return Triple::ARMSubArch_v7ve;
575 case ARM::ArchKind::ARMV7K:
576 return Triple::ARMSubArch_v7k;
577 case ARM::ArchKind::ARMV7M:
578 return Triple::ARMSubArch_v7m;
579 case ARM::ArchKind::ARMV7S:
580 return Triple::ARMSubArch_v7s;
581 case ARM::ArchKind::ARMV7EM:
582 return Triple::ARMSubArch_v7em;
583 case ARM::ArchKind::ARMV8A:
584 return Triple::ARMSubArch_v8;
585 case ARM::ArchKind::ARMV8_1A:
586 return Triple::ARMSubArch_v8_1a;
587 case ARM::ArchKind::ARMV8_2A:
588 return Triple::ARMSubArch_v8_2a;
589 case ARM::ArchKind::ARMV8_3A:
590 return Triple::ARMSubArch_v8_3a;
591 case ARM::ArchKind::ARMV8R:
592 return Triple::ARMSubArch_v8r;
593 case ARM::ArchKind::ARMV8MBaseline:
594 return Triple::ARMSubArch_v8m_baseline;
595 case ARM::ArchKind::ARMV8MMainline:
596 return Triple::ARMSubArch_v8m_mainline;
598 return Triple::NoSubArch;
602 static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
604 case Triple::UnknownObjectFormat: return "";
605 case Triple::COFF: return "coff";
606 case Triple::ELF: return "elf";
607 case Triple::MachO: return "macho";
608 case Triple::Wasm: return "wasm";
610 llvm_unreachable("unknown object format type");
613 static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
614 switch (T.getArch()) {
615 case Triple::UnknownArch:
616 case Triple::aarch64:
622 return Triple::MachO;
623 else if (T.isOSWindows())
627 case Triple::aarch64_be:
631 case Triple::amdil64:
636 case Triple::hexagon:
639 case Triple::hsail64:
640 case Triple::kalimba:
645 case Triple::mips64el:
650 case Triple::nvptx64:
651 case Triple::ppc64le:
653 case Triple::renderscript32:
654 case Triple::renderscript64:
655 case Triple::riscv32:
656 case Triple::riscv64:
659 case Triple::sparcel:
660 case Triple::sparcv9:
663 case Triple::systemz:
666 case Triple::thumbeb:
675 return Triple::MachO;
678 llvm_unreachable("unknown architecture");
681 /// \brief Construct a triple from the string representation provided.
683 /// This stores the string representation and parses the various pieces into
685 Triple::Triple(const Twine &Str)
686 : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
687 Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
688 ObjectFormat(UnknownObjectFormat) {
689 // Do minimal parsing by hand here.
690 SmallVector<StringRef, 4> Components;
691 StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
692 if (Components.size() > 0) {
693 Arch = parseArch(Components[0]);
694 SubArch = parseSubArch(Components[0]);
695 if (Components.size() > 1) {
696 Vendor = parseVendor(Components[1]);
697 if (Components.size() > 2) {
698 OS = parseOS(Components[2]);
699 if (Components.size() > 3) {
700 Environment = parseEnvironment(Components[3]);
701 ObjectFormat = parseFormat(Components[3]);
706 if (ObjectFormat == UnknownObjectFormat)
707 ObjectFormat = getDefaultFormat(*this);
710 /// \brief Construct a triple from string representations of the architecture,
713 /// This joins each argument into a canonical string representation and parses
714 /// them into enum members. It leaves the environment unknown and omits it from
715 /// the string representation.
716 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
717 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
718 Arch(parseArch(ArchStr.str())),
719 SubArch(parseSubArch(ArchStr.str())),
720 Vendor(parseVendor(VendorStr.str())),
721 OS(parseOS(OSStr.str())),
722 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
723 ObjectFormat = getDefaultFormat(*this);
726 /// \brief Construct a triple from string representations of the architecture,
727 /// vendor, OS, and environment.
729 /// This joins each argument into a canonical string representation and parses
730 /// them into enum members.
731 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
732 const Twine &EnvironmentStr)
733 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
734 EnvironmentStr).str()),
735 Arch(parseArch(ArchStr.str())),
736 SubArch(parseSubArch(ArchStr.str())),
737 Vendor(parseVendor(VendorStr.str())),
738 OS(parseOS(OSStr.str())),
739 Environment(parseEnvironment(EnvironmentStr.str())),
740 ObjectFormat(parseFormat(EnvironmentStr.str())) {
741 if (ObjectFormat == Triple::UnknownObjectFormat)
742 ObjectFormat = getDefaultFormat(*this);
745 std::string Triple::normalize(StringRef Str) {
746 bool IsMinGW32 = false;
747 bool IsCygwin = false;
749 // Parse into components.
750 SmallVector<StringRef, 4> Components;
751 Str.split(Components, '-');
753 // If the first component corresponds to a known architecture, preferentially
754 // use it for the architecture. If the second component corresponds to a
755 // known vendor, preferentially use it for the vendor, etc. This avoids silly
756 // component movement when a component parses as (eg) both a valid arch and a
758 ArchType Arch = UnknownArch;
759 if (Components.size() > 0)
760 Arch = parseArch(Components[0]);
761 VendorType Vendor = UnknownVendor;
762 if (Components.size() > 1)
763 Vendor = parseVendor(Components[1]);
764 OSType OS = UnknownOS;
765 if (Components.size() > 2) {
766 OS = parseOS(Components[2]);
767 IsCygwin = Components[2].startswith("cygwin");
768 IsMinGW32 = Components[2].startswith("mingw");
770 EnvironmentType Environment = UnknownEnvironment;
771 if (Components.size() > 3)
772 Environment = parseEnvironment(Components[3]);
773 ObjectFormatType ObjectFormat = UnknownObjectFormat;
774 if (Components.size() > 4)
775 ObjectFormat = parseFormat(Components[4]);
777 // Note which components are already in their final position. These will not
780 Found[0] = Arch != UnknownArch;
781 Found[1] = Vendor != UnknownVendor;
782 Found[2] = OS != UnknownOS;
783 Found[3] = Environment != UnknownEnvironment;
785 // If they are not there already, permute the components into their canonical
786 // positions by seeing if they parse as a valid architecture, and if so moving
787 // the component to the architecture position etc.
788 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
790 continue; // Already in the canonical position.
792 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
793 // Do not reparse any components that already matched.
794 if (Idx < array_lengthof(Found) && Found[Idx])
797 // Does this component parse as valid for the target position?
799 StringRef Comp = Components[Idx];
801 default: llvm_unreachable("unexpected component type!");
803 Arch = parseArch(Comp);
804 Valid = Arch != UnknownArch;
807 Vendor = parseVendor(Comp);
808 Valid = Vendor != UnknownVendor;
812 IsCygwin = Comp.startswith("cygwin");
813 IsMinGW32 = Comp.startswith("mingw");
814 Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
817 Environment = parseEnvironment(Comp);
818 Valid = Environment != UnknownEnvironment;
820 ObjectFormat = parseFormat(Comp);
821 Valid = ObjectFormat != UnknownObjectFormat;
826 continue; // Nope, try the next component.
828 // Move the component to the target position, pushing any non-fixed
829 // components that are in the way to the right. This tends to give
830 // good results in the common cases of a forgotten vendor component
831 // or a wrongly positioned environment.
833 // Insert left, pushing the existing components to the right. For
834 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
835 StringRef CurrentComponent(""); // The empty component.
836 // Replace the component we are moving with an empty component.
837 std::swap(CurrentComponent, Components[Idx]);
838 // Insert the component being moved at Pos, displacing any existing
839 // components to the right.
840 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
841 // Skip over any fixed components.
842 while (i < array_lengthof(Found) && Found[i])
844 // Place the component at the new position, getting the component
845 // that was at this position - it will be moved right.
846 std::swap(CurrentComponent, Components[i]);
848 } else if (Pos > Idx) {
849 // Push right by inserting empty components until the component at Idx
850 // reaches the target position Pos. For example, pc-a -> -pc-a when
851 // moving pc to the second position.
853 // Insert one empty component at Idx.
854 StringRef CurrentComponent(""); // The empty component.
855 for (unsigned i = Idx; i < Components.size();) {
856 // Place the component at the new position, getting the component
857 // that was at this position - it will be moved right.
858 std::swap(CurrentComponent, Components[i]);
859 // If it was placed on top of an empty component then we are done.
860 if (CurrentComponent.empty())
862 // Advance to the next component, skipping any fixed components.
863 while (++i < array_lengthof(Found) && Found[i])
866 // The last component was pushed off the end - append it.
867 if (!CurrentComponent.empty())
868 Components.push_back(CurrentComponent);
870 // Advance Idx to the component's new position.
871 while (++Idx < array_lengthof(Found) && Found[Idx])
873 } while (Idx < Pos); // Add more until the final position is reached.
875 assert(Pos < Components.size() && Components[Pos] == Comp &&
876 "Component moved wrong!");
882 // Special case logic goes here. At this point Arch, Vendor and OS have the
883 // correct values for the computed components.
884 std::string NormalizedEnvironment;
885 if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
886 StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
887 if (AndroidVersion.empty()) {
888 Components[3] = "android";
890 NormalizedEnvironment = Twine("android", AndroidVersion).str();
891 Components[3] = NormalizedEnvironment;
895 // SUSE uses "gnueabi" to mean "gnueabihf"
896 if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
897 Components[3] = "gnueabihf";
899 if (OS == Triple::Win32) {
900 Components.resize(4);
901 Components[2] = "windows";
902 if (Environment == UnknownEnvironment) {
903 if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
904 Components[3] = "msvc";
906 Components[3] = getObjectFormatTypeName(ObjectFormat);
908 } else if (IsMinGW32) {
909 Components.resize(4);
910 Components[2] = "windows";
911 Components[3] = "gnu";
912 } else if (IsCygwin) {
913 Components.resize(4);
914 Components[2] = "windows";
915 Components[3] = "cygnus";
917 if (IsMinGW32 || IsCygwin ||
918 (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
919 if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
920 Components.resize(5);
921 Components[4] = getObjectFormatTypeName(ObjectFormat);
925 // Stick the corrected components back together to form the normalized string.
926 std::string Normalized;
927 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
928 if (i) Normalized += '-';
929 Normalized += Components[i];
934 StringRef Triple::getArchName() const {
935 return StringRef(Data).split('-').first; // Isolate first component
938 StringRef Triple::getVendorName() const {
939 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
940 return Tmp.split('-').first; // Isolate second component
943 StringRef Triple::getOSName() const {
944 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
945 Tmp = Tmp.split('-').second; // Strip second component
946 return Tmp.split('-').first; // Isolate third component
949 StringRef Triple::getEnvironmentName() const {
950 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
951 Tmp = Tmp.split('-').second; // Strip second component
952 return Tmp.split('-').second; // Strip third component
955 StringRef Triple::getOSAndEnvironmentName() const {
956 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
957 return Tmp.split('-').second; // Strip second component
960 static unsigned EatNumber(StringRef &Str) {
961 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
965 // Consume the leading digit.
966 Result = Result*10 + (Str[0] - '0');
970 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
975 static void parseVersionFromName(StringRef Name, unsigned &Major,
976 unsigned &Minor, unsigned &Micro) {
977 // Any unset version defaults to 0.
978 Major = Minor = Micro = 0;
980 // Parse up to three components.
981 unsigned *Components[3] = {&Major, &Minor, &Micro};
982 for (unsigned i = 0; i != 3; ++i) {
983 if (Name.empty() || Name[0] < '0' || Name[0] > '9')
986 // Consume the leading number.
987 *Components[i] = EatNumber(Name);
989 // Consume the separator, if present.
990 if (Name.startswith("."))
991 Name = Name.substr(1);
995 void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
996 unsigned &Micro) const {
997 StringRef EnvironmentName = getEnvironmentName();
998 StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
999 if (EnvironmentName.startswith(EnvironmentTypeName))
1000 EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
1002 parseVersionFromName(EnvironmentName, Major, Minor, Micro);
1005 void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
1006 unsigned &Micro) const {
1007 StringRef OSName = getOSName();
1008 // Assume that the OS portion of the triple starts with the canonical name.
1009 StringRef OSTypeName = getOSTypeName(getOS());
1010 if (OSName.startswith(OSTypeName))
1011 OSName = OSName.substr(OSTypeName.size());
1012 else if (getOS() == MacOSX)
1013 OSName.consume_front("macos");
1015 parseVersionFromName(OSName, Major, Minor, Micro);
1018 bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
1019 unsigned &Micro) const {
1020 getOSVersion(Major, Minor, Micro);
1023 default: llvm_unreachable("unexpected OS for Darwin triple");
1025 // Default to darwin8, i.e., MacOSX 10.4.
1028 // Darwin version numbers are skewed from OS X versions.
1047 // Ignore the version from the triple. This is only handled because the
1048 // the clang driver combines OS X and IOS support into a common Darwin
1049 // toolchain that wants to know the OS X version number even when targeting
1059 void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
1060 unsigned &Micro) const {
1062 default: llvm_unreachable("unexpected OS for Darwin triple");
1065 // Ignore the version from the triple. This is only handled because the
1066 // the clang driver combines OS X and IOS support into a common Darwin
1067 // toolchain that wants to know the iOS version number even when targeting
1075 getOSVersion(Major, Minor, Micro);
1076 // Default to 5.0 (or 7.0 for arm64).
1078 Major = (getArch() == aarch64) ? 7 : 5;
1081 llvm_unreachable("conflicting triple info");
1085 void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
1086 unsigned &Micro) const {
1088 default: llvm_unreachable("unexpected OS for Darwin triple");
1091 // Ignore the version from the triple. This is only handled because the
1092 // the clang driver combines OS X and IOS support into a common Darwin
1093 // toolchain that wants to know the iOS version number even when targeting
1100 getOSVersion(Major, Minor, Micro);
1105 llvm_unreachable("conflicting triple info");
1109 void Triple::setTriple(const Twine &Str) {
1110 *this = Triple(Str);
1113 void Triple::setArch(ArchType Kind) {
1114 setArchName(getArchTypeName(Kind));
1117 void Triple::setVendor(VendorType Kind) {
1118 setVendorName(getVendorTypeName(Kind));
1121 void Triple::setOS(OSType Kind) {
1122 setOSName(getOSTypeName(Kind));
1125 void Triple::setEnvironment(EnvironmentType Kind) {
1126 if (ObjectFormat == getDefaultFormat(*this))
1127 return setEnvironmentName(getEnvironmentTypeName(Kind));
1129 setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
1130 getObjectFormatTypeName(ObjectFormat)).str());
1133 void Triple::setObjectFormat(ObjectFormatType Kind) {
1134 if (Environment == UnknownEnvironment)
1135 return setEnvironmentName(getObjectFormatTypeName(Kind));
1137 setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
1138 getObjectFormatTypeName(Kind)).str());
1141 void Triple::setArchName(StringRef Str) {
1142 // Work around a miscompilation bug for Twines in gcc 4.0.3.
1143 SmallString<64> Triple;
1146 Triple += getVendorName();
1148 Triple += getOSAndEnvironmentName();
1152 void Triple::setVendorName(StringRef Str) {
1153 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
1156 void Triple::setOSName(StringRef Str) {
1157 if (hasEnvironment())
1158 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
1159 "-" + getEnvironmentName());
1161 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1164 void Triple::setEnvironmentName(StringRef Str) {
1165 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1169 void Triple::setOSAndEnvironmentName(StringRef Str) {
1170 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1173 static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
1175 case llvm::Triple::UnknownArch:
1178 case llvm::Triple::avr:
1179 case llvm::Triple::msp430:
1182 case llvm::Triple::arc:
1183 case llvm::Triple::arm:
1184 case llvm::Triple::armeb:
1185 case llvm::Triple::hexagon:
1186 case llvm::Triple::le32:
1187 case llvm::Triple::mips:
1188 case llvm::Triple::mipsel:
1189 case llvm::Triple::nios2:
1190 case llvm::Triple::nvptx:
1191 case llvm::Triple::ppc:
1192 case llvm::Triple::r600:
1193 case llvm::Triple::riscv32:
1194 case llvm::Triple::sparc:
1195 case llvm::Triple::sparcel:
1196 case llvm::Triple::tce:
1197 case llvm::Triple::tcele:
1198 case llvm::Triple::thumb:
1199 case llvm::Triple::thumbeb:
1200 case llvm::Triple::x86:
1201 case llvm::Triple::xcore:
1202 case llvm::Triple::amdil:
1203 case llvm::Triple::hsail:
1204 case llvm::Triple::spir:
1205 case llvm::Triple::kalimba:
1206 case llvm::Triple::lanai:
1207 case llvm::Triple::shave:
1208 case llvm::Triple::wasm32:
1209 case llvm::Triple::renderscript32:
1212 case llvm::Triple::aarch64:
1213 case llvm::Triple::aarch64_be:
1214 case llvm::Triple::amdgcn:
1215 case llvm::Triple::bpfel:
1216 case llvm::Triple::bpfeb:
1217 case llvm::Triple::le64:
1218 case llvm::Triple::mips64:
1219 case llvm::Triple::mips64el:
1220 case llvm::Triple::nvptx64:
1221 case llvm::Triple::ppc64:
1222 case llvm::Triple::ppc64le:
1223 case llvm::Triple::riscv64:
1224 case llvm::Triple::sparcv9:
1225 case llvm::Triple::systemz:
1226 case llvm::Triple::x86_64:
1227 case llvm::Triple::amdil64:
1228 case llvm::Triple::hsail64:
1229 case llvm::Triple::spir64:
1230 case llvm::Triple::wasm64:
1231 case llvm::Triple::renderscript64:
1234 llvm_unreachable("Invalid architecture value");
1237 bool Triple::isArch64Bit() const {
1238 return getArchPointerBitWidth(getArch()) == 64;
1241 bool Triple::isArch32Bit() const {
1242 return getArchPointerBitWidth(getArch()) == 32;
1245 bool Triple::isArch16Bit() const {
1246 return getArchPointerBitWidth(getArch()) == 16;
1249 Triple Triple::get32BitArchVariant() const {
1251 switch (getArch()) {
1252 case Triple::UnknownArch:
1253 case Triple::amdgcn:
1257 case Triple::msp430:
1258 case Triple::systemz:
1259 case Triple::ppc64le:
1260 T.setArch(UnknownArch);
1269 case Triple::hexagon:
1270 case Triple::kalimba:
1273 case Triple::mipsel:
1278 case Triple::riscv32:
1280 case Triple::sparcel:
1284 case Triple::thumbeb:
1289 case Triple::wasm32:
1290 case Triple::renderscript32:
1294 case Triple::aarch64: T.setArch(Triple::arm); break;
1295 case Triple::aarch64_be: T.setArch(Triple::armeb); break;
1296 case Triple::le64: T.setArch(Triple::le32); break;
1297 case Triple::mips64: T.setArch(Triple::mips); break;
1298 case Triple::mips64el: T.setArch(Triple::mipsel); break;
1299 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
1300 case Triple::ppc64: T.setArch(Triple::ppc); break;
1301 case Triple::sparcv9: T.setArch(Triple::sparc); break;
1302 case Triple::riscv64: T.setArch(Triple::riscv32); break;
1303 case Triple::x86_64: T.setArch(Triple::x86); break;
1304 case Triple::amdil64: T.setArch(Triple::amdil); break;
1305 case Triple::hsail64: T.setArch(Triple::hsail); break;
1306 case Triple::spir64: T.setArch(Triple::spir); break;
1307 case Triple::wasm64: T.setArch(Triple::wasm32); break;
1308 case Triple::renderscript64: T.setArch(Triple::renderscript32); break;
1313 Triple Triple::get64BitArchVariant() const {
1315 switch (getArch()) {
1316 case Triple::UnknownArch:
1319 case Triple::hexagon:
1320 case Triple::kalimba:
1322 case Triple::msp430:
1328 case Triple::sparcel:
1330 T.setArch(UnknownArch);
1333 case Triple::aarch64:
1334 case Triple::aarch64_be:
1338 case Triple::amdil64:
1339 case Triple::amdgcn:
1340 case Triple::hsail64:
1341 case Triple::spir64:
1342 case Triple::mips64:
1343 case Triple::mips64el:
1344 case Triple::nvptx64:
1346 case Triple::ppc64le:
1347 case Triple::riscv64:
1348 case Triple::sparcv9:
1349 case Triple::systemz:
1350 case Triple::x86_64:
1351 case Triple::wasm64:
1352 case Triple::renderscript64:
1356 case Triple::arm: T.setArch(Triple::aarch64); break;
1357 case Triple::armeb: T.setArch(Triple::aarch64_be); break;
1358 case Triple::le32: T.setArch(Triple::le64); break;
1359 case Triple::mips: T.setArch(Triple::mips64); break;
1360 case Triple::mipsel: T.setArch(Triple::mips64el); break;
1361 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
1362 case Triple::ppc: T.setArch(Triple::ppc64); break;
1363 case Triple::sparc: T.setArch(Triple::sparcv9); break;
1364 case Triple::riscv32: T.setArch(Triple::riscv64); break;
1365 case Triple::x86: T.setArch(Triple::x86_64); break;
1366 case Triple::amdil: T.setArch(Triple::amdil64); break;
1367 case Triple::hsail: T.setArch(Triple::hsail64); break;
1368 case Triple::spir: T.setArch(Triple::spir64); break;
1369 case Triple::thumb: T.setArch(Triple::aarch64); break;
1370 case Triple::thumbeb: T.setArch(Triple::aarch64_be); break;
1371 case Triple::wasm32: T.setArch(Triple::wasm64); break;
1372 case Triple::renderscript32: T.setArch(Triple::renderscript64); break;
1377 Triple Triple::getBigEndianArchVariant() const {
1379 // Already big endian.
1380 if (!isLittleEndian())
1382 switch (getArch()) {
1383 case Triple::UnknownArch:
1384 case Triple::amdgcn:
1385 case Triple::amdil64:
1388 case Triple::hexagon:
1389 case Triple::hsail64:
1391 case Triple::kalimba:
1394 case Triple::msp430:
1396 case Triple::nvptx64:
1399 case Triple::riscv32:
1400 case Triple::riscv64:
1402 case Triple::spir64:
1404 case Triple::wasm32:
1405 case Triple::wasm64:
1407 case Triple::x86_64:
1409 case Triple::renderscript32:
1410 case Triple::renderscript64:
1412 // ARM is intentionally unsupported here, changing the architecture would
1413 // drop any arch suffixes.
1416 T.setArch(UnknownArch);
1419 case Triple::tcele: T.setArch(Triple::tce); break;
1420 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1421 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1422 case Triple::mips64el:T.setArch(Triple::mips64); break;
1423 case Triple::mipsel: T.setArch(Triple::mips); break;
1424 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1425 case Triple::sparcel: T.setArch(Triple::sparc); break;
1427 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1432 Triple Triple::getLittleEndianArchVariant() const {
1434 if (isLittleEndian())
1437 switch (getArch()) {
1438 case Triple::UnknownArch:
1441 case Triple::sparcv9:
1442 case Triple::systemz:
1444 // ARM is intentionally unsupported here, changing the architecture would
1445 // drop any arch suffixes.
1447 case Triple::thumbeb:
1448 T.setArch(UnknownArch);
1451 case Triple::tce: T.setArch(Triple::tcele); break;
1452 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1453 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1454 case Triple::mips64: T.setArch(Triple::mips64el); break;
1455 case Triple::mips: T.setArch(Triple::mipsel); break;
1456 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1457 case Triple::sparc: T.setArch(Triple::sparcel); break;
1459 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1464 bool Triple::isLittleEndian() const {
1465 switch (getArch()) {
1466 case Triple::aarch64:
1467 case Triple::amdgcn:
1468 case Triple::amdil64:
1473 case Triple::hexagon:
1474 case Triple::hsail64:
1476 case Triple::kalimba:
1479 case Triple::mips64el:
1480 case Triple::mipsel:
1481 case Triple::msp430:
1483 case Triple::nvptx64:
1485 case Triple::ppc64le:
1487 case Triple::riscv32:
1488 case Triple::riscv64:
1490 case Triple::sparcel:
1491 case Triple::spir64:
1494 case Triple::wasm32:
1495 case Triple::wasm64:
1497 case Triple::x86_64:
1500 case Triple::renderscript32:
1501 case Triple::renderscript64:
1508 bool Triple::isCompatibleWith(const Triple &Other) const {
1509 // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
1510 if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
1511 (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
1512 (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) ||
1513 (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) {
1514 if (getVendor() == Triple::Apple)
1515 return getSubArch() == Other.getSubArch() &&
1516 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1518 return getSubArch() == Other.getSubArch() &&
1519 getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
1520 getEnvironment() == Other.getEnvironment() &&
1521 getObjectFormat() == Other.getObjectFormat();
1524 // If vendor is apple, ignore the version number.
1525 if (getVendor() == Triple::Apple)
1526 return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
1527 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1529 return *this == Other;
1532 std::string Triple::merge(const Triple &Other) const {
1533 // If vendor is apple, pick the triple with the larger version number.
1534 if (getVendor() == Triple::Apple)
1535 if (Other.isOSVersionLT(*this))
1541 StringRef Triple::getARMCPUForArch(StringRef MArch) const {
1543 MArch = getArchName();
1544 MArch = ARM::getCanonicalArchName(MArch);
1546 // Some defaults are forced.
1548 case llvm::Triple::FreeBSD:
1549 case llvm::Triple::NetBSD:
1550 if (!MArch.empty() && MArch == "v6")
1551 return "arm1176jzf-s";
1553 case llvm::Triple::Win32:
1554 // FIXME: this is invalid for WindowsCE
1556 case llvm::Triple::MacOSX:
1557 case llvm::Triple::IOS:
1558 case llvm::Triple::WatchOS:
1559 case llvm::Triple::TvOS:
1570 StringRef CPU = ARM::getDefaultCPU(MArch);
1571 if (!CPU.empty() && !CPU.equals("invalid"))
1574 // If no specific architecture version is requested, return the minimum CPU
1575 // required by the OS and environment.
1577 case llvm::Triple::NetBSD:
1578 switch (getEnvironment()) {
1579 case llvm::Triple::GNUEABIHF:
1580 case llvm::Triple::GNUEABI:
1581 case llvm::Triple::EABIHF:
1582 case llvm::Triple::EABI:
1583 return "arm926ej-s";
1587 case llvm::Triple::NaCl:
1588 case llvm::Triple::OpenBSD:
1591 switch (getEnvironment()) {
1592 case llvm::Triple::EABIHF:
1593 case llvm::Triple::GNUEABIHF:
1594 case llvm::Triple::MuslEABIHF:
1595 return "arm1176jzf-s";
1601 llvm_unreachable("invalid arch name");