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";
210 case AMDPAL: return "amdpal";
213 llvm_unreachable("Invalid OSType");
216 StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
218 case UnknownEnvironment: return "unknown";
219 case GNU: return "gnu";
220 case GNUABIN32: return "gnuabin32";
221 case GNUABI64: return "gnuabi64";
222 case GNUEABIHF: return "gnueabihf";
223 case GNUEABI: return "gnueabi";
224 case GNUX32: return "gnux32";
225 case CODE16: return "code16";
226 case EABI: return "eabi";
227 case EABIHF: return "eabihf";
228 case Android: return "android";
229 case Musl: return "musl";
230 case MuslEABI: return "musleabi";
231 case MuslEABIHF: return "musleabihf";
232 case MSVC: return "msvc";
233 case Itanium: return "itanium";
234 case Cygnus: return "cygnus";
235 case CoreCLR: return "coreclr";
236 case Simulator: return "simulator";
239 llvm_unreachable("Invalid EnvironmentType!");
242 static Triple::ArchType parseBPFArch(StringRef ArchName) {
243 if (ArchName.equals("bpf")) {
244 if (sys::IsLittleEndianHost)
245 return Triple::bpfel;
247 return Triple::bpfeb;
248 } else if (ArchName.equals("bpf_be") || ArchName.equals("bpfeb")) {
249 return Triple::bpfeb;
250 } else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) {
251 return Triple::bpfel;
253 return Triple::UnknownArch;
257 Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
258 Triple::ArchType BPFArch(parseBPFArch(Name));
259 return StringSwitch<Triple::ArchType>(Name)
260 .Case("aarch64", aarch64)
261 .Case("aarch64_be", aarch64_be)
263 .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
265 .Case("armeb", armeb)
267 .StartsWith("bpf", BPFArch)
269 .Case("mipsel", mipsel)
270 .Case("mips64", mips64)
271 .Case("mips64el", mips64el)
272 .Case("msp430", msp430)
273 .Case("nios2", nios2)
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", Triple::mips)
401 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
402 .Cases("mips64", "mips64eb", Triple::mips64)
403 .Case("mips64el", Triple::mips64el)
404 .Case("nios2", Triple::nios2)
405 .Case("r600", Triple::r600)
406 .Case("amdgcn", Triple::amdgcn)
407 .Case("riscv32", Triple::riscv32)
408 .Case("riscv64", Triple::riscv64)
409 .Case("hexagon", Triple::hexagon)
410 .Cases("s390x", "systemz", Triple::systemz)
411 .Case("sparc", Triple::sparc)
412 .Case("sparcel", Triple::sparcel)
413 .Cases("sparcv9", "sparc64", Triple::sparcv9)
414 .Case("tce", Triple::tce)
415 .Case("tcele", Triple::tcele)
416 .Case("xcore", Triple::xcore)
417 .Case("nvptx", Triple::nvptx)
418 .Case("nvptx64", Triple::nvptx64)
419 .Case("le32", Triple::le32)
420 .Case("le64", Triple::le64)
421 .Case("amdil", Triple::amdil)
422 .Case("amdil64", Triple::amdil64)
423 .Case("hsail", Triple::hsail)
424 .Case("hsail64", Triple::hsail64)
425 .Case("spir", Triple::spir)
426 .Case("spir64", Triple::spir64)
427 .StartsWith("kalimba", Triple::kalimba)
428 .Case("lanai", Triple::lanai)
429 .Case("shave", Triple::shave)
430 .Case("wasm32", Triple::wasm32)
431 .Case("wasm64", Triple::wasm64)
432 .Case("renderscript32", Triple::renderscript32)
433 .Case("renderscript64", Triple::renderscript64)
434 .Default(Triple::UnknownArch);
436 // Some architectures require special parsing logic just to compute the
438 if (AT == Triple::UnknownArch) {
439 if (ArchName.startswith("arm") || ArchName.startswith("thumb") ||
440 ArchName.startswith("aarch64"))
441 return parseARMArch(ArchName);
442 if (ArchName.startswith("bpf"))
443 return parseBPFArch(ArchName);
449 static Triple::VendorType parseVendor(StringRef VendorName) {
450 return StringSwitch<Triple::VendorType>(VendorName)
451 .Case("apple", Triple::Apple)
452 .Case("pc", Triple::PC)
453 .Case("scei", Triple::SCEI)
454 .Case("bgp", Triple::BGP)
455 .Case("bgq", Triple::BGQ)
456 .Case("fsl", Triple::Freescale)
457 .Case("ibm", Triple::IBM)
458 .Case("img", Triple::ImaginationTechnologies)
459 .Case("mti", Triple::MipsTechnologies)
460 .Case("nvidia", Triple::NVIDIA)
461 .Case("csr", Triple::CSR)
462 .Case("myriad", Triple::Myriad)
463 .Case("amd", Triple::AMD)
464 .Case("mesa", Triple::Mesa)
465 .Case("suse", Triple::SUSE)
466 .Default(Triple::UnknownVendor);
469 static Triple::OSType parseOS(StringRef OSName) {
470 return StringSwitch<Triple::OSType>(OSName)
471 .StartsWith("ananas", Triple::Ananas)
472 .StartsWith("cloudabi", Triple::CloudABI)
473 .StartsWith("darwin", Triple::Darwin)
474 .StartsWith("dragonfly", Triple::DragonFly)
475 .StartsWith("freebsd", Triple::FreeBSD)
476 .StartsWith("fuchsia", Triple::Fuchsia)
477 .StartsWith("ios", Triple::IOS)
478 .StartsWith("kfreebsd", Triple::KFreeBSD)
479 .StartsWith("linux", Triple::Linux)
480 .StartsWith("lv2", Triple::Lv2)
481 .StartsWith("macos", Triple::MacOSX)
482 .StartsWith("netbsd", Triple::NetBSD)
483 .StartsWith("openbsd", Triple::OpenBSD)
484 .StartsWith("solaris", Triple::Solaris)
485 .StartsWith("win32", Triple::Win32)
486 .StartsWith("windows", Triple::Win32)
487 .StartsWith("haiku", Triple::Haiku)
488 .StartsWith("minix", Triple::Minix)
489 .StartsWith("rtems", Triple::RTEMS)
490 .StartsWith("nacl", Triple::NaCl)
491 .StartsWith("cnk", Triple::CNK)
492 .StartsWith("aix", Triple::AIX)
493 .StartsWith("cuda", Triple::CUDA)
494 .StartsWith("nvcl", Triple::NVCL)
495 .StartsWith("amdhsa", Triple::AMDHSA)
496 .StartsWith("ps4", Triple::PS4)
497 .StartsWith("elfiamcu", Triple::ELFIAMCU)
498 .StartsWith("tvos", Triple::TvOS)
499 .StartsWith("watchos", Triple::WatchOS)
500 .StartsWith("mesa3d", Triple::Mesa3D)
501 .StartsWith("contiki", Triple::Contiki)
502 .StartsWith("amdpal", Triple::AMDPAL)
503 .Default(Triple::UnknownOS);
506 static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
507 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
508 .StartsWith("eabihf", Triple::EABIHF)
509 .StartsWith("eabi", Triple::EABI)
510 .StartsWith("gnuabin32", Triple::GNUABIN32)
511 .StartsWith("gnuabi64", Triple::GNUABI64)
512 .StartsWith("gnueabihf", Triple::GNUEABIHF)
513 .StartsWith("gnueabi", Triple::GNUEABI)
514 .StartsWith("gnux32", Triple::GNUX32)
515 .StartsWith("code16", Triple::CODE16)
516 .StartsWith("gnu", Triple::GNU)
517 .StartsWith("android", Triple::Android)
518 .StartsWith("musleabihf", Triple::MuslEABIHF)
519 .StartsWith("musleabi", Triple::MuslEABI)
520 .StartsWith("musl", Triple::Musl)
521 .StartsWith("msvc", Triple::MSVC)
522 .StartsWith("itanium", Triple::Itanium)
523 .StartsWith("cygnus", Triple::Cygnus)
524 .StartsWith("coreclr", Triple::CoreCLR)
525 .StartsWith("simulator", Triple::Simulator)
526 .Default(Triple::UnknownEnvironment);
529 static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
530 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
531 .EndsWith("coff", Triple::COFF)
532 .EndsWith("elf", Triple::ELF)
533 .EndsWith("macho", Triple::MachO)
534 .EndsWith("wasm", Triple::Wasm)
535 .Default(Triple::UnknownObjectFormat);
538 static Triple::SubArchType parseSubArch(StringRef SubArchName) {
539 StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
541 // For now, this is the small part. Early return.
542 if (ARMSubArch.empty())
543 return StringSwitch<Triple::SubArchType>(SubArchName)
544 .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
545 .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
546 .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
547 .Default(Triple::NoSubArch);
550 switch(ARM::parseArch(ARMSubArch)) {
551 case ARM::ArchKind::ARMV4:
552 return Triple::NoSubArch;
553 case ARM::ArchKind::ARMV4T:
554 return Triple::ARMSubArch_v4t;
555 case ARM::ArchKind::ARMV5T:
556 return Triple::ARMSubArch_v5;
557 case ARM::ArchKind::ARMV5TE:
558 case ARM::ArchKind::IWMMXT:
559 case ARM::ArchKind::IWMMXT2:
560 case ARM::ArchKind::XSCALE:
561 case ARM::ArchKind::ARMV5TEJ:
562 return Triple::ARMSubArch_v5te;
563 case ARM::ArchKind::ARMV6:
564 return Triple::ARMSubArch_v6;
565 case ARM::ArchKind::ARMV6K:
566 case ARM::ArchKind::ARMV6KZ:
567 return Triple::ARMSubArch_v6k;
568 case ARM::ArchKind::ARMV6T2:
569 return Triple::ARMSubArch_v6t2;
570 case ARM::ArchKind::ARMV6M:
571 return Triple::ARMSubArch_v6m;
572 case ARM::ArchKind::ARMV7A:
573 case ARM::ArchKind::ARMV7R:
574 return Triple::ARMSubArch_v7;
575 case ARM::ArchKind::ARMV7VE:
576 return Triple::ARMSubArch_v7ve;
577 case ARM::ArchKind::ARMV7K:
578 return Triple::ARMSubArch_v7k;
579 case ARM::ArchKind::ARMV7M:
580 return Triple::ARMSubArch_v7m;
581 case ARM::ArchKind::ARMV7S:
582 return Triple::ARMSubArch_v7s;
583 case ARM::ArchKind::ARMV7EM:
584 return Triple::ARMSubArch_v7em;
585 case ARM::ArchKind::ARMV8A:
586 return Triple::ARMSubArch_v8;
587 case ARM::ArchKind::ARMV8_1A:
588 return Triple::ARMSubArch_v8_1a;
589 case ARM::ArchKind::ARMV8_2A:
590 return Triple::ARMSubArch_v8_2a;
591 case ARM::ArchKind::ARMV8_3A:
592 return Triple::ARMSubArch_v8_3a;
593 case ARM::ArchKind::ARMV8R:
594 return Triple::ARMSubArch_v8r;
595 case ARM::ArchKind::ARMV8MBaseline:
596 return Triple::ARMSubArch_v8m_baseline;
597 case ARM::ArchKind::ARMV8MMainline:
598 return Triple::ARMSubArch_v8m_mainline;
600 return Triple::NoSubArch;
604 static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
606 case Triple::UnknownObjectFormat: return "";
607 case Triple::COFF: return "coff";
608 case Triple::ELF: return "elf";
609 case Triple::MachO: return "macho";
610 case Triple::Wasm: return "wasm";
612 llvm_unreachable("unknown object format type");
615 static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
616 switch (T.getArch()) {
617 case Triple::UnknownArch:
618 case Triple::aarch64:
624 return Triple::MachO;
625 else if (T.isOSWindows())
629 case Triple::aarch64_be:
633 case Triple::amdil64:
638 case Triple::hexagon:
641 case Triple::hsail64:
642 case Triple::kalimba:
647 case Triple::mips64el:
652 case Triple::nvptx64:
653 case Triple::ppc64le:
655 case Triple::renderscript32:
656 case Triple::renderscript64:
657 case Triple::riscv32:
658 case Triple::riscv64:
661 case Triple::sparcel:
662 case Triple::sparcv9:
665 case Triple::systemz:
668 case Triple::thumbeb:
675 return Triple::MachO;
682 llvm_unreachable("unknown architecture");
685 /// Construct a triple from the string representation provided.
687 /// This stores the string representation and parses the various pieces into
689 Triple::Triple(const Twine &Str)
690 : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
691 Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
692 ObjectFormat(UnknownObjectFormat) {
693 // Do minimal parsing by hand here.
694 SmallVector<StringRef, 4> Components;
695 StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
696 if (Components.size() > 0) {
697 Arch = parseArch(Components[0]);
698 SubArch = parseSubArch(Components[0]);
699 if (Components.size() > 1) {
700 Vendor = parseVendor(Components[1]);
701 if (Components.size() > 2) {
702 OS = parseOS(Components[2]);
703 if (Components.size() > 3) {
704 Environment = parseEnvironment(Components[3]);
705 ObjectFormat = parseFormat(Components[3]);
710 if (ObjectFormat == UnknownObjectFormat)
711 ObjectFormat = getDefaultFormat(*this);
714 /// Construct a triple from string representations of the architecture,
717 /// This joins each argument into a canonical string representation and parses
718 /// them into enum members. It leaves the environment unknown and omits it from
719 /// the string representation.
720 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
721 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
722 Arch(parseArch(ArchStr.str())),
723 SubArch(parseSubArch(ArchStr.str())),
724 Vendor(parseVendor(VendorStr.str())),
725 OS(parseOS(OSStr.str())),
726 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
727 ObjectFormat = getDefaultFormat(*this);
730 /// Construct a triple from string representations of the architecture,
731 /// vendor, OS, and environment.
733 /// This joins each argument into a canonical string representation and parses
734 /// them into enum members.
735 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
736 const Twine &EnvironmentStr)
737 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
738 EnvironmentStr).str()),
739 Arch(parseArch(ArchStr.str())),
740 SubArch(parseSubArch(ArchStr.str())),
741 Vendor(parseVendor(VendorStr.str())),
742 OS(parseOS(OSStr.str())),
743 Environment(parseEnvironment(EnvironmentStr.str())),
744 ObjectFormat(parseFormat(EnvironmentStr.str())) {
745 if (ObjectFormat == Triple::UnknownObjectFormat)
746 ObjectFormat = getDefaultFormat(*this);
749 std::string Triple::normalize(StringRef Str) {
750 bool IsMinGW32 = false;
751 bool IsCygwin = false;
753 // Parse into components.
754 SmallVector<StringRef, 4> Components;
755 Str.split(Components, '-');
757 // If the first component corresponds to a known architecture, preferentially
758 // use it for the architecture. If the second component corresponds to a
759 // known vendor, preferentially use it for the vendor, etc. This avoids silly
760 // component movement when a component parses as (eg) both a valid arch and a
762 ArchType Arch = UnknownArch;
763 if (Components.size() > 0)
764 Arch = parseArch(Components[0]);
765 VendorType Vendor = UnknownVendor;
766 if (Components.size() > 1)
767 Vendor = parseVendor(Components[1]);
768 OSType OS = UnknownOS;
769 if (Components.size() > 2) {
770 OS = parseOS(Components[2]);
771 IsCygwin = Components[2].startswith("cygwin");
772 IsMinGW32 = Components[2].startswith("mingw");
774 EnvironmentType Environment = UnknownEnvironment;
775 if (Components.size() > 3)
776 Environment = parseEnvironment(Components[3]);
777 ObjectFormatType ObjectFormat = UnknownObjectFormat;
778 if (Components.size() > 4)
779 ObjectFormat = parseFormat(Components[4]);
781 // Note which components are already in their final position. These will not
784 Found[0] = Arch != UnknownArch;
785 Found[1] = Vendor != UnknownVendor;
786 Found[2] = OS != UnknownOS;
787 Found[3] = Environment != UnknownEnvironment;
789 // If they are not there already, permute the components into their canonical
790 // positions by seeing if they parse as a valid architecture, and if so moving
791 // the component to the architecture position etc.
792 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
794 continue; // Already in the canonical position.
796 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
797 // Do not reparse any components that already matched.
798 if (Idx < array_lengthof(Found) && Found[Idx])
801 // Does this component parse as valid for the target position?
803 StringRef Comp = Components[Idx];
805 default: llvm_unreachable("unexpected component type!");
807 Arch = parseArch(Comp);
808 Valid = Arch != UnknownArch;
811 Vendor = parseVendor(Comp);
812 Valid = Vendor != UnknownVendor;
816 IsCygwin = Comp.startswith("cygwin");
817 IsMinGW32 = Comp.startswith("mingw");
818 Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
821 Environment = parseEnvironment(Comp);
822 Valid = Environment != UnknownEnvironment;
824 ObjectFormat = parseFormat(Comp);
825 Valid = ObjectFormat != UnknownObjectFormat;
830 continue; // Nope, try the next component.
832 // Move the component to the target position, pushing any non-fixed
833 // components that are in the way to the right. This tends to give
834 // good results in the common cases of a forgotten vendor component
835 // or a wrongly positioned environment.
837 // Insert left, pushing the existing components to the right. For
838 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
839 StringRef CurrentComponent(""); // The empty component.
840 // Replace the component we are moving with an empty component.
841 std::swap(CurrentComponent, Components[Idx]);
842 // Insert the component being moved at Pos, displacing any existing
843 // components to the right.
844 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
845 // Skip over any fixed components.
846 while (i < array_lengthof(Found) && Found[i])
848 // Place the component at the new position, getting the component
849 // that was at this position - it will be moved right.
850 std::swap(CurrentComponent, Components[i]);
852 } else if (Pos > Idx) {
853 // Push right by inserting empty components until the component at Idx
854 // reaches the target position Pos. For example, pc-a -> -pc-a when
855 // moving pc to the second position.
857 // Insert one empty component at Idx.
858 StringRef CurrentComponent(""); // The empty component.
859 for (unsigned i = Idx; i < Components.size();) {
860 // Place the component at the new position, getting the component
861 // that was at this position - it will be moved right.
862 std::swap(CurrentComponent, Components[i]);
863 // If it was placed on top of an empty component then we are done.
864 if (CurrentComponent.empty())
866 // Advance to the next component, skipping any fixed components.
867 while (++i < array_lengthof(Found) && Found[i])
870 // The last component was pushed off the end - append it.
871 if (!CurrentComponent.empty())
872 Components.push_back(CurrentComponent);
874 // Advance Idx to the component's new position.
875 while (++Idx < array_lengthof(Found) && Found[Idx])
877 } while (Idx < Pos); // Add more until the final position is reached.
879 assert(Pos < Components.size() && Components[Pos] == Comp &&
880 "Component moved wrong!");
886 // Special case logic goes here. At this point Arch, Vendor and OS have the
887 // correct values for the computed components.
888 std::string NormalizedEnvironment;
889 if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
890 StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
891 if (AndroidVersion.empty()) {
892 Components[3] = "android";
894 NormalizedEnvironment = Twine("android", AndroidVersion).str();
895 Components[3] = NormalizedEnvironment;
899 // SUSE uses "gnueabi" to mean "gnueabihf"
900 if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
901 Components[3] = "gnueabihf";
903 if (OS == Triple::Win32) {
904 Components.resize(4);
905 Components[2] = "windows";
906 if (Environment == UnknownEnvironment) {
907 if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
908 Components[3] = "msvc";
910 Components[3] = getObjectFormatTypeName(ObjectFormat);
912 } else if (IsMinGW32) {
913 Components.resize(4);
914 Components[2] = "windows";
915 Components[3] = "gnu";
916 } else if (IsCygwin) {
917 Components.resize(4);
918 Components[2] = "windows";
919 Components[3] = "cygnus";
921 if (IsMinGW32 || IsCygwin ||
922 (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
923 if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
924 Components.resize(5);
925 Components[4] = getObjectFormatTypeName(ObjectFormat);
929 // Stick the corrected components back together to form the normalized string.
930 std::string Normalized;
931 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
932 if (i) Normalized += '-';
933 Normalized += Components[i];
938 StringRef Triple::getArchName() const {
939 return StringRef(Data).split('-').first; // Isolate first component
942 StringRef Triple::getVendorName() const {
943 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
944 return Tmp.split('-').first; // Isolate second component
947 StringRef Triple::getOSName() const {
948 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
949 Tmp = Tmp.split('-').second; // Strip second component
950 return Tmp.split('-').first; // Isolate third component
953 StringRef Triple::getEnvironmentName() const {
954 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
955 Tmp = Tmp.split('-').second; // Strip second component
956 return Tmp.split('-').second; // Strip third component
959 StringRef Triple::getOSAndEnvironmentName() const {
960 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
961 return Tmp.split('-').second; // Strip second component
964 static unsigned EatNumber(StringRef &Str) {
965 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
969 // Consume the leading digit.
970 Result = Result*10 + (Str[0] - '0');
974 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
979 static void parseVersionFromName(StringRef Name, unsigned &Major,
980 unsigned &Minor, unsigned &Micro) {
981 // Any unset version defaults to 0.
982 Major = Minor = Micro = 0;
984 // Parse up to three components.
985 unsigned *Components[3] = {&Major, &Minor, &Micro};
986 for (unsigned i = 0; i != 3; ++i) {
987 if (Name.empty() || Name[0] < '0' || Name[0] > '9')
990 // Consume the leading number.
991 *Components[i] = EatNumber(Name);
993 // Consume the separator, if present.
994 if (Name.startswith("."))
995 Name = Name.substr(1);
999 void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
1000 unsigned &Micro) const {
1001 StringRef EnvironmentName = getEnvironmentName();
1002 StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
1003 if (EnvironmentName.startswith(EnvironmentTypeName))
1004 EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
1006 parseVersionFromName(EnvironmentName, Major, Minor, Micro);
1009 void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
1010 unsigned &Micro) const {
1011 StringRef OSName = getOSName();
1012 // Assume that the OS portion of the triple starts with the canonical name.
1013 StringRef OSTypeName = getOSTypeName(getOS());
1014 if (OSName.startswith(OSTypeName))
1015 OSName = OSName.substr(OSTypeName.size());
1016 else if (getOS() == MacOSX)
1017 OSName.consume_front("macos");
1019 parseVersionFromName(OSName, Major, Minor, Micro);
1022 bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
1023 unsigned &Micro) const {
1024 getOSVersion(Major, Minor, Micro);
1027 default: llvm_unreachable("unexpected OS for Darwin triple");
1029 // Default to darwin8, i.e., MacOSX 10.4.
1032 // Darwin version numbers are skewed from OS X versions.
1051 // Ignore the version from the triple. This is only handled because the
1052 // the clang driver combines OS X and IOS support into a common Darwin
1053 // toolchain that wants to know the OS X version number even when targeting
1063 void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
1064 unsigned &Micro) const {
1066 default: llvm_unreachable("unexpected OS for Darwin triple");
1069 // Ignore the version from the triple. This is only handled because the
1070 // the clang driver combines OS X and IOS support into a common Darwin
1071 // toolchain that wants to know the iOS version number even when targeting
1079 getOSVersion(Major, Minor, Micro);
1080 // Default to 5.0 (or 7.0 for arm64).
1082 Major = (getArch() == aarch64) ? 7 : 5;
1085 llvm_unreachable("conflicting triple info");
1089 void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
1090 unsigned &Micro) const {
1092 default: llvm_unreachable("unexpected OS for Darwin triple");
1095 // Ignore the version from the triple. This is only handled because the
1096 // the clang driver combines OS X and IOS support into a common Darwin
1097 // toolchain that wants to know the iOS version number even when targeting
1104 getOSVersion(Major, Minor, Micro);
1109 llvm_unreachable("conflicting triple info");
1113 void Triple::setTriple(const Twine &Str) {
1114 *this = Triple(Str);
1117 void Triple::setArch(ArchType Kind) {
1118 setArchName(getArchTypeName(Kind));
1121 void Triple::setVendor(VendorType Kind) {
1122 setVendorName(getVendorTypeName(Kind));
1125 void Triple::setOS(OSType Kind) {
1126 setOSName(getOSTypeName(Kind));
1129 void Triple::setEnvironment(EnvironmentType Kind) {
1130 if (ObjectFormat == getDefaultFormat(*this))
1131 return setEnvironmentName(getEnvironmentTypeName(Kind));
1133 setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
1134 getObjectFormatTypeName(ObjectFormat)).str());
1137 void Triple::setObjectFormat(ObjectFormatType Kind) {
1138 if (Environment == UnknownEnvironment)
1139 return setEnvironmentName(getObjectFormatTypeName(Kind));
1141 setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
1142 getObjectFormatTypeName(Kind)).str());
1145 void Triple::setArchName(StringRef Str) {
1146 // Work around a miscompilation bug for Twines in gcc 4.0.3.
1147 SmallString<64> Triple;
1150 Triple += getVendorName();
1152 Triple += getOSAndEnvironmentName();
1156 void Triple::setVendorName(StringRef Str) {
1157 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
1160 void Triple::setOSName(StringRef Str) {
1161 if (hasEnvironment())
1162 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
1163 "-" + getEnvironmentName());
1165 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1168 void Triple::setEnvironmentName(StringRef Str) {
1169 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1173 void Triple::setOSAndEnvironmentName(StringRef Str) {
1174 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1177 static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
1179 case llvm::Triple::UnknownArch:
1182 case llvm::Triple::avr:
1183 case llvm::Triple::msp430:
1186 case llvm::Triple::arc:
1187 case llvm::Triple::arm:
1188 case llvm::Triple::armeb:
1189 case llvm::Triple::hexagon:
1190 case llvm::Triple::le32:
1191 case llvm::Triple::mips:
1192 case llvm::Triple::mipsel:
1193 case llvm::Triple::nios2:
1194 case llvm::Triple::nvptx:
1195 case llvm::Triple::ppc:
1196 case llvm::Triple::r600:
1197 case llvm::Triple::riscv32:
1198 case llvm::Triple::sparc:
1199 case llvm::Triple::sparcel:
1200 case llvm::Triple::tce:
1201 case llvm::Triple::tcele:
1202 case llvm::Triple::thumb:
1203 case llvm::Triple::thumbeb:
1204 case llvm::Triple::x86:
1205 case llvm::Triple::xcore:
1206 case llvm::Triple::amdil:
1207 case llvm::Triple::hsail:
1208 case llvm::Triple::spir:
1209 case llvm::Triple::kalimba:
1210 case llvm::Triple::lanai:
1211 case llvm::Triple::shave:
1212 case llvm::Triple::wasm32:
1213 case llvm::Triple::renderscript32:
1216 case llvm::Triple::aarch64:
1217 case llvm::Triple::aarch64_be:
1218 case llvm::Triple::amdgcn:
1219 case llvm::Triple::bpfel:
1220 case llvm::Triple::bpfeb:
1221 case llvm::Triple::le64:
1222 case llvm::Triple::mips64:
1223 case llvm::Triple::mips64el:
1224 case llvm::Triple::nvptx64:
1225 case llvm::Triple::ppc64:
1226 case llvm::Triple::ppc64le:
1227 case llvm::Triple::riscv64:
1228 case llvm::Triple::sparcv9:
1229 case llvm::Triple::systemz:
1230 case llvm::Triple::x86_64:
1231 case llvm::Triple::amdil64:
1232 case llvm::Triple::hsail64:
1233 case llvm::Triple::spir64:
1234 case llvm::Triple::wasm64:
1235 case llvm::Triple::renderscript64:
1238 llvm_unreachable("Invalid architecture value");
1241 bool Triple::isArch64Bit() const {
1242 return getArchPointerBitWidth(getArch()) == 64;
1245 bool Triple::isArch32Bit() const {
1246 return getArchPointerBitWidth(getArch()) == 32;
1249 bool Triple::isArch16Bit() const {
1250 return getArchPointerBitWidth(getArch()) == 16;
1253 Triple Triple::get32BitArchVariant() const {
1255 switch (getArch()) {
1256 case Triple::UnknownArch:
1257 case Triple::amdgcn:
1261 case Triple::msp430:
1262 case Triple::systemz:
1263 case Triple::ppc64le:
1264 T.setArch(UnknownArch);
1273 case Triple::hexagon:
1274 case Triple::kalimba:
1277 case Triple::mipsel:
1282 case Triple::riscv32:
1284 case Triple::sparcel:
1288 case Triple::thumbeb:
1293 case Triple::wasm32:
1294 case Triple::renderscript32:
1298 case Triple::aarch64: T.setArch(Triple::arm); break;
1299 case Triple::aarch64_be: T.setArch(Triple::armeb); break;
1300 case Triple::le64: T.setArch(Triple::le32); break;
1301 case Triple::mips64: T.setArch(Triple::mips); break;
1302 case Triple::mips64el: T.setArch(Triple::mipsel); break;
1303 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
1304 case Triple::ppc64: T.setArch(Triple::ppc); break;
1305 case Triple::sparcv9: T.setArch(Triple::sparc); break;
1306 case Triple::riscv64: T.setArch(Triple::riscv32); break;
1307 case Triple::x86_64: T.setArch(Triple::x86); break;
1308 case Triple::amdil64: T.setArch(Triple::amdil); break;
1309 case Triple::hsail64: T.setArch(Triple::hsail); break;
1310 case Triple::spir64: T.setArch(Triple::spir); break;
1311 case Triple::wasm64: T.setArch(Triple::wasm32); break;
1312 case Triple::renderscript64: T.setArch(Triple::renderscript32); break;
1317 Triple Triple::get64BitArchVariant() const {
1319 switch (getArch()) {
1320 case Triple::UnknownArch:
1323 case Triple::hexagon:
1324 case Triple::kalimba:
1326 case Triple::msp430:
1332 case Triple::sparcel:
1334 T.setArch(UnknownArch);
1337 case Triple::aarch64:
1338 case Triple::aarch64_be:
1342 case Triple::amdil64:
1343 case Triple::amdgcn:
1344 case Triple::hsail64:
1345 case Triple::spir64:
1346 case Triple::mips64:
1347 case Triple::mips64el:
1348 case Triple::nvptx64:
1350 case Triple::ppc64le:
1351 case Triple::riscv64:
1352 case Triple::sparcv9:
1353 case Triple::systemz:
1354 case Triple::x86_64:
1355 case Triple::wasm64:
1356 case Triple::renderscript64:
1360 case Triple::arm: T.setArch(Triple::aarch64); break;
1361 case Triple::armeb: T.setArch(Triple::aarch64_be); break;
1362 case Triple::le32: T.setArch(Triple::le64); break;
1363 case Triple::mips: T.setArch(Triple::mips64); break;
1364 case Triple::mipsel: T.setArch(Triple::mips64el); break;
1365 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
1366 case Triple::ppc: T.setArch(Triple::ppc64); break;
1367 case Triple::sparc: T.setArch(Triple::sparcv9); break;
1368 case Triple::riscv32: T.setArch(Triple::riscv64); break;
1369 case Triple::x86: T.setArch(Triple::x86_64); break;
1370 case Triple::amdil: T.setArch(Triple::amdil64); break;
1371 case Triple::hsail: T.setArch(Triple::hsail64); break;
1372 case Triple::spir: T.setArch(Triple::spir64); break;
1373 case Triple::thumb: T.setArch(Triple::aarch64); break;
1374 case Triple::thumbeb: T.setArch(Triple::aarch64_be); break;
1375 case Triple::wasm32: T.setArch(Triple::wasm64); break;
1376 case Triple::renderscript32: T.setArch(Triple::renderscript64); break;
1381 Triple Triple::getBigEndianArchVariant() const {
1383 // Already big endian.
1384 if (!isLittleEndian())
1386 switch (getArch()) {
1387 case Triple::UnknownArch:
1388 case Triple::amdgcn:
1389 case Triple::amdil64:
1392 case Triple::hexagon:
1393 case Triple::hsail64:
1395 case Triple::kalimba:
1398 case Triple::msp430:
1400 case Triple::nvptx64:
1403 case Triple::riscv32:
1404 case Triple::riscv64:
1406 case Triple::spir64:
1408 case Triple::wasm32:
1409 case Triple::wasm64:
1411 case Triple::x86_64:
1413 case Triple::renderscript32:
1414 case Triple::renderscript64:
1416 // ARM is intentionally unsupported here, changing the architecture would
1417 // drop any arch suffixes.
1420 T.setArch(UnknownArch);
1423 case Triple::tcele: T.setArch(Triple::tce); break;
1424 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1425 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1426 case Triple::mips64el:T.setArch(Triple::mips64); break;
1427 case Triple::mipsel: T.setArch(Triple::mips); break;
1428 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1429 case Triple::sparcel: T.setArch(Triple::sparc); break;
1431 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1436 Triple Triple::getLittleEndianArchVariant() const {
1438 if (isLittleEndian())
1441 switch (getArch()) {
1442 case Triple::UnknownArch:
1445 case Triple::sparcv9:
1446 case Triple::systemz:
1448 // ARM is intentionally unsupported here, changing the architecture would
1449 // drop any arch suffixes.
1451 case Triple::thumbeb:
1452 T.setArch(UnknownArch);
1455 case Triple::tce: T.setArch(Triple::tcele); break;
1456 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1457 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1458 case Triple::mips64: T.setArch(Triple::mips64el); break;
1459 case Triple::mips: T.setArch(Triple::mipsel); break;
1460 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1461 case Triple::sparc: T.setArch(Triple::sparcel); break;
1463 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1468 bool Triple::isLittleEndian() const {
1469 switch (getArch()) {
1470 case Triple::aarch64:
1471 case Triple::amdgcn:
1472 case Triple::amdil64:
1477 case Triple::hexagon:
1478 case Triple::hsail64:
1480 case Triple::kalimba:
1483 case Triple::mips64el:
1484 case Triple::mipsel:
1485 case Triple::msp430:
1487 case Triple::nvptx64:
1489 case Triple::ppc64le:
1491 case Triple::riscv32:
1492 case Triple::riscv64:
1494 case Triple::sparcel:
1495 case Triple::spir64:
1498 case Triple::wasm32:
1499 case Triple::wasm64:
1501 case Triple::x86_64:
1504 case Triple::renderscript32:
1505 case Triple::renderscript64:
1512 bool Triple::isCompatibleWith(const Triple &Other) const {
1513 // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
1514 if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
1515 (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
1516 (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) ||
1517 (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) {
1518 if (getVendor() == Triple::Apple)
1519 return getSubArch() == Other.getSubArch() &&
1520 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1522 return getSubArch() == Other.getSubArch() &&
1523 getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
1524 getEnvironment() == Other.getEnvironment() &&
1525 getObjectFormat() == Other.getObjectFormat();
1528 // If vendor is apple, ignore the version number.
1529 if (getVendor() == Triple::Apple)
1530 return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
1531 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1533 return *this == Other;
1536 std::string Triple::merge(const Triple &Other) const {
1537 // If vendor is apple, pick the triple with the larger version number.
1538 if (getVendor() == Triple::Apple)
1539 if (Other.isOSVersionLT(*this))
1545 StringRef Triple::getARMCPUForArch(StringRef MArch) const {
1547 MArch = getArchName();
1548 MArch = ARM::getCanonicalArchName(MArch);
1550 // Some defaults are forced.
1552 case llvm::Triple::FreeBSD:
1553 case llvm::Triple::NetBSD:
1554 if (!MArch.empty() && MArch == "v6")
1555 return "arm1176jzf-s";
1557 case llvm::Triple::Win32:
1558 // FIXME: this is invalid for WindowsCE
1560 case llvm::Triple::MacOSX:
1561 case llvm::Triple::IOS:
1562 case llvm::Triple::WatchOS:
1563 case llvm::Triple::TvOS:
1574 StringRef CPU = ARM::getDefaultCPU(MArch);
1575 if (!CPU.empty() && !CPU.equals("invalid"))
1578 // If no specific architecture version is requested, return the minimum CPU
1579 // required by the OS and environment.
1581 case llvm::Triple::NetBSD:
1582 switch (getEnvironment()) {
1583 case llvm::Triple::GNUEABIHF:
1584 case llvm::Triple::GNUEABI:
1585 case llvm::Triple::EABIHF:
1586 case llvm::Triple::EABI:
1587 return "arm926ej-s";
1591 case llvm::Triple::NaCl:
1592 case llvm::Triple::OpenBSD:
1595 switch (getEnvironment()) {
1596 case llvm::Triple::EABIHF:
1597 case llvm::Triple::GNUEABIHF:
1598 case llvm::Triple::MuslEABIHF:
1599 return "arm1176jzf-s";
1605 llvm_unreachable("invalid arch name");