From f466546ba6b09e874148348332e52a61ecf54028 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330150 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 3 +++ lib/Driver/ToolChains/Hexagon.cpp | 21 +++++++++++++------- lib/Driver/ToolChains/Hexagon.h | 1 + test/Driver/hexagon-vectorize.c | 2 ++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index ccc4db8fc7..a8da85f305 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/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/lib/Driver/ToolChains/Hexagon.cpp b/lib/Driver/ToolChains/Hexagon.cpp index 6402a8288b..04b09d9483 100644 --- a/lib/Driver/ToolChains/Hexagon.cpp +++ b/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/lib/Driver/ToolChains/Hexagon.h b/lib/Driver/ToolChains/Hexagon.h index 229a08c76d..e43b8a5b88 100644 --- a/lib/Driver/ToolChains/Hexagon.h +++ b/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/test/Driver/hexagon-vectorize.c b/test/Driver/hexagon-vectorize.c index d6a537ee8c..dcd6a09222 100644 --- a/test/Driver/hexagon-vectorize.c +++ b/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.40.0