[Hexagon] Emit a warning when -fvectorize is given without -mhvx
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Mon, 16 Apr 2018 19:11:17 +0000 (19:11 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Mon, 16 Apr 2018 19:11:17 +0000 (19:11 +0000)
llvm-svn: 330150

clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/ToolChains/Hexagon.h
clang/test/Driver/hexagon-vectorize.c

index ccc4db8..a8da85f 100644 (file)
@@ -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<OptionIgnored>;
 
 def err_drv_modules_validate_once_requires_timestamp : Error<
   "option '-fmodules-validate-once-per-build-session' requires "
index 6402a82..04b09d9 100644 (file)
@@ -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.
index 229a08c..e43b8a5 100644 (file)
@@ -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);
 
index d6a537e..dcd6a09 100644 (file)
@@ -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