[llvm] [SPIRV] LLVM IR DIScope nodes are now emitted after their dependencies. (PR #227361)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 05:48:51 PDT 2026
================
@@ -833,13 +835,160 @@ MCRegister SPIRVNonSemanticDebugHandler::findOrEmitOpTypeInt32(
return Reg;
}
-std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugTypePointer(
+// Each node emits its dependencies first. E.g. for `void f() { struct L; }`,
+// node L emits f, then L. For `struct S { S *p; }`, S* is a back edge, so S
+// is emitted without member p.
+SPIRVNonSemanticDebugHandler::EmitResult
+SPIRVNonSemanticDebugHandler::getOrCreateDebugScope(const DIScope *S) {
+ if (!S || FailedScopes.contains(S))
+ return EmitResult::unsupported();
+ if (auto Reg = lookupOptReg(DebugScopeRegs, S))
+ return EmitResult::emitted(*Reg);
+
+ // Mark the node as in progress while its dependencies are resolved/emitted.
+ // This also prevents cycles from happening.
+ if (!ScopesInProgress.insert(S).second)
+ return EmitResult::inProgress();
+ EmitResult R = emitDebugScope(S);
+ ScopesInProgress.erase(S);
+ assert((!R || !GlobalNSDIEnabled) &&
+ "debug type or scope created after module-scope NSDI emission");
+ if (R)
+ DebugScopeRegs[S] = R.Reg;
+ else if (R.Status == EmitStatus::Unsupported)
+ FailedScopes.insert(S);
----------------
jmmartinez wrote:
The algorithm is clear; it seems a bit unavoidable the big diff.
Though, I have an idea:
* I think `FailedScopes` is redundant with `ScopesInProgress`. When we "fail" we could just leave the scope in `ScopesInProgress`. Since we treat them in a very similar way (a scope that fails is a scope that doesn't end).
* Then, we only need 2 states in `EmitResult`: succeed and in progress.
* That means that we can just remove the state and simply use the `MCRegister()` as a "failed to remove" value.
* If we allow `DebugScopeRegs` to also hold "in progress / failed" scopes, we can simply use `DebugScopeRegs` to keep the full state without adding `ScopesInProgress`.
Is my train of thought right? Or did I derail?
https://github.com/llvm/llvm-project/pull/227361
More information about the llvm-commits
mailing list