[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #107493)
Michael Toguchi via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 16:13:15 PDT 2024
================
@@ -5116,15 +5123,39 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (const Arg *PF = Args.getLastArg(options::OPT_mprintf_kind_EQ))
PF->claim();
- if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false)) {
+ Arg *SYCLStdArg = Args.getLastArg(options::OPT_sycl_std_EQ);
+
+ if (IsSYCLDevice) {
+ // Host triple is needed when doing SYCL device compilations.
+ llvm::Triple AuxT = C.getDefaultToolChain().getTriple();
+ std::string NormalizedTriple = AuxT.normalize();
+ CmdArgs.push_back("-aux-triple");
+ CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
+
+ // We want to compile sycl kernels.
CmdArgs.push_back("-fsycl-is-device");
- if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
- A->render(Args, CmdArgs);
+ // Set O2 optimization level by default
+ if (!Args.getLastArg(options::OPT_O_Group))
+ CmdArgs.push_back("-O2");
+ }
+
+ if (IsSYCL) {
+ // Set options for both host and device
+ if (SYCLStdArg) {
+ SYCLStdArg->render(Args, CmdArgs);
} else {
// Ensure the default version in SYCL mode is 2020.
CmdArgs.push_back("-sycl-std=2020");
}
+
+ // Add any options that are needed specific to SYCL offload while
+ // performing the host side compilation.
+ if (!IsSYCLDevice) {
+ // Let the front-end host compilation flow know about SYCL offload
+ // compilation.
+ CmdArgs.push_back("-fsycl-is-host");
+ }
----------------
mdtoguchi wrote:
Being in an `else` for `IsSYCLDevice` will pass `-fsycl-is-host` to all non-SYCL device compilations, even when offloading isn't enabled. Maybe this can be structured to all be in an `IsSYCL` condition. I will look into that.
https://github.com/llvm/llvm-project/pull/107493
More information about the llvm-commits
mailing list