[llvm-branch-commits] [llvm] [SPIRV] Drop the DebugTypeFunction operand cache. (PR #229486)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Oct 7 03:50:25 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Manuel Carrasco (mgcarrasco)
<details>
<summary>Changes</summary>
This PR drops the DebugTypeFunction operand cache. Each DISubroutineType is already emitted once through DebugScopeRegs via pointer equality. This removed cache reused one DebugTypeFunction for every subroutine type with the same operands.
This is required to simplify the implementation for back edges when emitting DIScopes. The support uses OpExtInstWithForwardRefsKHR, and it is implemented in the following PRs.
A forward reference needs the result id of a DebugTypeFunction before that instruction is emitted. The back edge uses that id with OpExtInstWithForwardRefsKHR, and DebugTypeFunction has to be defined with the same id. This cache creates the id when it emits, from the operand list, so the forward reference and the definition would not use the same id.
---
Full diff: https://github.com/llvm/llvm-project/pull/229486.diff
3 Files Affected:
- (modified) llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp (+2-16)
- (modified) llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h (-11)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-type-function-void-prototypes.ll (+3-2)
``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
index 2e2e79dab4b0e..85ecd56df158b 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
@@ -348,7 +348,6 @@ void SPIRVNonSemanticDebugHandler::beginModule(Module *M) {
ScalarTypeCache.clear();
ScalarConstantCache.clear();
ConstantValueRegs.clear();
- DebugTypeFunctionCache.clear();
DebugOperationCache.clear();
DebugExpressionCache.clear();
ModuleScopeIds.clear();
@@ -555,20 +554,6 @@ MCRegister SPIRVNonSemanticDebugHandler::emitExtInst(
return Reg;
}
-MCRegister SPIRVNonSemanticDebugHandler::getOrEmitDebugTypeFunction(
- ArrayRef<MCRegister> Ops, MCRegister VoidTypeReg, MCRegister ExtInstSetReg,
- SPIRV::ModuleAnalysisInfo &MAI) {
- auto [It, Inserted] =
- DebugTypeFunctionCache.try_emplace(SmallVector<MCRegister, 8>(Ops));
- if (!Inserted)
- return It->second;
-
- MCRegister Reg = emitExtInst(SPIRV::NonSemanticExtInst::DebugTypeFunction,
- VoidTypeReg, ExtInstSetReg, Ops, MAI);
- It->second = Reg;
- return Reg;
-}
-
MCRegister SPIRVNonSemanticDebugHandler::getOrEmitOpTypeVoidReg(
SPIRV::ModuleAnalysisInfo &MAI) {
if (!CachedOpTypeVoidReg.isValid())
@@ -985,7 +970,8 @@ SPIRVNonSemanticDebugHandler::emitDebugTypeFunctionForSubroutineType(
}
}
return EmitResult::emitted(
- getOrEmitDebugTypeFunction(Ops, VoidTypeReg, ExtInstSetReg, MAI));
+ emitExtInst(SPIRV::NonSemanticExtInst::DebugTypeFunction, VoidTypeReg,
+ ExtInstSetReg, Ops, MAI));
}
// Match SPIRV-LLVM-Translator's selection logic for the Parent operand.
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
index a96ac8e33afed..0a7690efbab7b 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
@@ -190,10 +190,6 @@ class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
DenseMap<std::pair<const DIBasicType *, uint64_t>, MCRegister>
ConstantValueRegs;
- // Cache of already-emitted DebugTypeFunction instructions, keyed by operand
- // ids (flags, return type, parameters).
- DenseMap<SmallVector<MCRegister, 8>, MCRegister> DebugTypeFunctionCache;
-
// Cache of already-emitted DebugOperation instructions, keyed by NonSemantic
// opcode followed by the 32-bit operation arguments. Inline size 3 is the
// spec maximum (opcode plus at most two operands: BitPiece, Fragment).
@@ -362,13 +358,6 @@ class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
ArrayRef<MCRegister> Operands,
SPIRV::ModuleAnalysisInfo &MAI);
- /// Return a cached DebugTypeFunction id when \p Ops matches a prior emission,
- /// otherwise emit and cache a new instruction.
- MCRegister getOrEmitDebugTypeFunction(ArrayRef<MCRegister> Ops,
- MCRegister VoidTypeReg,
- MCRegister ExtInstSetReg,
- SPIRV::ModuleAnalysisInfo &MAI);
-
/// Return OpTypeVoid id for this module (lazy lookup / emit, then cache).
MCRegister getOrEmitOpTypeVoidReg(SPIRV::ModuleAnalysisInfo &MAI);
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-type-function-void-prototypes.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-type-function-void-prototypes.ll
index d9f41f4cf0bab..10ef297e37876 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-type-function-void-prototypes.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-type-function-void-prototypes.ll
@@ -2,13 +2,14 @@
; RUN: %if spirv-tools %{ llc --verify-machineinstrs --spirv-ext=+SPV_KHR_non_semantic_info -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; Void function types in LLVM metadata may be written as an empty type list (!{}) or with an explicit
-; null return slot (!{null}); both should produce the same SPIR-V DebugTypeFunction (flags + void only).
+; null return slot (!{null}). Those are two DISubroutineType nodes, so each gets its own
+; DebugTypeFunction. Both instructions have the same operands: flags and OpTypeVoid.
; CHECK: [[ext:%[0-9]+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
; CHECK-DAG: [[type_void:%[0-9]+]] = OpTypeVoid
; CHECK-DAG: [[type_int32:%[0-9]+]] = OpTypeInt 32 0
; CHECK-DAG: [[flag_zero:%[0-9]+]] = OpConstant [[type_int32]] 0{{$}}
-; CHECK-COUNT-1: OpExtInst [[type_void]] [[ext]] DebugTypeFunction [[flag_zero]] [[type_void]]
+; CHECK-COUNT-2: OpExtInst [[type_void]] [[ext]] DebugTypeFunction [[flag_zero]] [[type_void]]
target triple = "spirv64-unknown-unknown"
``````````
</details>
https://github.com/llvm/llvm-project/pull/229486
More information about the llvm-branch-commits
mailing list