[clang] [SYCL][Driver] Emit textual SPIR-V for device-only -S compilations (PR #227844)

Tom Honermann via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 15:01:37 PDT 2026


================
@@ -4493,8 +4493,11 @@ Action *Driver::ConstructPhaseAction(
       }
       return C.MakeAction<BackendJobAction>(Input, Output);
     }
+    // SYCL device compilations produce IR unless the user explicitly requested
+    // device-only assembly output, in which case emit textual SPIR-V.
     if (Args.hasArg(options::OPT_emit_llvm) ||
-        TargetDeviceOffloadKind == Action::OFK_SYCL) {
+        (TargetDeviceOffloadKind == Action::OFK_SYCL &&
+         !(offloadDeviceOnly() && Args.hasArg(options::OPT_S)))) {
----------------
tahonermann wrote:

TL;DR; The following records my own investigation to properly understand this change. The change looks good and improves consistency with CUDA and HIP compilation. There is still an inconsistency in behavior for HIP when assembling for both host and device, but that is a distinct issue from what this PR addresses.

I was initially surprised to see the `offloadDeviceOnly()` check here, but I think I understand. It looks like, when performing a combined host+device compilation with `-S`, the generated assembly contains the host assembly with an embedded device image. That seems very reasonable and useful.

I was curious what is done for other offload languages. CUDA (`clang++ -S t.cu`) does similarly. With `--offload-host-only`, host assembly is produced and with `--offload-device-only`, PTX assembly is produced. Again very reasonable and useful.

HIP compilation (`clang++ -S t.hip`) produces concatenated offload bundles containing LLVM IR for the device followed by assembly for the host. That seems less useful. Hip compilation is otherwise consistent with `--offload-host-only` resulting in host assembly and `--offload-device-only` resulting in amdgpu assembly.

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


More information about the cfe-commits mailing list