Skip to content

Commit 3a95a40

Browse files
vmaksimojsji
authored andcommitted
Cache CU value translated outside of usual flow (#2072)
Compilation unit can be translated earlier, e.g. in `transEntryPoint()`. We should save the translated LLVM value to be used further. Original commit: KhronosGroup/SPIRV-LLVM-Translator@803e528
1 parent 2989ed7 commit 3a95a40

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,8 @@ MDNode *SPIRVToLLVMDbgTran::transEntryPoint(const SPIRVExtInst *DebugInst) {
10521052
std::string Producer = getString(Ops[CompilerSignatureIdx]);
10531053
std::string CLArgs = getString(Ops[CommandLineArgsIdx]);
10541054

1055-
[[maybe_unused]] DICompileUnit *C =
1056-
transCompilationUnit(CU, Producer, CLArgs);
1055+
DICompileUnit *C = transCompilationUnit(CU, Producer, CLArgs); // NOLINT
1056+
DebugInstCache[CU] = C;
10571057

10581058
return transFunction(EP, true /*IsMainSubprogram*/);
10591059
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; This test covers assertion "Typedef should have a parent scope"
2+
3+
; RUN: llvm-as %s -o %t.bc
4+
; RUN: llvm-spirv %t.bc -spirv-text --spirv-debug-info-version=nonsemantic-shader-200 -o %t.spt
5+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
6+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-debug-info-version=nonsemantic-shader-200
7+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc
8+
; RUN: llvm-dis %t.rev.bc
9+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
10+
11+
; CHECK-SPIRV: String [[#TestStr:]] "test.cpp"
12+
; CHECK-SPIRV: String [[#StdStr:]] "stddef.h"
13+
; CHECK-SPIRV: [[#SourceCpp:]] [[#]] DebugSource [[#TestStr]]
14+
; CHECK-SPIRV: [[#Scope:]] [[#]] DebugCompilationUnit [[#]] [[#]] [[#SourceCpp]]
15+
; CHECK-SPIRV: [[#SourceHeader:]] [[#]] DebugSource [[#StdStr]]
16+
; CHECK-SPIRV: DebugTypedef [[#]] [[#]] [[#SourceHeader]] [[#]] [[#]] [[#Scope]]
17+
; CHECK-SPIRV: DebugEntryPoint [[#]] [[#Scope]]
18+
19+
; CHECK-LLVM: DW_TAG_typedef
20+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
21+
target triple = "spir64"
22+
23+
$_ZTSZ4mainEUlvE_ = comdat any
24+
25+
; Function Attrs: convergent mustprogress norecurse nounwind
26+
define weak_odr dso_local spir_kernel void @_ZTSZ4mainEUlvE_() #0 comdat !dbg !14 {
27+
entry:
28+
ret void
29+
}
30+
31+
attributes #0 = { convergent mustprogress norecurse nounwind }
32+
33+
!llvm.dbg.cu = !{!0}
34+
!llvm.module.flags = !{!10, !11, !12, !13}
35+
36+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang based compiler", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, imports: !2, splitDebugInlining: false, nameTableKind: None)
37+
!1 = !DIFile(filename: "test.cpp", directory: "")
38+
!2 = !{}
39+
!3 = !{!4}
40+
!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression(DW_OP_constu, 175, DW_OP_stack_value))
41+
!5 = distinct !DIGlobalVariable(name: "N", scope: !0, file: !1, line: 7, type: !6, isLocal: true, isDefinition: true)
42+
!6 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !7)
43+
!7 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !8, line: 62, baseType: !9)
44+
!8 = !DIFile(filename: "stddef.h", directory: "")
45+
!9 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
46+
!10 = !{i32 7, !"Dwarf Version", i32 4}
47+
!11 = !{i32 2, !"Debug Info Version", i32 3}
48+
!12 = !{i32 1, !"wchar_size", i32 4}
49+
!13 = !{i32 7, !"frame-pointer", i32 2}
50+
!14 = distinct !DISubprogram(name: "_ZTSZ4mainEUlvE_", scope: !1, file: !1, line: 24, type: !15, flags: DIFlagArtificial | DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
51+
!15 = !DISubroutineType(cc: DW_CC_nocall, types: !16)
52+
!16 = !{null}

0 commit comments

Comments
 (0)