[llvm-branch-commits] [clang] 9b2e09e - [PowerPC] Recognize long CPU name for -mtune in Clang
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 2 23:18:58 PST 2023
Author: Nemanja Ivanovic
Date: 2023-03-02T23:18:30-08:00
New Revision: 9b2e09e9fb1aa3bbe3668d7cc585188a3014d1b9
URL: https://github.com/llvm/llvm-project/commit/9b2e09e9fb1aa3bbe3668d7cc585188a3014d1b9
DIFF: https://github.com/llvm/llvm-project/commit/9b2e09e9fb1aa3bbe3668d7cc585188a3014d1b9.diff
LOG: [PowerPC] Recognize long CPU name for -mtune in Clang
There are two ways of specifying a CPU on PowerPC:
power<N> and pwr<N>. Clang/LLVM traditionally
supports the latter and Clang replaces the former
with the latter when passing it to the back end for
the -mcpu= option. However, when the -mtune= option
was introduced, this replacement was not implemented for it.
This leaves us in an inconsistent state of accepting
both forms for -mcpu= and and only the latter for
-mtune=. Furthermore, it leaves us incompatible with
GCC which only understands the power<N> version for
both options.
This patch just adds the same handling for the long
names for -mtune= as already exists for -mcpu=.
Differential revision: https://reviews.llvm.org/D144967
(cherry picked from commit 59cd692454c9430f0fb77ca14b65cb9afcfe2776)
Added:
Modified:
clang/lib/Driver/ToolChains/Arch/PPC.cpp
clang/lib/Driver/ToolChains/Arch/PPC.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/ppc-cpus.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index 6ec736bc701bb..e3c025fb24685 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -34,53 +34,60 @@ static std::string getPPCGenericTargetCPU(const llvm::Triple &T) {
return "ppc";
}
-/// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting.
-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();
-
- // Clang/LLVM does not actually support code generation
- // for the 405 CPU. However, there are uses of this CPU ID
- // in projects that previously used GCC and rely on Clang
- // accepting it. Clang has always ignored it and passed the
- // generic CPU ID to the back end.
- if (CPUName == "generic" || CPUName == "405")
+static std::string normalizeCPUName(StringRef CPUName, const llvm::Triple &T) {
+ // Clang/LLVM does not actually support code generation
+ // for the 405 CPU. However, there are uses of this CPU ID
+ // in projects that previously used GCC and rely on Clang
+ // accepting it. Clang has always ignored it and passed the
+ // generic CPU ID to the back end.
+ if (CPUName == "generic" || CPUName == "405")
+ return getPPCGenericTargetCPU(T);
+
+ if (CPUName == "native") {
+ std::string CPU = std::string(llvm::sys::getHostCPUName());
+ if (!CPU.empty() && CPU != "generic")
+ return CPU;
+ else
return getPPCGenericTargetCPU(T);
+ }
- if (CPUName == "native") {
- std::string CPU = std::string(llvm::sys::getHostCPUName());
- if (!CPU.empty() && CPU != "generic")
- return CPU;
- else
- return getPPCGenericTargetCPU(T);
- }
+ return llvm::StringSwitch<const char *>(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.data());
+}
- return llvm::StringSwitch<const char *>(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.data());
- }
+/// Get the (LLVM) name of the PowerPC cpu we are tuning for.
+std::string ppc::getPPCTuneCPU(const ArgList &Args, const llvm::Triple &T) {
+ if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ))
+ return normalizeCPUName(A->getValue(), T);
+ return getPPCGenericTargetCPU(T);
+}
+/// Get the (LLVM) name of the PowerPC cpu we are targeting.
+std::string ppc::getPPCTargetCPU(const ArgList &Args, const llvm::Triple &T) {
+ if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ))
+ return normalizeCPUName(A->getValue(), T);
return getPPCGenericTargetCPU(T);
}
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.h b/clang/lib/Driver/ToolChains/Arch/PPC.h
index cd2b47d392b65..97ac450838521 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.h
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.h
@@ -37,6 +37,8 @@ FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
std::string getPPCTargetCPU(const llvm::opt::ArgList &Args,
const llvm::Triple &T);
+std::string getPPCTuneCPU(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);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 832aaf0bc2323..ec6860113b7e3 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1989,17 +1989,15 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args,
void Clang::AddPPCTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
+ const llvm::Triple &T = getToolChain().getTriple();
if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
CmdArgs.push_back("-tune-cpu");
- if (strcmp(A->getValue(), "native") == 0)
- CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
- else
- CmdArgs.push_back(A->getValue());
+ std::string CPU = ppc::getPPCTuneCPU(Args, T);
+ CmdArgs.push_back(Args.MakeArgString(CPU));
}
// Select the ABI to use.
const char *ABIName = nullptr;
- const llvm::Triple &T = getToolChain().getTriple();
if (T.isOSBinFormatELF()) {
switch (getToolChain().getArch()) {
case llvm::Triple::ppc64: {
diff --git a/clang/test/Driver/ppc-cpus.c b/clang/test/Driver/ppc-cpus.c
index d623b25e88d95..050512f9d87be 100644
--- a/clang/test/Driver/ppc-cpus.c
+++ b/clang/test/Driver/ppc-cpus.c
@@ -31,6 +31,8 @@
// RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | FileCheck %s --check-prefix=TUNE
// TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
+// RUN: %clang -### -c --target=powerpc64le %s -mcpu=power9 -mtune=power10 2>&1 | FileCheck %s --check-prefix=TUNE-LONG
+// TUNE-LONG: "-target-cpu" "pwr9" "-tune-cpu" "pwr10"
/// Test mcpu options that are equivalent to "generic"
// RUN: %clang -### -c -target powerpc64 %s -mcpu=generic 2>&1 | FileCheck %s --check-prefix=GENERIC
More information about the llvm-branch-commits
mailing list