Index: clang/lib/Driver/ToolChains/Arch/PPC.h =================================================================== --- clang/lib/Driver/ToolChains/Arch/PPC.h +++ clang/lib/Driver/ToolChains/Arch/PPC.h @@ -35,7 +35,8 @@ FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args); -std::string getPPCTargetCPU(const llvm::opt::ArgList &Args); +std::string getPPCTargetCPU(const llvm::opt::ArgList &Args, + const llvm::Triple &T); const char *getPPCAsmModeForCPU(StringRef Name); ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args); Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ clang/lib/Driver/ToolChains/Arch/PPC.cpp @@ -20,74 +20,64 @@ using namespace clang; using namespace llvm::opt; +static std::string getPPCGenericTargetCPU(const llvm::Triple &T) { + // LLVM may default to generating code for the native CPU, + // but, like gcc, we default to a more generic option for + // each architecture. (except on AIX) + if (T.isOSAIX()) + return "pwr7"; + else if (T.getArch() == llvm::Triple::ppc64le) + return "ppc64le"; + else if (T.getArch() == llvm::Triple::ppc64) + return "ppc64"; + else + return "ppc"; +} + /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting. -std::string ppc::getPPCTargetCPU(const ArgList &Args) { +std::string ppc::getPPCTargetCPU(const ArgList &Args, const llvm::Triple &T) { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { StringRef CPUName = A->getValue(); + if (CPUName == "generic") + return getPPCGenericTargetCPU(T); + if (CPUName == "native") { std::string CPU = std::string(llvm::sys::getHostCPUName()); if (!CPU.empty() && CPU != "generic") return CPU; else - return ""; + return getPPCGenericTargetCPU(T); } - return llvm::StringSwitch(CPUName) - .Case("common", "generic") - .Case("440", "440") - .Case("440fp", "440") - .Case("450", "450") - .Case("601", "601") - .Case("602", "602") - .Case("603", "603") - .Case("603e", "603e") - .Case("603ev", "603ev") - .Case("604", "604") - .Case("604e", "604e") - .Case("620", "620") - .Case("630", "pwr3") - .Case("G3", "g3") - .Case("7400", "7400") - .Case("G4", "g4") - .Case("7450", "7450") - .Case("G4+", "g4+") - .Case("750", "750") - .Case("8548", "e500") - .Case("970", "970") - .Case("G5", "g5") - .Case("a2", "a2") - .Case("e500", "e500") - .Case("e500mc", "e500mc") - .Case("e5500", "e5500") - .Case("power3", "pwr3") - .Case("power4", "pwr4") - .Case("power5", "pwr5") - .Case("power5x", "pwr5x") - .Case("power6", "pwr6") - .Case("power6x", "pwr6x") - .Case("power7", "pwr7") - .Case("power8", "pwr8") - .Case("power9", "pwr9") - .Case("power10", "pwr10") - .Case("future", "future") - .Case("pwr3", "pwr3") - .Case("pwr4", "pwr4") - .Case("pwr5", "pwr5") - .Case("pwr5x", "pwr5x") - .Case("pwr6", "pwr6") - .Case("pwr6x", "pwr6x") - .Case("pwr7", "pwr7") - .Case("pwr8", "pwr8") - .Case("pwr9", "pwr9") - .Case("pwr10", "pwr10") - .Case("powerpc", "ppc") - .Case("powerpc64", "ppc64") - .Case("powerpc64le", "ppc64le") - .Default(""); + auto TargetCPUName = llvm::StringSwitch(CPUName) + .Case("common", "generic") + .Case("440fp", "440") + .Case("630", "pwr3") + .Case("G3", "g3") + .Case("G4", "g4") + .Case("G4+", "g4+") + .Case("8548", "e500") + .Case("G5", "g5") + .Case("power3", "pwr3") + .Case("power4", "pwr4") + .Case("power5", "pwr5") + .Case("power5x", "pwr5x") + .Case("power6", "pwr6") + .Case("power6x", "pwr6x") + .Case("power7", "pwr7") + .Case("power8", "pwr8") + .Case("power9", "pwr9") + .Case("power10", "pwr10") + .Case("future", "future") + .Case("powerpc", "ppc") + .Case("powerpc64", "ppc64") + .Case("powerpc64le", "ppc64le") + .Default(CPUName); + return TargetCPUName.str(); } - return ""; + return getPPCGenericTargetCPU(T); } const char *ppc::getPPCAsmModeForCPU(StringRef Name) { Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -409,25 +409,9 @@ case llvm::Triple::ppc: case llvm::Triple::ppcle: case llvm::Triple::ppc64: - case llvm::Triple::ppc64le: { - std::string TargetCPUName = ppc::getPPCTargetCPU(Args); - // LLVM may default to generating code for the native CPU, - // but, like gcc, we default to a more generic option for - // each architecture. (except on AIX) - if (!TargetCPUName.empty()) - return TargetCPUName; - - if (T.isOSAIX()) - TargetCPUName = "pwr7"; - else if (T.getArch() == llvm::Triple::ppc64le) - TargetCPUName = "ppc64le"; - else if (T.getArch() == llvm::Triple::ppc64) - TargetCPUName = "ppc64"; - else - TargetCPUName = "ppc"; + case llvm::Triple::ppc64le: + return ppc::getPPCTargetCPU(Args, T); - return TargetCPUName; - } case llvm::Triple::csky: if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) return A->getValue(); Index: clang/test/Driver/ppc-cpus.c =================================================================== --- clang/test/Driver/ppc-cpus.c +++ clang/test/Driver/ppc-cpus.c @@ -5,6 +5,15 @@ // RUN: %clang -### -c -target powerpc64 %s -mcpu=native 2>&1 | FileCheck --check-prefix=MCPU_NATIVE %s // MCPU_NATIVE-NOT: "-target-cpu" "native" +/// Check that we are passing unknown mcpu options to the backend so an error +/// can be triggered. +// RUN: %clang -### -c -target powerpc64 %s -mcpu=asdf1234 2>&1 | FileCheck --check-prefix=MCPU_UNKNOWN %s +// MCPU_UNKNOWN: "-target-cpu" "asdf1234" + +/// Check for the unknown target error if an unknown mcpu option is used. +// RUN: not %clang -c -target powerpc64 %s -mcpu=asdf1234 2>&1 | FileCheck --check-prefix=MCPU_ERR %s +// MCPU_ERR: unknown target CPU 'asdf1234' + // RUN: %clang -### -c -target powerpc64 %s -mcpu=7400 2>&1 | FileCheck --check-prefix=MCPU_7400 %s // MCPU_7400: "-target-cpu" "7400"