[flang-commits] [flang] 8cac995 - [flang][driver] Limit the usage of -mvscale-max and -mvscale-min (#77905)

via flang-commits flang-commits at lists.llvm.org
Mon Jan 15 00:50:02 PST 2024


Author: Andrzej WarzyƄski
Date: 2024-01-15T08:49:58Z
New Revision: 8cac995eadebbf23b10f8cebc9a42adcf91cc26b

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

LOG: [flang][driver] Limit the usage of -mvscale-max and -mvscale-min (#77905)

Make sure that `-mvscale-max` and `-mvscale-min` are only available for
targets that are known to support vscale and scalable vectors.

Also fix capitalization of function variables.

Added: 
    flang/test/Driver/unsupported-vscale-max-min.f90

Modified: 
    flang/lib/Frontend/CompilerInvocation.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 0732f4bef290f4..a3c41fb4611f56 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1056,28 +1056,45 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
 /// \param [out] diags DiagnosticsEngine to report erros with
 static bool parseVScaleArgs(CompilerInvocation &invoc, llvm::opt::ArgList &args,
                             clang::DiagnosticsEngine &diags) {
+  const auto *vscaleMin =
+      args.getLastArg(clang::driver::options::OPT_mvscale_min_EQ);
+  const auto *vscaleMax =
+      args.getLastArg(clang::driver::options::OPT_mvscale_max_EQ);
+
+  if (!vscaleMin && !vscaleMax)
+    return true;
+
+  llvm::Triple triple = llvm::Triple(invoc.getTargetOpts().triple);
+  if (!triple.isAArch64() && !triple.isRISCV()) {
+    const unsigned diagID =
+        diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+                              "`-mvscale-max` and `-mvscale-min` are not "
+                              "supported for this architecture: %0");
+    diags.Report(diagID) << triple.getArchName();
+    return false;
+  }
+
   LangOptions &opts = invoc.getLangOpts();
-  if (const auto arg =
-          args.getLastArg(clang::driver::options::OPT_mvscale_min_EQ)) {
-    llvm::StringRef argValue = llvm::StringRef(arg->getValue());
-    unsigned VScaleMin;
-    if (argValue.getAsInteger(/*Radix=*/10, VScaleMin)) {
+  if (vscaleMin) {
+    llvm::StringRef argValue = llvm::StringRef(vscaleMin->getValue());
+    unsigned vscaleMinVal;
+    if (argValue.getAsInteger(/*Radix=*/10, vscaleMinVal)) {
       diags.Report(clang::diag::err_drv_unsupported_option_argument)
-          << arg->getSpelling() << argValue;
+          << vscaleMax->getSpelling() << argValue;
       return false;
     }
-    opts.VScaleMin = VScaleMin;
+    opts.VScaleMin = vscaleMinVal;
   }
-  if (const auto arg =
-          args.getLastArg(clang::driver::options::OPT_mvscale_max_EQ)) {
-    llvm::StringRef argValue = llvm::StringRef(arg->getValue());
-    unsigned VScaleMax;
-    if (argValue.getAsInteger(/*Radix=w*/ 10, VScaleMax)) {
+
+  if (vscaleMax) {
+    llvm::StringRef argValue = llvm::StringRef(vscaleMax->getValue());
+    unsigned vscaleMaxVal;
+    if (argValue.getAsInteger(/*Radix=w*/ 10, vscaleMaxVal)) {
       diags.Report(clang::diag::err_drv_unsupported_option_argument)
-          << arg->getSpelling() << argValue;
+          << vscaleMax->getSpelling() << argValue;
       return false;
     }
-    opts.VScaleMax = VScaleMax;
+    opts.VScaleMax = vscaleMaxVal;
   }
   return true;
 }

diff  --git a/flang/test/Driver/unsupported-vscale-max-min.f90 b/flang/test/Driver/unsupported-vscale-max-min.f90
new file mode 100644
index 00000000000000..dffeb54b665b50
--- /dev/null
+++ b/flang/test/Driver/unsupported-vscale-max-min.f90
@@ -0,0 +1,8 @@
+! REQUIRES: x86-registered-target
+
+! RUN: not %flang_fc1 -triple x86_64-unknown-linux-gnu -mvscale-min=1 -mvscale-max=1 -fsyntax-only %s 2>&1 | FileCheck %s
+
+! CHECK: `-mvscale-max` and `-mvscale-min` are not supported for this architecture: x86_64
+
+subroutine func
+end subroutine func


        


More information about the flang-commits mailing list