Skip to content

[Driver][SYCL][FPGA] Improve help output for aoc with -fsycl-help #2446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1788,20 +1788,21 @@ llvm::Triple Driver::MakeSYCLDeviceTriple(StringRef TargetArch) const {
// Print the help from any of the given tools which are used for AOT
// compilation for SYCL
void Driver::PrintSYCLToolHelp(const Compilation &C) const {
SmallVector<std::tuple<llvm::Triple, StringRef, StringRef>, 4> HelpArgs;
SmallVector<std::tuple<llvm::Triple, StringRef, StringRef, StringRef>, 4>
HelpArgs;
// Populate the vector with the tools and help options
if (Arg *A = C.getArgs().getLastArg(options::OPT_fsycl_help_EQ)) {
StringRef AV(A->getValue());
llvm::Triple T;
if (AV == "gen" || AV == "all")
HelpArgs.push_back(std::make_tuple(MakeSYCLDeviceTriple("spir64_gen"),
"ocloc", "--help"));
"ocloc", "--help", ""));
if (AV == "fpga" || AV == "all")
HelpArgs.push_back(
std::make_tuple(MakeSYCLDeviceTriple("spir64_fpga"), "aoc", "-help"));
HelpArgs.push_back(std::make_tuple(MakeSYCLDeviceTriple("spir64_fpga"),
"aoc", "-help", "-sycl"));
if (AV == "x86_64" || AV == "all")
HelpArgs.push_back(std::make_tuple(MakeSYCLDeviceTriple("spir64_x86_64"),
"opencl-aot", "--help"));
"opencl-aot", "--help", ""));
if (HelpArgs.empty()) {
C.getDriver().Diag(diag::err_drv_unsupported_option_argument)
<< A->getOption().getName() << AV;
Expand All @@ -1814,7 +1815,8 @@ void Driver::PrintSYCLToolHelp(const Compilation &C) const {
llvm::outs() << "Emitting help information for " << std::get<1>(HA) << '\n'
<< "Use triple of '" << std::get<0>(HA).normalize() <<
"' to enable ahead of time compilation\n";
std::vector<StringRef> ToolArgs = { std::get<1>(HA), std::get<2>(HA) };
std::vector<StringRef> ToolArgs = {std::get<1>(HA), std::get<2>(HA),
std::get<3>(HA)};
SmallString<128> ExecPath(
C.getDefaultToolChain().GetProgramPath(std::get<1>(HA).data()));
auto ToolBinary = llvm::sys::findProgramByName(ExecPath);
Expand All @@ -1824,7 +1826,10 @@ void Driver::PrintSYCLToolHelp(const Compilation &C) const {
}
// do not run the tools with -###.
if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
llvm::errs() << "\"" << ExecPath << "\" \"" << ToolArgs[1] << "\"\n";
llvm::errs() << "\"" << ExecPath << "\" \"" << ToolArgs[1] << "\"";
if (!ToolArgs[2].empty())
llvm::errs() << " \"" << ToolArgs[2] << "\"";
Comment on lines +1829 to +1831
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, a while loop would've looked cleaner than a hardcoded [2]. But I see why one can prefer the code this way (to avoid extra complexity in an unlikely-to-change helper function).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could go either way. It was just a single argument used in a very specific output function with know limited array args.

llvm::errs() << "\n";
continue;
}
// Run the Tool.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/sycl.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
// SYCL-HELP-BADARG: unsupported argument 'foo' to option 'fsycl-help='
// SYCL-HELP-GEN: Emitting help information for ocloc
// SYCL-HELP-GEN: Use triple of 'spir64_gen-unknown-unknown-sycldevice' to enable ahead of time compilation
// SYCL-HELP-FPGA-OUT: "[[DIR]]{{[/\\]+}}aoc" "-help"
// SYCL-HELP-FPGA-OUT: "[[DIR]]{{[/\\]+}}aoc" "-help" "-sycl"
// SYCL-HELP-FPGA: Emitting help information for aoc
// SYCL-HELP-FPGA: Use triple of 'spir64_fpga-unknown-unknown-sycldevice' to enable ahead of time compilation
// SYCL-HELP-CPU: Emitting help information for opencl-aot
Expand Down