qiongsiwu1 updated this revision to Diff 483060.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140080/new/

https://reviews.llvm.org/D140080

Files:
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/test/Driver/ppc-cpus.c


Index: clang/test/Driver/ppc-cpus.c
===================================================================
--- clang/test/Driver/ppc-cpus.c
+++ 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"
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -20,6 +20,13 @@
 using namespace clang;
 using namespace llvm::opt;
 
+static constexpr llvm::StringLiteral GenericCPUNames[] = {{"generic"}, 
{"405"}};
+
+/// Check if Name is known to be equivalent to "generic".
+static bool isGenericCPUName(const StringRef &Name) {
+  return llvm::is_contained(GenericCPUNames, Name);
+}
+
 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
@@ -39,7 +46,7 @@
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
     StringRef CPUName = A->getValue();
 
-    if (CPUName == "generic")
+    if (isGenericCPUName(CPUName))
       return getPPCGenericTargetCPU(T);
 
     if (CPUName == "native") {


Index: clang/test/Driver/ppc-cpus.c
===================================================================
--- clang/test/Driver/ppc-cpus.c
+++ 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"
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -20,6 +20,13 @@
 using namespace clang;
 using namespace llvm::opt;
 
+static constexpr llvm::StringLiteral GenericCPUNames[] = {{"generic"}, {"405"}};
+
+/// Check if Name is known to be equivalent to "generic".
+static bool isGenericCPUName(const StringRef &Name) {
+  return llvm::is_contained(GenericCPUNames, Name);
+}
+
 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
@@ -39,7 +46,7 @@
   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
     StringRef CPUName = A->getValue();
 
-    if (CPUName == "generic")
+    if (isGenericCPUName(CPUName))
       return getPPCGenericTargetCPU(T);
 
     if (CPUName == "native") {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to