From d4d4da74a698588f12e885989175cccf97a5633e Mon Sep 17 00:00:00 2001 From: Renato Golin Date: Wed, 25 May 2016 12:02:58 +0000 Subject: [PATCH] [AArch64] Using new TargetParser in Clang Using AArch64TargetParser in clang to avoid repetitive string parsing. Use TargetParser to do ARCH/CPU/ArchExt parsing instead of local implementation. Patch by Jojo Ma. llvm-svn: 270688 --- clang/lib/Basic/Targets.cpp | 12 +++------ clang/lib/Driver/Tools.cpp | 54 +++++++++++-------------------------- 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 4d06ebb724bd..059dd62aea11 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -5665,14 +5665,10 @@ public: } bool setCPU(const std::string &Name) override { - bool CPUKnown = llvm::StringSwitch(Name) - .Case("generic", true) - .Cases("cortex-a53", "cortex-a57", "cortex-a72", - "cortex-a35", "exynos-m1", true) - .Case("cyclone", true) - .Case("kryo", true) - .Default(false); - return CPUKnown; + if (Name == "generic" || llvm::AArch64::parseCPUArch(Name) != llvm::ARM::AK_INVALID) + return true; + + return false; } void getTargetDefines(const LangOptions &Opts, diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 7c363e0d9ef8..f4d234907f28 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -2262,22 +2262,9 @@ static bool DecodeAArch64Features(const Driver &D, StringRef text, text.split(Split, StringRef("+"), -1, false); for (StringRef Feature : Split) { - const char *result = llvm::StringSwitch(Feature) - .Case("fp", "+fp-armv8") - .Case("simd", "+neon") - .Case("crc", "+crc") - .Case("crypto", "+crypto") - .Case("fp16", "+fullfp16") - .Case("profile", "+spe") - .Case("nofp", "-fp-armv8") - .Case("nosimd", "-neon") - .Case("nocrc", "-crc") - .Case("nocrypto", "-crypto") - .Case("nofp16", "-fullfp16") - .Case("noprofile", "-spe") - .Default(nullptr); - if (result) - Features.push_back(result); + const char *FeatureName = llvm::AArch64::getArchExtFeature(Feature); + if (FeatureName) + Features.push_back(FeatureName); else if (Feature == "neon" || Feature == "noneon") D.Diag(diag::err_drv_no_neon_modifier); else @@ -2292,20 +2279,16 @@ static bool DecodeAArch64Mcpu(const Driver &D, StringRef Mcpu, StringRef &CPU, std::vector &Features) { std::pair Split = Mcpu.split("+"); CPU = Split.first; - if (CPU == "cortex-a53" || CPU == "cortex-a57" || - CPU == "cortex-a72" || CPU == "cortex-a35" || CPU == "exynos-m1" || - CPU == "kryo") { - Features.push_back("+neon"); - Features.push_back("+crc"); - Features.push_back("+crypto"); - } else if (CPU == "cyclone") { - Features.push_back("+neon"); - Features.push_back("+crypto"); - } else if (CPU == "generic") { + + if (CPU == "generic") { Features.push_back("+neon"); } else { - return false; - } + unsigned ArchKind = llvm::AArch64::parseCPUArch(CPU); + unsigned Extersion = llvm::AArch64::getDefaultExtensions(CPU,ArchKind); + + if (!llvm::AArch64::getExtensionFeatures(Extersion,Features)) + return false; + } if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features)) return false; @@ -2317,20 +2300,13 @@ static bool getAArch64ArchFeaturesFromMarch(const Driver &D, StringRef March, const ArgList &Args, std::vector &Features) { + unsigned ArchKind; std::string MarchLowerCase = March.lower(); std::pair Split = StringRef(MarchLowerCase).split("+"); - if (Split.first == "armv8-a" || Split.first == "armv8a") { - // ok, no additional features. - } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") { - Features.push_back("+v8.1a"); - } else if (Split.first == "armv8.2-a" || Split.first == "armv8.2a" ) { - Features.push_back("+v8.2a"); - } else { - return false; - } - - if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features)) + ArchKind = llvm::AArch64::parseArch(Split.first); + if (ArchKind == llvm::ARM::AK_INVALID || !llvm::AArch64::getArchFeatures(ArchKind, Features) || + (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features))) return false; return true;