Skip to content

Commit

Permalink
[flang][driver] Limit the usage of -mvscale-max and -mvscale-min
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
banach-space committed Jan 12, 2024
1 parent 011ba72 commit 8a5dd55
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
45 changes: 31 additions & 14 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions flang/test/Driver/unsupported-vscale-max-min.f90
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8a5dd55

Please sign in to comment.