[llvm-branch-commits] [llvm] [NFC][SPIRV] Converge different `resolveDebugParentScope` versions into a single one (PR #219925)
Manuel Carrasco via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 1 01:46:44 PDT 2026
Juan Manuel Martinez =?utf-8?q?CaamaƱo?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/219925 at github.com>
================
@@ -650,60 +650,24 @@ SPIRVNonSemanticDebugHandler::emitDebugTypeFunctionForSubroutineType(
return getOrEmitDebugTypeFunction(Ops, VoidTypeReg, ExtInstSetReg, MAI);
}
-// Match SPIRV-LLVM-Translator's selection logic for the Parent operand.
-std::optional<MCRegister>
-SPIRVNonSemanticDebugHandler::resolveDebugFunctionParent(
- const DISubprogram *SP) const {
- const DIScope *Scope = SP->getScope();
- if (Scope && !isa<DIFile>(Scope)) {
- // Find the DINamespace that was emitted as a lexical block.
- if (isa<DINamespace>(Scope))
- return lookupOptReg(DebugLexicalBlockRegs, Scope);
- // TODO: Complete with other lookups once other scopes are supported
- // (subclasses of DIScope).
- const DIType *Ty = dyn_cast<DIType>(Scope);
- if (!Ty)
- return std::nullopt;
- return lookupOptReg(DebugTypeRegs, Ty);
- }
-
- const DICompileUnit *ParentCU = SP->getUnit();
- if (!ParentCU && !CompileUnits.empty())
- ParentCU = CompileUnits[0].TheCU;
- if (!ParentCU)
- return std::nullopt;
- return lookupOptReg(CUToCompilationUnitDbgReg, ParentCU);
-}
-
-std::optional<MCRegister> SPIRVNonSemanticDebugHandler::resolveTypeScopeParent(
- const DIScope *Scope) const {
- // When the scope is itself a type (e.g. a struct nested in another struct),
- // the parent is that enclosing type's debug id.
+std::optional<MCRegister> SPIRVNonSemanticDebugHandler::resolveScope(
+ const DIScope *Scope, const DICompileUnit *FallbackCU) const {
if (const auto *Ty = dyn_cast_or_null<DIType>(Scope))
return lookupOptReg(DebugTypeRegs, Ty);
- // Find the DINamespace that was emitted as a lexical block.
- if (isa_and_nonnull<DINamespace>(Scope))
+ if (isa_and_nonnull<DILexicalBlock, DINamespace>(Scope))
return lookupOptReg(DebugLexicalBlockRegs, Scope);
- // For a file, compile-unit, or absent scope, the parent is the first module
- // DebugCompilationUnit.
- if (CompileUnits.empty())
- return std::nullopt;
-
- return lookupOptReg(CUToCompilationUnitDbgReg, CompileUnits[0].TheCU);
-}
-
-std::optional<MCRegister>
-SPIRVNonSemanticDebugHandler::resolveLexicalBlockParent(
- const DIScope *Scope) const {
- if (isa_and_nonnull<DILexicalBlock>(Scope) ||
- isa_and_nonnull<DINamespace>(Scope))
- return lookupOptReg(DebugLexicalBlockRegs, Scope);
if (const auto *SP = dyn_cast_or_null<DISubprogram>(Scope))
return lookupOptReg(DebugFunctionRegs, SP);
+
+ // For a file, compile-unit, or absent scope, fall back to a compile unit.
+ if (FallbackCU)
+ return lookupOptReg(CUToCompilationUnitDbgReg, FallbackCU);
+
if (CompileUnits.empty())
----------------
mgcarrasco wrote:
Maybe this check is dead code. Also, we may not need to fallback to CompileUnits[0].TheCU if the function has a new fallback parameter. I mean it could directly return at:
```
// no need to check if FallbackCU is nonnull
return lookupOptReg(CUToCompilationUnitDbgReg, FallbackCU);
```
https://github.com/llvm/llvm-project/pull/219925
More information about the llvm-branch-commits
mailing list