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

Generated by: LCOV version 1.13