[flang-commits] [flang] [flang][driver] Limit the usage of -mvscale-max and -mvscale-min (PR #77905)
Andrzej WarzyĆski via flang-commits
flang-commits at lists.llvm.org
Fri Jan 12 02:52:29 PST 2024
https://github.com/banach-space created https://github.com/llvm/llvm-project/pull/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.
>From 8a5dd55738a4054563c6d31f512558408d083328 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Fri, 12 Jan 2024 10:48:10 +0000
Subject: [PATCH] [flang][driver] Limit the usage of -mvscale-max and
-mvscale-min
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.
---
flang/lib/Frontend/CompilerInvocation.cpp | 45 +++++++++++++------
.../Driver/unsupported-vscale-max-min.f90 | 8 ++++
2 files changed, 39 insertions(+), 14 deletions(-)
create mode 100644 flang/test/Driver/unsupported-vscale-max-min.f90
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