[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #107493)

Michael Toguchi via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 18 07:46:44 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");
----------------
mdtoguchi wrote:

The original implementation was based off of defaults that were applied for OpenCL:  https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/CompilerInvocation.cpp#L697-L700

Had a short interaction with @bader and he stated optimizations by default are critical for SYCL, as it adds a bit of C++ code like template instantiations to user's code.

https://github.com/llvm/llvm-project/pull/107493


More information about the cfe-commits mailing list