[llvm] [SPIRV] Emit NonSemantic DebugTypedef (PR #211883)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 27 02:28:22 PDT 2026
================
@@ -712,6 +717,47 @@ std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugTypeVector(
ExtInstSetReg, {BTIt->second, CountReg}, MAI);
}
+std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugTypedef(
+ const DIDerivedType *TD, MCRegister VoidTypeReg, MCRegister I32TypeReg,
+ MCRegister ExtInstSetReg, SPIRV::ModuleAnalysisInfo &MAI) {
+ // The underlying (base) type must already be in DebugTypeRegs.
+ auto BaseRegOpt = lookupOptReg(DebugTypeRegs, TD->getBaseType());
+ if (!BaseRegOpt)
+ return std::nullopt;
+
+ MCRegister NameReg = getCachedOpStringReg(TD->getName());
+ MCRegister FileStrReg = getCachedScopePathOpStringReg(
+ TD->getFile(), /*UseEmptyPathIfNullScope=*/true);
+ MCRegister SrcReg = getOrEmitDebugSourceForFileStrReg(FileStrReg, VoidTypeReg,
+ ExtInstSetReg, MAI);
+ MCRegister LineReg =
+ emitOpConstantI32(static_cast<uint32_t>(TD->getLine()), I32TypeReg, MAI);
+ // DIDerivedType typedefs carry no column, so emit 0.
+ MCRegister ColReg = emitOpConstantI32(0, I32TypeReg, MAI);
+
+ // Parent: the enclosing type when the scope is an emitted DIType (a typedef
+ // nested in another type), otherwise the compile unit. Fall back to the
+ // compile unit rather than dropping the typedef when the scope type is not
+ // emitted.
+ MCRegister ParentReg;
+ if (const auto *Ty = dyn_cast_or_null<DIType>(TD->getScope()))
----------------
jmmartinez wrote:
It can also be a `DISubprogram`, for example in:
```cpp
int foo() {
using A = int;
A a = 0;
return a;
}
```
we get:
```
!9 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !10, file: !10, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
...
!15 = !DIDerivedType(tag: DW_TAG_typedef, name: "A", scope: !9, file: !10, line: 2, baseType: !13)
```
---
Or is this a restriction coming from the SPIRV spec ? Does it make sense to simply go through `lookupOptReg` for whatever the scope is, and then fallback to the `CompileUnit` ?
https://github.com/llvm/llvm-project/pull/211883
More information about the llvm-commits
mailing list