[llvm] [SPIRV] Emit NonSemantic DebugGlobalVariable (PR #207230)
Manuel Carrasco via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 10 06:14:12 PDT 2026
================
@@ -561,6 +586,90 @@ std::optional<MCRegister> SPIRVNonSemanticDebugHandler::mapDISignatureTypeToReg(
return lookupOptReg(DebugTypeRegs, Ty);
}
+std::optional<MCRegister>
+SPIRVNonSemanticDebugHandler::resolveGlobalVariableParent(
+ const DIGlobalVariable *GV) const {
+ // TODO: When this backend emits debug instructions for namespace, subprogram,
+ // and module scopes, return GV->getScope()'s debug id.
+
+ // Fallback: first module compile unit (SPIRV-LLVM-Translator default).
+ if (CompileUnits.empty())
+ return std::nullopt;
+ return lookupOptReg(CUToCompilationUnitDbgReg, CompileUnits[0].TheCU);
+}
+
+// Unimplemented no-op; see emitDebugExpression declaration.
+std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugExpression(
+ const DIExpression *, MCRegister, MCRegister, SPIRV::ModuleAnalysisInfo &) {
+ return std::nullopt;
+}
+
+std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugGlobalVariable(
+ const DIGlobalVariable *GV, MCRegister VoidTypeReg, MCRegister I32TypeReg,
+ MCRegister ExtInstSetReg, SPIRV::ModuleAnalysisInfo &MAI) {
+ assert(GV && "GV must not be null in emitDebugGlobalVariable");
+
+ auto ParentRegOpt = resolveGlobalVariableParent(GV);
+ if (!ParentRegOpt)
+ return std::nullopt;
+
+ // TyReg: DebugInfoNone when GV has no DI type (as done in
+ // SPIRV-LLVM-Translator). Declarations (isDefinition: false) can have null
+ // getType() while definitions must have a non-null one (enforced by the IR
+ // verifier).
+ MCRegister TyReg = CachedDebugInfoNoneReg;
+ if (const DIType *Ty = GV->getType()) {
+ auto TyRegOpt = lookupOptReg(DebugTypeRegs, Ty);
+ if (!TyRegOpt)
+ return std::nullopt;
+ TyReg = *TyRegOpt;
+ }
+
+ std::optional<MCRegister> StaticMemberRegOpt;
+ if (const DIDerivedType *SM = GV->getStaticDataMemberDeclaration()) {
+ StaticMemberRegOpt = lookupOptReg(DebugTypeRegs, SM);
+ if (!StaticMemberRegOpt)
+ return std::nullopt;
+ }
+
+ MCRegister NameReg = getCachedOpStringReg(GV->getName());
+ MCRegister LinkageReg = getCachedOpStringReg(GV->getLinkageName());
+ MCRegister FileStrReg = getCachedOpStringReg(getDebugFullPath(GV->getFile()));
----------------
mgcarrasco wrote:
Done
https://github.com/llvm/llvm-project/pull/207230
More information about the llvm-commits
mailing list