Skip to content

Commit aef6882

Browse files
author
Cameron McInally
committed
[Driver] Move CommonArgs to a location visible by the Frontend Drivers
Update initial patch to use std::optional return values for the parsing functions. This is a more elegant way of returning just the Values to the Frontend Drivers.
1 parent 28c4762 commit aef6882

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

clang/include/clang/Driver/CommonArgs.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,9 @@ void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args,
271271
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args,
272272
llvm::opt::ArgStringList &CmdArgs);
273273

274-
void ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
275-
const llvm::opt::ArgList &Args,
276-
llvm::opt::ArgStringList &CmdArgs,
277-
bool isCompilerDriver);
274+
std::optional<StringRef> ParseMPreferVectorWidthOption(
275+
clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args,
276+
llvm::opt::ArgStringList &CmdArgs, bool isCompilerDriver);
278277

279278
} // end namespace tools
280279
} // end namespace driver

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,17 +3168,16 @@ void tools::handleInterchangeLoopsArgs(const ArgList &Args,
31683168
CmdArgs.push_back("-floop-interchange");
31693169
}
31703170

3171-
void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
3172-
const llvm::opt::ArgList &Args,
3173-
ArgStringList &CmdArgs,
3174-
bool isCompilerDriver) {
3171+
std::optional<StringRef> tools::ParseMPreferVectorWidthOption(
3172+
clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args,
3173+
ArgStringList &CmdArgs, bool isCompilerDriver) {
31753174
// If this was invoked by the Compiler Driver, we pass through the option
31763175
// as-is. Otherwise, if this is the Frontend Driver, we want just the value.
31773176
StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : "";
31783177

31793178
Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
31803179
if (!A)
3181-
return;
3180+
return std::nullopt;
31823181

31833182
StringRef Value = A->getValue();
31843183
unsigned Width;
@@ -3188,9 +3187,9 @@ void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
31883187
if (Value != "none" && Value.getAsInteger(10, Width)) {
31893188
Diags.Report(clang::diag::err_drv_invalid_value)
31903189
<< A->getOption().getName() << Value;
3191-
return;
3190+
return std::nullopt;
31923191
}
31933192

31943193
CmdArgs.push_back(Args.MakeArgString(Out + Value));
3195-
return;
3194+
return Value;
31963195
}

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,9 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
311311
opts.LLVMPassPlugins.push_back(a->getValue());
312312

313313
llvm::opt::ArgStringList result;
314-
clang::driver::tools::ParseMPreferVectorWidthOption(
314+
opts.PreferVectorWidth = clang::driver::tools::ParseMPreferVectorWidthOption(
315315
diags, args, result,
316-
/*isCompilerDriver=*/false);
317-
if (result.size() > 0)
318-
opts.PreferVectorWidth = result[0];
316+
/*isCompilerDriver=*/false).value_or("");
319317

320318
// -fembed-offload-object option
321319
for (auto *a :

0 commit comments

Comments
 (0)