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

Generated by: LCOV version 1.13