diff --git a/llvm-patches/llvm/0007-preserve-device-debug-info.patch b/llvm-patches/llvm/0007-preserve-device-debug-info.patch new file mode 100644 index 000000000..067cc5a73 --- /dev/null +++ b/llvm-patches/llvm/0007-preserve-device-debug-info.patch @@ -0,0 +1,70 @@ +From db7c9f28fff802bd9f4165a344c3b5ef5f6973a2 Mon Sep 17 00:00:00 2001 +From: chipStar +Date: Sat, 18 Jul 2026 14:18:22 +0300 +Subject: [PATCH] Preserve device debug info for gdb-oneapi + +HIPSPVToolChain::adjustDebugInfoKind() unconditionally forced NoDebugInfo, +so -g/-O0 produced device SPIR-V with no debug metadata at all. The stated +reason (SPIRV-LLVM-Translator aborting on DW_OP_LLVM_convert) no longer +applies: the translator now lowers it to SPIRVDebug::Convert. + +Stop clobbering the requested debug level, and when -g is given emit the +NonSemantic.Shader.DebugInfo form (--spirv-debug-info-version= +nonsemantic-shader-200 + SPV_KHR_non_semantic_info) that Intel's IGC and +gdb-oneapi consume to resolve source lines and locals in device code. + +Refs: CHIP-SPV/chipStar#1004 +--- + clang/lib/Driver/ToolChains/HIPSPV.cpp | 34 +++++++++++++++++++++----- + 1 file changed, 28 insertions(+), 6 deletions(-) + +diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp b/clang/lib/Driver/ToolChains/HIPSPV.cpp +index 4cde8f9..58892d6 100644 +--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp ++++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp +@@ -93,8 +93,23 @@ void HIPSPV::Linker::constructLinkAndEmitSpirvCommand( + // We need 1.2 when using warp-level primitivies via sub group extensions. + // Strictly put we'd need 1.3 for the standard non-extension shuffle + // operations, but it's not supported by any target yet. +- llvm::opt::ArgStringList TrArgs{"--spirv-max-version=1.2", +- "--spirv-ext=-all,+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups,+SPV_EXT_shader_atomic_float_add"}; ++ std::string SpirvExts = ++ "--spirv-ext=-all,+SPV_INTEL_function_pointers,+SPV_INTEL_subgroups," ++ "+SPV_EXT_shader_atomic_float_add"; ++ llvm::opt::ArgStringList TrArgs{"--spirv-max-version=1.2"}; ++ // When the user requests debug info (-g, but not -g0), preserve it into the ++ // SPIR-V in the NonSemantic.Shader.DebugInfo form. Intel's IGC and gdb-oneapi ++ // consume this to map device code back to source lines and local variables; ++ // the translator's default OpenCL.DebugInfo.100 form is not sufficient for ++ // that. Emitting the NonSemantic debug instructions requires the ++ // SPV_KHR_non_semantic_info extension, so it is only enabled here on demand ++ // to keep the default (non-debug) SPIR-V output unchanged. ++ if (const Arg *A = Args.getLastArg(options::OPT_g_Group); ++ A && !A->getOption().matches(options::OPT_g0)) { ++ SpirvExts += ",+SPV_KHR_non_semantic_info"; ++ TrArgs.push_back("--spirv-debug-info-version=nonsemantic-shader-200"); ++ } ++ TrArgs.push_back(Args.MakeArgString(SpirvExts)); + InputInfo TrInput = InputInfo(types::TY_LLVM_BC, TempFile, ""); + SPIRV::constructTranslateCommand(C, *this, JA, Output, TrInput, TrArgs); + } +@@ -283,8 +298,15 @@ VersionTuple HIPSPVToolChain::computeMSVCVersion(const Driver *D, + void HIPSPVToolChain::adjustDebugInfoKind( + llvm::codegenoptions::DebugInfoKind &DebugInfoKind, + const llvm::opt::ArgList &Args) const { +- // Debug info generation is disabled for SPIRV-LLVM-Translator +- // which currently aborts on the presence of DW_OP_LLVM_convert. +- // TODO: Enable debug info when the SPIR-V backend arrives. +- DebugInfoKind = llvm::codegenoptions::NoDebugInfo; ++ // Historically device debug info was force-disabled here because the ++ // SPIRV-LLVM-Translator aborted on DW_OP_LLVM_convert debug expressions. ++ // The translator now lowers that operation (SPIRVDebug::Convert), so honor ++ // the debug level the user requested (e.g. via -g) and let it flow into the ++ // emitted SPIR-V. constructLinkAndEmitSpirvCommand() additionally enables the ++ // NonSemantic.Shader.DebugInfo form at translation time so that Intel's IGC ++ // and gdb-oneapi can consume it. Leaving DebugInfoKind untouched keeps the ++ // default (no -g) behavior unchanged, since the driver defaults it to ++ // NoDebugInfo. ++ (void)DebugInfoKind; ++ (void)Args; + }