Skip to content

[clang][SYCL] Transfer opt level to clang target options #18470

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

Closed
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
21 changes: 21 additions & 0 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,27 @@ void CudaToolChain::addClangTargetOptions(
CC1Args.append({"-std=c++17", "-fsycl-is-host"});
}

if (DeviceOffloadingKind == Action::OFK_SYCL) {
StringRef OOpt = "3";
if (Arg *A = DriverArgs.getLastArg(options::OPT_O_Group)) {
if (A->getOption().matches(options::OPT_O4) ||
A->getOption().matches(options::OPT_Ofast))
OOpt = "3";
else if (A->getOption().matches(options::OPT_O0))
OOpt = "0";
else if (A->getOption().matches(options::OPT_O)) {
// -Os, -Oz, and -O(anything else) map to -O2, for lack of better options.
OOpt = llvm::StringSwitch<const char *>(A->getValue())
.Case("1", "1")
.Case("2", "2")
.Case("3", "3")
.Case("s", "2")
.Case("z", "2")
.Default("2");
}
}
CC1Args.push_back(DriverArgs.MakeArgString(llvm::Twine("-O") + OOpt));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test to cover the passing of the optimization setting and the default expectation.

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to make this a common function as it is also used for setting the opt level for the assembler?

auto NoLibSpirv = DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||
getDriver().offloadDeviceOnly();
if (DeviceOffloadingKind == Action::OFK_SYCL && !NoLibSpirv) {
Expand Down
Loading