From 0eac975b51cca5b54a1f516d05a233c215375eda Mon Sep 17 00:00:00 2001 From: Jian Cai Date: Wed, 23 Jun 2021 12:00:58 -0700 Subject: [PATCH] Reland "[AArch64] handle -Wa,-march=" This reverts commit fd11a26d368c5a909fb88548fef2cee7a6c2c931, which was reverted by 9145a3d4ab7eb05d9fb113b5392e8961df629b88 due to a test failure on aarch64 backend, e.g. https://lab.llvm.org/buildbot/#/builders/43/builds/7031. This patch fixed the test failure. Reviewed By: DavidSpickett, nickdesaulniers Differential Revision: https://reviews.llvm.org/D103184 --- clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 17 ++++++++-- clang/lib/Driver/ToolChains/Arch/AArch64.h | 3 +- clang/lib/Driver/ToolChains/Clang.cpp | 2 +- clang/test/Driver/aarch64-target-as-march.s | 46 ++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 clang/test/Driver/aarch64-target-as-march.s diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index 503685a..ed8c7e9 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -185,12 +185,25 @@ getAArch64MicroArchFeaturesFromMcpu(const Driver &D, StringRef Mcpu, void aarch64::getAArch64TargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, - std::vector &Features) { + std::vector &Features, + bool ForAS) { Arg *A; bool success = true; // Enable NEON by default. Features.push_back("+neon"); - if ((A = Args.getLastArg(options::OPT_march_EQ))) + llvm::StringRef WaMArch = ""; + if (ForAS) + for (const auto *A : + Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) + for (StringRef Value : A->getValues()) + if (Value.startswith("-march=")) + WaMArch = Value.substr(7); + // Call getAArch64ArchFeaturesFromMarch only if "-Wa,-march=" or + // "-Xassembler -march" is detected. Otherwise it may return false + // and causes Clang to error out. + if (WaMArch.size()) + success = getAArch64ArchFeaturesFromMarch(D, WaMArch, Args, Features); + else if ((A = Args.getLastArg(options::OPT_march_EQ))) success = getAArch64ArchFeaturesFromMarch(D, A->getValue(), Args, Features); else if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features); diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.h b/clang/lib/Driver/ToolChains/Arch/AArch64.h index 713af87..d47c402 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.h +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.h @@ -22,7 +22,8 @@ namespace aarch64 { void getAArch64TargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, - std::vector &Features); + std::vector &Features, + bool ForAS); std::string getAArch64TargetCPU(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, llvm::opt::Arg *&A); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index b358813..0d1fce3 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -344,7 +344,7 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple, case llvm::Triple::aarch64: case llvm::Triple::aarch64_32: case llvm::Triple::aarch64_be: - aarch64::getAArch64TargetFeatures(D, Triple, Args, Features); + aarch64::getAArch64TargetFeatures(D, Triple, Args, Features, ForAS); break; case llvm::Triple::x86: case llvm::Triple::x86_64: diff --git a/clang/test/Driver/aarch64-target-as-march.s b/clang/test/Driver/aarch64-target-as-march.s new file mode 100644 index 0000000..a9301ad --- /dev/null +++ b/clang/test/Driver/aarch64-target-as-march.s @@ -0,0 +1,46 @@ +/// These tests make sure that options passed to the assembler +/// via -Wa or -Xassembler are applied correctly to assembler inputs. + +/// Does not apply to non assembly files +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.1-a \ +// RUN: %S/Inputs/wildcard1.c 2>&1 | FileCheck --check-prefix=TARGET-FEATURE-1 %s +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Xassembler -march=armv8.1-a \ +// RUN: %S/Inputs/wildcard1.c 2>&1 | FileCheck --check-prefix=TARGET-FEATURE-1 %s + +// TARGET-FEATURE-1-NOT: "-target-feature" "+v8.1a" + +/// Does apply to assembler input +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.2-a %s 2>&1 | \ +// RUN: FileCheck --check-prefix=TARGET-FEATURE-2 %s +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Xassembler -march=armv8.2-a %s 2>&1 | \ +// RUN: FileCheck --check-prefix=TARGET-FEATURE-2 %s + +// TARGET-FEATURE-2: "-target-feature" "+v8.2a" + +/// No unused argument warnings when there are multiple values +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.1-a -Wa,-march=armv8.2-a %s 2>&1 | \ +// RUN: FileCheck --check-prefix=UNUSED-WARNING %s + +// UNUSED-WARNING-NOT: warning: argument unused during compilation + +/// Last march to assembler wins +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.2-a -Wa,-march=armv8.1-a %s 2>&1 | \ +// RUN: FileCheck --check-prefix=MULTIPLE-VALUES %s +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.2-a,-march=armv8.1-a %s 2>&1 | \ +// RUN: FileCheck --check-prefix=MULTIPLE-VALUES %s +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Xassembler -march=armv8.2-a -Xassembler \ +// RUN: -march=armv8.1-a %s 2>&1 | FileCheck --check-prefix=MULTIPLE-VALUES %s + +// MULTIPLE-VALUES: "-target-feature" "+v8.1a +// MULTIPLE-VALUES-NOT: "-target-feature" "+v8.2a + +/// march to compiler and assembler, we choose the one suited to the input file type +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.3-a -march=armv8.4-a %s 2>&1 | \ +// RUN: FileCheck --check-prefix=TARGET-FEATURE-3 %s +// RUN: %clang --target=aarch64-linux-gnueabi -### -c -Wa,-march=armv8.3-a -march=armv8.4-a \ +// RUN: %S/Inputs/wildcard1.c 2>&1 | FileCheck --check-prefix=TARGET-FEATURE-4 %s + +// TARGET-FEATURE-3: "-target-feature" "+v8.3a" +// TARGET-FEATURE-3-NOT: "-target-feature" "+v8.4a" +// TARGET-FEATURE-4: "-target-feature" "+v8.4a" +// TARGET-FEATURE-4-NOT: "-target-feature" "+v8.3a" -- 2.7.4