LCOV - code coverage report
Current view: top level - lib/Support - Triple.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 730 777 94.0 %
Date: 2018-10-20 13:21:21 Functions: 53 54 98.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- Triple.cpp - Target triple helper class --------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      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"
      17             : #include <cstring>
      18             : using namespace llvm;
      19             : 
      20       61297 : StringRef Triple::getArchTypeName(ArchType Kind) {
      21       61297 :   switch (Kind) {
      22         373 :   case UnknownArch:    return "unknown";
      23             : 
      24        1909 :   case aarch64:        return "aarch64";
      25         234 :   case aarch64_be:     return "aarch64_be";
      26        1551 :   case arm:            return "arm";
      27          80 :   case armeb:          return "armeb";
      28           1 :   case arc:            return "arc";
      29          85 :   case avr:            return "avr";
      30          71 :   case bpfel:          return "bpfel";
      31          18 :   case bpfeb:          return "bpfeb";
      32        1155 :   case hexagon:        return "hexagon";
      33        1231 :   case mips:           return "mips";
      34         948 :   case mipsel:         return "mipsel";
      35         771 :   case mips64:         return "mips64";
      36         447 :   case mips64el:       return "mips64el";
      37          35 :   case msp430:         return "msp430";
      38          10 :   case nios2:          return "nios2";
      39         254 :   case ppc64:          return "powerpc64";
      40         246 :   case ppc64le:        return "powerpc64le";
      41         184 :   case ppc:            return "powerpc";
      42         370 :   case r600:           return "r600";
      43        2230 :   case amdgcn:         return "amdgcn";
      44         152 :   case riscv32:        return "riscv32";
      45         152 :   case riscv64:        return "riscv64";
      46         266 :   case sparc:          return "sparc";
      47         178 :   case sparcv9:        return "sparcv9";
      48          33 :   case sparcel:        return "sparcel";
      49          55 :   case systemz:        return "s390x";
      50           3 :   case tce:            return "tce";
      51           3 :   case tcele:          return "tcele";
      52          84 :   case thumb:          return "thumb";
      53          22 :   case thumbeb:        return "thumbeb";
      54       22940 :   case x86:            return "i386";
      55       24442 :   case x86_64:         return "x86_64";
      56          77 :   case xcore:          return "xcore";
      57         181 :   case nvptx:          return "nvptx";
      58         360 :   case nvptx64:        return "nvptx64";
      59           8 :   case le32:           return "le32";
      60           6 :   case le64:           return "le64";
      61           4 :   case amdil:          return "amdil";
      62           4 :   case amdil64:        return "amdil64";
      63           4 :   case hsail:          return "hsail";
      64           4 :   case hsail64:        return "hsail64";
      65           4 :   case spir:           return "spir";
      66           4 :   case spir64:         return "spir64";
      67           1 :   case kalimba:        return "kalimba";
      68          21 :   case lanai:          return "lanai";
      69           8 :   case shave:          return "shave";
      70          53 :   case wasm32:         return "wasm32";
      71          19 :   case wasm64:         return "wasm64";
      72           3 :   case renderscript32: return "renderscript32";
      73           3 :   case renderscript64: return "renderscript64";
      74             :   }
      75             : 
      76           0 :   llvm_unreachable("Invalid ArchType!");
      77             : }
      78             : 
      79       22982 : StringRef Triple::getArchTypePrefix(ArchType Kind) {
      80       22982 :   switch (Kind) {
      81           0 :   default:
      82           0 :     return StringRef();
      83             : 
      84             :   case aarch64:
      85        2797 :   case aarch64_be:  return "aarch64";
      86             : 
      87           0 :   case arc:         return "arc";
      88             : 
      89             :   case arm:
      90             :   case armeb:
      91             :   case thumb:
      92        1723 :   case thumbeb:     return "arm";
      93             : 
      94           0 :   case avr:         return "avr";
      95             : 
      96             :   case ppc64:
      97             :   case ppc64le:
      98        4276 :   case ppc:         return "ppc";
      99             : 
     100             :   case mips:
     101             :   case mipsel:
     102             :   case mips64:
     103         755 :   case mips64el:    return "mips";
     104             : 
     105           0 :   case nios2:       return "nios2";
     106             : 
     107        1711 :   case hexagon:     return "hexagon";
     108             : 
     109         154 :   case amdgcn:      return "amdgcn";
     110           8 :   case r600:        return "r600";
     111             : 
     112             :   case bpfel:
     113           0 :   case bpfeb:       return "bpf";
     114             : 
     115             :   case sparcv9:
     116             :   case sparcel:
     117           0 :   case sparc:       return "sparc";
     118             : 
     119        1592 :   case systemz:     return "s390";
     120             : 
     121             :   case x86:
     122        8723 :   case x86_64:      return "x86";
     123             : 
     124           4 :   case xcore:       return "xcore";
     125             : 
     126             :   // NVPTX intrinsics are namespaced under nvvm.
     127         549 :   case nvptx:       return "nvvm";
     128         576 :   case nvptx64:     return "nvvm";
     129             : 
     130           0 :   case le32:        return "le32";
     131           0 :   case le64:        return "le64";
     132             : 
     133             :   case amdil:
     134           0 :   case amdil64:     return "amdil";
     135             : 
     136             :   case hsail:
     137           0 :   case hsail64:     return "hsail";
     138             : 
     139             :   case spir:
     140           0 :   case spir64:      return "spir";
     141           0 :   case kalimba:     return "kalimba";
     142           0 :   case lanai:       return "lanai";
     143           0 :   case shave:       return "shave";
     144             :   case wasm32:
     145         114 :   case wasm64:      return "wasm";
     146             : 
     147             :   case riscv32:
     148           0 :   case riscv64:     return "riscv";
     149             :   }
     150             : }
     151             : 
     152        1233 : StringRef Triple::getVendorTypeName(VendorType Kind) {
     153        1233 :   switch (Kind) {
     154         749 :   case UnknownVendor: return "unknown";
     155             : 
     156           2 :   case Apple: return "apple";
     157         468 :   case PC: return "pc";
     158           1 :   case SCEI: return "scei";
     159           1 :   case BGP: return "bgp";
     160           1 :   case BGQ: return "bgq";
     161           1 :   case Freescale: return "fsl";
     162           1 :   case IBM: return "ibm";
     163           1 :   case ImaginationTechnologies: return "img";
     164           1 :   case MipsTechnologies: return "mti";
     165           1 :   case NVIDIA: return "nvidia";
     166           1 :   case CSR: return "csr";
     167           1 :   case Myriad: return "myriad";
     168           1 :   case AMD: return "amd";
     169           1 :   case Mesa: return "mesa";
     170           1 :   case SUSE: return "suse";
     171           1 :   case OpenEmbedded: return "oe";
     172             :   }
     173             : 
     174           0 :   llvm_unreachable("Invalid VendorType!");
     175             : }
     176             : 
     177       39574 : StringRef Triple::getOSTypeName(OSType Kind) {
     178       39574 :   switch (Kind) {
     179         801 :   case UnknownOS: return "unknown";
     180             : 
     181           2 :   case Ananas: return "ananas";
     182           1 :   case CloudABI: return "cloudabi";
     183       23868 :   case Darwin: return "darwin";
     184           1 :   case DragonFly: return "dragonfly";
     185         211 :   case FreeBSD: return "freebsd";
     186           1 :   case Fuchsia: return "fuchsia";
     187        5481 :   case IOS: return "ios";
     188           1 :   case KFreeBSD: return "kfreebsd";
     189          14 :   case Linux: return "linux";
     190           1 :   case Lv2: return "lv2";
     191        8066 :   case MacOSX: return "macosx";
     192         215 :   case NetBSD: return "netbsd";
     193           1 :   case OpenBSD: return "openbsd";
     194           1 :   case Solaris: return "solaris";
     195         473 :   case Win32: return "windows";
     196           1 :   case Haiku: return "haiku";
     197           1 :   case Minix: return "minix";
     198           1 :   case RTEMS: return "rtems";
     199           1 :   case NaCl: return "nacl";
     200           1 :   case CNK: return "cnk";
     201           1 :   case AIX: return "aix";
     202           1 :   case CUDA: return "cuda";
     203           1 :   case NVCL: return "nvcl";
     204           1 :   case AMDHSA: return "amdhsa";
     205           1 :   case PS4: return "ps4";
     206           9 :   case ELFIAMCU: return "elfiamcu";
     207         208 :   case TvOS: return "tvos";
     208         205 :   case WatchOS: return "watchos";
     209           1 :   case Mesa3D: return "mesa3d";
     210           1 :   case Contiki: return "contiki";
     211           1 :   case AMDPAL: return "amdpal";
     212           1 :   case HermitCore: return "hermit";
     213             :   }
     214             : 
     215           0 :   llvm_unreachable("Invalid OSType");
     216             : }
     217             : 
     218        4345 : StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
     219        4345 :   switch (Kind) {
     220          69 :   case UnknownEnvironment: return "unknown";
     221         115 :   case GNU: return "gnu";
     222         149 :   case GNUABIN32: return "gnuabin32";
     223         166 :   case GNUABI64: return "gnuabi64";
     224           4 :   case GNUEABIHF: return "gnueabihf";
     225           1 :   case GNUEABI: return "gnueabi";
     226           3 :   case GNUX32: return "gnux32";
     227           2 :   case CODE16: return "code16";
     228           1 :   case EABI: return "eabi";
     229           1 :   case EABIHF: return "eabihf";
     230        1312 :   case Android: return "android";
     231           5 :   case Musl: return "musl";
     232           1 :   case MuslEABI: return "musleabi";
     233           1 :   case MuslEABIHF: return "musleabihf";
     234        2442 :   case MSVC: return "msvc";
     235           1 :   case Itanium: return "itanium";
     236           1 :   case Cygnus: return "cygnus";
     237           1 :   case CoreCLR: return "coreclr";
     238          70 :   case Simulator: return "simulator";
     239             :   }
     240             : 
     241           0 :   llvm_unreachable("Invalid EnvironmentType!");
     242             : }
     243             : 
     244        6459 : static Triple::ArchType parseBPFArch(StringRef ArchName) {
     245             :   if (ArchName.equals("bpf")) {
     246             :     if (sys::IsLittleEndianHost)
     247             :       return Triple::bpfel;
     248             :     else
     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         494 :     return Triple::bpfel;
     254             :   } else {
     255             :     return Triple::UnknownArch;
     256             :   }
     257             : }
     258             : 
     259        5870 : Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
     260        5870 :   Triple::ArchType BPFArch(parseBPFArch(Name));
     261        5870 :   return StringSwitch<Triple::ArchType>(Name)
     262        5870 :     .Case("aarch64", aarch64)
     263        5870 :     .Case("aarch64_be", aarch64_be)
     264        5870 :     .Case("arc", arc)
     265        5870 :     .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
     266        5870 :     .Case("arm", arm)
     267        5870 :     .Case("armeb", armeb)
     268        5870 :     .Case("avr", avr)
     269        5870 :     .StartsWith("bpf", BPFArch)
     270        5870 :     .Case("mips", mips)
     271        5870 :     .Case("mipsel", mipsel)
     272        5870 :     .Case("mips64", mips64)
     273        5870 :     .Case("mips64el", mips64el)
     274        5870 :     .Case("msp430", msp430)
     275        5870 :     .Case("nios2", nios2)
     276        5870 :     .Case("ppc64", ppc64)
     277        5870 :     .Case("ppc32", ppc)
     278        5870 :     .Case("ppc", ppc)
     279        5870 :     .Case("ppc64le", ppc64le)
     280        5870 :     .Case("r600", r600)
     281        5870 :     .Case("amdgcn", amdgcn)
     282        5870 :     .Case("riscv32", riscv32)
     283        5870 :     .Case("riscv64", riscv64)
     284        5870 :     .Case("hexagon", hexagon)
     285        5870 :     .Case("sparc", sparc)
     286        5870 :     .Case("sparcel", sparcel)
     287        5870 :     .Case("sparcv9", sparcv9)
     288        5870 :     .Case("systemz", systemz)
     289        5870 :     .Case("tce", tce)
     290        5870 :     .Case("tcele", tcele)
     291        5870 :     .Case("thumb", thumb)
     292        5870 :     .Case("thumbeb", thumbeb)
     293        5870 :     .Case("x86", x86)
     294        5870 :     .Case("x86-64", x86_64)
     295        5870 :     .Case("xcore", xcore)
     296        5870 :     .Case("nvptx", nvptx)
     297        5870 :     .Case("nvptx64", nvptx64)
     298        5870 :     .Case("le32", le32)
     299        5870 :     .Case("le64", le64)
     300        5870 :     .Case("amdil", amdil)
     301        5870 :     .Case("amdil64", amdil64)
     302        5870 :     .Case("hsail", hsail)
     303        5870 :     .Case("hsail64", hsail64)
     304        5870 :     .Case("spir", spir)
     305        5870 :     .Case("spir64", spir64)
     306        5870 :     .Case("kalimba", kalimba)
     307        5870 :     .Case("lanai", lanai)
     308        5870 :     .Case("shave", shave)
     309        5870 :     .Case("wasm32", wasm32)
     310        5870 :     .Case("wasm64", wasm64)
     311        5870 :     .Case("renderscript32", renderscript32)
     312        5870 :     .Case("renderscript64", renderscript64)
     313        5870 :     .Default(UnknownArch);
     314             : }
     315             : 
     316       37985 : static Triple::ArchType parseARMArch(StringRef ArchName) {
     317       37985 :   ARM::ISAKind ISA = ARM::parseArchISA(ArchName);
     318       37985 :   ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName);
     319             : 
     320             :   Triple::ArchType arch = Triple::UnknownArch;
     321       37985 :   switch (ENDIAN) {
     322       37097 :   case ARM::EndianKind::LITTLE: {
     323             :     switch (ISA) {
     324             :     case ARM::ISAKind::ARM:
     325             :       arch = Triple::arm;
     326             :       break;
     327             :     case ARM::ISAKind::THUMB:
     328             :       arch = Triple::thumb;
     329             :       break;
     330             :     case ARM::ISAKind::AARCH64:
     331             :       arch = Triple::aarch64;
     332             :       break;
     333             :     case ARM::ISAKind::INVALID:
     334             :       break;
     335             :     }
     336             :     break;
     337             :   }
     338         888 :   case ARM::EndianKind::BIG: {
     339             :     switch (ISA) {
     340             :     case ARM::ISAKind::ARM:
     341             :       arch = Triple::armeb;
     342             :       break;
     343             :     case ARM::ISAKind::THUMB:
     344             :       arch = Triple::thumbeb;
     345             :       break;
     346             :     case ARM::ISAKind::AARCH64:
     347             :       arch = Triple::aarch64_be;
     348             :       break;
     349             :     case ARM::ISAKind::INVALID:
     350             :       break;
     351             :     }
     352             :     break;
     353             :   }
     354             :   case ARM::EndianKind::INVALID: {
     355             :     break;
     356             :   }
     357             :   }
     358             : 
     359       37985 :   ArchName = ARM::getCanonicalArchName(ArchName);
     360       37985 :   if (ArchName.empty())
     361             :     return Triple::UnknownArch;
     362             : 
     363             :   // Thumb only exists in v4+
     364       37958 :   if (ISA == ARM::ISAKind::THUMB &&
     365             :       (ArchName.startswith("v2") || ArchName.startswith("v3")))
     366             :     return Triple::UnknownArch;
     367             : 
     368             :   // Thumb only for v6m
     369       37950 :   ARM::ProfileKind Profile = ARM::parseArchProfile(ArchName);
     370       37950 :   unsigned Version = ARM::parseArchVersion(ArchName);
     371       37950 :   if (Profile == ARM::ProfileKind::M && Version == 6) {
     372        1347 :     if (ENDIAN == ARM::EndianKind::BIG)
     373             :       return Triple::thumbeb;
     374             :     else
     375        1343 :       return Triple::thumb;
     376             :   }
     377             : 
     378             :   return arch;
     379             : }
     380             : 
     381     1590070 : static Triple::ArchType parseArch(StringRef ArchName) {
     382      101757 :   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", "ppc", "ppc32", Triple::ppc)
     388             :     .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64)
     389             :     .Cases("powerpc64le", "ppc64le", Triple::ppc64le)
     390     1590070 :     .Case("xscale", Triple::arm)
     391     1590070 :     .Case("xscaleeb", Triple::armeb)
     392     1590070 :     .Case("aarch64", Triple::aarch64)
     393     1590070 :     .Case("aarch64_be", Triple::aarch64_be)
     394     1590070 :     .Case("arc", Triple::arc)
     395     1590070 :     .Case("arm64", Triple::aarch64)
     396     1590070 :     .Case("arm", Triple::arm)
     397     1590070 :     .Case("armeb", Triple::armeb)
     398     1590070 :     .Case("thumb", Triple::thumb)
     399     1590070 :     .Case("thumbeb", Triple::thumbeb)
     400     1590070 :     .Case("avr", Triple::avr)
     401     1590070 :     .Case("msp430", Triple::msp430)
     402             :     .Cases("mips", "mipseb", "mipsallegrex", "mipsisa32r6",
     403             :            "mipsr6", Triple::mips)
     404             :     .Cases("mipsel", "mipsallegrexel", "mipsisa32r6el", "mipsr6el",
     405             :            Triple::mipsel)
     406             :     .Cases("mips64", "mips64eb", "mipsn32", "mipsisa64r6",
     407             :            "mips64r6", "mipsn32r6", Triple::mips64)
     408             :     .Cases("mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el",
     409             :            "mipsn32r6el", Triple::mips64el)
     410     1590070 :     .Case("nios2", Triple::nios2)
     411     1590070 :     .Case("r600", Triple::r600)
     412     1590070 :     .Case("amdgcn", Triple::amdgcn)
     413     1590070 :     .Case("riscv32", Triple::riscv32)
     414     1590070 :     .Case("riscv64", Triple::riscv64)
     415     1590070 :     .Case("hexagon", Triple::hexagon)
     416             :     .Cases("s390x", "systemz", Triple::systemz)
     417     1590070 :     .Case("sparc", Triple::sparc)
     418     1590070 :     .Case("sparcel", Triple::sparcel)
     419             :     .Cases("sparcv9", "sparc64", Triple::sparcv9)
     420     1590070 :     .Case("tce", Triple::tce)
     421     1590070 :     .Case("tcele", Triple::tcele)
     422     1590070 :     .Case("xcore", Triple::xcore)
     423     1590070 :     .Case("nvptx", Triple::nvptx)
     424     1590070 :     .Case("nvptx64", Triple::nvptx64)
     425     1590070 :     .Case("le32", Triple::le32)
     426     1590070 :     .Case("le64", Triple::le64)
     427     1590070 :     .Case("amdil", Triple::amdil)
     428     1590070 :     .Case("amdil64", Triple::amdil64)
     429     1590070 :     .Case("hsail", Triple::hsail)
     430     1590070 :     .Case("hsail64", Triple::hsail64)
     431     1590070 :     .Case("spir", Triple::spir)
     432     1590070 :     .Case("spir64", Triple::spir64)
     433     1590070 :     .StartsWith("kalimba", Triple::kalimba)
     434     1590070 :     .Case("lanai", Triple::lanai)
     435     1590070 :     .Case("shave", Triple::shave)
     436     1590070 :     .Case("wasm32", Triple::wasm32)
     437     1590070 :     .Case("wasm64", Triple::wasm64)
     438     1590070 :     .Case("renderscript32", Triple::renderscript32)
     439     1590070 :     .Case("renderscript64", Triple::renderscript64)
     440             :     .Default(Triple::UnknownArch);
     441             : 
     442             :   // Some architectures require special parsing logic just to compute the
     443             :   // ArchType result.
     444     1488313 :   if (AT == Triple::UnknownArch) {
     445             :     if (ArchName.startswith("arm") || ArchName.startswith("thumb") ||
     446             :         ArchName.startswith("aarch64"))
     447       37985 :       return parseARMArch(ArchName);
     448             :     if (ArchName.startswith("bpf"))
     449         589 :       return parseBPFArch(ArchName);
     450             :   }
     451             : 
     452             :   return AT;
     453             : }
     454             : 
     455     1584112 : static Triple::VendorType parseVendor(StringRef VendorName) {
     456     1584113 :   return StringSwitch<Triple::VendorType>(VendorName)
     457     1584112 :     .Case("apple", Triple::Apple)
     458     1584112 :     .Case("pc", Triple::PC)
     459     1584112 :     .Case("scei", Triple::SCEI)
     460     1584112 :     .Case("bgp", Triple::BGP)
     461     1584112 :     .Case("bgq", Triple::BGQ)
     462     1584112 :     .Case("fsl", Triple::Freescale)
     463     1584112 :     .Case("ibm", Triple::IBM)
     464     1584112 :     .Case("img", Triple::ImaginationTechnologies)
     465     1584112 :     .Case("mti", Triple::MipsTechnologies)
     466     1584112 :     .Case("nvidia", Triple::NVIDIA)
     467     1584112 :     .Case("csr", Triple::CSR)
     468     1584112 :     .Case("myriad", Triple::Myriad)
     469     1584112 :     .Case("amd", Triple::AMD)
     470     1584112 :     .Case("mesa", Triple::Mesa)
     471     1584112 :     .Case("suse", Triple::SUSE)
     472     1584112 :     .Case("oe", Triple::OpenEmbedded)
     473     1584113 :     .Default(Triple::UnknownVendor);
     474             : }
     475             : 
     476     1548930 : static Triple::OSType parseOS(StringRef OSName) {
     477     1548930 :   return StringSwitch<Triple::OSType>(OSName)
     478     1548930 :     .StartsWith("ananas", Triple::Ananas)
     479     1548930 :     .StartsWith("cloudabi", Triple::CloudABI)
     480     1548930 :     .StartsWith("darwin", Triple::Darwin)
     481     1548930 :     .StartsWith("dragonfly", Triple::DragonFly)
     482     1548930 :     .StartsWith("freebsd", Triple::FreeBSD)
     483     1548930 :     .StartsWith("fuchsia", Triple::Fuchsia)
     484     1548930 :     .StartsWith("ios", Triple::IOS)
     485     1548930 :     .StartsWith("kfreebsd", Triple::KFreeBSD)
     486     1548930 :     .StartsWith("linux", Triple::Linux)
     487     1548930 :     .StartsWith("lv2", Triple::Lv2)
     488     1548930 :     .StartsWith("macos", Triple::MacOSX)
     489     1548930 :     .StartsWith("netbsd", Triple::NetBSD)
     490     1548930 :     .StartsWith("openbsd", Triple::OpenBSD)
     491     1548930 :     .StartsWith("solaris", Triple::Solaris)
     492     1548930 :     .StartsWith("win32", Triple::Win32)
     493     1548930 :     .StartsWith("windows", Triple::Win32)
     494     1548930 :     .StartsWith("haiku", Triple::Haiku)
     495     1548930 :     .StartsWith("minix", Triple::Minix)
     496     1548930 :     .StartsWith("rtems", Triple::RTEMS)
     497     1548930 :     .StartsWith("nacl", Triple::NaCl)
     498     1548930 :     .StartsWith("cnk", Triple::CNK)
     499     1548930 :     .StartsWith("aix", Triple::AIX)
     500     1548930 :     .StartsWith("cuda", Triple::CUDA)
     501     1548930 :     .StartsWith("nvcl", Triple::NVCL)
     502     1548930 :     .StartsWith("amdhsa", Triple::AMDHSA)
     503     1548930 :     .StartsWith("ps4", Triple::PS4)
     504     1548930 :     .StartsWith("elfiamcu", Triple::ELFIAMCU)
     505     1548930 :     .StartsWith("tvos", Triple::TvOS)
     506     1548930 :     .StartsWith("watchos", Triple::WatchOS)
     507     1548930 :     .StartsWith("mesa3d", Triple::Mesa3D)
     508     1548930 :     .StartsWith("contiki", Triple::Contiki)
     509     1548930 :     .StartsWith("amdpal", Triple::AMDPAL)
     510     1548930 :     .StartsWith("hermit", Triple::HermitCore)
     511     1548930 :     .Default(Triple::UnknownOS);
     512             : }
     513             : 
     514     1244079 : static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
     515     1244079 :   return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
     516     1244079 :     .StartsWith("eabihf", Triple::EABIHF)
     517     1244079 :     .StartsWith("eabi", Triple::EABI)
     518     1244079 :     .StartsWith("gnuabin32", Triple::GNUABIN32)
     519     1244079 :     .StartsWith("gnuabi64", Triple::GNUABI64)
     520     1244079 :     .StartsWith("gnueabihf", Triple::GNUEABIHF)
     521     1244079 :     .StartsWith("gnueabi", Triple::GNUEABI)
     522     1244079 :     .StartsWith("gnux32", Triple::GNUX32)
     523     1244079 :     .StartsWith("code16", Triple::CODE16)
     524     1244079 :     .StartsWith("gnu", Triple::GNU)
     525     1244079 :     .StartsWith("android", Triple::Android)
     526     1244079 :     .StartsWith("musleabihf", Triple::MuslEABIHF)
     527     1244079 :     .StartsWith("musleabi", Triple::MuslEABI)
     528     1244079 :     .StartsWith("musl", Triple::Musl)
     529     1244079 :     .StartsWith("msvc", Triple::MSVC)
     530     1244079 :     .StartsWith("itanium", Triple::Itanium)
     531     1244079 :     .StartsWith("cygnus", Triple::Cygnus)
     532     1244079 :     .StartsWith("coreclr", Triple::CoreCLR)
     533     1244079 :     .StartsWith("simulator", Triple::Simulator)
     534     1244079 :     .Default(Triple::UnknownEnvironment);
     535             : }
     536             : 
     537      905362 : static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
     538      905362 :   return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
     539      905362 :     .EndsWith("coff", Triple::COFF)
     540      905362 :     .EndsWith("elf", Triple::ELF)
     541      905362 :     .EndsWith("macho", Triple::MachO)
     542      905362 :     .EndsWith("wasm", Triple::Wasm)
     543      905362 :     .Default(Triple::UnknownObjectFormat);
     544             : }
     545             : 
     546     1189470 : static Triple::SubArchType parseSubArch(StringRef SubArchName) {
     547             :   if (SubArchName.startswith("mips") &&
     548             :       (SubArchName.endswith("r6el") || SubArchName.endswith("r6")))
     549             :     return Triple::MipsSubArch_r6;
     550             : 
     551     1189138 :   StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
     552             : 
     553             :   // For now, this is the small part. Early return.
     554     1189138 :   if (ARMSubArch.empty())
     555       49409 :     return StringSwitch<Triple::SubArchType>(SubArchName)
     556       49409 :       .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
     557       49409 :       .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
     558       49409 :       .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
     559             :       .Default(Triple::NoSubArch);
     560             : 
     561             :   // ARM sub arch.
     562     1139729 :   switch(ARM::parseArch(ARMSubArch)) {
     563             :   case ARM::ArchKind::ARMV4:
     564             :     return Triple::NoSubArch;
     565             :   case ARM::ArchKind::ARMV4T:
     566             :     return Triple::ARMSubArch_v4t;
     567             :   case ARM::ArchKind::ARMV5T:
     568             :     return Triple::ARMSubArch_v5;
     569             :   case ARM::ArchKind::ARMV5TE:
     570             :   case ARM::ArchKind::IWMMXT:
     571             :   case ARM::ArchKind::IWMMXT2:
     572             :   case ARM::ArchKind::XSCALE:
     573             :   case ARM::ArchKind::ARMV5TEJ:
     574             :     return Triple::ARMSubArch_v5te;
     575             :   case ARM::ArchKind::ARMV6:
     576             :     return Triple::ARMSubArch_v6;
     577             :   case ARM::ArchKind::ARMV6K:
     578             :   case ARM::ArchKind::ARMV6KZ:
     579             :     return Triple::ARMSubArch_v6k;
     580             :   case ARM::ArchKind::ARMV6T2:
     581             :     return Triple::ARMSubArch_v6t2;
     582             :   case ARM::ArchKind::ARMV6M:
     583             :     return Triple::ARMSubArch_v6m;
     584             :   case ARM::ArchKind::ARMV7A:
     585             :   case ARM::ArchKind::ARMV7R:
     586             :     return Triple::ARMSubArch_v7;
     587             :   case ARM::ArchKind::ARMV7VE:
     588             :     return Triple::ARMSubArch_v7ve;
     589             :   case ARM::ArchKind::ARMV7K:
     590             :     return Triple::ARMSubArch_v7k;
     591             :   case ARM::ArchKind::ARMV7M:
     592             :     return Triple::ARMSubArch_v7m;
     593             :   case ARM::ArchKind::ARMV7S:
     594             :     return Triple::ARMSubArch_v7s;
     595             :   case ARM::ArchKind::ARMV7EM:
     596             :     return Triple::ARMSubArch_v7em;
     597             :   case ARM::ArchKind::ARMV8A:
     598             :     return Triple::ARMSubArch_v8;
     599             :   case ARM::ArchKind::ARMV8_1A:
     600             :     return Triple::ARMSubArch_v8_1a;
     601             :   case ARM::ArchKind::ARMV8_2A:
     602             :     return Triple::ARMSubArch_v8_2a;
     603             :   case ARM::ArchKind::ARMV8_3A:
     604             :     return Triple::ARMSubArch_v8_3a;
     605             :   case ARM::ArchKind::ARMV8_4A:
     606             :     return Triple::ARMSubArch_v8_4a;
     607             :   case ARM::ArchKind::ARMV8_5A:
     608             :     return Triple::ARMSubArch_v8_5a;
     609             :   case ARM::ArchKind::ARMV8R:
     610             :     return Triple::ARMSubArch_v8r;
     611             :   case ARM::ArchKind::ARMV8MBaseline:
     612             :     return Triple::ARMSubArch_v8m_baseline;
     613             :   case ARM::ArchKind::ARMV8MMainline:
     614             :     return Triple::ARMSubArch_v8m_mainline;
     615             :   default:
     616             :     return Triple::NoSubArch;
     617             :   }
     618             : }
     619             : 
     620         589 : static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
     621         589 :   switch (Kind) {
     622           0 :   case Triple::UnknownObjectFormat: return "";
     623         467 :   case Triple::COFF: return "coff";
     624          20 :   case Triple::ELF: return "elf";
     625         102 :   case Triple::MachO: return "macho";
     626           0 :   case Triple::Wasm: return "wasm";
     627             :   }
     628           0 :   llvm_unreachable("unknown object format type");
     629             : }
     630             : 
     631     1185895 : static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
     632     1185895 :   switch (T.getArch()) {
     633             :   case Triple::UnknownArch:
     634             :   case Triple::aarch64:
     635             :   case Triple::arm:
     636             :   case Triple::thumb:
     637             :   case Triple::x86:
     638             :   case Triple::x86_64:
     639             :     if (T.isOSDarwin())
     640             :       return Triple::MachO;
     641      989970 :     else if (T.isOSWindows())
     642       24544 :       return Triple::COFF;
     643             :     return Triple::ELF;
     644             : 
     645             :   case Triple::aarch64_be:
     646             :   case Triple::arc:
     647             :   case Triple::amdgcn:
     648             :   case Triple::amdil:
     649             :   case Triple::amdil64:
     650             :   case Triple::armeb:
     651             :   case Triple::avr:
     652             :   case Triple::bpfeb:
     653             :   case Triple::bpfel:
     654             :   case Triple::hexagon:
     655             :   case Triple::lanai:
     656             :   case Triple::hsail:
     657             :   case Triple::hsail64:
     658             :   case Triple::kalimba:
     659             :   case Triple::le32:
     660             :   case Triple::le64:
     661             :   case Triple::mips:
     662             :   case Triple::mips64:
     663             :   case Triple::mips64el:
     664             :   case Triple::mipsel:
     665             :   case Triple::msp430:
     666             :   case Triple::nios2:
     667             :   case Triple::nvptx:
     668             :   case Triple::nvptx64:
     669             :   case Triple::ppc64le:
     670             :   case Triple::r600:
     671             :   case Triple::renderscript32:
     672             :   case Triple::renderscript64:
     673             :   case Triple::riscv32:
     674             :   case Triple::riscv64:
     675             :   case Triple::shave:
     676             :   case Triple::sparc:
     677             :   case Triple::sparcel:
     678             :   case Triple::sparcv9:
     679             :   case Triple::spir:
     680             :   case Triple::spir64:
     681             :   case Triple::systemz:
     682             :   case Triple::tce:
     683             :   case Triple::tcele:
     684             :   case Triple::thumbeb:
     685             :   case Triple::xcore:
     686             :     return Triple::ELF;
     687             : 
     688             :   case Triple::ppc:
     689             :   case Triple::ppc64:
     690             :     if (T.isOSDarwin())
     691         137 :       return Triple::MachO;
     692             :     return Triple::ELF;
     693             : 
     694        2902 :   case Triple::wasm32:
     695             :   case Triple::wasm64:
     696        2902 :     return Triple::Wasm;
     697             :   }
     698           0 :   llvm_unreachable("unknown architecture");
     699             : }
     700             : 
     701             : /// Construct a triple from the string representation provided.
     702             : ///
     703             : /// This stores the string representation and parses the various pieces into
     704             : /// enum members.
     705     1189467 : Triple::Triple(const Twine &Str)
     706             :     : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
     707             :       Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
     708     1189467 :       ObjectFormat(UnknownObjectFormat) {
     709             :   // Do minimal parsing by hand here.
     710             :   SmallVector<StringRef, 4> Components;
     711     1189469 :   StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
     712     1189469 :   if (Components.size() > 0) {
     713     1189469 :     Arch = parseArch(Components[0]);
     714     1189468 :     SubArch = parseSubArch(Components[0]);
     715     1189469 :     if (Components.size() > 1) {
     716     1117323 :       Vendor = parseVendor(Components[1]);
     717     1117323 :       if (Components.size() > 2) {
     718     1111820 :         OS = parseOS(Components[2]);
     719     1111820 :         if (Components.size() > 3) {
     720      846629 :           Environment = parseEnvironment(Components[3]);
     721      846629 :           ObjectFormat = parseFormat(Components[3]);
     722             :         }
     723             :       }
     724             :     } else {
     725       72146 :       Environment =
     726       72146 :           StringSwitch<Triple::EnvironmentType>(Components[0])
     727             :               .StartsWith("mipsn32", Triple::GNUABIN32)
     728             :               .StartsWith("mips64", Triple::GNUABI64)
     729             :               .StartsWith("mipsisa64", Triple::GNUABI64)
     730             :               .StartsWith("mipsisa32", Triple::GNU)
     731             :               .Cases("mips", "mipsel", "mipsr6", "mipsr6el", Triple::GNU)
     732             :               .Default(UnknownEnvironment);
     733             :     }
     734             :   }
     735     1189469 :   if (ObjectFormat == UnknownObjectFormat)
     736     1185250 :     ObjectFormat = getDefaultFormat(*this);
     737     1189469 : }
     738             : 
     739             : /// Construct a triple from string representations of the architecture,
     740             : /// vendor, and OS.
     741             : ///
     742             : /// This joins each argument into a canonical string representation and parses
     743             : /// them into enum members. It leaves the environment unknown and omits it from
     744             : /// the string representation.
     745           0 : Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
     746           0 :     : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
     747           0 :       Arch(parseArch(ArchStr.str())),
     748           0 :       SubArch(parseSubArch(ArchStr.str())),
     749           0 :       Vendor(parseVendor(VendorStr.str())),
     750           0 :       OS(parseOS(OSStr.str())),
     751           0 :       Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
     752           0 :   ObjectFormat = getDefaultFormat(*this);
     753           0 : }
     754             : 
     755             : /// Construct a triple from string representations of the architecture,
     756             : /// vendor, OS, and environment.
     757             : ///
     758             : /// This joins each argument into a canonical string representation and parses
     759             : /// them into enum members.
     760           2 : Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
     761           2 :                const Twine &EnvironmentStr)
     762           2 :     : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
     763             :             EnvironmentStr).str()),
     764           2 :       Arch(parseArch(ArchStr.str())),
     765           2 :       SubArch(parseSubArch(ArchStr.str())),
     766           2 :       Vendor(parseVendor(VendorStr.str())),
     767           2 :       OS(parseOS(OSStr.str())),
     768           2 :       Environment(parseEnvironment(EnvironmentStr.str())),
     769          12 :       ObjectFormat(parseFormat(EnvironmentStr.str())) {
     770           2 :   if (ObjectFormat == Triple::UnknownObjectFormat)
     771           2 :     ObjectFormat = getDefaultFormat(*this);
     772           2 : }
     773             : 
     774      391537 : std::string Triple::normalize(StringRef Str) {
     775             :   bool IsMinGW32 = false;
     776             :   bool IsCygwin = false;
     777             : 
     778             :   // Parse into components.
     779             :   SmallVector<StringRef, 4> Components;
     780      391537 :   Str.split(Components, '-');
     781             : 
     782             :   // If the first component corresponds to a known architecture, preferentially
     783             :   // use it for the architecture.  If the second component corresponds to a
     784             :   // known vendor, preferentially use it for the vendor, etc.  This avoids silly
     785             :   // component movement when a component parses as (eg) both a valid arch and a
     786             :   // valid os.
     787             :   ArchType Arch = UnknownArch;
     788      391537 :   if (Components.size() > 0)
     789      391537 :     Arch = parseArch(Components[0]);
     790             :   VendorType Vendor = UnknownVendor;
     791      391537 :   if (Components.size() > 1)
     792      382320 :     Vendor = parseVendor(Components[1]);
     793             :   OSType OS = UnknownOS;
     794      391537 :   if (Components.size() > 2) {
     795      379124 :     OS = parseOS(Components[2]);
     796             :     IsCygwin = Components[2].startswith("cygwin");
     797             :     IsMinGW32 = Components[2].startswith("mingw");
     798             :   }
     799             :   EnvironmentType Environment = UnknownEnvironment;
     800      391537 :   if (Components.size() > 3)
     801      330331 :     Environment = parseEnvironment(Components[3]);
     802             :   ObjectFormatType ObjectFormat = UnknownObjectFormat;
     803      391537 :   if (Components.size() > 4)
     804         454 :     ObjectFormat = parseFormat(Components[4]);
     805             : 
     806             :   // Note which components are already in their final position.  These will not
     807             :   // be moved.
     808             :   bool Found[4];
     809      391537 :   Found[0] = Arch != UnknownArch;
     810      391537 :   Found[1] = Vendor != UnknownVendor;
     811      391537 :   Found[2] = OS != UnknownOS;
     812      391537 :   Found[3] = Environment != UnknownEnvironment;
     813             : 
     814             :   // If they are not there already, permute the components into their canonical
     815             :   // positions by seeing if they parse as a valid architecture, and if so moving
     816             :   // the component to the architecture position etc.
     817     1957685 :   for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
     818     1566148 :     if (Found[Pos])
     819             :       continue; // Already in the canonical position.
     820             : 
     821      619874 :     for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
     822             :       // Do not reparse any components that already matched.
     823      471191 :       if (Idx < array_lengthof(Found) && Found[Idx])
     824             :         continue;
     825             : 
     826             :       // Does this component parse as valid for the target position?
     827             :       bool Valid = false;
     828      218631 :       StringRef Comp = Components[Idx];
     829      218631 :       switch (Pos) {
     830           0 :       default: llvm_unreachable("unexpected component type!");
     831        9063 :       case 0:
     832        9063 :         Arch = parseArch(Comp);
     833        9063 :         Valid = Arch != UnknownArch;
     834        9063 :         break;
     835       84467 :       case 1:
     836       84467 :         Vendor = parseVendor(Comp);
     837       84467 :         Valid = Vendor != UnknownVendor;
     838       84467 :         break;
     839       57984 :       case 2:
     840       57984 :         OS = parseOS(Comp);
     841             :         IsCygwin = Comp.startswith("cygwin");
     842             :         IsMinGW32 = Comp.startswith("mingw");
     843       57984 :         Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
     844             :         break;
     845       67117 :       case 3:
     846       67117 :         Environment = parseEnvironment(Comp);
     847       67117 :         Valid = Environment != UnknownEnvironment;
     848       67117 :         if (!Valid) {
     849       58277 :           ObjectFormat = parseFormat(Comp);
     850       58277 :           Valid = ObjectFormat != UnknownObjectFormat;
     851             :         }
     852             :         break;
     853             :       }
     854      218631 :       if (!Valid)
     855             :         continue; // Nope, try the next component.
     856             : 
     857             :       // Move the component to the target position, pushing any non-fixed
     858             :       // components that are in the way to the right.  This tends to give
     859             :       // good results in the common cases of a forgotten vendor component
     860             :       // or a wrongly positioned environment.
     861       24074 :       if (Pos < Idx) {
     862             :         // Insert left, pushing the existing components to the right.  For
     863             :         // example, a-b-i386 -> i386-a-b when moving i386 to the front.
     864             :         StringRef CurrentComponent(""); // The empty component.
     865             :         // Replace the component we are moving with an empty component.
     866             :         std::swap(CurrentComponent, Components[Idx]);
     867             :         // Insert the component being moved at Pos, displacing any existing
     868             :         // components to the right.
     869       17345 :         for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
     870             :           // Skip over any fixed components.
     871       13304 :           while (i < array_lengthof(Found) && Found[i])
     872        1020 :             ++i;
     873             :           // Place the component at the new position, getting the component
     874             :           // that was at this position - it will be moved right.
     875       12284 :           std::swap(CurrentComponent, Components[i]);
     876             :         }
     877       19013 :       } else if (Pos > Idx) {
     878             :         // Push right by inserting empty components until the component at Idx
     879             :         // reaches the target position Pos.  For example, pc-a -> -pc-a when
     880             :         // moving pc to the second position.
     881             :         do {
     882             :           // Insert one empty component at Idx.
     883             :           StringRef CurrentComponent(""); // The empty component.
     884       24410 :           for (unsigned i = Idx; i < Components.size();) {
     885             :             // Place the component at the new position, getting the component
     886             :             // that was at this position - it will be moved right.
     887             :             std::swap(CurrentComponent, Components[i]);
     888             :             // If it was placed on top of an empty component then we are done.
     889       14820 :             if (CurrentComponent.empty())
     890             :               break;
     891             :             // Advance to the next component, skipping any fixed components.
     892       14855 :             while (++i < array_lengthof(Found) && Found[i])
     893             :               ;
     894             :           }
     895             :           // The last component was pushed off the end - append it.
     896        9594 :           if (!CurrentComponent.empty())
     897        9590 :             Components.push_back(CurrentComponent);
     898             : 
     899             :           // Advance Idx to the component's new position.
     900        9620 :           while (++Idx < array_lengthof(Found) && Found[Idx])
     901             :             ;
     902        9594 :         } while (Idx < Pos); // Add more until the final position is reached.
     903             :       }
     904             :       assert(Pos < Components.size() && Components[Pos] == Comp &&
     905             :              "Component moved wrong!");
     906       24074 :       Found[Pos] = true;
     907             :       break;
     908             :     }
     909             :   }
     910             : 
     911             :   // Replace empty components with "unknown" value.
     912     1884894 :   for (unsigned i = 0, e = Components.size(); i < e; ++i) {
     913     2986714 :     if (Components[i].empty())
     914       15862 :       Components[i] = "unknown";
     915             :   }
     916             : 
     917             :   // Special case logic goes here.  At this point Arch, Vendor and OS have the
     918             :   // correct values for the computed components.
     919             :   std::string NormalizedEnvironment;
     920      391537 :   if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
     921         118 :     StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
     922         118 :     if (AndroidVersion.empty()) {
     923          95 :       Components[3] = "android";
     924             :     } else {
     925          46 :       NormalizedEnvironment = Twine("android", AndroidVersion).str();
     926          23 :       Components[3] = NormalizedEnvironment;
     927             :     }
     928             :   }
     929             : 
     930             :   // SUSE uses "gnueabi" to mean "gnueabihf"
     931      391537 :   if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
     932           5 :     Components[3] = "gnueabihf";
     933             : 
     934      391537 :   if (OS == Triple::Win32) {
     935        5751 :     Components.resize(4);
     936        5751 :     Components[2] = "windows";
     937        5751 :     if (Environment == UnknownEnvironment) {
     938        1137 :       if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
     939        1087 :         Components[3] = "msvc";
     940             :       else
     941          50 :         Components[3] = getObjectFormatTypeName(ObjectFormat);
     942             :     }
     943      385786 :   } else if (IsMinGW32) {
     944         131 :     Components.resize(4);
     945         131 :     Components[2] = "windows";
     946         131 :     Components[3] = "gnu";
     947      385655 :   } else if (IsCygwin) {
     948          28 :     Components.resize(4);
     949          28 :     Components[2] = "windows";
     950          28 :     Components[3] = "cygnus";
     951             :   }
     952      391537 :   if (IsMinGW32 || IsCygwin ||
     953      391378 :       (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
     954        4773 :     if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
     955          12 :       Components.resize(5);
     956          12 :       Components[4] = getObjectFormatTypeName(ObjectFormat);
     957             :     }
     958             :   }
     959             : 
     960             :   // Stick the corrected components back together to form the normalized string.
     961             :   std::string Normalized;
     962     1885733 :   for (unsigned i = 0, e = Components.size(); i != e; ++i) {
     963     1494196 :     if (i) Normalized += '-';
     964     1494196 :     Normalized += Components[i];
     965             :   }
     966      391537 :   return Normalized;
     967             : }
     968             : 
     969       81852 : StringRef Triple::getArchName() const {
     970       81852 :   return StringRef(Data).split('-').first;           // Isolate first component
     971             : }
     972             : 
     973       38648 : StringRef Triple::getVendorName() const {
     974       38648 :   StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
     975       38648 :   return Tmp.split('-').first;                       // Isolate second component
     976             : }
     977             : 
     978      114197 : StringRef Triple::getOSName() const {
     979      114197 :   StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
     980      114197 :   Tmp = Tmp.split('-').second;                       // Strip second component
     981      114197 :   return Tmp.split('-').first;                       // Isolate third component
     982             : }
     983             : 
     984       24691 : StringRef Triple::getEnvironmentName() const {
     985       24691 :   StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
     986       24691 :   Tmp = Tmp.split('-').second;                       // Strip second component
     987       24691 :   return Tmp.split('-').second;                      // Strip third component
     988             : }
     989             : 
     990       41979 : StringRef Triple::getOSAndEnvironmentName() const {
     991       41979 :   StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
     992       41979 :   return Tmp.split('-').second;                      // Strip second component
     993             : }
     994             : 
     995       41971 : static unsigned EatNumber(StringRef &Str) {
     996             :   assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
     997             :   unsigned Result = 0;
     998             : 
     999             :   do {
    1000             :     // Consume the leading digit.
    1001      122416 :     Result = Result*10 + (Str[0] - '0');
    1002             : 
    1003             :     // Eat the digit.
    1004       61208 :     Str = Str.substr(1);
    1005       61208 :   } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
    1006             : 
    1007       41971 :   return Result;
    1008             : }
    1009             : 
    1010       40838 : static void parseVersionFromName(StringRef Name, unsigned &Major,
    1011             :                                  unsigned &Minor, unsigned &Micro) {
    1012             :   // Any unset version defaults to 0.
    1013       40838 :   Major = Minor = Micro = 0;
    1014             : 
    1015             :   // Parse up to three components.
    1016       40838 :   unsigned *Components[3] = {&Major, &Minor, &Micro};
    1017       82809 :   for (unsigned i = 0; i != 3; ++i) {
    1018       74647 :     if (Name.empty() || Name[0] < '0' || Name[0] > '9')
    1019             :       break;
    1020             : 
    1021             :     // Consume the leading number.
    1022       41971 :     *Components[i] = EatNumber(Name);
    1023             : 
    1024             :     // Consume the separator, if present.
    1025             :     if (Name.startswith("."))
    1026       19232 :       Name = Name.substr(1);
    1027             :   }
    1028       40838 : }
    1029             : 
    1030        2830 : void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
    1031             :                                    unsigned &Micro) const {
    1032        2830 :   StringRef EnvironmentName = getEnvironmentName();
    1033        2830 :   StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
    1034             :   if (EnvironmentName.startswith(EnvironmentTypeName))
    1035        2818 :     EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
    1036             : 
    1037        2830 :   parseVersionFromName(EnvironmentName, Major, Minor, Micro);
    1038        2830 : }
    1039             : 
    1040       38008 : void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
    1041             :                           unsigned &Micro) const {
    1042       38008 :   StringRef OSName = getOSName();
    1043             :   // Assume that the OS portion of the triple starts with the canonical name.
    1044       38008 :   StringRef OSTypeName = getOSTypeName(getOS());
    1045             :   if (OSName.startswith(OSTypeName))
    1046       37833 :     OSName = OSName.substr(OSTypeName.size());
    1047         175 :   else if (getOS() == MacOSX)
    1048             :     OSName.consume_front("macos");
    1049             : 
    1050       38008 :   parseVersionFromName(OSName, Major, Minor, Micro);
    1051       38008 : }
    1052             : 
    1053        3670 : bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
    1054             :                               unsigned &Micro) const {
    1055        3670 :   getOSVersion(Major, Minor, Micro);
    1056             : 
    1057        3670 :   switch (getOS()) {
    1058           0 :   default: llvm_unreachable("unexpected OS for Darwin triple");
    1059        2873 :   case Darwin:
    1060             :     // Default to darwin8, i.e., MacOSX 10.4.
    1061        2873 :     if (Major == 0)
    1062         544 :       Major = 8;
    1063             :     // Darwin version numbers are skewed from OS X versions.
    1064        2873 :     if (Major < 4)
    1065             :       return false;
    1066        2871 :     Micro = 0;
    1067        2871 :     Minor = Major - 4;
    1068        2871 :     Major = 10;
    1069        2871 :     break;
    1070         795 :   case MacOSX:
    1071             :     // Default to 10.4.
    1072         795 :     if (Major == 0) {
    1073          50 :       Major = 10;
    1074          50 :       Minor = 4;
    1075             :     }
    1076         795 :     if (Major != 10)
    1077           3 :       return false;
    1078             :     break;
    1079           2 :   case IOS:
    1080             :   case TvOS:
    1081             :   case WatchOS:
    1082             :     // Ignore the version from the triple.  This is only handled because the
    1083             :     // the clang driver combines OS X and IOS support into a common Darwin
    1084             :     // toolchain that wants to know the OS X version number even when targeting
    1085             :     // IOS.
    1086           2 :     Major = 10;
    1087           2 :     Minor = 4;
    1088           2 :     Micro = 0;
    1089           2 :     break;
    1090             :   }
    1091             :   return true;
    1092             : }
    1093             : 
    1094         312 : void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
    1095             :                            unsigned &Micro) const {
    1096         312 :   switch (getOS()) {
    1097           0 :   default: llvm_unreachable("unexpected OS for Darwin triple");
    1098          25 :   case Darwin:
    1099             :   case MacOSX:
    1100             :     // Ignore the version from the triple.  This is only handled because the
    1101             :     // the clang driver combines OS X and IOS support into a common Darwin
    1102             :     // toolchain that wants to know the iOS version number even when targeting
    1103             :     // OS X.
    1104          25 :     Major = 5;
    1105          25 :     Minor = 0;
    1106          25 :     Micro = 0;
    1107          25 :     break;
    1108         287 :   case IOS:
    1109             :   case TvOS:
    1110         287 :     getOSVersion(Major, Minor, Micro);
    1111             :     // Default to 5.0 (or 7.0 for arm64).
    1112         287 :     if (Major == 0)
    1113          56 :       Major = (getArch() == aarch64) ? 7 : 5;
    1114             :     break;
    1115             :   case WatchOS:
    1116             :     llvm_unreachable("conflicting triple info");
    1117             :   }
    1118         312 : }
    1119             : 
    1120          35 : void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
    1121             :                                unsigned &Micro) const {
    1122          35 :   switch (getOS()) {
    1123           0 :   default: llvm_unreachable("unexpected OS for Darwin triple");
    1124           1 :   case Darwin:
    1125             :   case MacOSX:
    1126             :     // Ignore the version from the triple.  This is only handled because the
    1127             :     // the clang driver combines OS X and IOS support into a common Darwin
    1128             :     // toolchain that wants to know the iOS version number even when targeting
    1129             :     // OS X.
    1130           1 :     Major = 2;
    1131           1 :     Minor = 0;
    1132           1 :     Micro = 0;
    1133           1 :     break;
    1134          34 :   case WatchOS:
    1135          34 :     getOSVersion(Major, Minor, Micro);
    1136          34 :     if (Major == 0)
    1137           5 :       Major = 2;
    1138             :     break;
    1139             :   case IOS:
    1140             :     llvm_unreachable("conflicting triple info");
    1141             :   }
    1142          35 : }
    1143             : 
    1144       63091 : void Triple::setTriple(const Twine &Str) {
    1145       63091 :   *this = Triple(Str);
    1146       63091 : }
    1147             : 
    1148       30747 : void Triple::setArch(ArchType Kind) {
    1149       30747 :   setArchName(getArchTypeName(Kind));
    1150       30747 : }
    1151             : 
    1152        1216 : void Triple::setVendor(VendorType Kind) {
    1153        1216 :   setVendorName(getVendorTypeName(Kind));
    1154        1216 : }
    1155             : 
    1156        1253 : void Triple::setOS(OSType Kind) {
    1157        1253 :   setOSName(getOSTypeName(Kind));
    1158        1253 : }
    1159             : 
    1160         643 : void Triple::setEnvironment(EnvironmentType Kind) {
    1161         643 :   if (ObjectFormat == getDefaultFormat(*this))
    1162         643 :     return setEnvironmentName(getEnvironmentTypeName(Kind));
    1163             : 
    1164           0 :   setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
    1165           0 :                       getObjectFormatTypeName(ObjectFormat)).str());
    1166             : }
    1167             : 
    1168         527 : void Triple::setObjectFormat(ObjectFormatType Kind) {
    1169         527 :   if (Environment == UnknownEnvironment)
    1170          60 :     return setEnvironmentName(getObjectFormatTypeName(Kind));
    1171             : 
    1172         934 :   setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
    1173        1401 :                       getObjectFormatTypeName(Kind)).str());
    1174             : }
    1175             : 
    1176       32383 : void Triple::setArchName(StringRef Str) {
    1177             :   // Work around a miscompilation bug for Twines in gcc 4.0.3.
    1178             :   SmallString<64> Triple;
    1179             :   Triple += Str;
    1180             :   Triple += "-";
    1181       32383 :   Triple += getVendorName();
    1182             :   Triple += "-";
    1183       32383 :   Triple += getOSAndEnvironmentName();
    1184       32383 :   setTriple(Triple);
    1185       32383 : }
    1186             : 
    1187        1225 : void Triple::setVendorName(StringRef Str) {
    1188        2450 :   setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
    1189        1225 : }
    1190             : 
    1191        2150 : void Triple::setOSName(StringRef Str) {
    1192             :   if (hasEnvironment())
    1193        1152 :     setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
    1194        1152 :               "-" + getEnvironmentName());
    1195             :   else
    1196        3148 :     setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
    1197        2150 : }
    1198             : 
    1199        2130 : void Triple::setEnvironmentName(StringRef Str) {
    1200        4260 :   setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
    1201        4260 :             "-" + Str);
    1202        2130 : }
    1203             : 
    1204           1 : void Triple::setOSAndEnvironmentName(StringRef Str) {
    1205           2 :   setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
    1206           1 : }
    1207             : 
    1208             : static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
    1209             :   switch (Arch) {
    1210             :   case llvm::Triple::UnknownArch:
    1211             :     return 0;
    1212             : 
    1213             :   case llvm::Triple::avr:
    1214             :   case llvm::Triple::msp430:
    1215             :     return 16;
    1216             : 
    1217             :   case llvm::Triple::arc:
    1218             :   case llvm::Triple::arm:
    1219             :   case llvm::Triple::armeb:
    1220             :   case llvm::Triple::hexagon:
    1221             :   case llvm::Triple::le32:
    1222             :   case llvm::Triple::mips:
    1223             :   case llvm::Triple::mipsel:
    1224             :   case llvm::Triple::nios2:
    1225             :   case llvm::Triple::nvptx:
    1226             :   case llvm::Triple::ppc:
    1227             :   case llvm::Triple::r600:
    1228             :   case llvm::Triple::riscv32:
    1229             :   case llvm::Triple::sparc:
    1230             :   case llvm::Triple::sparcel:
    1231             :   case llvm::Triple::tce:
    1232             :   case llvm::Triple::tcele:
    1233             :   case llvm::Triple::thumb:
    1234             :   case llvm::Triple::thumbeb:
    1235             :   case llvm::Triple::x86:
    1236             :   case llvm::Triple::xcore:
    1237             :   case llvm::Triple::amdil:
    1238             :   case llvm::Triple::hsail:
    1239             :   case llvm::Triple::spir:
    1240             :   case llvm::Triple::kalimba:
    1241             :   case llvm::Triple::lanai:
    1242             :   case llvm::Triple::shave:
    1243             :   case llvm::Triple::wasm32:
    1244             :   case llvm::Triple::renderscript32:
    1245             :     return 32;
    1246             : 
    1247             :   case llvm::Triple::aarch64:
    1248             :   case llvm::Triple::aarch64_be:
    1249             :   case llvm::Triple::amdgcn:
    1250             :   case llvm::Triple::bpfel:
    1251             :   case llvm::Triple::bpfeb:
    1252             :   case llvm::Triple::le64:
    1253             :   case llvm::Triple::mips64:
    1254             :   case llvm::Triple::mips64el:
    1255             :   case llvm::Triple::nvptx64:
    1256             :   case llvm::Triple::ppc64:
    1257             :   case llvm::Triple::ppc64le:
    1258             :   case llvm::Triple::riscv64:
    1259             :   case llvm::Triple::sparcv9:
    1260             :   case llvm::Triple::systemz:
    1261             :   case llvm::Triple::x86_64:
    1262             :   case llvm::Triple::amdil64:
    1263             :   case llvm::Triple::hsail64:
    1264             :   case llvm::Triple::spir64:
    1265             :   case llvm::Triple::wasm64:
    1266             :   case llvm::Triple::renderscript64:
    1267             :     return 64;
    1268             :   }
    1269           0 :   llvm_unreachable("Invalid architecture value");
    1270             : }
    1271             : 
    1272      316683 : bool Triple::isArch64Bit() const {
    1273      316683 :   return getArchPointerBitWidth(getArch()) == 64;
    1274             : }
    1275             : 
    1276      243102 : bool Triple::isArch32Bit() const {
    1277      243102 :   return getArchPointerBitWidth(getArch()) == 32;
    1278             : }
    1279             : 
    1280          73 : bool Triple::isArch16Bit() const {
    1281          73 :   return getArchPointerBitWidth(getArch()) == 16;
    1282             : }
    1283             : 
    1284       20247 : Triple Triple::get32BitArchVariant() const {
    1285       20247 :   Triple T(*this);
    1286       20247 :   switch (getArch()) {
    1287         176 :   case Triple::UnknownArch:
    1288             :   case Triple::amdgcn:
    1289             :   case Triple::avr:
    1290             :   case Triple::bpfel:
    1291             :   case Triple::bpfeb:
    1292             :   case Triple::msp430:
    1293             :   case Triple::systemz:
    1294             :   case Triple::ppc64le:
    1295         176 :     T.setArch(UnknownArch);
    1296         176 :     break;
    1297             : 
    1298             :   case Triple::amdil:
    1299             :   case Triple::hsail:
    1300             :   case Triple::spir:
    1301             :   case Triple::arc:
    1302             :   case Triple::arm:
    1303             :   case Triple::armeb:
    1304             :   case Triple::hexagon:
    1305             :   case Triple::kalimba:
    1306             :   case Triple::le32:
    1307             :   case Triple::mips:
    1308             :   case Triple::mipsel:
    1309             :   case Triple::nios2:
    1310             :   case Triple::nvptx:
    1311             :   case Triple::ppc:
    1312             :   case Triple::r600:
    1313             :   case Triple::riscv32:
    1314             :   case Triple::sparc:
    1315             :   case Triple::sparcel:
    1316             :   case Triple::tce:
    1317             :   case Triple::tcele:
    1318             :   case Triple::thumb:
    1319             :   case Triple::thumbeb:
    1320             :   case Triple::x86:
    1321             :   case Triple::xcore:
    1322             :   case Triple::lanai:
    1323             :   case Triple::shave:
    1324             :   case Triple::wasm32:
    1325             :   case Triple::renderscript32:
    1326             :     // Already 32-bit.
    1327             :     break;
    1328             : 
    1329         140 :   case Triple::aarch64:        T.setArch(Triple::arm);     break;
    1330           9 :   case Triple::aarch64_be:     T.setArch(Triple::armeb);   break;
    1331           1 :   case Triple::le64:           T.setArch(Triple::le32);    break;
    1332         103 :   case Triple::mips64:         T.setArch(Triple::mips);    break;
    1333          78 :   case Triple::mips64el:       T.setArch(Triple::mipsel);  break;
    1334           1 :   case Triple::nvptx64:        T.setArch(Triple::nvptx);   break;
    1335         110 :   case Triple::ppc64:          T.setArch(Triple::ppc);     break;
    1336          22 :   case Triple::sparcv9:        T.setArch(Triple::sparc);   break;
    1337          53 :   case Triple::riscv64:        T.setArch(Triple::riscv32); break;
    1338       19410 :   case Triple::x86_64:         T.setArch(Triple::x86);     break;
    1339           1 :   case Triple::amdil64:        T.setArch(Triple::amdil);   break;
    1340           1 :   case Triple::hsail64:        T.setArch(Triple::hsail);   break;
    1341           1 :   case Triple::spir64:         T.setArch(Triple::spir);    break;
    1342           5 :   case Triple::wasm64:         T.setArch(Triple::wasm32);  break;
    1343           1 :   case Triple::renderscript64: T.setArch(Triple::renderscript32); break;
    1344             :   }
    1345       20247 :   return T;
    1346             : }
    1347             : 
    1348        1551 : Triple Triple::get64BitArchVariant() const {
    1349        1551 :   Triple T(*this);
    1350        1551 :   switch (getArch()) {
    1351         100 :   case Triple::UnknownArch:
    1352             :   case Triple::arc:
    1353             :   case Triple::avr:
    1354             :   case Triple::hexagon:
    1355             :   case Triple::kalimba:
    1356             :   case Triple::lanai:
    1357             :   case Triple::msp430:
    1358             :   case Triple::nios2:
    1359             :   case Triple::r600:
    1360             :   case Triple::tce:
    1361             :   case Triple::tcele:
    1362             :   case Triple::xcore:
    1363             :   case Triple::sparcel:
    1364             :   case Triple::shave:
    1365         100 :     T.setArch(UnknownArch);
    1366         100 :     break;
    1367             : 
    1368             :   case Triple::aarch64:
    1369             :   case Triple::aarch64_be:
    1370             :   case Triple::bpfel:
    1371             :   case Triple::bpfeb:
    1372             :   case Triple::le64:
    1373             :   case Triple::amdil64:
    1374             :   case Triple::amdgcn:
    1375             :   case Triple::hsail64:
    1376             :   case Triple::spir64:
    1377             :   case Triple::mips64:
    1378             :   case Triple::mips64el:
    1379             :   case Triple::nvptx64:
    1380             :   case Triple::ppc64:
    1381             :   case Triple::ppc64le:
    1382             :   case Triple::riscv64:
    1383             :   case Triple::sparcv9:
    1384             :   case Triple::systemz:
    1385             :   case Triple::x86_64:
    1386             :   case Triple::wasm64:
    1387             :   case Triple::renderscript64:
    1388             :     // Already 64-bit.
    1389             :     break;
    1390             : 
    1391         235 :   case Triple::arm:             T.setArch(Triple::aarch64);    break;
    1392          17 :   case Triple::armeb:           T.setArch(Triple::aarch64_be); break;
    1393           1 :   case Triple::le32:            T.setArch(Triple::le64);       break;
    1394         264 :   case Triple::mips:            T.setArch(Triple::mips64);     break;
    1395         104 :   case Triple::mipsel:          T.setArch(Triple::mips64el);   break;
    1396           1 :   case Triple::nvptx:           T.setArch(Triple::nvptx64);    break;
    1397          26 :   case Triple::ppc:             T.setArch(Triple::ppc64);      break;
    1398          36 :   case Triple::sparc:           T.setArch(Triple::sparcv9);    break;
    1399          97 :   case Triple::riscv32:         T.setArch(Triple::riscv64);    break;
    1400         498 :   case Triple::x86:             T.setArch(Triple::x86_64);     break;
    1401           1 :   case Triple::amdil:           T.setArch(Triple::amdil64);    break;
    1402           1 :   case Triple::hsail:           T.setArch(Triple::hsail64);    break;
    1403           1 :   case Triple::spir:            T.setArch(Triple::spir64);     break;
    1404          13 :   case Triple::thumb:           T.setArch(Triple::aarch64);    break;
    1405          12 :   case Triple::thumbeb:         T.setArch(Triple::aarch64_be); break;
    1406           5 :   case Triple::wasm32:          T.setArch(Triple::wasm64);     break;
    1407           1 :   case Triple::renderscript32:  T.setArch(Triple::renderscript64);     break;
    1408             :   }
    1409        1551 :   return T;
    1410             : }
    1411             : 
    1412         167 : Triple Triple::getBigEndianArchVariant() const {
    1413         167 :   Triple T(*this);
    1414             :   // Already big endian.
    1415         167 :   if (!isLittleEndian())
    1416             :     return T;
    1417          98 :   switch (getArch()) {
    1418          46 :   case Triple::UnknownArch:
    1419             :   case Triple::amdgcn:
    1420             :   case Triple::amdil64:
    1421             :   case Triple::amdil:
    1422             :   case Triple::avr:
    1423             :   case Triple::hexagon:
    1424             :   case Triple::hsail64:
    1425             :   case Triple::hsail:
    1426             :   case Triple::kalimba:
    1427             :   case Triple::le32:
    1428             :   case Triple::le64:
    1429             :   case Triple::msp430:
    1430             :   case Triple::nios2:
    1431             :   case Triple::nvptx64:
    1432             :   case Triple::nvptx:
    1433             :   case Triple::r600:
    1434             :   case Triple::riscv32:
    1435             :   case Triple::riscv64:
    1436             :   case Triple::shave:
    1437             :   case Triple::spir64:
    1438             :   case Triple::spir:
    1439             :   case Triple::wasm32:
    1440             :   case Triple::wasm64:
    1441             :   case Triple::x86:
    1442             :   case Triple::x86_64:
    1443             :   case Triple::xcore:
    1444             :   case Triple::renderscript32:
    1445             :   case Triple::renderscript64:
    1446             : 
    1447             :   // ARM is intentionally unsupported here, changing the architecture would
    1448             :   // drop any arch suffixes.
    1449             :   case Triple::arm:
    1450             :   case Triple::thumb:
    1451          46 :     T.setArch(UnknownArch);
    1452          46 :     break;
    1453             : 
    1454           1 :   case Triple::tcele:   T.setArch(Triple::tce);        break;
    1455          42 :   case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
    1456           1 :   case Triple::bpfel:   T.setArch(Triple::bpfeb);      break;
    1457           2 :   case Triple::mips64el:T.setArch(Triple::mips64);     break;
    1458           3 :   case Triple::mipsel:  T.setArch(Triple::mips);       break;
    1459           2 :   case Triple::ppc64le: T.setArch(Triple::ppc64);      break;
    1460           1 :   case Triple::sparcel: T.setArch(Triple::sparc);      break;
    1461           0 :   default:
    1462           0 :     llvm_unreachable("getBigEndianArchVariant: unknown triple.");
    1463             :   }
    1464             :   return T;
    1465             : }
    1466             : 
    1467         197 : Triple Triple::getLittleEndianArchVariant() const {
    1468         197 :   Triple T(*this);
    1469         197 :   if (isLittleEndian())
    1470             :     return T;
    1471             : 
    1472          74 :   switch (getArch()) {
    1473          10 :   case Triple::UnknownArch:
    1474             :   case Triple::lanai:
    1475             :   case Triple::ppc:
    1476             :   case Triple::sparcv9:
    1477             :   case Triple::systemz:
    1478             : 
    1479             :   // ARM is intentionally unsupported here, changing the architecture would
    1480             :   // drop any arch suffixes.
    1481             :   case Triple::armeb:
    1482             :   case Triple::thumbeb:
    1483          10 :     T.setArch(UnknownArch);
    1484          10 :     break;
    1485             : 
    1486           1 :   case Triple::tce:        T.setArch(Triple::tcele);    break;
    1487          35 :   case Triple::aarch64_be: T.setArch(Triple::aarch64);  break;
    1488           1 :   case Triple::bpfeb:      T.setArch(Triple::bpfel);    break;
    1489           6 :   case Triple::mips64:     T.setArch(Triple::mips64el); break;
    1490          18 :   case Triple::mips:       T.setArch(Triple::mipsel);   break;
    1491           2 :   case Triple::ppc64:      T.setArch(Triple::ppc64le);  break;
    1492           1 :   case Triple::sparc:      T.setArch(Triple::sparcel);  break;
    1493           0 :   default:
    1494           0 :     llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
    1495             :   }
    1496             :   return T;
    1497             : }
    1498             : 
    1499       47581 : bool Triple::isLittleEndian() const {
    1500       47581 :   switch (getArch()) {
    1501             :   case Triple::aarch64:
    1502             :   case Triple::amdgcn:
    1503             :   case Triple::amdil64:
    1504             :   case Triple::amdil:
    1505             :   case Triple::arm:
    1506             :   case Triple::avr:
    1507             :   case Triple::bpfel:
    1508             :   case Triple::hexagon:
    1509             :   case Triple::hsail64:
    1510             :   case Triple::hsail:
    1511             :   case Triple::kalimba:
    1512             :   case Triple::le32:
    1513             :   case Triple::le64:
    1514             :   case Triple::mips64el:
    1515             :   case Triple::mipsel:
    1516             :   case Triple::msp430:
    1517             :   case Triple::nios2:
    1518             :   case Triple::nvptx64:
    1519             :   case Triple::nvptx:
    1520             :   case Triple::ppc64le:
    1521             :   case Triple::r600:
    1522             :   case Triple::riscv32:
    1523             :   case Triple::riscv64:
    1524             :   case Triple::shave:
    1525             :   case Triple::sparcel:
    1526             :   case Triple::spir64:
    1527             :   case Triple::spir:
    1528             :   case Triple::thumb:
    1529             :   case Triple::wasm32:
    1530             :   case Triple::wasm64:
    1531             :   case Triple::x86:
    1532             :   case Triple::x86_64:
    1533             :   case Triple::xcore:
    1534             :   case Triple::tcele:
    1535             :   case Triple::renderscript32:
    1536             :   case Triple::renderscript64:
    1537             :     return true;
    1538             :   default:
    1539             :     return false;
    1540             :   }
    1541             : }
    1542             : 
    1543         604 : bool Triple::isCompatibleWith(const Triple &Other) const {
    1544             :   // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
    1545         604 :   if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
    1546         601 :       (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
    1547        1205 :       (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) ||
    1548           0 :       (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) {
    1549           3 :     if (getVendor() == Triple::Apple)
    1550           0 :       return getSubArch() == Other.getSubArch() &&
    1551           0 :              getVendor() == Other.getVendor() && getOS() == Other.getOS();
    1552             :     else
    1553           6 :       return getSubArch() == Other.getSubArch() &&
    1554           3 :              getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
    1555           6 :              getEnvironment() == Other.getEnvironment() &&
    1556           3 :              getObjectFormat() == Other.getObjectFormat();
    1557             :   }
    1558             : 
    1559             :   // If vendor is apple, ignore the version number.
    1560         601 :   if (getVendor() == Triple::Apple)
    1561          67 :     return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
    1562         135 :            getVendor() == Other.getVendor() && getOS() == Other.getOS();
    1563             : 
    1564             :   return *this == Other;
    1565             : }
    1566             : 
    1567        1099 : std::string Triple::merge(const Triple &Other) const {
    1568             :   // If vendor is apple, pick the triple with the larger version number.
    1569        1099 :   if (getVendor() == Triple::Apple)
    1570          68 :     if (Other.isOSVersionLT(*this))
    1571             :       return str();
    1572             : 
    1573             :   return Other.str();
    1574             : }
    1575             : 
    1576        2985 : StringRef Triple::getARMCPUForArch(StringRef MArch) const {
    1577        2985 :   if (MArch.empty())
    1578          14 :     MArch = getArchName();
    1579        2985 :   MArch = ARM::getCanonicalArchName(MArch);
    1580             : 
    1581             :   // Some defaults are forced.
    1582        2985 :   switch (getOS()) {
    1583             :   case llvm::Triple::FreeBSD:
    1584             :   case llvm::Triple::NetBSD:
    1585         182 :     if (!MArch.empty() && MArch == "v6")
    1586           7 :       return "arm1176jzf-s";
    1587             :     break;
    1588             :   case llvm::Triple::Win32:
    1589             :     // FIXME: this is invalid for WindowsCE
    1590         195 :     return "cortex-a9";
    1591             :   case llvm::Triple::MacOSX:
    1592             :   case llvm::Triple::IOS:
    1593             :   case llvm::Triple::WatchOS:
    1594             :   case llvm::Triple::TvOS:
    1595             :     if (MArch == "v7k")
    1596         107 :       return "cortex-a7";
    1597             :     break;
    1598             :   default:
    1599             :     break;
    1600             :   }
    1601             : 
    1602        2676 :   if (MArch.empty())
    1603           3 :     return StringRef();
    1604             : 
    1605        2673 :   StringRef CPU = ARM::getDefaultCPU(MArch);
    1606        2673 :   if (!CPU.empty() && !CPU.equals("invalid"))
    1607        2228 :     return CPU;
    1608             : 
    1609             :   // If no specific architecture version is requested, return the minimum CPU
    1610             :   // required by the OS and environment.
    1611         445 :   switch (getOS()) {
    1612          56 :   case llvm::Triple::NetBSD:
    1613          56 :     switch (getEnvironment()) {
    1614             :     case llvm::Triple::GNUEABIHF:
    1615             :     case llvm::Triple::GNUEABI:
    1616             :     case llvm::Triple::EABIHF:
    1617             :     case llvm::Triple::EABI:
    1618          50 :       return "arm926ej-s";
    1619             :     default:
    1620           6 :       return "strongarm";
    1621             :     }
    1622             :   case llvm::Triple::NaCl:
    1623             :   case llvm::Triple::OpenBSD:
    1624          13 :     return "cortex-a8";
    1625         376 :   default:
    1626         376 :     switch (getEnvironment()) {
    1627             :     case llvm::Triple::EABIHF:
    1628             :     case llvm::Triple::GNUEABIHF:
    1629             :     case llvm::Triple::MuslEABIHF:
    1630          35 :       return "arm1176jzf-s";
    1631             :     default:
    1632         341 :       return "arm7tdmi";
    1633             :     }
    1634             :   }
    1635             : 
    1636             :   llvm_unreachable("invalid arch name");
    1637             : }

Generated by: LCOV version 1.13