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,14 @@ static unsigned getFPUNeonSupportLevel(unsigned FPUKind); static unsigned getFPURestriction(unsigned FPUKind); static unsigned getDefaultFPU(StringRef CPU); + static unsigned getDefaultExtensions(StringRef CPU); // 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 @@ -121,6 +121,8 @@ { "crypto", ARM::AEK_CRYPTO }, { "fp", ARM::AEK_FP }, { "idiv", (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV) }, + { "hwdiv-arm", ARM::AEK_HWDIVARM }, + { "hwdiv", ARM::AEK_HWDIV }, { "mp", ARM::AEK_MP }, { "simd", ARM::AEK_SIMD }, { "sec", ARM::AEK_SEC }, @@ -153,93 +155,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_NONE, false }, + { "cortex-a7", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), false }, + { "cortex-a8", ARM::AK_ARMV7A, ARM::FK_NEON, ARM::AEK_NONE, true }, + { "cortex-a9", ARM::AK_ARMV7A, ARM::FK_NEON_FP16, ARM::AEK_NONE, false }, + { "cortex-a12", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), false }, + { "cortex-a15", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), false }, + { "cortex-a17", ARM::AK_ARMV7A, ARM::FK_NEON_VFPV4, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), 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_HWDIV, true }, + { "cortex-r4f", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16, ARM::AEK_HWDIV, false }, + { "cortex-r5", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), false }, + { "cortex-r7", ARM::AK_ARMV7R, ARM::FK_VFPV3_D16_FP16, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), false }, + { "sc300", ARM::AK_ARMV7M, ARM::FK_NONE, ARM::AEK_HWDIV, false }, + { "cortex-m3", ARM::AK_ARMV7M, ARM::FK_NONE, ARM::AEK_HWDIV, true }, + { "cortex-m4", ARM::AK_ARMV7EM, ARM::FK_FPV4_SP_D16, ARM::AEK_HWDIV, true }, + { "cortex-m7", ARM::AK_ARMV7EM, ARM::FK_FPV5_D16, ARM::AEK_HWDIV, false }, + { "cortex-a53", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV | ARM::AEK_CRC), true }, + { "cortex-a57", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV | ARM::AEK_CRC), false }, + { "cortex-a72", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV | ARM::AEK_CRC), false }, + { "cyclone", ARM::AK_ARMV8A, ARM::FK_CRYPTO_NEON_FP_ARMV8, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV | ARM::AEK_CRC), false }, + { "generic", ARM::AK_ARMV8_1A, ARM::FK_NEON_FP_ARMV8, (ARM::AEK_HWDIVARM | ARM::AEK_HWDIV), 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_HWDIV, 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,6 +283,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; +} + +bool ARMTargetParser::getExtensionFeatures(unsigned Extensions, + llvm::StringMap &Features) { + + if (Extensions == ARM::AEK_INVALID) + return false; + + if (Extensions & ARM::AEK_NONE) + return true; + + for (const auto AE : ARCHExtNames) { + //FIXME clang currently ignores idiv + if (AE.Name == "idiv") + continue; + if (Extensions & AE.ID) + Features[AE.Name] = true; + } + + return true; +} + bool ARMTargetParser::getHWDivFeatures(unsigned HWDivKind, std::vector &Features) { @@ -365,6 +396,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: