1f5f373fcSRenato Golin //===-- TargetParser - Parser for target features ---------------*- C++ -*-===// 2f5f373fcSRenato Golin // 3f5f373fcSRenato Golin // The LLVM Compiler Infrastructure 4f5f373fcSRenato Golin // 5f5f373fcSRenato Golin // This file is distributed under the University of Illinois Open Source 6f5f373fcSRenato Golin // License. See LICENSE.TXT for details. 7f5f373fcSRenato Golin // 8f5f373fcSRenato Golin //===----------------------------------------------------------------------===// 9f5f373fcSRenato Golin // 10f5f373fcSRenato Golin // This file implements a target parser to recognise hardware features such as 11f5f373fcSRenato Golin // FPU/CPU/ARCH names as well as specific support such as HDIV, etc. 12f5f373fcSRenato Golin // 13f5f373fcSRenato Golin //===----------------------------------------------------------------------===// 14f5f373fcSRenato Golin 15f5f373fcSRenato Golin #include "llvm/Support/ARMBuildAttributes.h" 16f5f373fcSRenato Golin #include "llvm/Support/TargetParser.h" 17f5f373fcSRenato Golin #include "llvm/ADT/StringExtras.h" 18f5f373fcSRenato Golin #include "llvm/ADT/StringSwitch.h" 19ebdd12cbSRenato Golin #include <cctype> 20f5f373fcSRenato Golin 21f5f373fcSRenato Golin using namespace llvm; 22f5f373fcSRenato Golin 23f5f373fcSRenato Golin namespace { 24f5f373fcSRenato Golin 25d03d2292SJohn Brawn // List of canonical FPU names (use getFPUSynonym) and which architectural 26d03d2292SJohn Brawn // features they correspond to (use getFPUFeatures). 27f5f373fcSRenato Golin // FIXME: TableGen this. 28f5f373fcSRenato Golin struct { 29f5f373fcSRenato Golin const char * Name; 30f5f373fcSRenato Golin ARM::FPUKind ID; 31*1781a687SNAKAMURA Takumi unsigned FPUVersion; ///< Corresponds directly to the FP arch version number. 32d03d2292SJohn Brawn ARM::NeonSupportLevel NeonSupport; 33d03d2292SJohn Brawn ARM::FPURestriction Restriction; 34f5f373fcSRenato Golin } FPUNames[] = { 35d03d2292SJohn Brawn { "invalid", ARM::FK_INVALID, 0, ARM::NS_None, ARM::FR_None}, 36985c04e8SJohn Brawn { "none", ARM::FK_NONE, 0, ARM::NS_None, ARM::FR_None}, 37d03d2292SJohn Brawn { "vfp", ARM::FK_VFP, 2, ARM::NS_None, ARM::FR_None}, 38d03d2292SJohn Brawn { "vfpv2", ARM::FK_VFPV2, 2, ARM::NS_None, ARM::FR_None}, 39d03d2292SJohn Brawn { "vfpv3", ARM::FK_VFPV3, 3, ARM::NS_None, ARM::FR_None}, 40d03d2292SJohn Brawn { "vfpv3-d16", ARM::FK_VFPV3_D16, 3, ARM::NS_None, ARM::FR_D16}, 41d03d2292SJohn Brawn { "vfpv4", ARM::FK_VFPV4, 4, ARM::NS_None, ARM::FR_None}, 42d03d2292SJohn Brawn { "vfpv4-d16", ARM::FK_VFPV4_D16, 4, ARM::NS_None, ARM::FR_D16}, 43985c04e8SJohn Brawn { "fpv4-sp-d16", ARM::FK_FPV4_SP_D16, 4, ARM::NS_None, ARM::FR_SP_D16}, 44d03d2292SJohn Brawn { "fpv5-d16", ARM::FK_FPV5_D16, 5, ARM::NS_None, ARM::FR_D16}, 45985c04e8SJohn Brawn { "fpv5-sp-d16", ARM::FK_FPV5_SP_D16, 5, ARM::NS_None, ARM::FR_SP_D16}, 46d03d2292SJohn Brawn { "fp-armv8", ARM::FK_FP_ARMV8, 5, ARM::NS_None, ARM::FR_None}, 47d03d2292SJohn Brawn { "neon", ARM::FK_NEON, 3, ARM::NS_Neon, ARM::FR_None}, 48d03d2292SJohn Brawn { "neon-vfpv4", ARM::FK_NEON_VFPV4, 4, ARM::NS_Neon, ARM::FR_None}, 49d03d2292SJohn Brawn { "neon-fp-armv8", ARM::FK_NEON_FP_ARMV8, 5, ARM::NS_Neon, ARM::FR_None}, 50d03d2292SJohn Brawn { "crypto-neon-fp-armv8", 51d03d2292SJohn Brawn ARM::FK_CRYPTO_NEON_FP_ARMV8, 5, ARM::NS_Crypto, ARM::FR_None}, 52d03d2292SJohn Brawn { "softvfp", ARM::FK_SOFTVFP, 0, ARM::NS_None, ARM::FR_None}, 53f5f373fcSRenato Golin }; 54d03d2292SJohn Brawn 55f7c0d5f2SRenato Golin // List of canonical arch names (use getArchSynonym). 56f7c0d5f2SRenato Golin // This table also provides the build attribute fields for CPU arch 57f7c0d5f2SRenato Golin // and Arch ID, according to the Addenda to the ARM ABI, chapters 58f7c0d5f2SRenato Golin // 2.4 and 2.3.5.2 respectively. 5942dad647SRenato Golin // FIXME: SubArch values were simplified to fit into the expectations 6042dad647SRenato Golin // of the triples and are not conforming with their official names. 6142dad647SRenato Golin // Check to see if the expectation should be changed. 62f5f373fcSRenato Golin // FIXME: TableGen this. 63f5f373fcSRenato Golin struct { 64f5f373fcSRenato Golin const char *Name; 65f5f373fcSRenato Golin ARM::ArchKind ID; 66f7c0d5f2SRenato Golin const char *CPUAttr; // CPU class in build attributes. 6742dad647SRenato Golin const char *SubArch; // Sub-Arch name. 68f7c0d5f2SRenato Golin ARMBuildAttrs::CPUArch ArchAttr; // Arch ID in build attributes. 69f5f373fcSRenato Golin } ARCHNames[] = { 7042dad647SRenato Golin { "invalid", ARM::AK_INVALID, nullptr, nullptr, ARMBuildAttrs::CPUArch::Pre_v4 }, 7142dad647SRenato Golin { "armv2", ARM::AK_ARMV2, "2", "v2", ARMBuildAttrs::CPUArch::Pre_v4 }, 7242dad647SRenato Golin { "armv2a", ARM::AK_ARMV2A, "2A", "v2a", ARMBuildAttrs::CPUArch::Pre_v4 }, 7342dad647SRenato Golin { "armv3", ARM::AK_ARMV3, "3", "v3", ARMBuildAttrs::CPUArch::Pre_v4 }, 7442dad647SRenato Golin { "armv3m", ARM::AK_ARMV3M, "3M", "v3m", ARMBuildAttrs::CPUArch::Pre_v4 }, 7542dad647SRenato Golin { "armv4", ARM::AK_ARMV4, "4", "v4", ARMBuildAttrs::CPUArch::v4 }, 7642dad647SRenato Golin { "armv4t", ARM::AK_ARMV4T, "4T", "v4t", ARMBuildAttrs::CPUArch::v4T }, 7742dad647SRenato Golin { "armv5t", ARM::AK_ARMV5T, "5T", "v5", ARMBuildAttrs::CPUArch::v5T }, 7842dad647SRenato Golin { "armv5te", ARM::AK_ARMV5TE, "5TE", "v5e", ARMBuildAttrs::CPUArch::v5TE }, 7942dad647SRenato Golin { "armv5tej", ARM::AK_ARMV5TEJ, "5TEJ", "v5e", ARMBuildAttrs::CPUArch::v5TEJ }, 8042dad647SRenato Golin { "armv6", ARM::AK_ARMV6, "6", "v6", ARMBuildAttrs::CPUArch::v6 }, 8142dad647SRenato Golin { "armv6k", ARM::AK_ARMV6K, "6K", "v6k", ARMBuildAttrs::CPUArch::v6K }, 8242dad647SRenato Golin { "armv6t2", ARM::AK_ARMV6T2, "6T2", "v6t2", ARMBuildAttrs::CPUArch::v6T2 }, 8342dad647SRenato Golin { "armv6z", ARM::AK_ARMV6Z, "6Z", "v6z", ARMBuildAttrs::CPUArch::v6KZ }, 8442dad647SRenato Golin { "armv6zk", ARM::AK_ARMV6ZK, "6ZK", "v6zk", ARMBuildAttrs::CPUArch::v6KZ }, 8542dad647SRenato Golin { "armv6-m", ARM::AK_ARMV6M, "6-M", "v6m", ARMBuildAttrs::CPUArch::v6_M }, 8642dad647SRenato Golin { "armv6s-m", ARM::AK_ARMV6SM, "6S-M", "v6sm", ARMBuildAttrs::CPUArch::v6S_M }, 8742dad647SRenato Golin { "armv7-a", ARM::AK_ARMV7A, "7-A", "v7", ARMBuildAttrs::CPUArch::v7 }, 8842dad647SRenato Golin { "armv7-r", ARM::AK_ARMV7R, "7-R", "v7r", ARMBuildAttrs::CPUArch::v7 }, 8942dad647SRenato Golin { "armv7-m", ARM::AK_ARMV7M, "7-M", "v7m", ARMBuildAttrs::CPUArch::v7 }, 9042dad647SRenato Golin { "armv7e-m", ARM::AK_ARMV7EM, "7E-M", "v7em", ARMBuildAttrs::CPUArch::v7E_M }, 9142dad647SRenato Golin { "armv8-a", ARM::AK_ARMV8A, "8-A", "v8", ARMBuildAttrs::CPUArch::v8 }, 9242dad647SRenato Golin { "armv8.1-a", ARM::AK_ARMV8_1A, "8.1-A", "v8.1a", ARMBuildAttrs::CPUArch::v8 }, 93e8048f0dSRenato Golin // Non-standard Arch names. 9442dad647SRenato Golin { "iwmmxt", ARM::AK_IWMMXT, "iwmmxt", "", ARMBuildAttrs::CPUArch::v5TE }, 9542dad647SRenato Golin { "iwmmxt2", ARM::AK_IWMMXT2, "iwmmxt2", "", ARMBuildAttrs::CPUArch::v5TE }, 9642dad647SRenato Golin { "xscale", ARM::AK_XSCALE, "xscale", "", ARMBuildAttrs::CPUArch::v5TE }, 9742dad647SRenato Golin { "armv5", ARM::AK_ARMV5, "5T", "v5", ARMBuildAttrs::CPUArch::v5T }, 9842dad647SRenato Golin { "armv5e", ARM::AK_ARMV5E, "5TE", "v5e", ARMBuildAttrs::CPUArch::v5TE }, 9942dad647SRenato Golin { "armv6j", ARM::AK_ARMV6J, "6J", "v6", ARMBuildAttrs::CPUArch::v6 }, 10042dad647SRenato Golin { "armv6hl", ARM::AK_ARMV6HL, "6-M", "v6hl", ARMBuildAttrs::CPUArch::v6_M }, 10142dad647SRenato Golin { "armv7", ARM::AK_ARMV7, "7", "v7", ARMBuildAttrs::CPUArch::v7 }, 10242dad647SRenato Golin { "armv7l", ARM::AK_ARMV7L, "7-L", "v7l", ARMBuildAttrs::CPUArch::v7 }, 10342dad647SRenato Golin { "armv7hl", ARM::AK_ARMV7HL, "7-L", "v7hl", ARMBuildAttrs::CPUArch::v7 }, 10442dad647SRenato Golin { "armv7s", ARM::AK_ARMV7S, "7-S", "v7s", ARMBuildAttrs::CPUArch::v7 } 105f5f373fcSRenato Golin }; 106e1326cadSRenato Golin // List of Arch Extension names. 107f5f373fcSRenato Golin // FIXME: TableGen this. 108f5f373fcSRenato Golin struct { 109f5f373fcSRenato Golin const char *Name; 110f5f373fcSRenato Golin ARM::ArchExtKind ID; 111f5f373fcSRenato Golin } ARCHExtNames[] = { 11235de35d0SRenato Golin { "invalid", ARM::AEK_INVALID }, 11335de35d0SRenato Golin { "crc", ARM::AEK_CRC }, 11435de35d0SRenato Golin { "crypto", ARM::AEK_CRYPTO }, 11535de35d0SRenato Golin { "fp", ARM::AEK_FP }, 11635de35d0SRenato Golin { "idiv", ARM::AEK_HWDIV }, 11735de35d0SRenato Golin { "mp", ARM::AEK_MP }, 118230d2983SRenato Golin { "simd", ARM::AEK_SIMD }, 11935de35d0SRenato Golin { "sec", ARM::AEK_SEC }, 120230d2983SRenato Golin { "virt", ARM::AEK_VIRT }, 121230d2983SRenato Golin { "os", ARM::AEK_OS }, 122230d2983SRenato Golin { "iwmmxt", ARM::AEK_IWMMXT }, 123230d2983SRenato Golin { "iwmmxt2", ARM::AEK_IWMMXT2 }, 124230d2983SRenato Golin { "maverick", ARM::AEK_MAVERICK }, 125230d2983SRenato Golin { "xscale", ARM::AEK_XSCALE } 126f5f373fcSRenato Golin }; 127e8048f0dSRenato Golin // List of CPU names and their arches. 128e8048f0dSRenato Golin // The same CPU can have multiple arches and can be default on multiple arches. 129e8048f0dSRenato Golin // When finding the Arch for a CPU, first-found prevails. Sort them accordingly. 1307374fcdbSRenato Golin // When this becomes table-generated, we'd probably need two tables. 131e8048f0dSRenato Golin // FIXME: TableGen this. 132e8048f0dSRenato Golin struct { 133e8048f0dSRenato Golin const char *Name; 134e8048f0dSRenato Golin ARM::ArchKind ArchID; 135e8048f0dSRenato Golin bool Default; 136e8048f0dSRenato Golin } CPUNames[] = { 137e8048f0dSRenato Golin { "arm2", ARM::AK_ARMV2, true }, 1387374fcdbSRenato Golin { "arm3", ARM::AK_ARMV2A, true }, 139e8048f0dSRenato Golin { "arm6", ARM::AK_ARMV3, true }, 140e8048f0dSRenato Golin { "arm7m", ARM::AK_ARMV3M, true }, 1417374fcdbSRenato Golin { "arm8", ARM::AK_ARMV4, false }, 1427374fcdbSRenato Golin { "arm810", ARM::AK_ARMV4, false }, 143e8048f0dSRenato Golin { "strongarm", ARM::AK_ARMV4, true }, 1447374fcdbSRenato Golin { "strongarm110", ARM::AK_ARMV4, false }, 1457374fcdbSRenato Golin { "strongarm1100", ARM::AK_ARMV4, false }, 1467374fcdbSRenato Golin { "strongarm1110", ARM::AK_ARMV4, false }, 147e8048f0dSRenato Golin { "arm7tdmi", ARM::AK_ARMV4T, true }, 148e8048f0dSRenato Golin { "arm7tdmi-s", ARM::AK_ARMV4T, false }, 149e8048f0dSRenato Golin { "arm710t", ARM::AK_ARMV4T, false }, 150e8048f0dSRenato Golin { "arm720t", ARM::AK_ARMV4T, false }, 151e8048f0dSRenato Golin { "arm9", ARM::AK_ARMV4T, false }, 152e8048f0dSRenato Golin { "arm9tdmi", ARM::AK_ARMV4T, false }, 153e8048f0dSRenato Golin { "arm920", ARM::AK_ARMV4T, false }, 154e8048f0dSRenato Golin { "arm920t", ARM::AK_ARMV4T, false }, 155e8048f0dSRenato Golin { "arm922t", ARM::AK_ARMV4T, false }, 156e8048f0dSRenato Golin { "arm9312", ARM::AK_ARMV4T, false }, 157e8048f0dSRenato Golin { "arm940t", ARM::AK_ARMV4T, false }, 158e8048f0dSRenato Golin { "ep9312", ARM::AK_ARMV4T, false }, 159e8048f0dSRenato Golin { "arm10tdmi", ARM::AK_ARMV5T, true }, 160e8048f0dSRenato Golin { "arm1020t", ARM::AK_ARMV5T, false }, 161e8048f0dSRenato Golin { "arm9e", ARM::AK_ARMV5TE, false }, 1627374fcdbSRenato Golin { "arm946e-s", ARM::AK_ARMV5TE, false }, 163e8048f0dSRenato Golin { "arm966e-s", ARM::AK_ARMV5TE, false }, 164e8048f0dSRenato Golin { "arm968e-s", ARM::AK_ARMV5TE, false }, 1657374fcdbSRenato Golin { "arm10e", ARM::AK_ARMV5TE, false }, 166e8048f0dSRenato Golin { "arm1020e", ARM::AK_ARMV5TE, false }, 167e8048f0dSRenato Golin { "arm1022e", ARM::AK_ARMV5TE, true }, 168e8048f0dSRenato Golin { "iwmmxt", ARM::AK_ARMV5TE, false }, 1697374fcdbSRenato Golin { "xscale", ARM::AK_ARMV5TE, false }, 1707374fcdbSRenato Golin { "arm926ej-s", ARM::AK_ARMV5TEJ, true }, 171e8048f0dSRenato Golin { "arm1136jf-s", ARM::AK_ARMV6, true }, 172e8048f0dSRenato Golin { "arm1176j-s", ARM::AK_ARMV6K, false }, 1737374fcdbSRenato Golin { "arm1176jz-s", ARM::AK_ARMV6K, false }, 174e8048f0dSRenato Golin { "mpcore", ARM::AK_ARMV6K, false }, 175e8048f0dSRenato Golin { "mpcorenovfp", ARM::AK_ARMV6K, false }, 176e8048f0dSRenato Golin { "arm1176jzf-s", ARM::AK_ARMV6K, true }, 177e8048f0dSRenato Golin { "arm1176jzf-s", ARM::AK_ARMV6Z, true }, 178e8048f0dSRenato Golin { "arm1176jzf-s", ARM::AK_ARMV6ZK, true }, 179e8048f0dSRenato Golin { "arm1156t2-s", ARM::AK_ARMV6T2, true }, 180e8048f0dSRenato Golin { "arm1156t2f-s", ARM::AK_ARMV6T2, false }, 181e8048f0dSRenato Golin { "cortex-m0", ARM::AK_ARMV6M, true }, 182e8048f0dSRenato Golin { "cortex-m0plus", ARM::AK_ARMV6M, false }, 183e8048f0dSRenato Golin { "cortex-m1", ARM::AK_ARMV6M, false }, 184e8048f0dSRenato Golin { "sc000", ARM::AK_ARMV6M, false }, 185e8048f0dSRenato Golin { "cortex-a5", ARM::AK_ARMV7A, false }, 186e8048f0dSRenato Golin { "cortex-a7", ARM::AK_ARMV7A, false }, 187e8048f0dSRenato Golin { "cortex-a8", ARM::AK_ARMV7A, true }, 188e8048f0dSRenato Golin { "cortex-a9", ARM::AK_ARMV7A, false }, 189e8048f0dSRenato Golin { "cortex-a12", ARM::AK_ARMV7A, false }, 190e8048f0dSRenato Golin { "cortex-a15", ARM::AK_ARMV7A, false }, 191e8048f0dSRenato Golin { "cortex-a17", ARM::AK_ARMV7A, false }, 192e8048f0dSRenato Golin { "krait", ARM::AK_ARMV7A, false }, 193e8048f0dSRenato Golin { "cortex-r4", ARM::AK_ARMV7R, true }, 194e8048f0dSRenato Golin { "cortex-r4f", ARM::AK_ARMV7R, false }, 195e8048f0dSRenato Golin { "cortex-r5", ARM::AK_ARMV7R, false }, 196e8048f0dSRenato Golin { "cortex-r7", ARM::AK_ARMV7R, false }, 197e8048f0dSRenato Golin { "sc300", ARM::AK_ARMV7M, false }, 198e8048f0dSRenato Golin { "cortex-m3", ARM::AK_ARMV7M, true }, 1997374fcdbSRenato Golin { "cortex-m4", ARM::AK_ARMV7EM, true }, 2007374fcdbSRenato Golin { "cortex-m7", ARM::AK_ARMV7EM, false }, 201e8048f0dSRenato Golin { "cortex-a53", ARM::AK_ARMV8A, true }, 202e8048f0dSRenato Golin { "cortex-a57", ARM::AK_ARMV8A, false }, 203e8048f0dSRenato Golin { "cortex-a72", ARM::AK_ARMV8A, false }, 204e8048f0dSRenato Golin { "cyclone", ARM::AK_ARMV8A, false }, 205e8048f0dSRenato Golin { "generic", ARM::AK_ARMV8_1A, true }, 206e8048f0dSRenato Golin // Non-standard Arch names. 2077374fcdbSRenato Golin { "iwmmxt", ARM::AK_IWMMXT, true }, 2087374fcdbSRenato Golin { "xscale", ARM::AK_XSCALE, true }, 2097374fcdbSRenato Golin { "arm10tdmi", ARM::AK_ARMV5, true }, 210e8048f0dSRenato Golin { "arm1022e", ARM::AK_ARMV5E, true }, 2117374fcdbSRenato Golin { "arm1136j-s", ARM::AK_ARMV6J, true }, 2127374fcdbSRenato Golin { "arm1136jz-s", ARM::AK_ARMV6J, false }, 213e8048f0dSRenato Golin { "cortex-m0", ARM::AK_ARMV6SM, true }, 214b6b9e056SRenato Golin { "arm1176jzf-s", ARM::AK_ARMV6HL, true }, 2157374fcdbSRenato Golin { "cortex-a8", ARM::AK_ARMV7, true }, 216e8048f0dSRenato Golin { "cortex-a8", ARM::AK_ARMV7L, true }, 217b6b9e056SRenato Golin { "cortex-a8", ARM::AK_ARMV7HL, true }, 218e8048f0dSRenato Golin { "cortex-m4", ARM::AK_ARMV7EM, true }, 219e8048f0dSRenato Golin { "swift", ARM::AK_ARMV7S, true }, 220e8048f0dSRenato Golin // Invalid CPU 221e8048f0dSRenato Golin { "invalid", ARM::AK_INVALID, true } 222e8048f0dSRenato Golin }; 223f5f373fcSRenato Golin 224f5f373fcSRenato Golin } // namespace 225f5f373fcSRenato Golin 226f5f373fcSRenato Golin // ======================================================= // 227f5f373fcSRenato Golin // Information by ID 228f5f373fcSRenato Golin // ======================================================= // 229f5f373fcSRenato Golin 230e8048f0dSRenato Golin const char *ARMTargetParser::getFPUName(unsigned FPUKind) { 231e8048f0dSRenato Golin if (FPUKind >= ARM::FK_LAST) 232f5f373fcSRenato Golin return nullptr; 233e8048f0dSRenato Golin return FPUNames[FPUKind].Name; 234f5f373fcSRenato Golin } 235f5f373fcSRenato Golin 236d03d2292SJohn Brawn unsigned ARMTargetParser::getFPUVersion(unsigned FPUKind) { 237d03d2292SJohn Brawn if (FPUKind >= ARM::FK_LAST) 238d03d2292SJohn Brawn return 0; 239d03d2292SJohn Brawn return FPUNames[FPUKind].FPUVersion; 240d03d2292SJohn Brawn } 241d03d2292SJohn Brawn 242f2d06a57SBenjamin Kramer unsigned ARMTargetParser::getFPUNeonSupportLevel(unsigned FPUKind) { 243d03d2292SJohn Brawn if (FPUKind >= ARM::FK_LAST) 244d03d2292SJohn Brawn return 0; 245d03d2292SJohn Brawn return FPUNames[FPUKind].NeonSupport; 246d03d2292SJohn Brawn } 247d03d2292SJohn Brawn 248f2d06a57SBenjamin Kramer unsigned ARMTargetParser::getFPURestriction(unsigned FPUKind) { 249d03d2292SJohn Brawn if (FPUKind >= ARM::FK_LAST) 250d03d2292SJohn Brawn return 0; 251d03d2292SJohn Brawn return FPUNames[FPUKind].Restriction; 252d03d2292SJohn Brawn } 253d03d2292SJohn Brawn 254d03d2292SJohn Brawn bool ARMTargetParser::getFPUFeatures(unsigned FPUKind, 255d03d2292SJohn Brawn std::vector<const char *> &Features) { 256d03d2292SJohn Brawn 257d03d2292SJohn Brawn if (FPUKind >= ARM::FK_LAST || FPUKind == ARM::FK_INVALID) 258d03d2292SJohn Brawn return false; 259d03d2292SJohn Brawn 260d03d2292SJohn Brawn // fp-only-sp and d16 subtarget features are independent of each other, so we 261d03d2292SJohn Brawn // must enable/disable both. 262d03d2292SJohn Brawn switch (FPUNames[FPUKind].Restriction) { 263d03d2292SJohn Brawn case ARM::FR_SP_D16: 264d03d2292SJohn Brawn Features.push_back("+fp-only-sp"); 265d03d2292SJohn Brawn Features.push_back("+d16"); 266d03d2292SJohn Brawn break; 267d03d2292SJohn Brawn case ARM::FR_D16: 268d03d2292SJohn Brawn Features.push_back("-fp-only-sp"); 269d03d2292SJohn Brawn Features.push_back("+d16"); 270d03d2292SJohn Brawn break; 271d03d2292SJohn Brawn case ARM::FR_None: 272d03d2292SJohn Brawn Features.push_back("-fp-only-sp"); 273d03d2292SJohn Brawn Features.push_back("-d16"); 274d03d2292SJohn Brawn break; 275d03d2292SJohn Brawn } 276d03d2292SJohn Brawn 277d03d2292SJohn Brawn // FPU version subtarget features are inclusive of lower-numbered ones, so 278d03d2292SJohn Brawn // enable the one corresponding to this version and disable all that are 279d03d2292SJohn Brawn // higher. 280d03d2292SJohn Brawn switch (FPUNames[FPUKind].FPUVersion) { 281d03d2292SJohn Brawn case 5: 282d03d2292SJohn Brawn Features.push_back("+fp-armv8"); 283d03d2292SJohn Brawn break; 284d03d2292SJohn Brawn case 4: 285d03d2292SJohn Brawn Features.push_back("+vfp4"); 286d03d2292SJohn Brawn Features.push_back("-fp-armv8"); 287d03d2292SJohn Brawn break; 288d03d2292SJohn Brawn case 3: 289d03d2292SJohn Brawn Features.push_back("+vfp3"); 290d03d2292SJohn Brawn Features.push_back("-vfp4"); 291d03d2292SJohn Brawn Features.push_back("-fp-armv8"); 292d03d2292SJohn Brawn break; 293d03d2292SJohn Brawn case 2: 294d03d2292SJohn Brawn Features.push_back("+vfp2"); 295d03d2292SJohn Brawn Features.push_back("-vfp3"); 296d03d2292SJohn Brawn Features.push_back("-vfp4"); 297d03d2292SJohn Brawn Features.push_back("-fp-armv8"); 298d03d2292SJohn Brawn break; 299d03d2292SJohn Brawn case 0: 300d03d2292SJohn Brawn Features.push_back("-vfp2"); 301d03d2292SJohn Brawn Features.push_back("-vfp3"); 302d03d2292SJohn Brawn Features.push_back("-vfp4"); 303d03d2292SJohn Brawn Features.push_back("-fp-armv8"); 304d03d2292SJohn Brawn break; 305d03d2292SJohn Brawn } 306d03d2292SJohn Brawn 307d03d2292SJohn Brawn // crypto includes neon, so we handle this similarly to FPU version. 308d03d2292SJohn Brawn switch (FPUNames[FPUKind].NeonSupport) { 309d03d2292SJohn Brawn case ARM::NS_Crypto: 310d03d2292SJohn Brawn Features.push_back("+crypto"); 311d03d2292SJohn Brawn break; 312d03d2292SJohn Brawn case ARM::NS_Neon: 313d03d2292SJohn Brawn Features.push_back("+neon"); 314d03d2292SJohn Brawn Features.push_back("-crypto"); 315d03d2292SJohn Brawn break; 316d03d2292SJohn Brawn case ARM::NS_None: 317d03d2292SJohn Brawn Features.push_back("-neon"); 318d03d2292SJohn Brawn Features.push_back("-crypto"); 319d03d2292SJohn Brawn break; 320d03d2292SJohn Brawn } 321d03d2292SJohn Brawn 322d03d2292SJohn Brawn return true; 323d03d2292SJohn Brawn } 324d03d2292SJohn Brawn 325e8048f0dSRenato Golin const char *ARMTargetParser::getArchName(unsigned ArchKind) { 326e8048f0dSRenato Golin if (ArchKind >= ARM::AK_LAST) 327f5f373fcSRenato Golin return nullptr; 328e8048f0dSRenato Golin return ARCHNames[ArchKind].Name; 329f5f373fcSRenato Golin } 330f5f373fcSRenato Golin 331f7c0d5f2SRenato Golin const char *ARMTargetParser::getCPUAttr(unsigned ArchKind) { 332e8048f0dSRenato Golin if (ArchKind >= ARM::AK_LAST) 333f5f373fcSRenato Golin return nullptr; 334f7c0d5f2SRenato Golin return ARCHNames[ArchKind].CPUAttr; 335f5f373fcSRenato Golin } 336f5f373fcSRenato Golin 33742dad647SRenato Golin const char *ARMTargetParser::getSubArch(unsigned ArchKind) { 33842dad647SRenato Golin if (ArchKind >= ARM::AK_LAST) 33942dad647SRenato Golin return nullptr; 34042dad647SRenato Golin return ARCHNames[ArchKind].SubArch; 34142dad647SRenato Golin } 34242dad647SRenato Golin 343f7c0d5f2SRenato Golin unsigned ARMTargetParser::getArchAttr(unsigned ArchKind) { 344e8048f0dSRenato Golin if (ArchKind >= ARM::AK_LAST) 345e8048f0dSRenato Golin return ARMBuildAttrs::CPUArch::Pre_v4; 346f7c0d5f2SRenato Golin return ARCHNames[ArchKind].ArchAttr; 347f5f373fcSRenato Golin } 348f5f373fcSRenato Golin 349e8048f0dSRenato Golin const char *ARMTargetParser::getArchExtName(unsigned ArchExtKind) { 350e8048f0dSRenato Golin if (ArchExtKind >= ARM::AEK_LAST) 351f5f373fcSRenato Golin return nullptr; 352e8048f0dSRenato Golin return ARCHExtNames[ArchExtKind].Name; 353e8048f0dSRenato Golin } 354e8048f0dSRenato Golin 355e8048f0dSRenato Golin const char *ARMTargetParser::getDefaultCPU(StringRef Arch) { 356e8048f0dSRenato Golin unsigned AK = parseArch(Arch); 357e8048f0dSRenato Golin if (AK == ARM::AK_INVALID) 358e8048f0dSRenato Golin return nullptr; 359e8048f0dSRenato Golin 360e8048f0dSRenato Golin // Look for multiple AKs to find the default for pair AK+Name. 361e8048f0dSRenato Golin for (const auto CPU : CPUNames) { 362e8048f0dSRenato Golin if (CPU.ArchID == AK && CPU.Default) 363e8048f0dSRenato Golin return CPU.Name; 364e8048f0dSRenato Golin } 365e8048f0dSRenato Golin return nullptr; 366f5f373fcSRenato Golin } 367f5f373fcSRenato Golin 368f5f373fcSRenato Golin // ======================================================= // 369f5f373fcSRenato Golin // Parsers 370f5f373fcSRenato Golin // ======================================================= // 371f5f373fcSRenato Golin 372f5f373fcSRenato Golin StringRef ARMTargetParser::getFPUSynonym(StringRef FPU) { 373f5f373fcSRenato Golin return StringSwitch<StringRef>(FPU) 374f5f373fcSRenato Golin .Cases("fpa", "fpe2", "fpe3", "maverick", "invalid") // Unsupported 375f5f373fcSRenato Golin .Case("vfp2", "vfpv2") 376f5f373fcSRenato Golin .Case("vfp3", "vfpv3") 377f5f373fcSRenato Golin .Case("vfp4", "vfpv4") 378f5f373fcSRenato Golin .Case("vfp3-d16", "vfpv3-d16") 379f5f373fcSRenato Golin .Case("vfp4-d16", "vfpv4-d16") 380985c04e8SJohn Brawn .Cases("fp4-sp-d16", "vfpv4-sp-d16", "fpv4-sp-d16") 381f5f373fcSRenato Golin .Cases("fp4-dp-d16", "fpv4-dp-d16", "vfpv4-d16") 382985c04e8SJohn Brawn .Case("fp5-sp-d16", "fpv5-sp-d16") 383f5f373fcSRenato Golin .Cases("fp5-dp-d16", "fpv5-dp-d16", "fpv5-d16") 384f5f373fcSRenato Golin // FIXME: Clang uses it, but it's bogus, since neon defaults to vfpv3. 385f5f373fcSRenato Golin .Case("neon-vfpv3", "neon") 386f5f373fcSRenato Golin .Default(FPU); 387f5f373fcSRenato Golin } 388f5f373fcSRenato Golin 389f5f373fcSRenato Golin StringRef ARMTargetParser::getArchSynonym(StringRef Arch) { 390f5f373fcSRenato Golin return StringSwitch<StringRef>(Arch) 39185aebc8cSArtyom Skrobov .Case("v6sm", "v6s-m") 39285aebc8cSArtyom Skrobov .Case("v6m", "v6-m") 39385aebc8cSArtyom Skrobov .Case("v7a", "v7-a") 39485aebc8cSArtyom Skrobov .Case("v7r", "v7-r") 39585aebc8cSArtyom Skrobov .Case("v7m", "v7-m") 39685aebc8cSArtyom Skrobov .Case("v7em", "v7e-m") 397acd1cd66SArtyom Skrobov .Cases("v8", "v8a", "aarch64", "arm64", "v8-a") 39885aebc8cSArtyom Skrobov .Case("v8.1a", "v8.1-a") 399f5f373fcSRenato Golin .Default(Arch); 400f5f373fcSRenato Golin } 401f5f373fcSRenato Golin 402e8048f0dSRenato Golin // MArch is expected to be of the form (arm|thumb)?(eb)?(v.+)?(eb)?, but 403e8048f0dSRenato Golin // (iwmmxt|xscale)(eb)? is also permitted. If the former, return 404ebdd12cbSRenato Golin // "v.+", if the latter, return unmodified string, minus 'eb'. 405ebdd12cbSRenato Golin // If invalid, return empty string. 406e8048f0dSRenato Golin StringRef ARMTargetParser::getCanonicalArchName(StringRef Arch) { 407e8048f0dSRenato Golin size_t offset = StringRef::npos; 408e8048f0dSRenato Golin StringRef A = Arch; 409b6b9e056SRenato Golin StringRef Error = ""; 410e8048f0dSRenato Golin 411e8048f0dSRenato Golin // Begins with "arm" / "thumb", move past it. 412ebdd12cbSRenato Golin if (A.startswith("arm64")) 413ebdd12cbSRenato Golin offset = 5; 414ebdd12cbSRenato Golin else if (A.startswith("arm")) 415e8048f0dSRenato Golin offset = 3; 416e8048f0dSRenato Golin else if (A.startswith("thumb")) 417e8048f0dSRenato Golin offset = 5; 418b6b9e056SRenato Golin else if (A.startswith("aarch64")) { 419b6b9e056SRenato Golin offset = 7; 420b6b9e056SRenato Golin // AArch64 uses "_be", not "eb" suffix. 421b6b9e056SRenato Golin if (A.find("eb") != StringRef::npos) 422b6b9e056SRenato Golin return Error; 423b6b9e056SRenato Golin if (A.substr(offset,3) == "_be") 424b6b9e056SRenato Golin offset += 3; 425b6b9e056SRenato Golin } 426b6b9e056SRenato Golin 427e8048f0dSRenato Golin // Ex. "armebv7", move past the "eb". 428e8048f0dSRenato Golin if (offset != StringRef::npos && A.substr(offset, 2) == "eb") 429e8048f0dSRenato Golin offset += 2; 430e8048f0dSRenato Golin // Or, if it ends with eb ("armv7eb"), chop it off. 431e8048f0dSRenato Golin else if (A.endswith("eb")) 432e8048f0dSRenato Golin A = A.substr(0, A.size() - 2); 433ebdd12cbSRenato Golin // Trim the head 434ebdd12cbSRenato Golin if (offset != StringRef::npos) 435e8048f0dSRenato Golin A = A.substr(offset); 436e8048f0dSRenato Golin 437ebdd12cbSRenato Golin // Empty string means offset reached the end, which means it's valid. 438e8048f0dSRenato Golin if (A.empty()) 439e8048f0dSRenato Golin return Arch; 440e8048f0dSRenato Golin 441ebdd12cbSRenato Golin // Only match non-marketing names 442ebdd12cbSRenato Golin if (offset != StringRef::npos) { 443ebdd12cbSRenato Golin // Must start with 'vN'. 444ebdd12cbSRenato Golin if (A[0] != 'v' || !std::isdigit(A[1])) 445b6b9e056SRenato Golin return Error; 446ebdd12cbSRenato Golin // Can't have an extra 'eb'. 447ebdd12cbSRenato Golin if (A.find("eb") != StringRef::npos) 448ebdd12cbSRenato Golin return Error; 449ebdd12cbSRenato Golin } 450e8048f0dSRenato Golin 451ebdd12cbSRenato Golin // Arch will either be a 'v' name (v7a) or a marketing name (xscale). 452e8048f0dSRenato Golin return A; 453e8048f0dSRenato Golin } 454e8048f0dSRenato Golin 455f5f373fcSRenato Golin unsigned ARMTargetParser::parseFPU(StringRef FPU) { 456f5f373fcSRenato Golin StringRef Syn = getFPUSynonym(FPU); 457f5f373fcSRenato Golin for (const auto F : FPUNames) { 458f5f373fcSRenato Golin if (Syn == F.Name) 459f5f373fcSRenato Golin return F.ID; 460f5f373fcSRenato Golin } 46135de35d0SRenato Golin return ARM::FK_INVALID; 462f5f373fcSRenato Golin } 463f5f373fcSRenato Golin 464e8048f0dSRenato Golin // Allows partial match, ex. "v7a" matches "armv7a". 465f5f373fcSRenato Golin unsigned ARMTargetParser::parseArch(StringRef Arch) { 46685aebc8cSArtyom Skrobov Arch = getCanonicalArchName(Arch); 467f5f373fcSRenato Golin StringRef Syn = getArchSynonym(Arch); 468f5f373fcSRenato Golin for (const auto A : ARCHNames) { 469e8048f0dSRenato Golin if (StringRef(A.Name).endswith(Syn)) 470f5f373fcSRenato Golin return A.ID; 471f5f373fcSRenato Golin } 47235de35d0SRenato Golin return ARM::AK_INVALID; 473f5f373fcSRenato Golin } 474f5f373fcSRenato Golin 475f5f373fcSRenato Golin unsigned ARMTargetParser::parseArchExt(StringRef ArchExt) { 476f5f373fcSRenato Golin for (const auto A : ARCHExtNames) { 477f5f373fcSRenato Golin if (ArchExt == A.Name) 478f5f373fcSRenato Golin return A.ID; 479f5f373fcSRenato Golin } 48035de35d0SRenato Golin return ARM::AEK_INVALID; 481f5f373fcSRenato Golin } 482f5f373fcSRenato Golin 483e8048f0dSRenato Golin unsigned ARMTargetParser::parseCPUArch(StringRef CPU) { 484e8048f0dSRenato Golin for (const auto C : CPUNames) { 485e8048f0dSRenato Golin if (CPU == C.Name) 486e8048f0dSRenato Golin return C.ArchID; 487e8048f0dSRenato Golin } 488e8048f0dSRenato Golin return ARM::AK_INVALID; 489e8048f0dSRenato Golin } 490e8048f0dSRenato Golin 491b6b9e056SRenato Golin // ARM, Thumb, AArch64 492b6b9e056SRenato Golin unsigned ARMTargetParser::parseArchISA(StringRef Arch) { 493b6b9e056SRenato Golin return StringSwitch<unsigned>(Arch) 494b6b9e056SRenato Golin .StartsWith("aarch64", ARM::IK_AARCH64) 495b6b9e056SRenato Golin .StartsWith("arm64", ARM::IK_AARCH64) 496b6b9e056SRenato Golin .StartsWith("thumb", ARM::IK_THUMB) 497b6b9e056SRenato Golin .StartsWith("arm", ARM::IK_ARM) 498b6b9e056SRenato Golin .Default(ARM::EK_INVALID); 499b6b9e056SRenato Golin } 500b6b9e056SRenato Golin 501b6b9e056SRenato Golin // Little/Big endian 502b6b9e056SRenato Golin unsigned ARMTargetParser::parseArchEndian(StringRef Arch) { 503b6b9e056SRenato Golin if (Arch.startswith("armeb") || 504b6b9e056SRenato Golin Arch.startswith("thumbeb") || 505b6b9e056SRenato Golin Arch.startswith("aarch64_be")) 506b6b9e056SRenato Golin return ARM::EK_BIG; 507b6b9e056SRenato Golin 508b6b9e056SRenato Golin if (Arch.startswith("arm") || Arch.startswith("thumb")) { 509b6b9e056SRenato Golin if (Arch.endswith("eb")) 510b6b9e056SRenato Golin return ARM::EK_BIG; 511b6b9e056SRenato Golin else 512b6b9e056SRenato Golin return ARM::EK_LITTLE; 513b6b9e056SRenato Golin } 514b6b9e056SRenato Golin 515b6b9e056SRenato Golin if (Arch.startswith("aarch64")) 516b6b9e056SRenato Golin return ARM::EK_LITTLE; 517b6b9e056SRenato Golin 518b6b9e056SRenato Golin return ARM::EK_INVALID; 519b6b9e056SRenato Golin } 520b6b9e056SRenato Golin 521fadc2108SRenato Golin // Profile A/R/M 522fadc2108SRenato Golin unsigned ARMTargetParser::parseArchProfile(StringRef Arch) { 523fadc2108SRenato Golin Arch = getCanonicalArchName(Arch); 524fadc2108SRenato Golin switch(parseArch(Arch)) { 525fadc2108SRenato Golin case ARM::AK_ARMV6M: 526fadc2108SRenato Golin case ARM::AK_ARMV7M: 527fadc2108SRenato Golin case ARM::AK_ARMV6SM: 528fadc2108SRenato Golin case ARM::AK_ARMV7EM: 529fadc2108SRenato Golin return ARM::PK_M; 530fadc2108SRenato Golin case ARM::AK_ARMV7R: 531fadc2108SRenato Golin return ARM::PK_R; 532fadc2108SRenato Golin case ARM::AK_ARMV7: 533fadc2108SRenato Golin case ARM::AK_ARMV7A: 534fadc2108SRenato Golin case ARM::AK_ARMV8A: 535fadc2108SRenato Golin case ARM::AK_ARMV8_1A: 536fadc2108SRenato Golin return ARM::PK_A; 537fadc2108SRenato Golin } 538fadc2108SRenato Golin return ARM::PK_INVALID; 539fadc2108SRenato Golin } 540fadc2108SRenato Golin 541ebdd12cbSRenato Golin // Version number (ex. v7 = 7). 542fadc2108SRenato Golin unsigned ARMTargetParser::parseArchVersion(StringRef Arch) { 543fadc2108SRenato Golin Arch = getCanonicalArchName(Arch); 544fadc2108SRenato Golin switch(parseArch(Arch)) { 545fadc2108SRenato Golin case ARM::AK_ARMV2: 546fadc2108SRenato Golin case ARM::AK_ARMV2A: 547fadc2108SRenato Golin return 2; 548fadc2108SRenato Golin case ARM::AK_ARMV3: 549fadc2108SRenato Golin case ARM::AK_ARMV3M: 550fadc2108SRenato Golin return 3; 551fadc2108SRenato Golin case ARM::AK_ARMV4: 552fadc2108SRenato Golin case ARM::AK_ARMV4T: 553fadc2108SRenato Golin return 4; 554fadc2108SRenato Golin case ARM::AK_ARMV5: 555fadc2108SRenato Golin case ARM::AK_ARMV5T: 556fadc2108SRenato Golin case ARM::AK_ARMV5TE: 557fadc2108SRenato Golin case ARM::AK_IWMMXT: 558fadc2108SRenato Golin case ARM::AK_IWMMXT2: 559fadc2108SRenato Golin case ARM::AK_XSCALE: 560fadc2108SRenato Golin case ARM::AK_ARMV5E: 561fadc2108SRenato Golin case ARM::AK_ARMV5TEJ: 562fadc2108SRenato Golin return 5; 563fadc2108SRenato Golin case ARM::AK_ARMV6: 564fadc2108SRenato Golin case ARM::AK_ARMV6J: 565fadc2108SRenato Golin case ARM::AK_ARMV6K: 566fadc2108SRenato Golin case ARM::AK_ARMV6T2: 567fadc2108SRenato Golin case ARM::AK_ARMV6Z: 568fadc2108SRenato Golin case ARM::AK_ARMV6ZK: 569fadc2108SRenato Golin case ARM::AK_ARMV6M: 570fadc2108SRenato Golin case ARM::AK_ARMV6SM: 571fadc2108SRenato Golin case ARM::AK_ARMV6HL: 572fadc2108SRenato Golin return 6; 573fadc2108SRenato Golin case ARM::AK_ARMV7: 574fadc2108SRenato Golin case ARM::AK_ARMV7A: 575fadc2108SRenato Golin case ARM::AK_ARMV7R: 576fadc2108SRenato Golin case ARM::AK_ARMV7M: 577fadc2108SRenato Golin case ARM::AK_ARMV7L: 578fadc2108SRenato Golin case ARM::AK_ARMV7HL: 579fadc2108SRenato Golin case ARM::AK_ARMV7S: 580fadc2108SRenato Golin case ARM::AK_ARMV7EM: 581fadc2108SRenato Golin return 7; 582fadc2108SRenato Golin case ARM::AK_ARMV8A: 583fadc2108SRenato Golin case ARM::AK_ARMV8_1A: 584fadc2108SRenato Golin return 8; 585fadc2108SRenato Golin } 586fadc2108SRenato Golin return 0; 587fadc2108SRenato Golin } 588