[AIX] Change the default target CPU to power4 for AIX on Power
authorSteven Wan <wanyu9511@gmail.com>
Wed, 3 Jun 2020 17:49:47 +0000 (13:49 -0400)
committerSteven Wan <wanyu9511@gmail.com>
Wed, 3 Jun 2020 17:50:26 +0000 (13:50 -0400)
Summary: This patch changes the AIX default target CPU to power4 since this is the the lowest arch for the lowest OS level supported.

Reviewers: hubert.reinterpretcast, cebowleratibm, daltenty

Reviewed By: hubert.reinterpretcast

Subscribers: cfe-commits

Tags: #clang

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

clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/aix-mcpu-default.c [new file with mode: 0644]

index b2c9849..0ddbfac 100644 (file)
@@ -294,14 +294,18 @@ std::string tools::getCPUName(const ArgList &Args, const llvm::Triple &T,
     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 Darwin)
-    if (TargetCPUName.empty() && !T.isOSDarwin()) {
-      if (T.getArch() == llvm::Triple::ppc64)
-        TargetCPUName = "ppc64";
-      else if (T.getArch() == llvm::Triple::ppc64le)
-        TargetCPUName = "ppc64le";
-      else
-        TargetCPUName = "ppc";
+    // each architecture. (except on AIX or Darwin)
+    if (TargetCPUName.empty()) {
+      if (T.isOSAIX())
+        TargetCPUName = "pwr4";
+      else if (!T.isOSDarwin()) {
+        if (T.getArch() == llvm::Triple::ppc64)
+          TargetCPUName = "ppc64";
+        else if (T.getArch() == llvm::Triple::ppc64le)
+          TargetCPUName = "ppc64le";
+        else
+          TargetCPUName = "ppc";
+      }
     }
     return TargetCPUName;
   }
diff --git a/clang/test/Driver/aix-mcpu-default.c b/clang/test/Driver/aix-mcpu-default.c
new file mode 100644 (file)
index 0000000..10636ab
--- /dev/null
@@ -0,0 +1,16 @@
+// Check that the target cpu defaults to power4 on AIX.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:        -target powerpc-ibm-aix \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-DEFAULT %s
+// CHECK-MCPU-DEFAULT-NOT: warning:
+// CHECK-MCPU-DEFAULT:     {{.*}}clang{{.*}}" "-cc1"
+// CHECK-MCPU-DEFAULT:     "-target-cpu" "pwr4"
+
+// Check that the user is able to overwrite the default with '-mcpu'.
+// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \
+// RUN:        -mcpu=pwr6 \
+// RUN:        -target powerpc-ibm-aix \
+// RUN:   | FileCheck --check-prefix=CHECK-MCPU-USER %s
+// CHECK-MCPU-USER-NOT: warning:
+// CHECK-MCPU-USER:     {{.*}}clang{{.*}}" "-cc1"
+// CHECK-MCPU-USER:     "-target-cpu" "pwr6"