r349382 - [darwin][arm64] use the "cyclone" CPU for Darwin even when `-arch`

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 17 11:30:46 PST 2018


Author: arphaman
Date: Mon Dec 17 11:30:46 2018
New Revision: 349382

URL: http://llvm.org/viewvc/llvm-project?rev=349382&view=rev
Log:
[darwin][arm64] use the "cyclone" CPU for Darwin even when `-arch`
is not specified

The -target option allows the user to specify the build target using LLVM
triple. The triple includes the arch, and so the -arch option is redundant.
This should work just as well without the -arch. However, the driver has a bug
in which it doesn't target the "Cyclone" CPU for darwin if -target is used
without -arch. This commit fixes this issue.

rdar://46743182

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

Modified:
    cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp
    cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.h
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
    cfe/trunk/test/Driver/aarch64-cpus.c

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp?rev=349382&r1=349381&r2=349382&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp Mon Dec 17 11:30:46 2018
@@ -19,10 +19,17 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
+/// \returns true if the given triple can determine the default CPU type even
+/// if -arch is not specified.
+static bool isCPUDeterminedByTriple(const llvm::Triple &Triple) {
+  return Triple.isOSDarwin();
+}
+
 /// getAArch64TargetCPU - Get the (LLVM) name of the AArch64 cpu we are
 /// targeting. Set \p A to the Arg corresponding to the -mcpu argument if it is
 /// provided, or to nullptr otherwise.
-std::string aarch64::getAArch64TargetCPU(const ArgList &Args, Arg *&A) {
+std::string aarch64::getAArch64TargetCPU(const ArgList &Args,
+                                         const llvm::Triple &Triple, Arg *&A) {
   std::string CPU;
   // If we have -mcpu, use that.
   if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
@@ -36,9 +43,9 @@ std::string aarch64::getAArch64TargetCPU
   else if (CPU.size())
     return CPU;
 
-  // Make sure we pick "cyclone" if -arch is used.
-  // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  // Make sure we pick "cyclone" if -arch is used or when targetting a Darwin
+  // OS.
+  if (Args.getLastArg(options::OPT_arch) || Triple.isOSDarwin())
     return "cyclone";
 
   return "generic";
@@ -152,7 +159,9 @@ getAArch64MicroArchFeaturesFromMcpu(cons
   return getAArch64MicroArchFeaturesFromMtune(D, CPU, Args, Features);
 }
 
-void aarch64::getAArch64TargetFeatures(const Driver &D, const ArgList &Args,
+void aarch64::getAArch64TargetFeatures(const Driver &D,
+                                       const llvm::Triple &Triple,
+                                       const ArgList &Args,
                                        std::vector<StringRef> &Features) {
   Arg *A;
   bool success = true;
@@ -162,9 +171,9 @@ void aarch64::getAArch64TargetFeatures(c
     success = getAArch64ArchFeaturesFromMarch(D, A->getValue(), Args, Features);
   else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
     success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
-  else if (Args.hasArg(options::OPT_arch))
-    success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args, A),
-                                             Args, Features);
+  else if (Args.hasArg(options::OPT_arch) || isCPUDeterminedByTriple(Triple))
+    success = getAArch64ArchFeaturesFromMcpu(
+        D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
 
   if (success && (A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)))
     success =
@@ -172,9 +181,10 @@ void aarch64::getAArch64TargetFeatures(c
   else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
     success =
         getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
-  else if (success && Args.hasArg(options::OPT_arch))
+  else if (success &&
+           (Args.hasArg(options::OPT_arch) || isCPUDeterminedByTriple(Triple)))
     success = getAArch64MicroArchFeaturesFromMcpu(
-        D, getAArch64TargetCPU(Args, A), Args, Features);
+        D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
 
   if (!success)
     D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.h?rev=349382&r1=349381&r2=349382&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.h Mon Dec 17 11:30:46 2018
@@ -21,11 +21,12 @@ namespace driver {
 namespace tools {
 namespace aarch64 {
 
-void getAArch64TargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
+void getAArch64TargetFeatures(const Driver &D, const llvm::Triple &Triple,
+                              const llvm::opt::ArgList &Args,
                               std::vector<llvm::StringRef> &Features);
 
 std::string getAArch64TargetCPU(const llvm::opt::ArgList &Args,
-                                llvm::opt::Arg *&A);
+                                const llvm::Triple &Triple, llvm::opt::Arg *&A);
 
 } // end namespace aarch64
 } // end namespace target

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=349382&r1=349381&r2=349382&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Dec 17 11:30:46 2018
@@ -341,7 +341,7 @@ static void getTargetFeatures(const Tool
     break;
   case llvm::Triple::aarch64:
   case llvm::Triple::aarch64_be:
-    aarch64::getAArch64TargetFeatures(D, Args, Features);
+    aarch64::getAArch64TargetFeatures(D, Triple, Args, Features);
     break;
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=349382&r1=349381&r2=349382&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Mon Dec 17 11:30:46 2018
@@ -271,7 +271,7 @@ std::string tools::getCPUName(const ArgL
 
   case llvm::Triple::aarch64:
   case llvm::Triple::aarch64_be:
-    return aarch64::getAArch64TargetCPU(Args, A);
+    return aarch64::getAArch64TargetCPU(Args, T, A);
 
   case llvm::Triple::arm:
   case llvm::Triple::armeb:

Modified: cfe/trunk/test/Driver/aarch64-cpus.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-cpus.c?rev=349382&r1=349381&r2=349382&view=diff
==============================================================================
--- cfe/trunk/test/Driver/aarch64-cpus.c (original)
+++ cfe/trunk/test/Driver/aarch64-cpus.c Mon Dec 17 11:30:46 2018
@@ -21,7 +21,10 @@
 // ARM64-NATIVE-NOT: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "native"
 
 // RUN: %clang -target arm64-apple-darwin -arch arm64 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
+// RUN: %clang -target arm64-apple-darwin -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
+// RUN: %clang -target arm64-apple-ios12.0 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
 // ARM64-DARWIN: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "cyclone"
+// ARM64-DARWIN-SAME: "-target-feature" "+aes"
 
 // RUN: %clang -target aarch64 -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35 %s
 // RUN: %clang -target aarch64 -mlittle-endian -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35 %s




More information about the cfe-commits mailing list