LCOV - code coverage report
Current view: top level - lib/Support - Triple.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 611 664 92.0 %
Date: 2018-07-13 00:08:38 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       44877 : StringRef Triple::getArchTypeName(ArchType Kind) {
      21       44877 :   switch (Kind) {
      22         354 :   case UnknownArch:    return "unknown";
      23             : 
      24        1484 :   case aarch64:        return "aarch64";
      25         174 :   case aarch64_be:     return "aarch64_be";
      26        1437 :   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        1130 :   case hexagon:        return "hexagon";
      33        1227 :   case mips:           return "mips";
      34         946 :   case mipsel:         return "mipsel";
      35         770 :   case mips64:         return "mips64";
      36         458 :   case mips64el:       return "mips64el";
      37          35 :   case msp430:         return "msp430";
      38          10 :   case nios2:          return "nios2";
      39         231 :   case ppc64:          return "powerpc64";
      40         213 :   case ppc64le:        return "powerpc64le";
      41         186 :   case ppc:            return "powerpc";
      42         369 :   case r600:           return "r600";
      43        2120 :   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       16258 :   case x86:            return "i386";
      55       15705 :   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       22541 : StringRef Triple::getArchTypePrefix(ArchType Kind) {
      80       22541 :   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        1721 :   case thumbeb:     return "arm";
      93             : 
      94           0 :   case avr:         return "avr";
      95             : 
      96             :   case ppc64:
      97             :   case ppc64le:
      98        4268 :   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        8353 :   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        4845 : StringRef Triple::getVendorTypeName(VendorType Kind) {
     153        4845 :   switch (Kind) {
     154        4286 :   case UnknownVendor: return "unknown";
     155             : 
     156          87 :   case Apple: return "apple";
     157         452 :   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           1 :   case OpenEmbedded: return "oe";
     172             :   }
     173             : 
     174           0 :   llvm_unreachable("Invalid VendorType!");
     175             : }
     176             : 
     177       44602 : StringRef Triple::getOSTypeName(OSType Kind) {
     178       44602 :   switch (Kind) {
     179         852 :   case UnknownOS: return "unknown";
     180             : 
     181           2 :   case Ananas: return "ananas";
     182           1 :   case CloudABI: return "cloudabi";
     183       24819 :   case Darwin: return "darwin";
     184           1 :   case DragonFly: return "dragonfly";
     185         226 :   case FreeBSD: return "freebsd";
     186           1 :   case Fuchsia: return "fuchsia";
     187        5437 :   case IOS: return "ios";
     188           1 :   case KFreeBSD: return "kfreebsd";
     189        3925 :   case Linux: return "linux";
     190           1 :   case Lv2: return "lv2";
     191        8114 :   case MacOSX: return "macosx";
     192         240 :   case NetBSD: return "netbsd";
     193           1 :   case OpenBSD: return "openbsd";
     194           1 :   case Solaris: return "solaris";
     195         545 :   case Win32: return "windows";
     196           1 :   case Haiku: return "haiku";
     197           1 :   case Minix: return "minix";
     198           1 :   case RTEMS: return "rtems";
     199           1 :   case NaCl: return "nacl";
     200           1 :   case CNK: return "cnk";
     201           1 :   case AIX: return "aix";
     202           1 :   case CUDA: return "cuda";
     203           1 :   case NVCL: return "nvcl";
     204           1 :   case AMDHSA: return "amdhsa";
     205           1 :   case PS4: return "ps4";
     206           9 :   case ELFIAMCU: return "elfiamcu";
     207         208 :   case TvOS: return "tvos";
     208         205 :   case WatchOS: return "watchos";
     209           1 :   case Mesa3D: return "mesa3d";
     210           1 :   case Contiki: return "contiki";
     211           1 :   case AMDPAL: return "amdpal";
     212             :   }
     213             : 
     214           0 :   llvm_unreachable("Invalid OSType");
     215             : }
     216             : 
     217        3231 : StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
     218        3231 :   switch (Kind) {
     219          33 :   case UnknownEnvironment: return "unknown";
     220           5 :   case GNU: return "gnu";
     221           1 :   case GNUABIN32: return "gnuabin32";
     222           1 :   case GNUABI64: return "gnuabi64";
     223           4 :   case GNUEABIHF: return "gnueabihf";
     224           1 :   case GNUEABI: return "gnueabi";
     225           3 :   case GNUX32: return "gnux32";
     226           2 :   case CODE16: return "code16";
     227           1 :   case EABI: return "eabi";
     228           1 :   case EABIHF: return "eabihf";
     229         755 :   case Android: return "android";
     230           1 :   case Musl: return "musl";
     231           1 :   case MuslEABI: return "musleabi";
     232           1 :   case MuslEABIHF: return "musleabihf";
     233        2348 :   case MSVC: return "msvc";
     234           1 :   case Itanium: return "itanium";
     235           1 :   case Cygnus: return "cygnus";
     236           1 :   case CoreCLR: return "coreclr";
     237          70 :   case Simulator: return "simulator";
     238             :   }
     239             : 
     240           0 :   llvm_unreachable("Invalid EnvironmentType!");
     241             : }
     242             : 
     243        6359 : static Triple::ArchType parseBPFArch(StringRef ArchName) {
     244             :   if (ArchName.equals("bpf")) {
     245             :     if (sys::IsLittleEndianHost)
     246             :       return Triple::bpfel;
     247             :     else
     248             :       return Triple::bpfeb;
     249             :   } else if (ArchName.equals("bpf_be") || ArchName.equals("bpfeb")) {
     250             :     return Triple::bpfeb;
     251             :   } else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) {
     252             :     return Triple::bpfel;
     253             :   } else {
     254             :     return Triple::UnknownArch;
     255             :   }
     256             : }
     257             : 
     258        5797 : Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
     259        5797 :   Triple::ArchType BPFArch(parseBPFArch(Name));
     260        5797 :   return StringSwitch<Triple::ArchType>(Name)
     261             :     .Case("aarch64", aarch64)
     262             :     .Case("aarch64_be", aarch64_be)
     263             :     .Case("arc", arc)
     264             :     .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
     265             :     .Case("arm", arm)
     266             :     .Case("armeb", armeb)
     267             :     .Case("avr", avr)
     268             :     .StartsWith("bpf", BPFArch)
     269             :     .Case("mips", mips)
     270             :     .Case("mipsel", mipsel)
     271             :     .Case("mips64", mips64)
     272             :     .Case("mips64el", mips64el)
     273             :     .Case("msp430", msp430)
     274             :     .Case("nios2", nios2)
     275             :     .Case("ppc64", ppc64)
     276             :     .Case("ppc32", ppc)
     277             :     .Case("ppc", ppc)
     278             :     .Case("ppc64le", ppc64le)
     279             :     .Case("r600", r600)
     280             :     .Case("amdgcn", amdgcn)
     281             :     .Case("riscv32", riscv32)
     282             :     .Case("riscv64", riscv64)
     283             :     .Case("hexagon", hexagon)
     284             :     .Case("sparc", sparc)
     285             :     .Case("sparcel", sparcel)
     286             :     .Case("sparcv9", sparcv9)
     287             :     .Case("systemz", systemz)
     288             :     .Case("tce", tce)
     289             :     .Case("tcele", tcele)
     290             :     .Case("thumb", thumb)
     291             :     .Case("thumbeb", thumbeb)
     292             :     .Case("x86", x86)
     293             :     .Case("x86-64", x86_64)
     294             :     .Case("xcore", xcore)
     295             :     .Case("nvptx", nvptx)
     296             :     .Case("nvptx64", nvptx64)
     297             :     .Case("le32", le32)
     298             :     .Case("le64", le64)
     299             :     .Case("amdil", amdil)
     300             :     .Case("amdil64", amdil64)
     301             :     .Case("hsail", hsail)
     302             :     .Case("hsail64", hsail64)
     303             :     .Case("spir", spir)
     304             :     .Case("spir64", spir64)
     305             :     .Case("kalimba", kalimba)
     306             :     .Case("lanai", lanai)
     307             :     .Case("shave", shave)
     308             :     .Case("wasm32", wasm32)
     309             :     .Case("wasm64", wasm64)
     310             :     .Case("renderscript32", renderscript32)
     311             :     .Case("renderscript64", renderscript64)
     312        5797 :     .Default(UnknownArch);
     313             : }
     314             : 
     315       37400 : static Triple::ArchType parseARMArch(StringRef ArchName) {
     316       37400 :   ARM::ISAKind ISA = ARM::parseArchISA(ArchName);
     317       37400 :   ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName);
     318             : 
     319             :   Triple::ArchType arch = Triple::UnknownArch;
     320       37400 :   switch (ENDIAN) {
     321       36596 :   case ARM::EndianKind::LITTLE: {
     322       36596 :     switch (ISA) {
     323             :     case ARM::ISAKind::ARM:
     324             :       arch = Triple::arm;
     325             :       break;
     326             :     case ARM::ISAKind::THUMB:
     327             :       arch = Triple::thumb;
     328             :       break;
     329             :     case ARM::ISAKind::AARCH64:
     330             :       arch = Triple::aarch64;
     331             :       break;
     332             :     case ARM::ISAKind::INVALID:
     333             :       break;
     334             :     }
     335             :     break;
     336             :   }
     337         804 :   case ARM::EndianKind::BIG: {
     338         804 :     switch (ISA) {
     339             :     case ARM::ISAKind::ARM:
     340             :       arch = Triple::armeb;
     341             :       break;
     342             :     case ARM::ISAKind::THUMB:
     343             :       arch = Triple::thumbeb;
     344             :       break;
     345             :     case ARM::ISAKind::AARCH64:
     346             :       arch = Triple::aarch64_be;
     347             :       break;
     348             :     case ARM::ISAKind::INVALID:
     349             :       break;
     350             :     }
     351             :     break;
     352             :   }
     353             :   case ARM::EndianKind::INVALID: {
     354             :     break;
     355             :   }
     356             :   }
     357             : 
     358       37400 :   ArchName = ARM::getCanonicalArchName(ArchName);
     359       37400 :   if (ArchName.empty())
     360             :     return Triple::UnknownArch;
     361             : 
     362             :   // Thumb only exists in v4+
     363       37373 :   if (ISA == ARM::ISAKind::THUMB &&
     364             :       (ArchName.startswith("v2") || ArchName.startswith("v3")))
     365             :     return Triple::UnknownArch;
     366             : 
     367             :   // Thumb only for v6m
     368       37365 :   ARM::ProfileKind Profile = ARM::parseArchProfile(ArchName);
     369       37365 :   unsigned Version = ARM::parseArchVersion(ArchName);
     370       37365 :   if (Profile == ARM::ProfileKind::M && Version == 6) {
     371        1267 :     if (ENDIAN == ARM::EndianKind::BIG)
     372             :       return Triple::thumbeb;
     373             :     else
     374        1263 :       return Triple::thumb;
     375             :   }
     376             : 
     377             :   return arch;
     378             : }
     379             : 
     380     1374468 : static Triple::ArchType parseArch(StringRef ArchName) {
     381     1374469 :   auto AT = StringSwitch<Triple::ArchType>(ArchName)
     382             :     .Cases("i386", "i486", "i586", "i686", Triple::x86)
     383             :     // FIXME: Do we need to support these?
     384             :     .Cases("i786", "i886", "i986", Triple::x86)
     385             :     .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
     386             :     .Cases("powerpc", "ppc", "ppc32", Triple::ppc)
     387             :     .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64)
     388             :     .Cases("powerpc64le", "ppc64le", Triple::ppc64le)
     389             :     .Case("xscale", Triple::arm)
     390             :     .Case("xscaleeb", Triple::armeb)
     391             :     .Case("aarch64", Triple::aarch64)
     392             :     .Case("aarch64_be", Triple::aarch64_be)
     393             :     .Case("arc", Triple::arc)
     394             :     .Case("arm64", Triple::aarch64)
     395             :     .Case("arm", Triple::arm)
     396             :     .Case("armeb", Triple::armeb)
     397             :     .Case("thumb", Triple::thumb)
     398             :     .Case("thumbeb", Triple::thumbeb)
     399             :     .Case("avr", Triple::avr)
     400             :     .Case("msp430", Triple::msp430)
     401             :     .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
     402             :     .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
     403             :     .Cases("mips64", "mips64eb", Triple::mips64)
     404             :     .Case("mips64el", Triple::mips64el)
     405             :     .Case("nios2", Triple::nios2)
     406             :     .Case("r600", Triple::r600)
     407             :     .Case("amdgcn", Triple::amdgcn)
     408             :     .Case("riscv32", Triple::riscv32)
     409             :     .Case("riscv64", Triple::riscv64)
     410             :     .Case("hexagon", Triple::hexagon)
     411             :     .Cases("s390x", "systemz", Triple::systemz)
     412             :     .Case("sparc", Triple::sparc)
     413             :     .Case("sparcel", Triple::sparcel)
     414             :     .Cases("sparcv9", "sparc64", Triple::sparcv9)
     415             :     .Case("tce", Triple::tce)
     416             :     .Case("tcele", Triple::tcele)
     417             :     .Case("xcore", Triple::xcore)
     418             :     .Case("nvptx", Triple::nvptx)
     419             :     .Case("nvptx64", Triple::nvptx64)
     420             :     .Case("le32", Triple::le32)
     421             :     .Case("le64", Triple::le64)
     422             :     .Case("amdil", Triple::amdil)
     423             :     .Case("amdil64", Triple::amdil64)
     424             :     .Case("hsail", Triple::hsail)
     425             :     .Case("hsail64", Triple::hsail64)
     426             :     .Case("spir", Triple::spir)
     427             :     .Case("spir64", Triple::spir64)
     428             :     .StartsWith("kalimba", Triple::kalimba)
     429             :     .Case("lanai", Triple::lanai)
     430             :     .Case("shave", Triple::shave)
     431             :     .Case("wasm32", Triple::wasm32)
     432             :     .Case("wasm64", Triple::wasm64)
     433             :     .Case("renderscript32", Triple::renderscript32)
     434             :     .Case("renderscript64", Triple::renderscript64)
     435             :     .Default(Triple::UnknownArch);
     436             : 
     437             :   // Some architectures require special parsing logic just to compute the
     438             :   // ArchType result.
     439     1174449 :   if (AT == Triple::UnknownArch) {
     440             :     if (ArchName.startswith("arm") || ArchName.startswith("thumb") ||
     441             :         ArchName.startswith("aarch64"))
     442       37400 :       return parseARMArch(ArchName);
     443             :     if (ArchName.startswith("bpf"))
     444         562 :       return parseBPFArch(ArchName);
     445             :   }
     446             : 
     447             :   return AT;
     448             : }
     449             : 
     450     1309696 : static Triple::VendorType parseVendor(StringRef VendorName) {
     451     1309694 :   return StringSwitch<Triple::VendorType>(VendorName)
     452             :     .Case("apple", Triple::Apple)
     453             :     .Case("pc", Triple::PC)
     454             :     .Case("scei", Triple::SCEI)
     455             :     .Case("bgp", Triple::BGP)
     456             :     .Case("bgq", Triple::BGQ)
     457             :     .Case("fsl", Triple::Freescale)
     458             :     .Case("ibm", Triple::IBM)
     459             :     .Case("img", Triple::ImaginationTechnologies)
     460             :     .Case("mti", Triple::MipsTechnologies)
     461             :     .Case("nvidia", Triple::NVIDIA)
     462             :     .Case("csr", Triple::CSR)
     463             :     .Case("myriad", Triple::Myriad)
     464             :     .Case("amd", Triple::AMD)
     465             :     .Case("mesa", Triple::Mesa)
     466             :     .Case("suse", Triple::SUSE)
     467             :     .Case("oe", Triple::OpenEmbedded)
     468     1309694 :     .Default(Triple::UnknownVendor);
     469             : }
     470             : 
     471     1273494 : static Triple::OSType parseOS(StringRef OSName) {
     472     1273496 :   return StringSwitch<Triple::OSType>(OSName)
     473             :     .StartsWith("ananas", Triple::Ananas)
     474             :     .StartsWith("cloudabi", Triple::CloudABI)
     475             :     .StartsWith("darwin", Triple::Darwin)
     476             :     .StartsWith("dragonfly", Triple::DragonFly)
     477             :     .StartsWith("freebsd", Triple::FreeBSD)
     478             :     .StartsWith("fuchsia", Triple::Fuchsia)
     479             :     .StartsWith("ios", Triple::IOS)
     480             :     .StartsWith("kfreebsd", Triple::KFreeBSD)
     481             :     .StartsWith("linux", Triple::Linux)
     482             :     .StartsWith("lv2", Triple::Lv2)
     483             :     .StartsWith("macos", Triple::MacOSX)
     484             :     .StartsWith("netbsd", Triple::NetBSD)
     485             :     .StartsWith("openbsd", Triple::OpenBSD)
     486             :     .StartsWith("solaris", Triple::Solaris)
     487             :     .StartsWith("win32", Triple::Win32)
     488             :     .StartsWith("windows", Triple::Win32)
     489             :     .StartsWith("haiku", Triple::Haiku)
     490             :     .StartsWith("minix", Triple::Minix)
     491             :     .StartsWith("rtems", Triple::RTEMS)
     492             :     .StartsWith("nacl", Triple::NaCl)
     493             :     .StartsWith("cnk", Triple::CNK)
     494             :     .StartsWith("aix", Triple::AIX)
     495             :     .StartsWith("cuda", Triple::CUDA)
     496             :     .StartsWith("nvcl", Triple::NVCL)
     497             :     .StartsWith("amdhsa", Triple::AMDHSA)
     498             :     .StartsWith("ps4", Triple::PS4)
     499             :     .StartsWith("elfiamcu", Triple::ELFIAMCU)
     500             :     .StartsWith("tvos", Triple::TvOS)
     501             :     .StartsWith("watchos", Triple::WatchOS)
     502             :     .StartsWith("mesa3d", Triple::Mesa3D)
     503             :     .StartsWith("contiki", Triple::Contiki)
     504             :     .StartsWith("amdpal", Triple::AMDPAL)
     505     1273496 :     .Default(Triple::UnknownOS);
     506             : }
     507             : 
     508      938345 : static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
     509      938345 :   return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
     510             :     .StartsWith("eabihf", Triple::EABIHF)
     511             :     .StartsWith("eabi", Triple::EABI)
     512             :     .StartsWith("gnuabin32", Triple::GNUABIN32)
     513             :     .StartsWith("gnuabi64", Triple::GNUABI64)
     514             :     .StartsWith("gnueabihf", Triple::GNUEABIHF)
     515             :     .StartsWith("gnueabi", Triple::GNUEABI)
     516             :     .StartsWith("gnux32", Triple::GNUX32)
     517             :     .StartsWith("code16", Triple::CODE16)
     518             :     .StartsWith("gnu", Triple::GNU)
     519             :     .StartsWith("android", Triple::Android)
     520             :     .StartsWith("musleabihf", Triple::MuslEABIHF)
     521             :     .StartsWith("musleabi", Triple::MuslEABI)
     522             :     .StartsWith("musl", Triple::Musl)
     523             :     .StartsWith("msvc", Triple::MSVC)
     524             :     .StartsWith("itanium", Triple::Itanium)
     525             :     .StartsWith("cygnus", Triple::Cygnus)
     526             :     .StartsWith("coreclr", Triple::CoreCLR)
     527             :     .StartsWith("simulator", Triple::Simulator)
     528      938345 :     .Default(Triple::UnknownEnvironment);
     529             : }
     530             : 
     531      719489 : static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
     532      719489 :   return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
     533             :     .EndsWith("coff", Triple::COFF)
     534             :     .EndsWith("elf", Triple::ELF)
     535             :     .EndsWith("macho", Triple::MachO)
     536             :     .EndsWith("wasm", Triple::Wasm)
     537      719489 :     .Default(Triple::UnknownObjectFormat);
     538             : }
     539             : 
     540     1024013 : static Triple::SubArchType parseSubArch(StringRef SubArchName) {
     541     1024013 :   StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
     542             : 
     543             :   // For now, this is the small part. Early return.
     544     1024010 :   if (ARMSubArch.empty())
     545       82114 :     return StringSwitch<Triple::SubArchType>(SubArchName)
     546             :       .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
     547             :       .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
     548             :       .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
     549             :       .Default(Triple::NoSubArch);
     550             : 
     551             :   // ARM sub arch.
     552      941896 :   switch(ARM::parseArch(ARMSubArch)) {
     553             :   case ARM::ArchKind::ARMV4:
     554             :     return Triple::NoSubArch;
     555        1179 :   case ARM::ArchKind::ARMV4T:
     556        1179 :     return Triple::ARMSubArch_v4t;
     557         387 :   case ARM::ArchKind::ARMV5T:
     558         387 :     return Triple::ARMSubArch_v5;
     559         298 :   case ARM::ArchKind::ARMV5TE:
     560             :   case ARM::ArchKind::IWMMXT:
     561             :   case ARM::ArchKind::IWMMXT2:
     562             :   case ARM::ArchKind::XSCALE:
     563             :   case ARM::ArchKind::ARMV5TEJ:
     564         298 :     return Triple::ARMSubArch_v5te;
     565        1425 :   case ARM::ArchKind::ARMV6:
     566        1425 :     return Triple::ARMSubArch_v6;
     567         351 :   case ARM::ArchKind::ARMV6K:
     568             :   case ARM::ArchKind::ARMV6KZ:
     569         351 :     return Triple::ARMSubArch_v6k;
     570         265 :   case ARM::ArchKind::ARMV6T2:
     571         265 :     return Triple::ARMSubArch_v6t2;
     572        1050 :   case ARM::ArchKind::ARMV6M:
     573        1050 :     return Triple::ARMSubArch_v6m;
     574       19814 :   case ARM::ArchKind::ARMV7A:
     575             :   case ARM::ArchKind::ARMV7R:
     576       19814 :     return Triple::ARMSubArch_v7;
     577          30 :   case ARM::ArchKind::ARMV7VE:
     578          30 :     return Triple::ARMSubArch_v7ve;
     579         632 :   case ARM::ArchKind::ARMV7K:
     580         632 :     return Triple::ARMSubArch_v7k;
     581        1206 :   case ARM::ArchKind::ARMV7M:
     582        1206 :     return Triple::ARMSubArch_v7m;
     583         732 :   case ARM::ArchKind::ARMV7S:
     584         732 :     return Triple::ARMSubArch_v7s;
     585         369 :   case ARM::ArchKind::ARMV7EM:
     586         369 :     return Triple::ARMSubArch_v7em;
     587       33265 :   case ARM::ArchKind::ARMV8A:
     588       33265 :     return Triple::ARMSubArch_v8;
     589         136 :   case ARM::ArchKind::ARMV8_1A:
     590         136 :     return Triple::ARMSubArch_v8_1a;
     591          88 :   case ARM::ArchKind::ARMV8_2A:
     592          88 :     return Triple::ARMSubArch_v8_2a;
     593           4 :   case ARM::ArchKind::ARMV8_3A:
     594           4 :     return Triple::ARMSubArch_v8_3a;
     595           0 :   case ARM::ArchKind::ARMV8_4A:
     596           0 :     return Triple::ARMSubArch_v8_4a;
     597          47 :   case ARM::ArchKind::ARMV8R:
     598          47 :     return Triple::ARMSubArch_v8r;
     599         271 :   case ARM::ArchKind::ARMV8MBaseline:
     600         271 :     return Triple::ARMSubArch_v8m_baseline;
     601         336 :   case ARM::ArchKind::ARMV8MMainline:
     602         336 :     return Triple::ARMSubArch_v8m_mainline;
     603             :   default:
     604             :     return Triple::NoSubArch;
     605             :   }
     606             : }
     607             : 
     608         570 : static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
     609         570 :   switch (Kind) {
     610           0 :   case Triple::UnknownObjectFormat: return "";
     611         448 :   case Triple::COFF: return "coff";
     612          22 :   case Triple::ELF: return "elf";
     613         100 :   case Triple::MachO: return "macho";
     614           0 :   case Triple::Wasm: return "wasm";
     615             :   }
     616           0 :   llvm_unreachable("unknown object format type");
     617             : }
     618             : 
     619     1020746 : static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
     620     1020746 :   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      820972 :     else if (T.isOSWindows())
     630             :       return Triple::COFF;
     631      797788 :     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        2541 :   case Triple::wasm32:
     683             :   case Triple::wasm64:
     684        2541 :     return Triple::Wasm;
     685             :   }
     686           0 :   llvm_unreachable("unknown architecture");
     687             : }
     688             : 
     689             : /// 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     1024011 : Triple::Triple(const Twine &Str)
     694             :     : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
     695             :       Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
     696     1024011 :       ObjectFormat(UnknownObjectFormat) {
     697             :   // Do minimal parsing by hand here.
     698             :   SmallVector<StringRef, 4> Components;
     699     1024012 :   StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
     700     1024011 :   if (Components.size() > 0) {
     701     1024011 :     Arch = parseArch(Components[0]);
     702     1024011 :     SubArch = parseSubArch(Components[0]);
     703     1024012 :     if (Components.size() > 1) {
     704      925154 :       Vendor = parseVendor(Components[1]);
     705      925153 :       if (Components.size() > 2) {
     706      919910 :         OS = parseOS(Components[2]);
     707      919911 :         if (Components.size() > 3) {
     708      625238 :           Environment = parseEnvironment(Components[3]);
     709      625238 :           ObjectFormat = parseFormat(Components[3]);
     710             :         }
     711             :       }
     712             :     }
     713             :   }
     714     1024012 :   if (ObjectFormat == UnknownObjectFormat)
     715     1020197 :     ObjectFormat = getDefaultFormat(*this);
     716     1024012 : }
     717             : 
     718             : /// 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             : /// 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      308170 : 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      308170 :   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      308168 :   if (Components.size() > 0)
     768      308168 :     Arch = parseArch(Components[0]);
     769             :   VendorType Vendor = UnknownVendor;
     770      308170 :   if (Components.size() > 1)
     771      265304 :     Vendor = parseVendor(Components[1]);
     772             :   OSType OS = UnknownOS;
     773      308169 :   if (Components.size() > 2) {
     774      262173 :     OS = parseOS(Components[2]);
     775             :     IsCygwin = Components[2].startswith("cygwin");
     776             :     IsMinGW32 = Components[2].startswith("mingw");
     777             :   }
     778             :   EnvironmentType Environment = UnknownEnvironment;
     779      308170 :   if (Components.size() > 3)
     780      210956 :     Environment = parseEnvironment(Components[3]);
     781             :   ObjectFormatType ObjectFormat = UnknownObjectFormat;
     782      308170 :   if (Components.size() > 4)
     783         443 :     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      308170 :   Found[0] = Arch != UnknownArch;
     789      308170 :   Found[1] = Vendor != UnknownVendor;
     790      308170 :   Found[2] = OS != UnknownOS;
     791      308170 :   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     2773530 :   for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
     797     1232680 :     if (Found[Pos])
     798      921872 :       continue; // Already in the canonical position.
     799             : 
     800     2404276 :     for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
     801             :       // Do not reparse any components that already matched.
     802      617375 :       if (Idx < array_lengthof(Found) && Found[Idx])
     803      262294 :         continue;
     804             : 
     805             :       // Does this component parse as valid for the target position?
     806             :       bool Valid = false;
     807      355081 :       StringRef Comp = Components[Idx];
     808      355081 :       switch (Pos) {
     809           0 :       default: llvm_unreachable("unexpected component type!");
     810       42287 :       case 0:
     811       42287 :         Arch = parseArch(Comp);
     812       42287 :         Valid = Arch != UnknownArch;
     813       42287 :         break;
     814      119236 :       case 1:
     815      119236 :         Vendor = parseVendor(Comp);
     816      119236 :         Valid = Vendor != UnknownVendor;
     817      119236 :         break;
     818       91409 :       case 2:
     819       91409 :         OS = parseOS(Comp);
     820             :         IsCygwin = Comp.startswith("cygwin");
     821             :         IsMinGW32 = Comp.startswith("mingw");
     822       91409 :         Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
     823             :         break;
     824      102149 :       case 3:
     825      102149 :         Environment = parseEnvironment(Comp);
     826      102149 :         Valid = Environment != UnknownEnvironment;
     827      102149 :         if (!Valid) {
     828       93806 :           ObjectFormat = parseFormat(Comp);
     829       93806 :           Valid = ObjectFormat != UnknownObjectFormat;
     830             :         }
     831             :         break;
     832             :       }
     833      355081 :       if (!Valid)
     834      331926 :         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       23155 :       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       29336 :         for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
     849             :           // Skip over any fixed components.
     850       14185 :           while (i < array_lengthof(Found) && Found[i])
     851        1011 :             ++i;
     852             :           // Place the component at the new position, getting the component
     853             :           // that was at this position - it will be moved right.
     854       12163 :           std::swap(CurrentComponent, Components[i]);
     855             :         }
     856       18145 :       } 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       45852 :           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       13897 :             if (CurrentComponent.empty())
     869             :               break;
     870             :             // Advance to the next component, skipping any fixed components.
     871       13936 :             while (++i < array_lengthof(Found) && Found[i])
     872             :               ;
     873             :           }
     874             :           // The last component was pushed off the end - append it.
     875        9033 :           if (!CurrentComponent.empty())
     876        9029 :             Components.push_back(CurrentComponent);
     877             : 
     878             :           // Advance Idx to the component's new position.
     879        9063 :           while (++Idx < array_lengthof(Found) && Found[Idx])
     880             :             ;
     881        9033 :         } 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       23155 :       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      308170 :   if (Environment == Triple::Android && Components[3].startswith("androideabi")) {
     894         116 :     StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
     895         116 :     if (AndroidVersion.empty()) {
     896          94 :       Components[3] = "android";
     897             :     } else {
     898          44 :       NormalizedEnvironment = Twine("android", AndroidVersion).str();
     899          22 :       Components[3] = NormalizedEnvironment;
     900             :     }
     901             :   }
     902             : 
     903             :   // SUSE uses "gnueabi" to mean "gnueabihf"
     904      308170 :   if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
     905           5 :     Components[3] = "gnueabihf";
     906             : 
     907      308170 :   if (OS == Triple::Win32) {
     908        5725 :     Components.resize(4);
     909        5725 :     Components[2] = "windows";
     910        5725 :     if (Environment == UnknownEnvironment) {
     911        1140 :       if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
     912        1088 :         Components[3] = "msvc";
     913             :       else
     914          52 :         Components[3] = getObjectFormatTypeName(ObjectFormat);
     915             :     }
     916      302445 :   } else if (IsMinGW32) {
     917         121 :     Components.resize(4);
     918         121 :     Components[2] = "windows";
     919         121 :     Components[3] = "gnu";
     920      302324 :   } else if (IsCygwin) {
     921          28 :     Components.resize(4);
     922          28 :     Components[2] = "windows";
     923          28 :     Components[3] = "cygnus";
     924             :   }
     925      616193 :   if (IsMinGW32 || IsCygwin ||
     926      308021 :       (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
     927        4734 :     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     1365092 :   for (unsigned i = 0, e = Components.size(); i != e; ++i) {
     936     1056922 :     if (i) Normalized += '-';
     937     1056922 :     Normalized += Components[i];
     938             :   }
     939      308170 :   return Normalized;
     940             : }
     941             : 
     942       90256 : StringRef Triple::getArchName() const {
     943       90257 :   return StringRef(Data).split('-').first;           // Isolate first component
     944             : }
     945             : 
     946       53473 : StringRef Triple::getVendorName() const {
     947       53473 :   StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
     948       53473 :   return Tmp.split('-').first;                       // Isolate second component
     949             : }
     950             : 
     951       75859 : StringRef Triple::getOSName() const {
     952       75859 :   StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
     953       75859 :   Tmp = Tmp.split('-').second;                       // Strip second component
     954       75859 :   return Tmp.split('-').first;                       // Isolate third component
     955             : }
     956             : 
     957       15898 : StringRef Triple::getEnvironmentName() const {
     958       15898 :   StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
     959       15898 :   Tmp = Tmp.split('-').second;                       // Strip second component
     960       15898 :   return Tmp.split('-').second;                      // Strip third component
     961             : }
     962             : 
     963       41231 : StringRef Triple::getOSAndEnvironmentName() const {
     964       41231 :   StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
     965       41231 :   return Tmp.split('-').second;                      // Strip second component
     966             : }
     967             : 
     968       42948 : 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      123798 :     Result = Result*10 + (Str[0] - '0');
     975             : 
     976             :     // Eat the digit.
     977       61899 :     Str = Str.substr(1);
     978      100462 :   } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
     979             : 
     980       42948 :   return Result;
     981             : }
     982             : 
     983       41217 : static void parseVersionFromName(StringRef Name, unsigned &Major,
     984             :                                  unsigned &Minor, unsigned &Micro) {
     985             :   // Any unset version defaults to 0.
     986       41217 :   Major = Minor = Micro = 0;
     987             : 
     988             :   // Parse up to three components.
     989       41217 :   unsigned *Components[3] = {&Major, &Minor, &Micro};
     990      127113 :   for (unsigned i = 0; i != 3; ++i) {
     991      118834 :     if (Name.empty() || Name[0] < '0' || Name[0] > '9')
     992             :       break;
     993             : 
     994             :     // Consume the leading number.
     995       42948 :     *Components[i] = EatNumber(Name);
     996             : 
     997             :     // Consume the separator, if present.
     998             :     if (Name.startswith("."))
     999       19604 :       Name = Name.substr(1);
    1000             :   }
    1001       41217 : }
    1002             : 
    1003        2217 : void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor,
    1004             :                                    unsigned &Micro) const {
    1005        2217 :   StringRef EnvironmentName = getEnvironmentName();
    1006        2217 :   StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
    1007             :   if (EnvironmentName.startswith(EnvironmentTypeName))
    1008        2205 :     EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
    1009             : 
    1010        2217 :   parseVersionFromName(EnvironmentName, Major, Minor, Micro);
    1011        2217 : }
    1012             : 
    1013       39000 : void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
    1014             :                           unsigned &Micro) const {
    1015       39000 :   StringRef OSName = getOSName();
    1016             :   // Assume that the OS portion of the triple starts with the canonical name.
    1017       39000 :   StringRef OSTypeName = getOSTypeName(getOS());
    1018             :   if (OSName.startswith(OSTypeName))
    1019       38801 :     OSName = OSName.substr(OSTypeName.size());
    1020         199 :   else if (getOS() == MacOSX)
    1021             :     OSName.consume_front("macos");
    1022             : 
    1023       39000 :   parseVersionFromName(OSName, Major, Minor, Micro);
    1024       39000 : }
    1025             : 
    1026        3735 : bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
    1027             :                               unsigned &Micro) const {
    1028        3735 :   getOSVersion(Major, Minor, Micro);
    1029             : 
    1030        3735 :   switch (getOS()) {
    1031           0 :   default: llvm_unreachable("unexpected OS for Darwin triple");
    1032        2938 :   case Darwin:
    1033             :     // Default to darwin8, i.e., MacOSX 10.4.
    1034        2938 :     if (Major == 0)
    1035         528 :       Major = 8;
    1036             :     // Darwin version numbers are skewed from OS X versions.
    1037        2938 :     if (Major < 4)
    1038             :       return false;
    1039        2936 :     Micro = 0;
    1040        2936 :     Minor = Major - 4;
    1041        2936 :     Major = 10;
    1042        2936 :     break;
    1043         795 :   case MacOSX:
    1044             :     // Default to 10.4.
    1045         795 :     if (Major == 0) {
    1046          57 :       Major = 10;
    1047          57 :       Minor = 4;
    1048             :     }
    1049         795 :     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         309 : void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
    1068             :                            unsigned &Micro) const {
    1069         309 :   switch (getOS()) {
    1070           0 :   default: llvm_unreachable("unexpected OS for Darwin triple");
    1071          25 :   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          25 :     Major = 5;
    1078          25 :     Minor = 0;
    1079          25 :     Micro = 0;
    1080          25 :     break;
    1081         284 :   case IOS:
    1082             :   case TvOS:
    1083         284 :     getOSVersion(Major, Minor, Micro);
    1084             :     // Default to 5.0 (or 7.0 for arm64).
    1085         284 :     if (Major == 0)
    1086          30 :       Major = (getArch() == aarch64) ? 7 : 5;
    1087             :     break;
    1088           0 :   case WatchOS:
    1089           0 :     llvm_unreachable("conflicting triple info");
    1090             :   }
    1091         309 : }
    1092             : 
    1093          35 : void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor,
    1094             :                                unsigned &Micro) const {
    1095          35 :   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          34 :   case WatchOS:
    1108          34 :     getOSVersion(Major, Minor, Micro);
    1109          34 :     if (Major == 0)
    1110           5 :       Major = 2;
    1111             :     break;
    1112           0 :   case IOS:
    1113           0 :     llvm_unreachable("conflicting triple info");
    1114             :   }
    1115          35 : }
    1116             : 
    1117       87694 : void Triple::setTriple(const Twine &Str) {
    1118      175388 :   *this = Triple(Str);
    1119       87694 : }
    1120             : 
    1121       23669 : void Triple::setArch(ArchType Kind) {
    1122       23669 :   setArchName(getArchTypeName(Kind));
    1123       23669 : }
    1124             : 
    1125        4828 : void Triple::setVendor(VendorType Kind) {
    1126        4828 :   setVendorName(getVendorTypeName(Kind));
    1127        4828 : }
    1128             : 
    1129        5298 : void Triple::setOS(OSType Kind) {
    1130        5298 :   setOSName(getOSTypeName(Kind));
    1131        5298 : }
    1132             : 
    1133         547 : void Triple::setEnvironment(EnvironmentType Kind) {
    1134         547 :   if (ObjectFormat == getDefaultFormat(*this))
    1135         547 :     return setEnvironmentName(getEnvironmentTypeName(Kind));
    1136             : 
    1137           0 :   setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
    1138           0 :                       getObjectFormatTypeName(ObjectFormat)).str());
    1139             : }
    1140             : 
    1141         506 : void Triple::setObjectFormat(ObjectFormatType Kind) {
    1142         506 :   if (Environment == UnknownEnvironment)
    1143          58 :     return setEnvironmentName(getObjectFormatTypeName(Kind));
    1144             : 
    1145        1344 :   setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
    1146        1792 :                       getObjectFormatTypeName(Kind)).str());
    1147             : }
    1148             : 
    1149       32220 : 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       32220 :   Triple += getVendorName();
    1155             :   Triple += "-";
    1156       32220 :   Triple += getOSAndEnvironmentName();
    1157       32220 :   setTriple(Triple);
    1158       32220 : }
    1159             : 
    1160        9011 : void Triple::setVendorName(StringRef Str) {
    1161       27033 :   setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
    1162        9011 : }
    1163             : 
    1164        7154 : void Triple::setOSName(StringRef Str) {
    1165             :   if (hasEnvironment())
    1166        2196 :     setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
    1167        1647 :               "-" + getEnvironmentName());
    1168             :   else
    1169       19815 :     setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
    1170        7154 : }
    1171             : 
    1172        1981 : void Triple::setEnvironmentName(StringRef Str) {
    1173        9905 :   setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
    1174        3962 :             "-" + Str);
    1175        1981 : }
    1176             : 
    1177           1 : void Triple::setOSAndEnvironmentName(StringRef Str) {
    1178           3 :   setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
    1179           1 : }
    1180             : 
    1181      649395 : static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
    1182      649395 :   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       63965 :   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       63965 :     return 32;
    1219             : 
    1220      585404 :   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      585404 :     return 64;
    1241             :   }
    1242           0 :   llvm_unreachable("Invalid architecture value");
    1243             : }
    1244             : 
    1245      362050 : bool Triple::isArch64Bit() const {
    1246      362050 :   return getArchPointerBitWidth(getArch()) == 64;
    1247             : }
    1248             : 
    1249      287273 : bool Triple::isArch32Bit() const {
    1250      287273 :   return getArchPointerBitWidth(getArch()) == 32;
    1251             : }
    1252             : 
    1253          72 : bool Triple::isArch16Bit() const {
    1254          72 :   return getArchPointerBitWidth(getArch()) == 16;
    1255             : }
    1256             : 
    1257       13526 : Triple Triple::get32BitArchVariant() const {
    1258       13526 :   Triple T(*this);
    1259       13527 :   switch (getArch()) {
    1260         174 :   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         174 :     T.setArch(UnknownArch);
    1269         174 :     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         111 :   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          86 :   case Triple::mips64:         T.setArch(Triple::mips);    break;
    1306          71 :   case Triple::mips64el:       T.setArch(Triple::mipsel);  break;
    1307           1 :   case Triple::nvptx64:        T.setArch(Triple::nvptx);   break;
    1308         110 :   case Triple::ppc64:          T.setArch(Triple::ppc);     break;
    1309          22 :   case Triple::sparcv9:        T.setArch(Triple::sparc);   break;
    1310          12 :   case Triple::riscv64:        T.setArch(Triple::riscv32); break;
    1311       12800 :   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       13527 :   return T;
    1319             : }
    1320             : 
    1321        5454 : Triple Triple::get64BitArchVariant() const {
    1322        5454 :   Triple T(*this);
    1323        5454 :   switch (getArch()) {
    1324         100 :   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         100 :     T.setArch(UnknownArch);
    1339         100 :     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         226 :   case Triple::arm:             T.setArch(Triple::aarch64);    break;
    1365          12 :   case Triple::armeb:           T.setArch(Triple::aarch64_be); break;
    1366           1 :   case Triple::le32:            T.setArch(Triple::le64);       break;
    1367         255 :   case Triple::mips:            T.setArch(Triple::mips64);     break;
    1368         103 :   case Triple::mipsel:          T.setArch(Triple::mips64el);   break;
    1369           1 :   case Triple::nvptx:           T.setArch(Triple::nvptx64);    break;
    1370          26 :   case Triple::ppc:             T.setArch(Triple::ppc64);      break;
    1371          36 :   case Triple::sparc:           T.setArch(Triple::sparcv9);    break;
    1372          17 :   case Triple::riscv32:         T.setArch(Triple::riscv64);    break;
    1373         490 :   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        5454 :   return T;
    1383             : }
    1384             : 
    1385         135 : Triple Triple::getBigEndianArchVariant() const {
    1386         135 :   Triple T(*this);
    1387             :   // Already big endian.
    1388         135 :   if (!isLittleEndian())
    1389             :     return T;
    1390          76 :   switch (getArch()) {
    1391          34 :   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          34 :     T.setArch(UnknownArch);
    1425          34 :     break;
    1426             : 
    1427           1 :   case Triple::tcele:   T.setArch(Triple::tce);        break;
    1428          32 :   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         166 : Triple Triple::getLittleEndianArchVariant() const {
    1441         166 :   Triple T(*this);
    1442         166 :   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       43091 : bool Triple::isLittleEndian() const {
    1473       43091 :   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        5478 :   default:
    1512        5478 :     return false;
    1513             :   }
    1514             : }
    1515             : 
    1516         566 : bool Triple::isCompatibleWith(const Triple &Other) const {
    1517             :   // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
    1518         570 :   if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
    1519           4 :       (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
    1520         566 :       (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         563 :   if (getVendor() == Triple::Apple)
    1534         202 :     return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
    1535         202 :            getVendor() == Other.getVendor() && getOS() == Other.getOS();
    1536             : 
    1537             :   return *this == Other;
    1538             : }
    1539             : 
    1540        1055 : std::string Triple::merge(const Triple &Other) const {
    1541             :   // If vendor is apple, pick the triple with the larger version number.
    1542        1055 :   if (getVendor() == Triple::Apple)
    1543          68 :     if (Other.isOSVersionLT(*this))
    1544             :       return str();
    1545             : 
    1546             :   return Other.str();
    1547             : }
    1548             : 
    1549        2814 : StringRef Triple::getARMCPUForArch(StringRef MArch) const {
    1550        2814 :   if (MArch.empty())
    1551          14 :     MArch = getArchName();
    1552        2814 :   MArch = ARM::getCanonicalArchName(MArch);
    1553             : 
    1554             :   // Some defaults are forced.
    1555        2814 :   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         195 :     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         107 :       return "cortex-a7";
    1570             :     break;
    1571             :   default:
    1572             :     break;
    1573             :   }
    1574             : 
    1575        2505 :   if (MArch.empty())
    1576           3 :     return StringRef();
    1577             : 
    1578        2502 :   StringRef CPU = ARM::getDefaultCPU(MArch);
    1579        2502 :   if (!CPU.empty() && !CPU.equals("invalid"))
    1580        2065 :     return CPU;
    1581             : 
    1582             :   // If no specific architecture version is requested, return the minimum CPU
    1583             :   // required by the OS and environment.
    1584         437 :   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         372 :   default:
    1599         372 :     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         337 :       return "arm7tdmi";
    1606             :     }
    1607             :   }
    1608             : 
    1609             :   llvm_unreachable("invalid arch name");
    1610             : }

Generated by: LCOV version 1.13