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

Conversation

omarahmed1111
Copy link
Contributor

@omarahmed1111 omarahmed1111 commented May 14, 2025

Currently, without transferring the opt level to clang target options if we called:

clang -O3 -fsycl -fsycl-targets=nvptx64-nvidia-cuda a.cpp -o b

it will not transfer this -O3 to the CC1 args underneath that compiles the nvptx kernels:

clang -cc1 -triple nvptx64-nvidia-cuda ...

This PR would make it more consistent by explicitly transfer driver opt level called to CC1 args:

clang -cc1 -triple nvptx64-nvidia-cuda -O3 ...

The PR also make -O3 the default opt level. I tried to mimic the default opt level passed here.

@omarahmed1111 omarahmed1111 force-pushed the transfer-opt-level-to-clang-target-options branch from a9796d4 to 63f3e57 Compare May 14, 2025 16:31
@omarahmed1111 omarahmed1111 force-pushed the transfer-opt-level-to-clang-target-options branch from 63f3e57 to 81813a1 Compare May 14, 2025 16:33
@omarahmed1111 omarahmed1111 force-pushed the transfer-opt-level-to-clang-target-options branch from 81813a1 to 082f04b Compare May 14, 2025 16:35
@omarahmed1111 omarahmed1111 force-pushed the transfer-opt-level-to-clang-target-options branch from 082f04b to 09fa1a9 Compare May 20, 2025 12:16
@dm-vodopyanov dm-vodopyanov changed the title [clang][SYCl] Transfer opt level to clang target options [clang][SYCL] Transfer opt level to clang target options May 20, 2025
@omarahmed1111 omarahmed1111 marked this pull request as ready for review May 20, 2025 14:21
@omarahmed1111 omarahmed1111 requested a review from a team as a code owner May 20, 2025 14:21
}
}
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.

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

.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.

@omarahmed1111
Copy link
Contributor Author

@mdtoguchi I actually solved this problem wrong, the solution was not in this PR, but the underneath problem was that adding any potential early return could skip the opt level transfer. I added a PR to solve that upstream here. I think we shouldn't add that here as addClangTargetOptions should always come from clang toolchain. So, I will close this for now, but let me know if there is another path for calling this function that would make this PR still useful. Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants