From 11e68c7e7ffb430f17a02c5ca28f6884b5de563a Mon Sep 17 00:00:00 2001 From: Mats Petersson Date: Mon, 2 Oct 2023 12:01:12 +0100 Subject: [flang]Add vscale argument parsing (#67676) Support for vector scale range arguments, for AArch64 scalable vector extension (SVE) support. Adds -msve-vector-bits to the flang frontend, and for flang fc1 the options are -mvscale-min and -mvscale-max (optional). These match the clang and clang cc1 options for the same purposes. A further patch will actually USE these arguments. --- flang/lib/Frontend/CompilerInvocation.cpp | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'flang/lib/Frontend/CompilerInvocation.cpp') diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 6c0b90c..37315e0 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -986,6 +986,41 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc, return true; } +/// Parses vscale range options and populates the CompilerInvocation +/// accordingly. +/// Returns false if new errors are generated. +/// +/// \param [out] invoc Stores the processed arguments +/// \param [in] args The compiler invocation arguments to parse +/// \param [out] diags DiagnosticsEngine to report erros with +static bool parseVScaleArgs(CompilerInvocation &invoc, llvm::opt::ArgList &args, + clang::DiagnosticsEngine &diags) { + 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)) { + diags.Report(clang::diag::err_drv_unsupported_option_argument) + << arg->getSpelling() << argValue; + return false; + } + opts.VScaleMin = VScaleMin; + } + 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)) { + diags.Report(clang::diag::err_drv_unsupported_option_argument) + << arg->getSpelling() << argValue; + return false; + } + opts.VScaleMax = VScaleMax; + } + return true; +} + bool CompilerInvocation::createFromArgs( CompilerInvocation &res, llvm::ArrayRef commandLineArgs, clang::DiagnosticsEngine &diags, const char *argv0) { @@ -1079,6 +1114,8 @@ bool CompilerInvocation::createFromArgs( success &= parseFloatingPointArgs(res, args, diags); + success &= parseVScaleArgs(res, args, diags); + // Set the string to be used as the return value of the COMPILER_OPTIONS // intrinsic of iso_fortran_env. This is either passed in from the parent // compiler driver invocation with an environment variable, or failing that -- cgit v1.1