Skip to content

Commit 02f5545

Browse files
MrSidimssys-ce-bb
authored andcommitted
Fix CU translation when GV goes before CU (#2010)
Translation of DebugInfo compilation units and entry points moved before translation of GVs. In other case we might end up in a situation when while quering for CUs we find none of them. Signed-off-by: Sidorov, Dmitry <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@47b1628
1 parent 0d72c5b commit 02f5545

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -3300,14 +3300,6 @@ bool SPIRVToLLVM::translate() {
33003300
if (!transAddressingModel())
33013301
return false;
33023302

3303-
for (unsigned I = 0, E = BM->getNumVariables(); I != E; ++I) {
3304-
auto BV = BM->getVariable(I);
3305-
if (BV->getStorageClass() != StorageClassFunction)
3306-
transValue(BV, nullptr, nullptr);
3307-
else
3308-
transGlobalCtorDtors(BV);
3309-
}
3310-
33113303
// Entry Points should be translated before all debug intrinsics.
33123304
for (SPIRVExtInst *EI : BM->getDebugInstVec()) {
33133305
if (EI->getExtOp() == SPIRVDebug::EntryPoint)
@@ -3321,6 +3313,14 @@ bool SPIRVToLLVM::translate() {
33213313
DbgTran->transDebugInst(EI);
33223314
}
33233315

3316+
for (unsigned I = 0, E = BM->getNumVariables(); I != E; ++I) {
3317+
auto BV = BM->getVariable(I);
3318+
if (BV->getStorageClass() != StorageClassFunction)
3319+
transValue(BV, nullptr, nullptr);
3320+
else
3321+
transGlobalCtorDtors(BV);
3322+
}
3323+
33243324
// Then translate all debug instructions.
33253325
for (SPIRVExtInst *EI : BM->getDebugInstVec()) {
33263326
DbgTran->transDebugInst(EI);
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o - | llvm-dis -o %t.ll
4+
; RUN: FileCheck < %t.ll %s
5+
6+
; CHECK: [[#GVExpr:]] = !DIGlobalVariableExpression(var: ![[#GV:]], expr: !DIExpression())
7+
; CHECK: ![[#GV]] = distinct !DIGlobalVariable(scope: ![[#CU:]], file: ![[#File:]], line: 1, type: ![[#]], isLocal: true, isDefinition: true)
8+
; CHECK: ![[#CU]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_17, file: ![[#File]], producer: "C++ compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: ![[#GVs:]])
9+
; CHECK: ![[#File]] = !DIFile(filename: "test.cpp", directory: "/dev/null")
10+
; CHECK: ![[#GVs]] = !{![[#GVExpr]]}
11+
12+
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"
13+
target triple = "spir64-unknown-unknown"
14+
15+
@.str = internal unnamed_addr addrspace(2) constant [3 x i8] c"bar", align 1, !dbg !0
16+
17+
define spir_func void @_Z3barBase() !dbg !12 {
18+
entry:
19+
%0 = getelementptr inbounds [13 x i8], ptr addrspace(2) @.str, i64 0, i64 0
20+
ret void
21+
}
22+
23+
define spir_kernel void @_Z3fooBase() !dbg !13 {
24+
entry:
25+
call spir_func void @_Z3barBase(), !dbg !15
26+
ret void
27+
}
28+
29+
!llvm.dbg.cu = !{!2}
30+
!llvm.module.flags = !{!10, !11}
31+
32+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
33+
!1 = distinct !DIGlobalVariable(scope: !2, file: !3, line: 1, type: !5, isLocal: true, isDefinition: true)
34+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "C++ compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4)
35+
!3 = !DIFile(filename: "test.cpp", directory: "/dev/null")
36+
!4 = !{!0}
37+
!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 104, elements: !8)
38+
!6 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !7)
39+
!7 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
40+
!8 = !{!9}
41+
!9 = !DISubrange(count: 3, lowerBound: 0)
42+
!10 = !{i32 7, !"Dwarf Version", i32 4}
43+
!11 = !{i32 2, !"Debug Info Version", i32 3}
44+
!12 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barBase", scope: null, file: !3, line: 1, type: null, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
45+
!13 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooBase", scope: null, file: !3, line: 3, type: null, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
46+
!14 = distinct !DILexicalBlock(scope: !13, file: !3, line: 3, column: 1)
47+
!15 = !DILocation(line: 3, column: 1, scope: !14)

0 commit comments

Comments
 (0)