[clang] [HIP][SPIRV] Enable the SPIRV backend instead of the translator through an experimental flag. (PR #162282)

Manuel Carrasco via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 15 02:18:44 PDT 2025


================
@@ -175,15 +175,33 @@ void AMDGCN::Linker::constructLinkAndEmitSpirvCommand(
 
   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);
+  bool UseSPIRVBackend = Args.hasFlag(
+      options::OPT_use_experimental_spirv_backend,
+      options::OPT_no_use_experimental_spirv_backend, /*Default=*/false);
+
+  // Emit SPIR-V binary either using the SPIRV backend or the translator.
+  if (UseSPIRVBackend) {
+    llvm::opt::ArgStringList CmdArgs;
+    const char *Triple =
+        C.getArgs().MakeArgString("-triple=spirv64-amd-amdhsa");
+    CmdArgs.append({"-cc1", Triple, "-emit-obj", LinkedBCFile.getFilename(),
----------------
mgcarrasco wrote:

Thank you all for the feedback. 

@arsenm `-emit-obj` is not breaking `-save-temps` (files are saved). There is no existing function to call for this. 

@jhuber6 Following up on @AlexVlx's [comment](https://github.com/llvm/llvm-project/pull/162282/#discussion_r2420855314), making the target directly emit object instead of IR would require substantial changes in places like the Driver and also it would make the code less maintainable when it comes to keep it in sync with the existing translator code. That is why I prefer to call -cc1 as we do now.


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


More information about the cfe-commits mailing list