[clang] a67c0fc - [Hexagon] Revamp HVX flag verification in driver

Krzysztof Parzyszek via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 23 15:18:38 PST 2021


Author: Krzysztof Parzyszek
Date: 2021-12-23T15:18:08-08:00
New Revision: a67c0fc1fbe8479eb5b3d7c189395bfe6cb98086

URL: https://github.com/llvm/llvm-project/commit/a67c0fc1fbe8479eb5b3d7c189395bfe6cb98086
DIFF: https://github.com/llvm/llvm-project/commit/a67c0fc1fbe8479eb5b3d7c189395bfe6cb98086.diff

LOG: [Hexagon] Revamp HVX flag verification in driver

Generalize warning/error messages (for reuse), refactor flag verification
code, rewrite HVX flag driver testcase.

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticDriverKinds.td
    clang/lib/Driver/ToolChains/Hexagon.cpp
    clang/test/Driver/hexagon-hvx-ieee-fp.c
    clang/test/Driver/hexagon-hvx-qfloat.c
    clang/test/Driver/hexagon-hvx.c
    clang/test/Driver/hexagon-vectorize.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index c623aeff11f05..a7fd2f26478cf 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -443,16 +443,13 @@ def err_analyzer_checker_option_invalid_input : Error<
 def err_analyzer_checker_incompatible_analyzer_option : Error<
   "checker cannot be enabled with analyzer option '%0' == %1">;
 
-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">,
+def warn_drv_needs_hvx : Warning<
+  "%0 requires HVX, use -mhvx/-mhvx= to enable it">,
   InGroup<OptionIgnored>;
-
-def err_drv_invalid_hvx_qfloat : Error<
-  "-mhvx-qfloat is not supported without a -mhvx/-mhvx= flag.">;
-def err_drv_invalid_arch_hvx_qfloat : Error<
-  "-mhvx-qfloat is not supported on HVX %0.">;
+def err_drv_needs_hvx : Error<
+  "%0 requires HVX, use -mhvx/-mhvx= to enable it">;
+def err_drv_needs_hvx_version : Error<
+  "%0 is not supported on HVX %1">;
 
 def err_drv_module_header_wrong_kind : Error<
   "header file '%0' input type '%1' does not match type of prior input "

diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp
index f9785e42025cc..ba3040636604f 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -26,8 +26,8 @@ using namespace clang;
 using namespace llvm::opt;
 
 // Default hvx-length for various versions.
