[clang] de8deb5 - [clang][PPC] Supporting -mcpu=405

Qiongsi Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 15 07:56:38 PST 2022


Author: Qiongsi Wu
Date: 2022-12-15T10:55:26-05:00
New Revision: de8deb5189c948db89c753ff2dff65b8e7840e8b

URL: https://github.com/llvm/llvm-project/commit/de8deb5189c948db89c753ff2dff65b8e7840e8b
DIFF: https://github.com/llvm/llvm-project/commit/de8deb5189c948db89c753ff2dff65b8e7840e8b.diff

LOG: [clang][PPC] Supporting -mcpu=405

The  ClangBuiltLinux  project relies on `-mcpu=405`. Before https://reviews.llvm.org/D139720, `clang` treated `-mcpu=405` implicitly in the same way as `-mcpu=generic`, because `405` was an unknown value and `clang` did not validate unknown input values. https://reviews.llvm.org/D139720 added the validation of `-mcpu` input value, and `clang` now generates an error with `-mcpu=405`. For further details of the problem, see https://github.com/ClangBuiltLinux/linux/issues/1771.

This patch adds support of `-mcpu=405` explicitly, and treats it as an equivalent of `-mcpu=generic`.

Reviewed By: nemanjai

Differential Revision: https://reviews.llvm.org/D140080

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Arch/PPC.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 f90a772ed5a21..6ec736bc701bb 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -39,7 +39,12 @@ 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")
+    // 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") {

diff  --git a/clang/test/Driver/ppc-cpus.c b/clang/test/Driver/ppc-cpus.c
index 08da07ec7b176..d623b25e88d95 100644
--- a/clang/test/Driver/ppc-cpus.c
+++ b/clang/test/Driver/ppc-cpus.c
@@ -31,3 +31,9 @@
 
 // RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | FileCheck %s --check-prefix=TUNE
 // TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
+
+/// Test mcpu options that are equivalent to "generic"
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=generic 2>&1 | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang -### -c -target powerpc64 %s -mcpu=405     2>&1 | FileCheck %s --check-prefix=GENERIC
+//
+// GENERIC: "-target-cpu" "ppc64"


        


More information about the cfe-commits mailing list