[clang] [clang][Driver] Support for the SPIR-V backend in the new driver when compiling HIP (PR #167543)

Manuel Carrasco via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 20 06:23:42 PST 2025


mgcarrasco wrote:

> Hello,
> 
> Just to add one data point: I've cherry-picked this PR over amd-staging and added 2 quick and dirty workarounds* for the SPIRV backend to work in https://github.com/ROCm/llvm-project/commits/users/jmmartinez/spirv/hacks_but_it_works .
> 
> I then tried the following combinations over the `vectoradd_hip.cpp` (`clang -x hip -use-spirv-backend --offload-arch=amdgcnspirv vectoradd_hip.cpp $flags`) with the following values for `flags`:
> 
> * `--offload-device-only -S` -> prints textual spirv code (with and without `--offload-new-driver`)
> * `--offload-device-only -S -fgpu-rdc` -> prints textual llvm-ir (with and without `--offload-new-driver`)
> * `-O3 -o a.out -lstdc++ && ./a.out` -> compiles and the test passes (with and without `--offload-new-driver`; with and without `-fgpu-rdc`)
> 
> I haven't tested the SPIRV translator path.
> 
> * The workaround are related to visibility-hidden not being representable in SPIRV (the backend crashes when there are declarations with this visibility) * The SPIRV backend tries to use the `SPV_KHR_float_controls2` extension that is not implemented in the translator, so Comgr cannot translate SPIRV back to LLVM-IR.

Thanks @jmmartinez. I've tested the translator path too. 

There is only one minor expected difference between the output types for `-use-spriv-backend` and `-no-use-spirv-backend` with `--offload-device-only -S` in the new driver. Prior to this PR,  the new driver is not emitting textual SPIRV for `--offload-device-only` when `-S` is set. This is because the translator is invoked as the linker, so `-S` emits LLVM bitcode. Now, in this PR, this inherited behavior and reflected when toggling `-use-spriv-backend` and `-no-use-spirv-backend`.

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


More information about the cfe-commits mailing list