-static StringRef getDefaultHvxLength(StringRef Cpu) {
-  return llvm::StringSwitch<StringRef>(Cpu)
+static StringRef getDefaultHvxLength(StringRef HvxVer) {
+  return llvm::StringSwitch<StringRef>(HvxVer)
       .Case("v60", "64b")
       .Case("v62", "64b")
       .Case("v65", "64b")
@@ -51,63 +51,107 @@ static void handleHVXTargetFeatures(const Driver &D, const ArgList &Args,
   // Handle HVX warnings.
   handleHVXWarnings(D, Args);
 
-  // Add the +hvx* features based on commandline flags.
-  StringRef HVXFeature, HVXLength;
-
-  // Handle -mhvx, -mhvx=, -mno-hvx.
-  if (Arg *A = Args.getLastArg(options::OPT_mno_hexagon_hvx,
-                               options::OPT_mhexagon_hvx,
-                               options::OPT_mhexagon_hvx_EQ)) {
-    if (A->getOption().matches(options::OPT_mno_hexagon_hvx))
-      return;
-    if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ)) {
-      HasHVX = true;
-      HVXFeature = Cpu = A->getValue();
-      HVXFeature = Args.MakeArgString(llvm::Twine("+hvx") + HVXFeature.lower());
-    } else if (A->getOption().matches(options::OPT_mhexagon_hvx)) {
-      HasHVX = true;
-      HVXFeature = Args.MakeArgString(llvm::Twine("+hvx") + Cpu);
+  auto makeFeature = [&Args](Twine T, bool Enable) -> StringRef {
+    const std::string &S = T.str();
+    StringRef Opt(S);
+    if (Opt.endswith("="))
+      Opt = Opt.drop_back(1);
+    if (Opt.startswith("mno-"))
+      Opt = Opt.drop_front(4);
+    else if (Opt.startswith("m"))
+      Opt = Opt.drop_front(1);
+    return Args.MakeArgString(Twine(Enable ? "+" : "-") + Twine(Opt));
+  };
+
+  auto withMinus = [](StringRef S) -> std::string {
+    return "-" + S.str();
+  };
+
+  // Drop tiny core suffix for HVX version.
+  std::string HvxVer =
+      (Cpu.back() == 'T' || Cpu.back() == 't' ? Cpu.drop_back(1) : Cpu).str();
+  HasHVX = false;
+
+  // Handle -mhvx, -mhvx=, -mno-hvx. If both present, -mhvx= wins over -mhvx.
+  auto argOrNull = [&Args](auto FlagOn, auto FlagOff) -> Arg* {
+    if (Arg *A = Args.getLastArg(FlagOn, FlagOff)) {
+      if (A->getOption().matches(FlagOn))
+        return A;
     }
-    Features.push_back(HVXFeature);
+    return nullptr;
+  };
+
+  Arg *HvxBareA =
+      argOrNull(options::OPT_mhexagon_hvx, options::OPT_mno_hexagon_hvx);
+  Arg *HvxVerA =
+      argOrNull(options::OPT_mhexagon_hvx_EQ, options::OPT_mno_hexagon_hvx);
+
+  if (Arg *A = HvxVerA ? HvxVerA : HvxBareA) {
+    if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ))
+      HvxVer = StringRef(A->getValue()).lower(); // lower produces std:string
+    HasHVX = true;
+    Features.push_back(makeFeature(Twine("hvx") + HvxVer, true));
+  } else if (Arg *A = Args.getLastArg(options::OPT_mno_hexagon_hvx)) {
+    // If there was an explicit -mno-hvx, add -hvx to target features.
+    Features.push_back(makeFeature(A->getOption().getName(), false));
   }
 
+  StringRef HvxLen = getDefaultHvxLength(HvxVer);
+
   // Handle -mhvx-length=.
   if (Arg *A = Args.getLastArg(options::OPT_mhexagon_hvx_length_EQ)) {
     // These flags are valid only if HVX in enabled.
     if (!HasHVX)
-      D.Diag(diag::err_drv_invalid_hvx_length);
+      D.Diag(diag::err_drv_needs_hvx) << withMinus(A->getOption().getName());
     else if (A->getOption().matches(options::OPT_mhexagon_hvx_length_EQ))
-      HVXLength = A->getValue();
+      HvxLen = A->getValue();
   }
-  // Default hvx-length based on Cpu.
-  else if (HasHVX)
-    HVXLength = getDefaultHvxLength(Cpu);
-
-  if (!HVXLength.empty()) {
-    HVXFeature =
-        Args.MakeArgString(llvm::Twine("+hvx-length") + HVXLength.lower());
-    Features.push_back(HVXFeature);
+
+  if (HasHVX) {
+    StringRef L = makeFeature(Twine("hvx-length") + HvxLen.lower(), true);
+    Features.push_back(L);
   }
 
-  // Handle -mhvx-qfloat.
-  // QFloat is valid only on HVX v68/v68+ as of now.
-  unsigned short CpuVer;
-  Cpu.drop_front(1).getAsInteger(10, CpuVer);
-  if (Arg *A = Args.getLastArg(options::OPT_mhexagon_hvx_qfloat,
-                               options::OPT_mno_hexagon_hvx_qfloat)) {
-    if (A->getOption().matches(options::OPT_mno_hexagon_hvx_qfloat)) {
-      StringRef OptName = A->getOption().getName().substr(4);
-      Features.push_back(Args.MakeArgString("-" + OptName));
-      return;
+  unsigned HvxVerNum;
+  // getAsInteger returns 'true' on error.
+  if (StringRef(HvxVer).drop_front(1).getAsInteger(10, HvxVerNum))
+    HvxVerNum = 0;
+
+  // Handle HVX floating point flags.
+  auto checkFlagHvxVersion = [&](auto FlagOn, auto FlagOff,
+                                 unsigned MinVerNum) -> Optional<StringRef> {
+    // Return an Optional<StringRef>:
+    // - None indicates a verification failure, or that the flag was not
+    //   present in Args.
+    // - Otherwise the returned value is that name of the feature to add
+    //   to Features.
+    Arg *A = Args.getLastArg(FlagOn, FlagOff);
+    if (!A)
+      return None;
+
+    StringRef OptName = A->getOption().getName();
+    if (A->getOption().matches(FlagOff))
+      return makeFeature(OptName, false);
+
+    if (!HasHVX) {
+      D.Diag(diag::err_drv_needs_hvx) << withMinus(OptName);
+      return None;
+    }
+    if (HvxVerNum < MinVerNum) {
+      D.Diag(diag::err_drv_needs_hvx_version)
+          << withMinus(OptName) << ("v" + std::to_string(HvxVerNum));
+      return None;
     }
-    StringRef OptName = A->getOption().getName().substr(1);
-    if (HasHVX) {
-      if (CpuVer >= 68)
-        Features.push_back(Args.MakeArgString("+" + OptName));
-      else
-        D.Diag(diag::err_drv_invalid_arch_hvx_qfloat) << Cpu;
-    } else
-      D.Diag(diag::err_drv_invalid_hvx_qfloat);
+    return makeFeature(OptName, true);
+  };
+
+  if (auto F = checkFlagHvxVersion(options::OPT_mhexagon_hvx_qfloat,
+                                   options::OPT_mno_hexagon_hvx_qfloat, 68)) {
+    Features.push_back(*F);
+  }
+  if (auto F = checkFlagHvxVersion(options::OPT_mhexagon_hvx_ieee_fp,
+                                   options::OPT_mno_hexagon_hvx_ieee_fp, 68)) {
+    Features.push_back(*F);
   }
 }
 
@@ -138,7 +182,7 @@ void hexagon::getHexagonTargetFeatures(const Driver &D, const ArgList &Args,
   handleHVXTargetFeatures(D, Args, Features, Cpu, HasHVX);
 
   if (HexagonToolChain::isAutoHVXEnabled(Args) && !HasHVX)
-    D.Diag(diag::warn_drv_vectorize_needs_hvx);
+    D.Diag(diag::warn_drv_needs_hvx) << "auto-vectorization";
 }
 
 // Hexagon tools start.

diff  --git a/clang/test/Driver/hexagon-hvx-ieee-fp.c b/clang/test/Driver/hexagon-hvx-ieee-fp.c
index acc9a910f0f12..cd6e11ef06fe2 100644
--- a/clang/test/Driver/hexagon-hvx-ieee-fp.c
+++ b/clang/test/Driver/hexagon-hvx-ieee-fp.c
@@ -12,3 +12,14 @@
 // RUN:  -mno-hvx-ieee-fp 2>&1 | FileCheck -check-prefix=CHECK-NO-IEEEFP %s
 // CHECK-NO-IEEEFP: "-target-feature" "-hvx-ieee-fp"
 
+// IEEE-FP is valid only on hvxv68 and hvxv68+.
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx=v66 \
+// RUN: -mhvx-ieee-fp 2>&1 | FileCheck -check-prefix=CHECK-ERROR1 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx -mhvx-ieee-fp \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-ERROR1 %s
+// CHECK-ERROR1: error: -mhvx-ieee-fp is not supported on HVX v66
+
+// IEEE-FP is valid only if HVX is enabled.
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx-ieee-fp \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-ERROR2 %s
+// CHECK-ERROR2: error: -mhvx-ieee-fp requires HVX, use -mhvx/-mhvx= to enable it

diff  --git a/clang/test/Driver/hexagon-hvx-qfloat.c b/clang/test/Driver/hexagon-hvx-qfloat.c
index 698451aae58ff..fc647f7b06abd 100644
--- a/clang/test/Driver/hexagon-hvx-qfloat.c
+++ b/clang/test/Driver/hexagon-hvx-qfloat.c
@@ -12,14 +12,14 @@
 // RUN:  -mno-hvx-qfloat 2>&1 | FileCheck -check-prefix=CHECK-NO-QFLOAT %s
 // CHECK-NO-QFLOAT: "-target-feature" "-hvx-qfloat"
 
-// QFloat is valid only on hvxv68 and hvxv68+.
+// QFloat is valid only on hvxv68+.
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx=v66 \
 // RUN: -mhvx-qfloat 2>&1 | FileCheck -check-prefix=CHECK-ERROR1 %s
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx -mhvx-qfloat \
 // RUN:  2>&1 | FileCheck -check-prefix=CHECK-ERROR1 %s
-// CHECK-ERROR1: error: -mhvx-qfloat is not supported on HVX v66.
+// CHECK-ERROR1: error: -mhvx-qfloat is not supported on HVX v66
 
 // QFloat is valid only if HVX is enabled.
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx-qfloat \
 // RUN:  2>&1 | FileCheck -check-prefix=CHECK-ERROR2 %s
-// CHECK-ERROR2: error: -mhvx-qfloat is not supported without a -mhvx/-mhvx= flag.
+// CHECK-ERROR2: error: -mhvx-qfloat requires HVX, use -mhvx/-mhvx= to enable it

diff  --git a/clang/test/Driver/hexagon-hvx.c b/clang/test/Driver/hexagon-hvx.c
index aab7e329471b8..10bb8fe9327f0 100644
--- a/clang/test/Driver/hexagon-hvx.c
+++ b/clang/test/Driver/hexagon-hvx.c
@@ -2,117 +2,227 @@
 // Tests for the hvx features and warnings.
 // -----------------------------------------------------------------------------
 
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECKHVX165 %s
-// CHECKHVX165: "-target-feature" "+hvxv65"
+// No HVX without -mhvx/-mhvx=
+
+// CHECK-HVX-ON:      "-target-feature" "+hvx
+// CHECK-HVX-ON-NOT:  "-target-feature" "-hvx
+// CHECK-HVX-OFF-NOT: "-target-feature" "+hvx
+
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv5 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv55 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67t \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+
+// Infer HVX version from flag:
+
+// CHECK-HVX-V60: "-target-feature" "+hvxv60"
+// CHECK-HVX-V62: "-target-feature" "+hvxv62"
+// CHECK-HVX-V65: "-target-feature" "+hvxv65"
+// CHECK-HVX-V66: "-target-feature" "+hvxv66"
+// CHECK-HVX-V67: "-target-feature" "+hvxv67"
+// CHECK-HVX-V68: "-target-feature" "+hvxv68"
+// CHECK-HVX-V69: "-target-feature" "+hvxv69"
+
+// Direct version flag:
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
+
+// Direct version flag with 
diff erent CPU version:
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mv62 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 -mv65 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 -mv66 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 -mv67 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 -mv68 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 -mv69 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mv60 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
+
+// Direct version flag with 
diff erent CPU version and versionless -mhvx:
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mv62 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 -mv65 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 -mv66 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 -mv67 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 -mv68 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 -mv69 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mv60 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
+
+// Direct version flag with 
diff erent CPU version, versionless -mhvx
+// and -mno-hvx. The -mno-hvx cancels -mhvx=, versionless -mhvx wins:
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 -mno-hvx -mv62 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 -mno-hvx -mv65 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 -mno-hvx -mv66 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 -mno-hvx -mv67 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 -mno-hvx -mv68 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 -mno-hvx -mv69 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mno-hvx -mv60 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
+
+// Direct version flag with 
diff erent CPU version, versionless -mhvx
+// and -mno-hvx. The -mno-hvx cancels versionless -mhvx, -mhvx= wins:
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx -mno-hvx -mhvx=v60 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx -mno-hvx -mhvx=v62 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx -mno-hvx -mhvx=v65 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67 -mhvx -mno-hvx -mhvx=v66 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx -mno-hvx -mhvx=v67 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mno-hvx -mhvx=v68 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx -mno-hvx -mhvx=v69 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
+
+// Infer HVX version from CPU version:
 
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V60 %s
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECKHVX162 %s
-// CHECKHVX162: "-target-feature" "+hvxv62"
-
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V62 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V65 %s
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECKHVX166 %s
-// CHECKHVX166: "-target-feature" "+hvxv66"
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V66 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv67t -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V67 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv68 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V68 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-V69 %s
+
+// Infer HVX length from flag:
+
+// CHECK-HVX-L64:  "-target-feature" "+hvx-length64b"
+// CHECK-HVX-L64-NOT:  "-target-feature" "+hvx-length128b"
+// CHECK-HVX-L128: "-target-feature" "+hvx-length128b"
+// CHECK-HVX-L128-NOT: "-target-feature" "+hvx-length64b"
+
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx -mhvx-length=64b \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L64 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx -mhvx-length=128b \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L128 %s
+
+// Infer HVX length from HVX version:
+
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v60 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L64 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v62 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L64 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v65 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L64 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v66 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L128 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v67 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L128 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v68 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L128 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-L128 %s
+
+// No HVX with trailing -mno-hvx
+
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mno-hvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mno-hvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx=v69 -mhvx-length=128b -mno-hvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mhvx-qfloat -mno-hvx \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-OFF %s
+
+// Float
+
+// CHECK-HVX-QFLOAT-ON:      "-target-feature" "+hvx-qfloat"
+// CHECK-HVX-QFLOAT-OFF-NOT: "-target-feature" "+hvx-qfloat"
+// CHECK-HVX-IEEE-ON:        "-target-feature" "+hvx-ieee-fp"
+// CHECK-HVX-IEEE-OFF-NOT:   "-target-feature" "+hvx-ieee-fp"
+
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mhvx-qfloat \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-QFLOAT-ON %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mno-hvx-qfloat \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-QFLOAT-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mno-hvx-qfloat -mhvx-qfloat \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-QFLOAT-ON %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mhvx-qfloat -mno-hvx-qfloat \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-QFLOAT-OFF %s
 
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 -mhvx \
-// RUN:  -mhvx-length=128B 2>&1 | FileCheck -check-prefix=CHECKHVX2 %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mhvx-ieee-fp \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-IEEE-ON %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mno-hvx-ieee-fp \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-IEEE-OFF %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mno-hvx-ieee-fp -mhvx-ieee-fp \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-IEEE-ON %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mhvx-ieee-fp -mno-hvx-ieee-fp \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-IEEE-OFF %s
+
+// HVX flags heed HVX:
+
+// CHECK-NEEDS-HVX: error: {{.*}} requires HVX, use -mhvx/-mhvx= to enable it
+
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx-length=64b \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-NEEDS-HVX %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx-length=128b \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-NEEDS-HVX %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx-qfloat \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-NEEDS-HVX %s
+// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx-ieee-fp \
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-NEEDS-HVX %s
 
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \
-// RUN:  -mhvx-length=128B 2>&1 | FileCheck -check-prefix=CHECKHVX2 %s
+// Invalid HVX length:
+
+// CHECK-HVX-BAD-LENGTH: error: unsupported argument '{{.*}}' to option 'mhvx-length='
 
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \
-// RUN:  -mhvx-length=128b 2>&1 | FileCheck -check-prefix=CHECKHVX2 %s
-// CHECKHVX2-NOT: "-target-feature" "+hvx-length64b"
-// CHECKHVX2: "-target-feature" "+hvx-length128b"
-
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv65 2>&1 \
-// RUN:  | FileCheck -check-prefix=CHECKHVX3 %s
-
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 2>&1 \
-// RUN:  | FileCheck -check-prefix=CHECKHVX3 %s
-// CHECKHVX3-NOT: "-target-feature" "+hvx
-
-// No hvx target feature must be added if -mno-hvx occurs last
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mno-hvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-NOHVX %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx -mno-hvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-NOHVX %s
-// CHECK-NOHVX-NOT: "-target-feature" "+hvx
-
-// No hvx-ieee-fp target feature must be added if -mno-hvx-ieee-fp occurs last
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx-ieee-fp -mno-hvx \
-// RUN:  -mno-hvx-ieee-fp 2>&1 | FileCheck -check-prefix=CHECK-NOHVX-IEEE-FP %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx-ieee-fp -mhvx \
-// RUN:  -mno-hvx-ieee-fp 2>&1 | FileCheck -check-prefix=CHECK-HVX-NOHVX-IEEE-FP %s
-//
-// CHECK-NOHVX-IEEE-FP-NOT: "-target-feature" "+hvx-ieee-fp"
-// CHECK-HVX-NOHVX-IEEE-FP-NOT: "-target-feature" "+hvx-ieee-fp"
-// CHECK-HVX-NOHVX-IEEE-FP: "-target-feature" "+hvx
-// CHECK-HVX-NOHVX-IEEE-FP-NOT: "-target-feature" "+hvx-ieee-fp"
-
-// Hvx target feature should be added if -mno-hvx doesn't occur last
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mno-hvx -mhvx\
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXFEAT %s
-// CHECK-HVXFEAT: "-target-feature" "+hvxv62"
-
-// With -mhvx, the version of hvx defaults to Cpu
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-DEFAULT %s
-// CHECK-HVX-DEFAULT: "-target-feature" "+hvxv60"
-
-// Test -mhvx= flag
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx=v62 \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXEQ %s
-// CHECK-HVXEQ: "-target-feature" "+hvxv62"
-
-// Honor the last occurred -mhvx=, -mhvx flag.
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx=v62 -mhvx\
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXEQ-PRE %s
-// CHECK-HVXEQ-PRE-NOT: "-target-feature" "+hvxv62"
-// CHECK-HVXEQ-PRE: "-target-feature" "+hvxv60"
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx -mhvx=v62\
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXEQ-PRE2 %s
-// CHECK-HVXEQ-PRE2-NOT: "-target-feature" "+hvxv60"
-// CHECK-HVXEQ-PRE2: "-target-feature" "+hvxv62"
-
-// Test -mhvx-length flag
-// The default mode on v60,v62 is 64B.
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-64B %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
-// RUN:  -mhvx-length=64b 2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-64B %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
-// RUN:  -mhvx-length=64B 2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-64B %s
-// CHECK-HVXLENGTH-64B: "-target-feature" "+hvx{{.*}}" "-target-feature" "+hvx-length64b"
-// The default mode on v66 and future archs is 128B.
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv66 -mhvx \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-128B %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx -mhvx-length=128B\
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-128B %s
-// CHECK-HVXLENGTH-128B: "-target-feature" "+hvx{{.*}}" "-target-feature" "+hvx-length128b"
-
-// Bail out if -mhvx-length is specified without HVX enabled
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx-length=64B \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-ERROR %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx-length=128B \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-ERROR %s
-// CHECK-HVXLENGTH-ERROR: error: -mhvx-length is not supported without a -mhvx/-mhvx= flag
-
-// Error out if an unsupported value is passed to -mhvx-length.
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx -mhvx-length=B \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-VALUE-ERROR %s
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-BAD-LENGTH %s
 // RUN: %clang -c %s -### -target hexagon-unknown-elf -mhvx -mhvx-length=128 \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-VALUE-ERROR %s
-// CHECK-HVXLENGTH-VALUE-ERROR: error: unsupported argument '{{.*}}' to option 'mhvx-length='
-
-// Test -mhvx-ieee-fp flag
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx-ieee-fp \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXIEEEFP-LONE %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mhvx -mhvx-ieee-fp \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXIEEEFP %s
-// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv69 -mno-hvx -mhvx-ieee-fp \
-// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXIEEEFP %s
-// CHECK-HVXIEEEFP-LONE-NOT: "-target-feature" "+hvx"
-// CHECK-HVXIEEEFP-LONE: "-target-feature" "+hvx-ieee-fp"
-// CHECK-HVXIEEEFP: "-target-feature" "+hvx-ieee-fp"
-// CHECK-HVXIEEEFP-LONE-NOT: "-target-feature" "+hvx"
+// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVX-BAD-LENGTH %s

diff  --git a/clang/test/Driver/hexagon-vectorize.c b/clang/test/Driver/hexagon-vectorize.c
index dcd6a09222eb1..6a142e30cd949 100644
--- a/clang/test/Driver/hexagon-vectorize.c
+++ b/clang/test/Driver/hexagon-vectorize.c
@@ -6,4 +6,4 @@
 // 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
+// CHECK-NEEDHVX: warning: auto-vectorization requires HVX, use -mhvx/-mhvx= to enable it


        


More information about the cfe-commits mailing list