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 AMDOpenCL: return "amdopencl";
236 case CoreCLR: return "coreclr";
237 case OpenCL: return "opencl";
238 case Simulator: return "simulator";
241 llvm_unreachable("Invalid EnvironmentType!");
244 static Triple::ArchType parseBPFArch(StringRef ArchName) {
245 if (ArchName.equals("bpf")) {
246 if (sys::IsLittleEndianHost)
247 return Triple::bpfel;
249 return Triple::bpfeb;
250 } else if (ArchName.equals("bpf_be") || ArchName.equals("bpfeb")) {
251 return Triple::bpfeb;
252 } else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) {
253 return Triple::bpfel;
255 return Triple::UnknownArch;
259 Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
260 Triple::ArchType BPFArch(parseBPFArch(Name));
261 return StringSwitch<Triple::ArchType>(Name)
262 .Case("aarch64", aarch64)
263 .Case("aarch64_be", aarch64_be)
265 .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
267 .Case("armeb", armeb)
269 .StartsWith("bpf", BPFArch)
271 .Case("mipsel", mipsel)
272 .Case("mips64", mips64)
273 .Case("mips64el", mips64el)
274 .Case("msp430", msp430)
275 .Case("nios2", nios2)
276 .Case("ppc64", ppc64)
279 .Case("ppc64le", ppc64le)
281 .Case("amdgcn", amdgcn)
282 .Case("riscv32", riscv32)
283 .Case("riscv64", riscv64)
284 .Case("hexagon", hexagon)
285 .Case("sparc", sparc)
286 .Case("sparcel", sparcel)
287 .Case("sparcv9", sparcv9)
288 .Case("systemz", systemz)
290 .Case("tcele", tcele)
291 .Case("thumb", thumb)
292 .Case("thumbeb", thumbeb)
294 .Case("x86-64", x86_64)
295 .Case("xcore", xcore)
296 .Case("nvptx", nvptx)
297 .Case("nvptx64", nvptx64)
300 .Case("amdil", amdil)
301 .Case("amdil64", amdil64)
302 .Case("hsail", hsail)
303 .Case("hsail64", hsail64)
305 .Case("spir64", spir64)
306 .Case("kalimba", kalimba)
307 .Case("lanai", lanai)
308 .Case("shave", shave)
309 .Case("wasm32", wasm32)
310 .Case("wasm64", wasm64)
311 .Case("renderscript32", renderscript32)
312 .Case("renderscript64", renderscript64)
313 .Default(UnknownArch);
316 static Triple::ArchType parseARMArch(StringRef ArchName) {
317 ARM::ISAKind ISA = ARM::parseArchISA(ArchName);
318 ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName);
320 Triple::ArchType arch = Triple::UnknownArch;
322 case ARM::EndianKind::LITTLE: {
324 case ARM::ISAKind::ARM:
327 case ARM::ISAKind::THUMB:
328 arch = Triple::thumb;
330 case ARM::ISAKind::AARCH64:
331 arch = Triple::aarch64;
333 case ARM::ISAKind::INVALID:
338 case ARM::EndianKind::BIG: {
340 case ARM::ISAKind::ARM:
341 arch = Triple::armeb;
343 case ARM::ISAKind::THUMB:
344 arch = Triple::thumbeb;
346 case ARM::ISAKind::AARCH64:
347 arch = Triple::aarch64_be;
349 case ARM::ISAKind::INVALID:
354 case ARM::EndianKind::INVALID: {
359 ArchName = ARM::getCanonicalArchName(ArchName);
360 if (ArchName.empty())
361 return Triple::UnknownArch;
363 // Thumb only exists in v4+
364 if (ISA == ARM::ISAKind::THUMB &&
365 (ArchName.startswith("v2") || ArchName.startswith("v3")))
366 return Triple::UnknownArch;
368 // Thumb only for v6m
369 ARM::ProfileKind Profile = ARM::parseArchProfile(ArchName);
370 unsigned Version = ARM::parseArchVersion(ArchName);
371 if (Profile == ARM::ProfileKind::M && Version == 6) {
372 if (ENDIAN == ARM::EndianKind::BIG)
373 return Triple::thumbeb;
375 return Triple::thumb;
381 static Triple::ArchType parseArch(StringRef ArchName) {
382 auto AT = StringSwitch<Triple::ArchType>(ArchName)
383 .Cases("i386", "i486", "i586", "i686", Triple::x86)
384 // FIXME: Do we need to support these?
385 .Cases("i786", "i886", "i986", Triple::x86)
386 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
387 .Cases("powerpc", "ppc32", Triple::ppc)
388 .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64)
389 .Cases("powerpc64le", "ppc64le", Triple::ppc64le)
390 .Case("xscale", Triple::arm)
391 .Case("xscaleeb", Triple::armeb)
392 .Case("aarch64", Triple::aarch64)
393 .Case("aarch64_be", Triple::aarch64_be)
394 .Case("arc", Triple::arc)
395 .Case("arm64", Triple::aarch64)
396 .Case("arm", Triple::arm)
397 .Case("armeb", Triple::armeb)
398 .Case("thumb", Triple::thumb)
399 .Case("thumbeb", Triple::thumbeb)
400 .Case("avr", Triple::avr)
401 .Case("msp430", Triple::msp430)
402 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
403 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
404 .Cases("mips64", "mips64eb", Triple::mips64)
405 .Case("mips64el", Triple::mips64el)
406 .Case("nios2", Triple::nios2)
407 .Case("r600", Triple::r600)
408 .Case("amdgcn", Triple::amdgcn)
409 .Case("riscv32", Triple::riscv32)
410 .Case("riscv64", Triple::riscv64)
411 .Case("hexagon", Triple::hexagon)
412 .Cases("s390x", "systemz", Triple::systemz)
413 .Case("sparc", Triple::sparc)
414 .Case("sparcel", Triple::sparcel)
415 .Cases("sparcv9", "sparc64", Triple::sparcv9)
416 .Case("tce", Triple::tce)
417 .Case("tcele", Triple::tcele)
418 .Case("xcore", Triple::xcore)
419 .Case("nvptx", Triple::nvptx)
420 .Case("nvptx64", Triple::nvptx64)
421 .Case("le32", Triple::le32)
422 .Case("le64", Triple::le64)
423 .Case("amdil", Triple::amdil)
424 .Case("amdil64", Triple::amdil64)
425 .Case("hsail", Triple::hsail)
426 .Case("hsail64", Triple::hsail64)
427 .Case("spir", Triple::spir)
428 .Case("spir64", Triple::spir64)
429 .StartsWith("kalimba", Triple::kalimba)
430 .Case("lanai", Triple::lanai)
431 .Case("shave", Triple::shave)
432 .Case("wasm32", Triple::wasm32)
433 .Case("wasm64", Triple::wasm64)
434 .Case("renderscript32", Triple::renderscript32)
435 .Case("renderscript64", Triple::renderscript64)
436 .Default(Triple::UnknownArch);
438 // Some architectures require special parsing logic just to compute the
440 if (AT == Triple::UnknownArch) {
441 if (ArchName.startswith("arm") || ArchName.startswith("thumb") ||
442 ArchName.startswith("aarch64"))
443 return parseARMArch(ArchName);
444 if (ArchName.startswith("bpf"))
445 return parseBPFArch(ArchName);
451 static Triple::VendorType parseVendor(StringRef VendorName) {
452 return StringSwitch<Triple::VendorType>(VendorName)
453 .Case("apple", Triple::Apple)
454 .Case("pc", Triple::PC)
455 .Case("scei", Triple::SCEI)
456 .Case("bgp", Triple::BGP)
457 .Case("bgq", Triple::BGQ)
458 .Case("fsl", Triple::Freescale)
459 .Case("ibm", Triple::IBM)
460 .Case("img", Triple::ImaginationTechnologies)
461 .Case("mti", Triple::MipsTechnologies)
462 .Case("nvidia", Triple::NVIDIA)
463 .Case("csr", Triple::CSR)
464 .Case("myriad", Triple::Myriad)
465 .Case("amd", Triple::AMD)
466 .Case("mesa", Triple::Mesa)
467 .Case("suse", Triple::SUSE)
468 .Default(Triple::UnknownVendor);
471 static Triple::OSType parseOS(StringRef OSName) {
472 return StringSwitch<Triple::OSType>(OSName)
473 .StartsWith("ananas", Triple::Ananas)
474 .StartsWith("cloudabi", Triple::CloudABI)
475 .StartsWith("darwin", Triple::Darwin)
476 .StartsWith("dragonfly", Triple::DragonFly)
477 .StartsWith("freebsd", Triple::FreeBSD)
478 .StartsWith("fuchsia", Triple::Fuchsia)
479 .StartsWith("ios", Triple::IOS)
480 .StartsWith("kfreebsd", Triple::KFreeBSD)
481 .StartsWith("linux", Triple::Linux)
482 .StartsWith("lv2", Triple::Lv2)
483 .StartsWith("macos", Triple::MacOSX)
484 .StartsWith("netbsd", Triple::NetBSD)
485 .StartsWith("openbsd", Triple::OpenBSD)
486 .StartsWith("solaris", Triple::Solaris)
487 .StartsWith("win32", Triple::Win32)
488 .StartsWith("windows", Triple::Win32)
489 .StartsWith("haiku", Triple::Haiku)
490 .StartsWith("minix", Triple::Minix)
491 .StartsWith("rtems", Triple::RTEMS)
492 .StartsWith("nacl", Triple::NaCl)
493 .StartsWith("cnk", Triple::CNK)
494 .StartsWith("aix", Triple::AIX)
495 .StartsWith("cuda", Triple::CUDA)
496 .StartsWith("nvcl", Triple::NVCL)
497 .StartsWith("amdhsa", Triple::AMDHSA)
498 .StartsWith("ps4", Triple::PS4)
499 .StartsWith("elfiamcu", Triple::ELFIAMCU)
500 .StartsWith("tvos", Triple::TvOS)
501 .StartsWith("watchos", Triple::WatchOS)
502 .StartsWith("mesa3d", Triple::Mesa3D)
503 .StartsWith("contiki", Triple::Contiki)
504 .StartsWith("amdpal", Triple::AMDPAL)
505 .Default(Triple::UnknownOS);
508 static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
509 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
510 .StartsWith("eabihf", Triple::EABIHF)
511 .StartsWith("eabi", Triple::EABI)
512 .StartsWith("gnuabin32", Triple::GNUABIN32)
513 .StartsWith("gnuabi64", Triple::GNUABI64)
514 .StartsWith("gnueabihf", Triple::GNUEABIHF)
515 .StartsWith("gnueabi", Triple::GNUEABI)
516 .StartsWith("gnux32", Triple::GNUX32)
517 .StartsWith("code16", Triple::CODE16)
518 .StartsWith("gnu", Triple::GNU)
519 .StartsWith("android", Triple::Android)
520 .StartsWith("musleabihf", Triple::MuslEABIHF)
521 .StartsWith("musleabi", Triple::MuslEABI)
522 .StartsWith("musl", Triple::Musl)
523 .StartsWith("msvc", Triple::MSVC)
524 .StartsWith("itanium", Triple::Itanium)
525 .StartsWith("cygnus", Triple::Cygnus)
526 .StartsWith("amdopencl", Triple::AMDOpenCL)
527 .StartsWith("coreclr", Triple::CoreCLR)
528 .StartsWith("opencl", Triple::OpenCL)
529 .StartsWith("simulator", Triple::Simulator)
530 .Default(Triple::UnknownEnvironment);
533 static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
534 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
535 .EndsWith("coff", Triple::COFF)
536 .EndsWith("elf", Triple::ELF)
537 .EndsWith("macho", Triple::MachO)
538 .EndsWith("wasm", Triple::Wasm)
539 .Default(Triple::UnknownObjectFormat);
542 static Triple::SubArchType parseSubArch(StringRef SubArchName) {
543 StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
545 // For now, this is the small part. Early return.
546 if (ARMSubArch.empty())
547 return StringSwitch<Triple::SubArchType>(SubArchName)
548 .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
549 .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
550 .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
551 .Default(Triple::NoSubArch);
554 switch(ARM::parseArch(ARMSubArch)) {
555 case ARM::ArchKind::ARMV4:
556 return Triple::NoSubArch;
557 case ARM::ArchKind::ARMV4T:
558 return Triple::ARMSubArch_v4t;
559 case ARM::ArchKind::ARMV5T:
560 return Triple::ARMSubArch_v5;
561 case ARM::ArchKind::ARMV5TE:
562 case ARM::ArchKind::IWMMXT:
563 case ARM::ArchKind::IWMMXT2:
564 case ARM::ArchKind::XSCALE:
565 case ARM::ArchKind::ARMV5TEJ:
566 return Triple::ARMSubArch_v5te;
567 case ARM::ArchKind::ARMV6:
568 return Triple::ARMSubArch_v6;
569 case ARM::ArchKind::ARMV6K:
570 case ARM::ArchKind::ARMV6KZ:
571 return Triple::ARMSubArch_v6k;
572 case ARM::ArchKind::ARMV6T2:
573 return Triple::ARMSubArch_v6t2;
574 case ARM::ArchKind::ARMV6M:
575 return Triple::ARMSubArch_v6m;
576 case ARM::ArchKind::ARMV7A:
577 case ARM::ArchKind::ARMV7R:
578 return Triple::ARMSubArch_v7;
579 case ARM::ArchKind::ARMV7VE:
580 return Triple::ARMSubArch_v7ve;
581 case ARM::ArchKind::ARMV7K:
582 return Triple::ARMSubArch_v7k;
583 case ARM::ArchKind::ARMV7M:
584 return Triple::ARMSubArch_v7m;
585 case ARM::ArchKind::ARMV7S:
586 return Triple::ARMSubArch_v7s;
587 case ARM::ArchKind::ARMV7EM:
588 return Triple::ARMSubArch_v7em;
589 case ARM::ArchKind::ARMV8A:
590 return Triple::ARMSubArch_v8;
591 case ARM::ArchKind::ARMV8_1A:
592 return Triple::ARMSubArch_v8_1a;
593 case ARM::ArchKind::ARMV8_2A:
594 return Triple::ARMSubArch_v8_2a;
595 case ARM::ArchKind::ARMV8_3A:
596 return Triple::ARMSubArch_v8_3a;
597 case ARM::ArchKind::ARMV8R:
598 return Triple::ARMSubArch_v8r;
599 case ARM::ArchKind::ARMV8MBaseline:
600 return Triple::ARMSubArch_v8m_baseline;
601 case ARM::ArchKind::ARMV8MMainline:
602 return Triple::ARMSubArch_v8m_mainline;
604 return Triple::NoSubArch;
608 static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
610 case Triple::UnknownObjectFormat: return "";
611 case Triple::COFF: return "coff";
612 case Triple::ELF: return "elf";
613 case Triple::MachO: return "macho";
614 case Triple::Wasm: return "wasm";
616 llvm_unreachable("unknown object format type");
619 static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
620 switch (T.getArch()) {
621 case Triple::UnknownArch:
622 case Triple::aarch64:
628 return Triple::MachO;
629 else if (T.isOSWindows())
633 case Triple::aarch64_be:
637 case Triple::amdil64:
642 case Triple::hexagon:
645 case Triple::hsail64:
646 case Triple::kalimba:
651 case Triple::mips64el:
656 case Triple::nvptx64:
657 case Triple::ppc64le:
659 case Triple::renderscript32:
660 case Triple::renderscript64:
661 case Triple::riscv32:
662 case Triple::riscv64:
665 case Triple::sparcel:
666 case Triple::sparcv9:
669 case Triple::systemz:
672 case Triple::thumbeb:
681 return Triple::MachO;
684 llvm_unreachable("unknown architecture");
687 /// \brief Construct a triple from the string representation provided.
689 /// This stores the string representation and parses the various pieces into
691 Triple::Triple(const Twine &Str)
692 : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
693 Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
694 ObjectFormat(UnknownObjectFormat) {
695 // Do minimal parsing by hand here.
696 SmallVector<StringRef, 4> Components;
697 StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
698 if (Components.size() > 0) {
699 Arch = parseArch(Components[0]);
700 SubArch = parseSubArch(Components[0]);
701 if (Components.size() > 1) {
702 Vendor = parseVendor(Components[1]);
703 if (Components.size() > 2) {
704 OS = parseOS(Components[2]);
705 if (Components.size() > 3) {
706 Environment = parseEnvironment(Components[3]);
707 ObjectFormat = parseFormat(Components[3]);
712 if (ObjectFormat == UnknownObjectFormat)
713 ObjectFormat = getDefaultFormat(*this);
716 /// \brief Construct a triple from string representations of the architecture,
719 /// This joins each argument into a canonical string representation and parses
720 /// them into enum members. It leaves the environment unknown and omits it from
721 /// the string representation.
722 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
723 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
724 Arch(parseArch(ArchStr.str())),
725 SubArch(parseSubArch(ArchStr.str())),
726 Vendor(parseVendor(VendorStr.str())),
727 OS(parseOS(OSStr.str())),
728 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
729 ObjectFormat = getDefaultFormat(*this);
732 /// \brief Construct a triple from string representations of the architecture,
733 /// vendor, OS, and environment.
735 /// This joins each argument into a canonical string representation and parses
736 /// them into enum members.
737 Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
738 const Twine &EnvironmentStr)
739 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
740 EnvironmentStr).str()),
741 Arch(parseArch(ArchStr.str())),
742 SubArch(parseSubArch(ArchStr.str())),
743 Vendor(parseVendor(VendorStr.str())),
744 OS(parseOS(OSStr.str())),
745 Environment(parseEnvironment(EnvironmentStr.str())),
746 ObjectFormat(parseFormat(EnvironmentStr.str())) {
747 if (ObjectFormat == Triple::UnknownObjectFormat)
748 ObjectFormat = getDefaultFormat(*this);
751 std::string Triple::normalize(StringRef Str) {
752 bool IsMinGW32 = false;
753 bool IsCygwin = false;
755 // Parse into components.
756 SmallVector<StringRef, 4> Components;
757 Str.split(Components, '-');
759 // If the first component corresponds to a known architecture, preferentially
760 // use it for the architecture. If the second component corresponds to a
761 // known vendor, preferentially use it for the vendor, etc. This avoids silly
762 // component movement when a component parses as (eg) both a valid arch and a
764 ArchType Arch = UnknownArch;
765 if (Components.size() > 0)
766 Arch = parseArch(Components[0]);
767 VendorType Vendor = UnknownVendor;
768 if (Components.size() > 1)
769 Vendor = parseVendor(Components[1]);
770 OSType OS = UnknownOS;
771 if (Components.size() > 2) {
772 OS = parseOS(Components[2]);
773 IsCygwin = Components[2].startswith("cygwin");
774 IsMinGW32 = Components[2].startswith("mingw");
776 EnvironmentType Environment = UnknownEnvironment;
777 if (Components.size() > 3)
778 Environment = parseEnvironment(Components[3]);
779 ObjectFormatType ObjectFormat = UnknownObjectFormat;
780 if (Components.size() > 4)
781 ObjectFormat = parseFormat(Components[4]);
783 // Note which components are already in their final position. These will not
786 Found[0] = Arch != UnknownArch;
787 Found[1] = Vendor != UnknownVendor;
788 Found[2] = OS != UnknownOS;
789 Found[3] = Environment != UnknownEnvironment;
791 // If they are not there already, permute the components into their canonical
792 // positions by seeing if they parse as a valid architecture, and if so moving
793 // the component to the architecture position etc.
794 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
796 continue; // Already in the canonical position.
798 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
799 // Do not reparse any components that already matched.
800 if (Idx < array_lengthof(Found) && Found[Idx])
803 // Does this component parse as valid for the target position?
805 StringRef Comp = Components[Idx];
807 default: llvm_unreachable("unexpected component type!");
809 Arch = parseArch(Comp);
810 Valid = Arch != UnknownArch;
813 Vendor = parseVendor(Comp);
814 Valid = Vendor != UnknownVendor;
818 IsCygwin = Comp.startswith("cygwin");
819 IsMinGW32 = Comp.startswith("mingw");
820 Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
823 Environment = parseEnvironment(Comp);
824 Valid = Environment != UnknownEnvironment;
826 ObjectFormat = parseFormat(Comp);
827 Valid = ObjectFormat != UnknownObjectFormat;
832 continue; // Nope, try the next component.
834 // Move the component to the target position, pushing any non-fixed
835 // components that are in the way to the right. This tends to give
836 // good results in the common cases of a forgotten vendor component
837 // or a wrongly positioned environment.
839 // Insert left, pushing the existing components to the right. For
840 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
841 StringRef CurrentComponent(""); // The empty component.
842 // Replace the component we are moving with an empty component.
843 std::swap(CurrentComponent, Components[Idx]);
844 // Insert the component being moved at Pos, displacing any existing
845 // components to the right.
846 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
847 // Skip over any fixed components.
848 while (i < array_lengthof(Found) && Found[i])
850 // Place the component at the new position, getting the component
851 // that was at this position - it will be moved right.
852 std::swap(CurrentComponent, Components[i]);
854 } else if (Pos > Idx) {
855 // Push right by inserting empty components until the component at Idx
856 // reaches the target position Pos. For example, pc-a -> -pc-a when
857 // moving pc to the second position.
859 // Insert one empty component at Idx.
860 StringRef CurrentComponent(""); // The empty component.
861 for (unsigned i = Idx; i < Components.size();) {
862 // Place the component at the new position, getting the component
863 // that was at this position - it will be moved right.
864 std::swap(CurrentComponent, Components[i]);
865 // If it was placed on top of an empty component then we are done.
866 if (CurrentComponent.empty())
868 // Advance to the next component, skipping any fixed components.
869 while (++i < array_lengthof(Found) && Found[i])
872 // The last component was pushed off the end - append it.
873 if (!CurrentComponent.empty())
874 Components.push_back(CurrentComponent);
876 // Advance Idx to the component's new position.
877 while (++Idx < array_lengthof(Found) && Found[Idx])
879 } while (Idx < Pos); // Add more until the final position is reached.
881 assert(Pos < Components.size() && Components[Pos] == Comp &&
882 "Component moved wrong!");
888 // Special case logic goes here. At this point Arch, Vendor and OS have the
889 // correct values for the computed components.
890 std::string NormalizedEnvironment;
891 if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
892 StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
893 if (AndroidVersion.empty()) {
894 Components[3] = "android";
896 NormalizedEnvironment = Twine("android", AndroidVersion).str();
897 Components[3] = NormalizedEnvironment;
901 // SUSE uses "gnueabi" to mean "gnueabihf"
902 if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
903 Components[3] = "gnueabihf";
905 if (OS == Triple::Win32) {
906 Components.resize(4);
907 Components[2] = "windows";
908 if (Environment == UnknownEnvironment) {
909 if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
910 Components[3] = "msvc";
912 Components[3] = getObjectFormatTypeName(ObjectFormat);
914 } else if (IsMinGW32) {
915 Components.resize(4);
916 Components[2] = "windows";
917 Components[3] = "gnu";
918 } else if (IsCygwin) {
919 Components.resize(4);
920 Components[2] = "windows";
921 Components[3] = "cygnus";
923 if (IsMinGW32 || IsCygwin ||
924 (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
925 if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
926 Components.resize(5);
927 Components[4] = getObjectFormatTypeName(ObjectFormat);
931 // Stick the corrected components back together to form the normalized string.
932 std::string Normalized;
933 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
934 if (i) Normalized += '-';
935 Normalized += Components[i];
940 StringRef Triple::getArchName() const {
941 return StringRef(Data).split('-').first; // Isolate first component
944 StringRef Triple::getVendorName() const {
945 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
946 return Tmp.split('-').first; // Isolate second component
949 StringRef Triple::getOSName() const {
950 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
951 Tmp = Tmp.split('-').second; // Strip second component
952 return Tmp.split('-').first; // Isolate third component
955 StringRef Triple::getEnvironmentName() const {
956 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
957 Tmp = Tmp.split('-').second; // Strip second component
958 return Tmp.split('-').second; // Strip third component
961 StringRef Triple::getOSAndEnvironmentName() const {
962 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
963 return Tmp.split('-').second; // Strip second component
966 static unsigned EatNumber(StringRef &Str) {
967 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
971 // Consume the leading digit.
972 Result = Result*10 + (Str[0] - '0');
976 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
981 static void parseVersionFromName(StringRef Name, unsigned &Major,
982 unsigned &Minor, unsigned &Micro) {
983 // Any unset version defaults to 0.
984 Major = Minor = Micro = 0;
986 // Parse up to three components.
987 unsigned *Components[3] = {&Major, &Minor, &Micro};
988 for (unsigned i = 0; i != 3; ++i) {
989 if (Name.empty() || Name[0] < '0' || Name[0] > '9')
992 // Consume the leading number.
993 *Components[i] = EatNumber(Name);
995 // Consume the separator, if present.
996 if (Name.startswith("."))
997 Name = Name.substr(1);
1001 void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
1002 unsigned &Micro) const {
1003 StringRef EnvironmentName = getEnvironmentName();
1004 StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
1005 if (EnvironmentName.startswith(EnvironmentTypeName))
1006 EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
1008 parseVersionFromName(EnvironmentName, Major, Minor, Micro);
1011 void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
1012 unsigned &Micro) const {
1013 StringRef OSName = getOSName();
1014 // Assume that the OS portion of the triple starts with the canonical name.
1015 StringRef OSTypeName = getOSTypeName(getOS());
1016 if (OSName.startswith(OSTypeName))
1017 OSName = OSName.substr(OSTypeName.size());
1018 else if (getOS() == MacOSX)
1019 OSName.consume_front("macos");
1021 parseVersionFromName(OSName, Major, Minor, Micro);
1024 bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
1025 unsigned &Micro) const {
1026 getOSVersion(Major, Minor, Micro);
1029 default: llvm_unreachable("unexpected OS for Darwin triple");
1031 // Default to darwin8, i.e., MacOSX 10.4.
1034 // Darwin version numbers are skewed from OS X versions.
1053 // Ignore the version from the triple. This is only handled because the
1054 // the clang driver combines OS X and IOS support into a common Darwin
1055 // toolchain that wants to know the OS X version number even when targeting
1065 void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
1066 unsigned &Micro) const {
1068 default: llvm_unreachable("unexpected OS for Darwin triple");
1071 // Ignore the version from the triple. This is only handled because the
1072 // the clang driver combines OS X and IOS support into a common Darwin
1073 // toolchain that wants to know the iOS version number even when targeting
1081 getOSVersion(Major, Minor, Micro);
1082 // Default to 5.0 (or 7.0 for arm64).
1084 Major = (getArch() == aarch64) ? 7 : 5;
1087 llvm_unreachable("conflicting triple info");
1091 void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
1092 unsigned &Micro) const {
1094 default: llvm_unreachable("unexpected OS for Darwin triple");
1097 // Ignore the version from the triple. This is only handled because the
1098 // the clang driver combines OS X and IOS support into a common Darwin
1099 // toolchain that wants to know the iOS version number even when targeting
1106 getOSVersion(Major, Minor, Micro);
1111 llvm_unreachable("conflicting triple info");
1115 void Triple::setTriple(const Twine &Str) {
1116 *this = Triple(Str);
1119 void Triple::setArch(ArchType Kind) {
1120 setArchName(getArchTypeName(Kind));
1123 void Triple::setVendor(VendorType Kind) {
1124 setVendorName(getVendorTypeName(Kind));
1127 void Triple::setOS(OSType Kind) {
1128 setOSName(getOSTypeName(Kind));
1131 void Triple::setEnvironment(EnvironmentType Kind) {
1132 if (ObjectFormat == getDefaultFormat(*this))
1133 return setEnvironmentName(getEnvironmentTypeName(Kind));
1135 setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
1136 getObjectFormatTypeName(ObjectFormat)).str());
1139 void Triple::setObjectFormat(ObjectFormatType Kind) {
1140 if (Environment == UnknownEnvironment)
1141 return setEnvironmentName(getObjectFormatTypeName(Kind));
1143 setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
1144 getObjectFormatTypeName(Kind)).str());
1147 void Triple::setArchName(StringRef Str) {
1148 // Work around a miscompilation bug for Twines in gcc 4.0.3.
1149 SmallString<64> Triple;
1152 Triple += getVendorName();
1154 Triple += getOSAndEnvironmentName();
1158 void Triple::setVendorName(StringRef Str) {
1159 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
1162 void Triple::setOSName(StringRef Str) {
1163 if (hasEnvironment())
1164 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
1165 "-" + getEnvironmentName());
1167 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1170 void Triple::setEnvironmentName(StringRef Str) {
1171 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1175 void Triple::setOSAndEnvironmentName(StringRef Str) {
1176 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1179 static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
1181 case llvm::Triple::UnknownArch:
1184 case llvm::Triple::avr:
1185 case llvm::Triple::msp430:
1188 case llvm::Triple::arc:
1189 case llvm::Triple::arm:
1190 case llvm::Triple::armeb:
1191 case llvm::Triple::hexagon:
1192 case llvm::Triple::le32:
1193 case llvm::Triple::mips:
1194 case llvm::Triple::mipsel:
1195 case llvm::Triple::nios2:
1196 case llvm::Triple::nvptx:
1197 case llvm::Triple::ppc:
1198 case llvm::Triple::r600:
1199 case llvm::Triple::riscv32:
1200 case llvm::Triple::sparc:
1201 case llvm::Triple::sparcel:
1202 case llvm::Triple::tce:
1203 case llvm::Triple::tcele:
1204 case llvm::Triple::thumb:
1205 case llvm::Triple::thumbeb:
1206 case llvm::Triple::x86:
1207 case llvm::Triple::xcore:
1208 case llvm::Triple::amdil:
1209 case llvm::Triple::hsail:
1210 case llvm::Triple::spir:
1211 case llvm::Triple::kalimba:
1212 case llvm::Triple::lanai:
1213 case llvm::Triple::shave:
1214 case llvm::Triple::wasm32:
1215 case llvm::Triple::renderscript32:
1218 case llvm::Triple::aarch64:
1219 case llvm::Triple::aarch64_be:
1220 case llvm::Triple::amdgcn:
1221 case llvm::Triple::bpfel:
1222 case llvm::Triple::bpfeb:
1223 case llvm::Triple::le64:
1224 case llvm::Triple::mips64:
1225 case llvm::Triple::mips64el:
1226 case llvm::Triple::nvptx64:
1227 case llvm::Triple::ppc64:
1228 case llvm::Triple::ppc64le:
1229 case llvm::Triple::riscv64:
1230 case llvm::Triple::sparcv9:
1231 case llvm::Triple::systemz:
1232 case llvm::Triple::x86_64:
1233 case llvm::Triple::amdil64:
1234 case llvm::Triple::hsail64:
1235 case llvm::Triple::spir64:
1236 case llvm::Triple::wasm64:
1237 case llvm::Triple::renderscript64:
1240 llvm_unreachable("Invalid architecture value");
1243 bool Triple::isArch64Bit() const {
1244 return getArchPointerBitWidth(getArch()) == 64;
1247 bool Triple::isArch32Bit() const {
1248 return getArchPointerBitWidth(getArch()) == 32;
1251 bool Triple::isArch16Bit() const {
1252 return getArchPointerBitWidth(getArch()) == 16;
1255 Triple Triple::get32BitArchVariant() const {
1257 switch (getArch()) {
1258 case Triple::UnknownArch:
1259 case Triple::amdgcn:
1263 case Triple::msp430:
1264 case Triple::systemz:
1265 case Triple::ppc64le:
1266 T.setArch(UnknownArch);
1275 case Triple::hexagon:
1276 case Triple::kalimba:
1279 case Triple::mipsel:
1284 case Triple::riscv32:
1286 case Triple::sparcel:
1290 case Triple::thumbeb:
1295 case Triple::wasm32:
1296 case Triple::renderscript32:
1300 case Triple::aarch64: T.setArch(Triple::arm); break;
1301 case Triple::aarch64_be: T.setArch(Triple::armeb); break;
1302 case Triple::le64: T.setArch(Triple::le32); break;
1303 case Triple::mips64: T.setArch(Triple::mips); break;
1304 case Triple::mips64el: T.setArch(Triple::mipsel); break;
1305 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
1306 case Triple::ppc64: T.setArch(Triple::ppc); break;
1307 case Triple::sparcv9: T.setArch(Triple::sparc); break;
1308 case Triple::riscv64: T.setArch(Triple::riscv32); break;
1309 case Triple::x86_64: T.setArch(Triple::x86); break;
1310 case Triple::amdil64: T.setArch(Triple::amdil); break;
1311 case Triple::hsail64: T.setArch(Triple::hsail); break;
1312 case Triple::spir64: T.setArch(Triple::spir); break;
1313 case Triple::wasm64: T.setArch(Triple::wasm32); break;
1314 case Triple::renderscript64: T.setArch(Triple::renderscript32); break;
1319 Triple Triple::get64BitArchVariant() const {
1321 switch (getArch()) {
1322 case Triple::UnknownArch:
1325 case Triple::hexagon:
1326 case Triple::kalimba:
1328 case Triple::msp430:
1334 case Triple::sparcel:
1336 T.setArch(UnknownArch);
1339 case Triple::aarch64:
1340 case Triple::aarch64_be:
1344 case Triple::amdil64:
1345 case Triple::amdgcn:
1346 case Triple::hsail64:
1347 case Triple::spir64:
1348 case Triple::mips64:
1349 case Triple::mips64el:
1350 case Triple::nvptx64:
1352 case Triple::ppc64le:
1353 case Triple::riscv64:
1354 case Triple::sparcv9:
1355 case Triple::systemz:
1356 case Triple::x86_64:
1357 case Triple::wasm64:
1358 case Triple::renderscript64:
1362 case Triple::arm: T.setArch(Triple::aarch64); break;
1363 case Triple::armeb: T.setArch(Triple::aarch64_be); break;
1364 case Triple::le32: T.setArch(Triple::le64); break;
1365 case Triple::mips: T.setArch(Triple::mips64); break;
1366 case Triple::mipsel: T.setArch(Triple::mips64el); break;
1367 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
1368 case Triple::ppc: T.setArch(Triple::ppc64); break;
1369 case Triple::sparc: T.setArch(Triple::sparcv9); break;
1370 case Triple::riscv32: T.setArch(Triple::riscv64); break;
1371 case Triple::x86: T.setArch(Triple::x86_64); break;
1372 case Triple::amdil: T.setArch(Triple::amdil64); break;
1373 case Triple::hsail: T.setArch(Triple::hsail64); break;
1374 case Triple::spir: T.setArch(Triple::spir64); break;
1375 case Triple::thumb: T.setArch(Triple::aarch64); break;
1376 case Triple::thumbeb: T.setArch(Triple::aarch64_be); break;
1377 case Triple::wasm32: T.setArch(Triple::wasm64); break;
1378 case Triple::renderscript32: T.setArch(Triple::renderscript64); break;
1383 Triple Triple::getBigEndianArchVariant() const {
1385 // Already big endian.
1386 if (!isLittleEndian())
1388 switch (getArch()) {
1389 case Triple::UnknownArch:
1390 case Triple::amdgcn:
1391 case Triple::amdil64:
1394 case Triple::hexagon:
1395 case Triple::hsail64:
1397 case Triple::kalimba:
1400 case Triple::msp430:
1402 case Triple::nvptx64:
1405 case Triple::riscv32:
1406 case Triple::riscv64:
1408 case Triple::spir64:
1410 case Triple::wasm32:
1411 case Triple::wasm64:
1413 case Triple::x86_64:
1415 case Triple::renderscript32:
1416 case Triple::renderscript64:
1418 // ARM is intentionally unsupported here, changing the architecture would
1419 // drop any arch suffixes.
1422 T.setArch(UnknownArch);
1425 case Triple::tcele: T.setArch(Triple::tce); break;
1426 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1427 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1428 case Triple::mips64el:T.setArch(Triple::mips64); break;
1429 case Triple::mipsel: T.setArch(Triple::mips); break;
1430 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1431 case Triple::sparcel: T.setArch(Triple::sparc); break;
1433 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1438 Triple Triple::getLittleEndianArchVariant() const {
1440 if (isLittleEndian())
1443 switch (getArch()) {
1444 case Triple::UnknownArch:
1447 case Triple::sparcv9:
1448 case Triple::systemz:
1450 // ARM is intentionally unsupported here, changing the architecture would
1451 // drop any arch suffixes.
1453 case Triple::thumbeb:
1454 T.setArch(UnknownArch);
1457 case Triple::tce: T.setArch(Triple::tcele); break;
1458 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1459 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1460 case Triple::mips64: T.setArch(Triple::mips64el); break;
1461 case Triple::mips: T.setArch(Triple::mipsel); break;
1462 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1463 case Triple::sparc: T.setArch(Triple::sparcel); break;
1465 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1470 bool Triple::isLittleEndian() const {
1471 switch (getArch()) {
1472 case Triple::aarch64:
1473 case Triple::amdgcn:
1474 case Triple::amdil64:
1479 case Triple::hexagon:
1480 case Triple::hsail64:
1482 case Triple::kalimba:
1485 case Triple::mips64el:
1486 case Triple::mipsel:
1487 case Triple::msp430:
1489 case Triple::nvptx64:
1491 case Triple::ppc64le:
1493 case Triple::riscv32:
1494 case Triple::riscv64:
1496 case Triple::sparcel:
1497 case Triple::spir64:
1500 case Triple::wasm32:
1501 case Triple::wasm64:
1503 case Triple::x86_64:
1506 case Triple::renderscript32:
1507 case Triple::renderscript64:
1514 bool Triple::isCompatibleWith(const Triple &Other) const {
1515 // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
1516 if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
1517 (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
1518 (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) ||
1519 (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) {
1520 if (getVendor() == Triple::Apple)
1521 return getSubArch() == Other.getSubArch() &&
1522 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1524 return getSubArch() == Other.getSubArch() &&
1525 getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
1526 getEnvironment() == Other.getEnvironment() &&
1527 getObjectFormat() == Other.getObjectFormat();
1530 // If vendor is apple, ignore the version number.
1531 if (getVendor() == Triple::Apple)
1532 return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
1533 getVendor() == Other.getVendor() && getOS() == Other.getOS();
1535 return *this == Other;
1538 std::string Triple::merge(const Triple &Other) const {
1539 // If vendor is apple, pick the triple with the larger version number.
1540 if (getVendor() == Triple::Apple)
1541 if (Other.isOSVersionLT(*this))
1547 StringRef Triple::getARMCPUForArch(StringRef MArch) const {
1549 MArch = getArchName();
1550 MArch = ARM::getCanonicalArchName(MArch);
1552 // Some defaults are forced.
1554 case llvm::Triple::FreeBSD:
1555 case llvm::Triple::NetBSD:
1556 if (!MArch.empty() && MArch == "v6")
1557 return "arm1176jzf-s";
1559 case llvm::Triple::Win32:
1560 // FIXME: this is invalid for WindowsCE
1562 case llvm::Triple::MacOSX:
1563 case llvm::Triple::IOS:
1564 case llvm::Triple::WatchOS:
1565 case llvm::Triple::TvOS:
1576 StringRef CPU = ARM::getDefaultCPU(MArch);
1577 if (!CPU.empty() && !CPU.equals("invalid"))
1580 // If no specific architecture version is requested, return the minimum CPU
1581 // required by the OS and environment.
1583 case llvm::Triple::NetBSD:
1584 switch (getEnvironment()) {
1585 case llvm::Triple::GNUEABIHF:
1586 case llvm::Triple::GNUEABI:
1587 case llvm::Triple::EABIHF:
1588 case llvm::Triple::EABI:
1589 return "arm926ej-s";
1593 case llvm::Triple::NaCl:
1594 case llvm::Triple::OpenBSD:
1597 switch (getEnvironment()) {
1598 case llvm::Triple::EABIHF:
1599 case llvm::Triple::GNUEABIHF:
1600 case llvm::Triple::MuslEABIHF:
1601 return "arm1176jzf-s";
1607 llvm_unreachable("invalid arch name");