Skip to content

Commit 121c41a

Browse files
author
Cameron McInally
committed
Rework ParseMPreferVectorWidthOption(...) to return the Value StringRef.
This patch reworks ParseMPreferVectorWidthOption(...) to only return the Value StringRef. It will now be the responsibility of the caller to handle the Value appropriately. This allows more flexibily and makes ParseMPreferVectorWidthOption(...) useful in different contexts. Also, add a docstring for this function.
1 parent ef34cdf commit 121c41a

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

clang/include/clang/Driver/CommonArgs.h

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

274-
std::optional<StringRef> ParseMPreferVectorWidthOption(
275-
clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args,
276-
llvm::opt::ArgStringList &CmdArgs, bool isCompilerDriver);
274+
// Parse -mprefer-vector-width=. Return the Value string if well-formed.
275+
// Otherwise, return an empty string and issue a diagnosic message if needed.
276+
StringRef ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
277+
const llvm::opt::ArgList &Args);
277278

278279
} // end namespace tools
279280
} // end namespace driver

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7586,8 +7586,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
75867586

75877587
handleVectorizeLoopsArgs(Args, CmdArgs);
75887588
handleVectorizeSLPArgs(Args, CmdArgs);
7589-
ParseMPreferVectorWidthOption(D.getDiags(), Args, CmdArgs,
7590-
/*isCompilerDriver=*/true);
7589+
7590+
StringRef VecWidth = ParseMPreferVectorWidthOption(D.getDiags(), Args);
7591+
if (!VecWidth.empty())
7592+
CmdArgs.push_back(Args.MakeArgString("-mprefer-vector-width=" + VecWidth));
75917593

75927594
Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
75937595
Args.AddLastArg(CmdArgs,

clang/lib/Driver/ToolChains/CommonArgs.cpp

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

3171-
std::optional<StringRef> tools::ParseMPreferVectorWidthOption(
3172-
clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args,
3173-
ArgStringList &CmdArgs, bool isCompilerDriver) {
3174-
// If this was invoked by the Compiler Driver, we pass through the option
3175-
// as-is. Otherwise, if this is the Frontend Driver, we want just the value.
3176-
StringRef Out = isCompilerDriver ? "-mprefer-vector-width=" : "";
3177-
3171+
// Parse -mprefer-vector-width=. Return the Value string if well-formed.
3172+
// Otherwise, return an empty string and issue a diagnosic message if needed.
3173+
StringRef tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
3174+
const llvm::opt::ArgList &Args) {
31783175
Arg *A = Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
31793176
if (!A)
3180-
return std::nullopt;
3177+
return "";
31813178

31823179
StringRef Value = A->getValue();
31833180
unsigned Width __attribute((uninitialized));
@@ -3187,9 +3184,8 @@ std::optional<StringRef> tools::ParseMPreferVectorWidthOption(
31873184
if (Value != "none" && Value.getAsInteger(10, Width)) {
31883185
Diags.Report(clang::diag::err_drv_invalid_value)
31893186
<< A->getOption().getName() << Value;
3190-
return std::nullopt;
3187+
return "";
31913188
}
31923189

3193-
CmdArgs.push_back(Args.MakeArgString(Out + Value));
31943190
return Value;
31953191
}

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,8 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
310310
for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
311311
opts.LLVMPassPlugins.push_back(a->getValue());
312312

313-
llvm::opt::ArgStringList result;
314-
opts.PreferVectorWidth = clang::driver::tools::ParseMPreferVectorWidthOption(
315-
diags, args, result,
316-
/*isCompilerDriver=*/false)
317-
.value_or("");
313+
opts.PreferVectorWidth =
314+
clang::driver::tools::ParseMPreferVectorWidthOption(diags, args);
318315

319316
// -fembed-offload-object option
320317
for (auto *a :

0 commit comments

Comments
 (0)