Index: include/llvm/Support/TargetParser.h =================================================================== --- include/llvm/Support/TargetParser.h +++ include/llvm/Support/TargetParser.h @@ -18,6 +18,7 @@ // FIXME: vector is used because that's what clang uses for subtarget feature // lists, but SmallVector would probably be better #include +#include "llvm/ADT/StringMap.h" namespace llvm { class StringRef; @@ -181,11 +182,15 @@ static unsigned getFPUNeonSupportLevel(unsigned FPUKind); static unsigned getFPURestriction(unsigned FPUKind); static unsigned getDefaultFPU(StringRef CPU); + static unsigned getDefaultExtensions(StringRef CPU); + static unsigned getHWDivKind(unsigned ArchKind); // FIXME: This should be moved to TargetTuple once it exists static bool getFPUFeatures(unsigned FPUKind, std::vector &Features); static bool getHWDivFeatures(unsigned HWDivKind, std::vector &Features); + static bool getExtensionFeatures(unsigned Extensions, + llvm::StringMap &Features); static const char * getArchName(unsigned ArchKind); static unsigned getArchAttr(unsigned ArchKind); static const char * getCPUAttr(unsigned ArchKind); Index: lib/Support/TargetParser.cpp =================================================================== --- lib/Support/TargetParser.cpp +++ lib/Support/TargetParser.cpp @@ -114,22 +114,26 @@ struct { const char *Name; unsigned ID; + bool IsBackendOption; } ARCHExtNames[] = { - { "invalid", ARM::AEK_INVALID }, - { "none", ARM::AEK_NONE }, - { "crc", ARM::AEK_CRC }, - { "crypto", ARM::AEK_CRYPTO }, - { "fp", ARM::AEK_FP }, - { "idiv", (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV) }, - { "mp", ARM::AEK_MP }, - { "simd", ARM::AEK_SIMD }, - { "sec", ARM::AEK_SEC }, - { "virt", ARM::AEK_VIRT }, - { "os", ARM::AEK_OS }, - { "iwmmxt", ARM::AEK_IWMMXT }, - { "iwmmxt2", ARM::AEK_IWMMXT2 }, - { "maverick", ARM::AEK_MAVERICK }, - { "xscale", ARM::AEK_XSCALE } + { "invalid", ARM::AEK_INVALID, false }, + { "none", ARM::AEK_NONE, false }, + { "crc", ARM::AEK_CRC, true }, + { "crypto", ARM::AEK_CRYPTO, true }, + { "fp", ARM::AEK_FP, false }, + { "idiv", (ARM::AEK_HWDIVARM | + ARM::AEK_HWDIV), false }, + { "hwdiv-arm", ARM::AEK_HWDIVARM, true }, + { "hwdiv", ARM::AEK_HWDIV, true }, + { "mp", ARM::AEK_MP, false }, + { "simd", ARM::AEK_SIMD, false }, + { "sec", ARM::AEK_SEC, false }, + { "virt", ARM::AEK_VIRT, false }, + { "os", ARM::AEK_OS, false }, + { "iwmmxt", ARM::AEK_IWMMXT, false }, + { "iwmmxt2", ARM::AEK_IWMMXT2, false }, + { "maverick", ARM::AEK_MAVERICK, false }, + { "xscale", ARM::AEK_XSCALE, false } }; // List of HWDiv names (use getHWDivSynonym) and which architectural // features they correspond to (use getHWDivFeatures). @@ -153,93 +157,94 @@ const char *Name; ARM::ArchKind ArchID; ARM::FPUKind DefaultFPU; + unsigned DefaultExtensions; bool Default; // is $Name the default CPU for $ArchID ? } CPUNames[] = { - { "arm2", ARM::AK_ARMV2, ARM::FK_NONE, true }, - { "arm3", ARM::AK_ARMV2A, ARM::FK_NONE, true }, - { "arm6", ARM::AK_ARMV3, ARM::FK_NONE, true }, - { "arm7m", ARM::AK_ARMV3M, ARM::FK_NONE, true }, - { "arm8", ARM::AK_ARMV4, ARM::FK_NONE, false }, - { "arm810", ARM::AK_ARMV4, ARM::FK_NONE, false }, - { "strongarm", ARM::AK_ARMV4, ARM::FK_NONE, true }, - { "strongarm110", ARM::AK_ARMV4, ARM::FK_NONE, false }, - { "strongarm1100", ARM::AK_ARMV4, ARM::FK_NONE, false }, - { "strongarm1110", ARM::AK_ARMV4, ARM::FK_NONE, false }, - { "arm7tdmi", ARM::AK_ARMV4T, ARM::FK_NONE, true }, - { "arm7tdmi-s", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm710t", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm720t", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm9", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm9tdmi", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm920", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm920t", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm922t", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm9312", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm940t", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "ep9312", ARM::AK_ARMV4T, ARM::FK_NONE, false }, - { "arm10tdmi", ARM::AK_ARMV5T, ARM::FK_NONE, true }, - { "arm1020t", ARM::AK_ARMV5T, ARM::FK_NONE, false }, - { "arm9e", ARM::AK_ARMV5TE, ARM::FK_NONE, false }, - { "arm946e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, false }, - { "arm966e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, false }, - { "arm968e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, false }, - { "arm10e", ARM::AK_ARMV5TE, ARM::FK_NONE, false }, - { "arm1020e", ARM::AK_ARMV5TE, ARM::FK_NONE, false }, - { "arm1022e", ARM::AK_ARMV5TE, ARM::FK_NONE, true }, - { "iwmmxt", ARM::AK_ARMV5TE, ARM::FK_NONE, false }, - { "xscale", ARM::AK_ARMV5TE, ARM::FK_NONE, false }, - { "arm926ej-s", ARM::AK_ARMV5TEJ, ARM::FK_NONE, true }, - { "arm1136jf-s", ARM::AK_ARMV6, ARM::FK_VFPV2, true }, - { "arm1176j-s", ARM::AK_ARMV6K, ARM::FK_NONE, false }, - { "arm1176jz-s", ARM::AK_ARMV6K, ARM::FK_NONE, false }, - { "mpcore", ARM::AK_ARMV6K, ARM::FK_VFPV2, false }, - { "mpcorenovfp", ARM::AK_ARMV6K, ARM::FK_NONE, false }, - { "arm1176jzf-s", ARM::AK_ARMV6K, ARM::FK_VFPV2, true }, - { "arm1176jzf-s", ARM::AK_ARMV6Z, ARM::FK_VFPV2, true }, - { "arm1176jzf-s", ARM::AK_ARMV6ZK, ARM::FK_VFPV2, true }, - { "arm1156t2-s", ARM::AK_ARMV6T2, ARM::FK_NONE, true }, - { "arm1156t2f-s", ARM::AK_ARMV6T2, ARM::FK_VFPV2, false }, - { "cortex-m0", ARM::AK_ARMV6M, ARM::FK_NONE, true }, - { "cortex-m0plus", ARM::AK_ARMV6M, ARM::FK_NONE, false }, - { "cortex-m1", ARM::AK_ARMV6M, ARM::FK_NONE, false }, - { "sc000", ARM::AK_ARMV6M, ARM::FK_NONE, false }, - { "cortex-a5", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false }, - { "cortex-a7", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false }, - { "cortex-a8", ARM::AK_ARMV7A, ARM::FK_NEON, true }, - { "cortex-a9", ARM::AK_ARMV7A, ARM::FK_NEON_FP16, false }, - { "cortex-a12", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false }, - { "cortex-a15", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false }, - { "cortex-a17", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false }, - { "krait", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, false }, - { "cortex-r4", ARM::AK_ARMV7R, ARM::FK_NONE, true }, - { "cortex-r4f", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16, false }, - { "cortex-r5", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16, false }, - { "cortex-r7", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16_FP16, false }, - { "sc300", ARM::AK_ARMV7M, ARM::FK_NONE, false }, - { "cortex-m3", ARM::AK_ARMV7M, ARM::FK_NONE, true }, - { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_FPV4_SP_D16, true }, - { "cortex-m7", ARM::AK_ARMV7EM, ARM::FK_FPV5_D16, false }, - { "cortex-a53", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, true }, - { "cortex-a57", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false }, - { "cortex-a72", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false }, - { "cyclone", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, false }, - { "generic", ARM::AK_ARMV8_1A, ARM::FK_NEON_FP_ARMV8, true }, + { "arm2", ARM::AK_ARMV2, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm3", ARM::AK_ARMV2A, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm6", ARM::AK_ARMV3, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm7m", ARM::AK_ARMV3M, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm8", ARM::AK_ARMV4, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm810", ARM::AK_ARMV4, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "strongarm", ARM::AK_ARMV4, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "strongarm110", ARM::AK_ARMV4, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "strongarm1100", ARM::AK_ARMV4, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "strongarm1110", ARM::AK_ARMV4, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm7tdmi", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm7tdmi-s", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm710t", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm720t", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm9", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm9tdmi", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm920", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm920t", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm922t", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm9312", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm940t", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "ep9312", ARM::AK_ARMV4T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm10tdmi", ARM::AK_ARMV5T, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm1020t", ARM::AK_ARMV5T, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm9e", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm946e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm966e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm968e-s", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm10e", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm1020e", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm1022e", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "iwmmxt", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "xscale", ARM::AK_ARMV5TE, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm926ej-s", ARM::AK_ARMV5TEJ, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm1136jf-s", ARM::AK_ARMV6, ARM::FK_VFPV2, ARM::AEK_NONE, true }, + { "arm1176j-s", ARM::AK_ARMV6K, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm1176jz-s", ARM::AK_ARMV6K, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "mpcore", ARM::AK_ARMV6K, ARM::FK_VFPV2, ARM::AEK_NONE, false }, + { "mpcorenovfp", ARM::AK_ARMV6K, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "arm1176jzf-s", ARM::AK_ARMV6K, ARM::FK_VFPV2, ARM::AEK_NONE, true }, + { "arm1176jzf-s", ARM::AK_ARMV6Z, ARM::FK_VFPV2, ARM::AEK_NONE, true }, + { "arm1176jzf-s", ARM::AK_ARMV6ZK, ARM::FK_VFPV2, ARM::AEK_NONE, true }, + { "arm1156t2-s", ARM::AK_ARMV6T2, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm1156t2f-s", ARM::AK_ARMV6T2, ARM::FK_VFPV2, ARM::AEK_NONE, false }, + { "cortex-m0", ARM::AK_ARMV6M, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "cortex-m0plus", ARM::AK_ARMV6M, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "cortex-m1", ARM::AK_ARMV6M, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "sc000", ARM::AK_ARMV6M, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "cortex-a5", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, ARM::AEK_MP, false }, + { "cortex-a7", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV | ARM::AEK_MP | ARM::AEK_VIRT), false }, + { "cortex-a8", ARM::AK_ARMV7A, ARM::FK_NEON, ARM::AEK_NONE, true }, + { "cortex-a9", ARM::AK_ARMV7A, ARM::FK_NEON_FP16, ARM::AEK_MP, false }, + { "cortex-a12", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV | ARM::AEK_MP | ARM::AEK_VIRT), false }, + { "cortex-a15", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV | ARM::AEK_MP | ARM::AEK_VIRT), false }, + { "cortex-a17", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV | ARM::AEK_MP | ARM::AEK_VIRT), false }, + { "krait", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), false }, + { "cortex-r4", ARM::AK_ARMV7R, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "cortex-r4f", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16, ARM::AEK_NONE, false }, + { "cortex-r5", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16, (ARM::AEK_HWDIVARM | ARM::AEK_MP), false }, + { "cortex-r7", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16_FP16, (ARM::AEK_HWDIVARM | ARM::AEK_MP), false }, + { "sc300", ARM::AK_ARMV7M, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "cortex-m3", ARM::AK_ARMV7M, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_FPV4_SP_D16, ARM::AEK_NONE, true }, + { "cortex-m7", ARM::AK_ARMV7EM, ARM::FK_FPV5_D16, ARM::AEK_NONE, false }, + { "cortex-a53", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, ARM::AEK_CRC, true }, + { "cortex-a57", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, ARM::AEK_CRC, false }, + { "cortex-a72", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, ARM::AEK_CRC, false }, + { "cyclone", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, ARM::AEK_CRC, false }, + { "generic", ARM::AK_ARMV8_1A, ARM::FK_NEON_FP_ARMV8, ARM::AEK_NONE, true }, // Non-standard Arch names. - { "iwmmxt", ARM::AK_IWMMXT, ARM::FK_NONE, true }, - { "xscale", ARM::AK_XSCALE, ARM::FK_NONE, true }, - { "arm10tdmi", ARM::AK_ARMV5, ARM::FK_NONE, true }, - { "arm1022e", ARM::AK_ARMV5E, ARM::FK_NONE, true }, - { "arm1136j-s", ARM::AK_ARMV6J, ARM::FK_NONE, true }, - { "arm1136jz-s", ARM::AK_ARMV6J, ARM::FK_NONE, false }, - { "cortex-m0", ARM::AK_ARMV6SM, ARM::FK_NONE, true }, - { "arm1176jzf-s", ARM::AK_ARMV6HL, ARM::FK_VFPV2, true }, - { "cortex-a8", ARM::AK_ARMV7, ARM::FK_NEON, true }, - { "cortex-a8", ARM::AK_ARMV7L, ARM::FK_NEON, true }, - { "cortex-a8", ARM::AK_ARMV7HL, ARM::FK_NEON, true }, - { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_NONE, true }, - { "swift", ARM::AK_ARMV7S, ARM::FK_NEON_VFPV4, true }, + { "iwmmxt", ARM::AK_IWMMXT, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "xscale", ARM::AK_XSCALE, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm10tdmi", ARM::AK_ARMV5, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm1022e", ARM::AK_ARMV5E, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm1136j-s", ARM::AK_ARMV6J, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm1136jz-s", ARM::AK_ARMV6J, ARM::FK_NONE, ARM::AEK_NONE, false }, + { "cortex-m0", ARM::AK_ARMV6SM, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "arm1176jzf-s", ARM::AK_ARMV6HL, ARM::FK_VFPV2, ARM::AEK_NONE, true }, + { "cortex-a8", ARM::AK_ARMV7, ARM::FK_NEON, ARM::AEK_NONE, true }, + { "cortex-a8", ARM::AK_ARMV7L, ARM::FK_NEON, ARM::AEK_NONE, true }, + { "cortex-a8", ARM::AK_ARMV7HL, ARM::FK_NEON, ARM::AEK_NONE, true }, + { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_NONE, ARM::AEK_NONE, true }, + { "swift", ARM::AK_ARMV7S, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), true }, // Invalid CPU - { "invalid", ARM::AK_INVALID, ARM::FK_INVALID, true } + { "invalid", ARM::AK_INVALID, ARM::FK_INVALID, ARM::AEK_INVALID, true } }; } // namespace @@ -280,9 +285,34 @@ return ARM::FK_INVALID; } +unsigned ARMTargetParser::getDefaultExtensions(StringRef CPU) { + for (const auto C : CPUNames) { + if (CPU == C.Name) + return C.DefaultExtensions; + } + return ARM::AEK_INVALID; +} + +unsigned ARMTargetParser::getHWDivKind(unsigned ArchKind) { + + if (ArchKind >= ARM::AK_LAST) + return ARM::AEK_INVALID; + + switch(ArchKind) { + case ARM::AK_ARMV8A: + case ARM::AK_ARMV8_1A: + return (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV); + case ARM::AK_ARMV7R: + case ARM::AK_ARMV7M: + case ARM::AK_ARMV7EM: + return ARM::AEK_HWDIV; + default: + return ARM::AEK_NONE; + } +} + bool ARMTargetParser::getHWDivFeatures(unsigned HWDivKind, std::vector &Features) { - if (HWDivKind == ARM::AEK_INVALID) return false; @@ -365,6 +395,7 @@ // crypto includes neon, so we handle this similarly to FPU version. switch (FPUNames[FPUKind].NeonSupport) { case ARM::NS_Crypto: + Features.push_back("+neon"); Features.push_back("+crypto"); break; case ARM::NS_Neon: @@ -380,6 +411,19 @@ return true; } +bool ARMTargetParser::getExtensionFeatures(unsigned Extensions, + llvm::StringMap &Features) { + if (Extensions == ARM::AEK_INVALID) + return false; + + for (const auto AE : ARCHExtNames) { + if ((Extensions & AE.ID) && AE.IsBackendOption) + Features[AE.Name] = true; + } + + return true; +} + const char *ARMTargetParser::getArchName(unsigned ArchKind) { if (ArchKind >= ARM::AK_LAST) return nullptr;