From 92ad94e7cd8f95019d66b1534d6187f87c293a9c Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 16 Apr 2018 19:11:17 +0000 Subject: [PATCH] [Hexagon] Emit a warning when -fvectorize is given without -mhvx llvm-svn: 330150 --- clang/include/clang/Basic/DiagnosticDriverKinds.td | 3 +++ clang/lib/Driver/ToolChains/Hexagon.cpp | 21 ++++++++++++++------- clang/lib/Driver/ToolChains/Hexagon.h | 1 + clang/test/Driver/hexagon-vectorize.c | 2 ++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index ccc4db8..a8da85f 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -288,6 +288,9 @@ def err_analyzer_config_multiple_values : Error< def err_drv_invalid_hvx_length : Error< "-mhvx-length is not supported without a -mhvx/-mhvx= flag">; +def warn_drv_vectorize_needs_hvx : Warning< + "auto-vectorization requires HVX, use -mhvx to enable it">, + InGroup; def err_drv_modules_validate_once_requires_timestamp : Error< "option '-fmodules-validate-once-per-build-session' requires " diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp index 6402a82..04b09d9 100644 --- a/clang/lib/Driver/ToolChains/Hexagon.cpp +++ b/clang/lib/Driver/ToolChains/Hexagon.cpp @@ -108,8 +108,11 @@ void hexagon::getHexagonTargetFeatures(const Driver &D, const ArgList &Args, Features.push_back(UseLongCalls ? "+long-calls" : "-long-calls"); - bool HasHVX(false); + bool HasHVX = false; handleHVXTargetFeatures(D, Args, Features, HasHVX); + + if (HexagonToolChain::isAutoHVXEnabled(Args) && !HasHVX) + D.Diag(diag::warn_drv_vectorize_needs_hvx); } // Hexagon tools start. @@ -520,12 +523,9 @@ void HexagonToolChain::addClangTargetOptions(const ArgList &DriverArgs, CC1Args.push_back("-target-feature"); CC1Args.push_back("+reserved-r19"); } - if (Arg *A = DriverArgs.getLastArg(options::OPT_fvectorize, - options::OPT_fno_vectorize)) { - if (A->getOption().matches(options::OPT_fvectorize)) { - CC1Args.push_back("-mllvm"); - CC1Args.push_back("-hexagon-autohvx"); - } + if (isAutoHVXEnabled(DriverArgs)) { + CC1Args.push_back("-mllvm"); + CC1Args.push_back("-hexagon-autohvx"); } } @@ -564,6 +564,13 @@ HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const { return ToolChain::CST_Libstdcxx; } +bool HexagonToolChain::isAutoHVXEnabled(const llvm::opt::ArgList &Args) { + if (Arg *A = Args.getLastArg(options::OPT_fvectorize, + options::OPT_fno_vectorize)) + return A->getOption().matches(options::OPT_fvectorize); + return false; +} + // // Returns the default CPU for Hexagon. This is the default compilation target // if no Hexagon processor is selected at the command-line. diff --git a/clang/lib/Driver/ToolChains/Hexagon.h b/clang/lib/Driver/ToolChains/Hexagon.h index 229a08c..e43b8a5 100644 --- a/clang/lib/Driver/ToolChains/Hexagon.h +++ b/clang/lib/Driver/ToolChains/Hexagon.h @@ -94,6 +94,7 @@ public: void getHexagonLibraryPaths(const llvm::opt::ArgList &Args, ToolChain::path_list &LibPaths) const; + static bool isAutoHVXEnabled(const llvm::opt::ArgList &Args); static const StringRef GetDefaultCPU(); static const StringRef GetTargetCPUVersion(const llvm::opt::ArgList &Args); diff --git a/clang/test/Driver/hexagon-vectorize.c b/clang/test/Driver/hexagon-vectorize.c index d6a537e..dcd6a09 100644 --- a/clang/test/Driver/hexagon-vectorize.c +++ b/clang/test/Driver/hexagon-vectorize.c @@ -1,7 +1,9 @@ // RUN: %clang -target hexagon -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT // RUN: %clang -target hexagon -fvectorize -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-VECTOR // RUN: %clang -target hexagon -fvectorize -fno-vectorize -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOVECTOR +// RUN: %clang -target hexagon -fvectorize -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-NEEDHVX // CHECK-DEFAULT-NOT: hexagon-autohvx // CHECK-VECTOR: "-mllvm" "-hexagon-autohvx" // CHECK-NOVECTOR-NOT: hexagon-autohvx +// CHECK-NEEDHVX: warning: auto-vectorization requires HVX, use -mhvx to enable it -- 2.7.4