[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
Wed Nov 19 09:33:15 PST 2025


================
@@ -173,17 +172,40 @@ void AMDGCN::Linker::constructLinkAndEmitSpirvCommand(
   const char *LinkedBCFilePath = HIP::getTempFile(C, LinkedBCFilePrefix, "bc");
   InputInfo LinkedBCFile(&JA, LinkedBCFilePath, Output.getBaseInput());
 
+  bool UseSPIRVBackend =
+      Args.hasFlag(options::OPT_use_spirv_backend,
+                   options::OPT_no_use_spirv_backend, /*Default=*/false);
+
   constructLlvmLinkCommand(C, JA, Inputs, LinkedBCFile, Args);
 
-  // Emit SPIR-V binary.
-  llvm::opt::ArgStringList TrArgs{
-      "--spirv-max-version=1.6",
-      "--spirv-ext=+all",
-      "--spirv-allow-unknown-intrinsics",
-      "--spirv-lower-const-expr",
-      "--spirv-preserve-auxdata",
-      "--spirv-debug-info-version=nonsemantic-shader-200"};
-  SPIRV::constructTranslateCommand(C, *this, JA, Output, LinkedBCFile, TrArgs);
+  if (UseSPIRVBackend) {
----------------
mgcarrasco wrote:

@jhuber6 This PR is designed for the new driver and this handling here is required for the _new_ driver when `clang-linker-wrapper` calls `clang`. We link the bitcode first because we can't have a dependency with `spirv-link`, this is required for `-fgpu-rdc`.

I'm writing this comment to make a question for the _old_ driver. The old driver always builds SPIR-V in the linking step (this function). This new code for the new driver works out-of-the-box for the old driver. This enables `-use-spirv-backend` also for the old driver.

Would it be OK to let the _old driver_ use this new code to handle `-use-spirv-backend` as we need? I mean considering that this change is already required for the _new driver_.

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


More information about the cfe-commits mailing list