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

Alexey Bader via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 31 16:52:57 PDT 2024


================
@@ -5116,11 +5123,34 @@ 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)) {
-    CmdArgs.push_back("-fsycl-is-device");
+  Arg *SYCLStdArg = Args.getLastArg(options::OPT_sycl_std_EQ);
 
-    if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
-      A->render(Args, CmdArgs);
+  if (IsSYCL) {
+    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");
+
+      // Set O2 optimization level by default
+      if (!Args.getLastArg(options::OPT_O_Group))
+        CmdArgs.push_back("-O2");
----------------
bader wrote:

I'm not sure if it's directly related to the "debugging". 
SYCL compiler follows common pattern for GPU programming model implementations, which optimize the offload code by default.
>From my POV, more users expect compiler to optimize for speed the code targeting compute accelerator than make code debugger friendly. Is this the right metric for selecting default value from your POV?

BTW, this code has been discussed here too: https://github.com/llvm/llvm-project/pull/107493#discussion_r1763982225.

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


More information about the cfe-commits mailing list