[flang-commits] [clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)
Tarun Prabhu via flang-commits
flang-commits at lists.llvm.org
Thu Jun 5 15:33:02 PDT 2025
================
@@ -3167,3 +3167,29 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args,
options::OPT_fno_loop_interchange, EnableInterchange))
CmdArgs.push_back("-floop-interchange");
}
+
+std::optional<StringRef> tools::ParseMPreferVectorWidthOption(
+ clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args,
+ ArgStringList &CmdArgs, bool isCompilerDriver) {
+ // If this was invoked by the Compiler Driver, we pass through the option
+ // as-is. Otherwise, if this is the Frontend Driver, we want just the value.
+ StringRef Out = isCompilerDriver ? "-mprefer-vector-width=" : "";
+
+ Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
+ if (!A)
+ return std::nullopt;
+
+ StringRef Value = A->getValue();
+ unsigned Width __attribute((uninitialized));
+
+ // Only "none" and Integer values are accepted by
+ // -mprefer-vector-width=<value>.
+ if (Value != "none" && Value.getAsInteger(10, Width)) {
+ Diags.Report(clang::diag::err_drv_invalid_value)
+ << A->getOption().getName() << Value;
+ return std::nullopt;
+ }
+
+ CmdArgs.push_back(Args.MakeArgString(Out + Value));
----------------
tarunprabhu wrote:
The alternative would be to not add to `CmdArgs` here, but to do it in the caller instead. I think that is ok too. It would be a bit of a departure from the way the rest of the code works, but it feels like a more "natural" way of handling this. The rest of the code could, gradually, be made more consistent with this approach.
https://github.com/llvm/llvm-project/pull/142800
More information about the flang-commits
mailing list