[llvm] [SPIRV] Emit NonSemantic DebugGlobalVariable (PR #207230)
Manuel Carrasco via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 17 06:28:16 PDT 2026
================
@@ -251,6 +255,27 @@ void SPIRVNonSemanticDebugHandler::beginModule(Module *M) {
if (!SP->isDefinition())
SubprogramDeclarations.push_back(SP);
}
+
+ // Map DIGlobalVariable -> llvm::GlobalVariable for globals that attach !dbg.
+ // The link lives on the IR global (via DIGlobalVariableExpression); DIGV
+ // metadata has no back-reference to its @g.
+ for (const GlobalVariable &G : M->globals()) {
+ SmallVector<DIGlobalVariableExpression *, 4> GVEs;
+ G.getDebugInfo(GVEs);
+ for (DIGlobalVariableExpression *GVE : GVEs)
+ DIGVToLLVMGV.try_emplace(GVE->getVariable(), &G);
+ }
+
+ // DebugInfoFinder deduplicates expressions but not by their pointed
+ // variables. We use a SmallSetVector to deduplicate them.
----------------
mgcarrasco wrote:
It seems to be the only one in clang, although it may also happen in the Fortran's front-end. Then, there are optimizations such as GlobalMerge. This is what the AI has found out.
https://github.com/llvm/llvm-project/blob/a163cf9268e89097dae55580f2ce2a1a7a99194b/llvm/test/Transforms/GlobalMerge/debug-info.ll#L7
https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/GlobalMerge.cpp
https://github.com/llvm/llvm-project/pull/207230
More information about the llvm-commits
mailing list