r336429 - [Driver,AArch64] Add support for -mcpu=native.

Florian Hahn via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 6 03:49:59 PDT 2018


Author: fhahn
Date: Fri Jul  6 03:49:59 2018
New Revision: 336429

URL: http://llvm.org/viewvc/llvm-project?rev=336429&view=rev
Log:
[Driver,AArch64] Add support for -mcpu=native.

This patches adds support for passing -mcpu=native for AArch64. It will
get turned into the host CPU name, before we get the target features.

CPU = native is handled in a similar fashion in
getAArch64MicroArchFetauresFromMtune and getAArch64TargetCPU already.

Having a good test case for this is hard, as it depends on the host CPU
of the machine running the test. But we can check that native has been
replaced with something else.

When cross-compiling, we will get a CPU name from the host architecture
and get ` the clang compiler does not support '-mcpu=native'` as error
message, which seems reasonable to me.

Reviewers: rengolin, peter.smith, dlj, javed.absar, t.p.northover

Reviewed By: peter.smith

Tags: #clang

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

Modified:
    cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.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=336429&r1=336428&r2=336429&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/AArch64.cpp Fri Jul  6 03:49:59 2018
@@ -69,6 +69,9 @@ static bool DecodeAArch64Mcpu(const Driv
   std::pair<StringRef, StringRef> Split = Mcpu.split("+");
   CPU = Split.first;
 
+  if (CPU == "native")
+    CPU = llvm::sys::getHostCPUName();
+
   if (CPU == "generic") {
     Features.push_back("+neon");
   } else {

Modified: cfe/trunk/test/Driver/aarch64-cpus.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-cpus.c?rev=336429&r1=336428&r2=336429&view=diff
==============================================================================
--- cfe/trunk/test/Driver/aarch64-cpus.c (original)
+++ cfe/trunk/test/Driver/aarch64-cpus.c Fri Jul  6 03:49:59 2018
@@ -15,6 +15,11 @@
 
 // ARM64-GENERIC: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "generic"
 
+// We cannot check much for -mcpu=native, but it should be replaced by either generic or a valid
+// Arm cpu string, depending on the host.
+// RUN: %clang -target arm64 -mcpu=native -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-NATIVE %s
+// 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
 // ARM64-DARWIN: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "cyclone"
 




More information about the cfe-commits mailing list