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

Generated by: LCOV version 1.13