Skip to content

Commit 5053679

Browse files
vmaksimoagainull
authored andcommitted
Translate inline namespace debug info (intel#1978)
In NonSemantic.Shader.DebugInfo.200 DebugLexicalBlock has Inline namespace parameter, which specifies if C/C++ namespace is inline or not. It allows us to save `exportSymbols` field of `DINamespace` metadata. Spec: KhronosGroup/SPIRV-Registry#186 Original commit: KhronosGroup/SPIRV-LLVM-Translator@9729086
1 parent 40dcbc7 commit 5053679

File tree

4 files changed

+91
-8
lines changed

4 files changed

+91
-8
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,12 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgScope(const DIScope *S) {
12901290
Ops[LineIdx] = 0; // This version of DINamespace has no line number
12911291
Ops[ColumnIdx] = 0; // This version of DINamespace has no column number
12921292
Ops.push_back(BM->getString(NS->getName().str())->getId());
1293+
if (BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) {
1294+
SPIRVValue *ExpConst = BM->addConstant(
1295+
SPIRVWriter->transType(Type::getInt1Ty(M->getContext())),
1296+
NS->getExportSymbols() /*Is inlined namespace*/);
1297+
Ops.push_back(ExpConst->getId());
1298+
}
12931299
}
12941300
if (isNonSemanticDebugInfo())
12951301
transformToConstant(Ops, {LineIdx, ColumnIdx});

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,17 @@ DINode *SPIRVToLLVMDbgTran::transLexicalBlock(const SPIRVExtInst *DebugInst) {
712712
DIFile *File = getFile(Ops[SourceIdx]);
713713
SPIRVWord LineNo =
714714
getConstantValueOrLiteral(Ops, LineIdx, DebugInst->getExtSetKind());
715-
if (Ops.size() > NameIdx) {
715+
if (Ops.size() > MinOperandCount) {
716716
StringRef Name = getString(Ops[NameIdx]);
717+
bool InlinedNamespace = false;
718+
if (DebugInst->getExtSetKind() ==
719+
SPIRVEIS_NonSemantic_Shader_DebugInfo_200) {
720+
SPIRVValue *V = BM->get<SPIRVValue>(Ops[InlineNamespaceIdx]);
721+
Value *Var = SPIRVReader->transValue(V, nullptr, nullptr);
722+
InlinedNamespace = cast<ConstantInt>(Var)->isOne();
723+
}
717724
return getDIBuilder(DebugInst).createNameSpace(ParentScope, Name,
718-
false /*inlined namespace*/);
725+
InlinedNamespace);
719726
}
720727
unsigned Column = Ops[ColumnIdx];
721728
return getDIBuilder(DebugInst).createLexicalBlock(ParentScope, File, LineNo,

llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,13 @@ enum {
581581

582582
namespace LexicalBlock {
583583
enum {
584-
SourceIdx = 0,
585-
LineIdx = 1,
586-
ColumnIdx = 2,
587-
ParentIdx = 3,
588-
NameIdx = 4,
589-
MinOperandCount = 4
584+
SourceIdx = 0,
585+
LineIdx = 1,
586+
ColumnIdx = 2,
587+
ParentIdx = 3,
588+
MinOperandCount = 4,
589+
NameIdx = 4,
590+
InlineNamespaceIdx = 5,
590591
};
591592
}
592593

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv -spirv-text %t.bc -o %t.spt --spirv-debug-info-version=nonsemantic-shader-200
3+
; RUN: FileCheck < %t.spt %s -check-prefix=CHECK-SPIRV
4+
; RUN: llvm-spirv -to-binary %t.spt -o %t.spv
5+
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
8+
; RUN: FileCheck < %t.rev.ll %s -check-prefix=CHECK-LLVM
9+
10+
; Source:
11+
; -- inline-namespace.cxx -----------------------------------------------------
12+
; 1 inline namespace Outer {
13+
; 2 namespace Inner {
14+
; 3 int global;
15+
; 4 }
16+
; 5 }
17+
; 6
18+
; 7 void foo() {
19+
; 8 Inner::global++;
20+
; 9 }
21+
; -- inline-namespace.cxx -----------------------------------------------------
22+
23+
; CHECK-SPIRV: String [[#StrOuter:]] "Outer"
24+
; CHECK-SPIRV: String [[#StrInner:]] "Inner"
25+
; CHECK-SPIRV: TypeBool [[#TypeBool:]]
26+
; CHECK-SPIRV: ConstantTrue [[#TypeBool]] [[#ConstTrue:]]
27+
; CHECK-SPIRV: ConstantFalse [[#TypeBool]] [[#ConstFalse:]]
28+
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugLexicalBlock [[#]] [[#]] [[#]] [[#]] [[#StrOuter]] [[#ConstTrue]]
29+
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugLexicalBlock [[#]] [[#]] [[#]] [[#]] [[#StrInner]] [[#ConstFalse]]
30+
31+
; CHECK-LLVM: !DINamespace(name: "Inner", scope: ![[#OuterSpace:]])
32+
; CHECK-LLVM: ![[#OuterSpace]] = !DINamespace(name: "Outer", scope: null, exportSymbols: true)
33+
34+
; ModuleID = 'inline-namespace.cxx'
35+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
36+
target triple = "spir64-unknown-unknown"
37+
38+
@_ZN5Outer5Inner6globalE = dso_local global i32 0, align 4, !dbg !0
39+
40+
; Function Attrs: noinline nounwind optnone uwtable mustprogress
41+
define dso_local void @_Z3foov() #0 !dbg !11 {
42+
entry:
43+
%0 = load i32, i32* @_ZN5Outer5Inner6globalE, align 4, !dbg !14
44+
%inc = add nsw i32 %0, 1, !dbg !14
45+
store i32 %inc, i32* @_ZN5Outer5Inner6globalE, align 4, !dbg !14
46+
ret void, !dbg !15
47+
}
48+
49+
attributes #0 = { noinline nounwind optnone uwtable mustprogress }
50+
51+
!llvm.dbg.cu = !{!6}
52+
!llvm.module.flags = !{!9, !10}
53+
54+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
55+
!1 = distinct !DIGlobalVariable(name: "global", linkageName: "_ZN5Outer5Inner6globalE", scope: !2, file: !4, line: 3, type: !5, isLocal: false, isDefinition: true)
56+
!2 = !DINamespace(name: "Inner", scope: !3)
57+
!3 = !DINamespace(name: "Outer", scope: null, exportSymbols: true)
58+
!4 = !DIFile(filename: "inlined-namespace.cxx", directory: "/path/to")
59+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
60+
!6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !4, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, globals: !8, splitDebugInlining: false, nameTableKind: None)
61+
!7 = !{}
62+
!8 = !{!0}
63+
!9 = !{i32 7, !"Dwarf Version", i32 4}
64+
!10 = !{i32 2, !"Debug Info Version", i32 3}
65+
!11 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !4, file: !4, line: 7, type: !12, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !7)
66+
!12 = !DISubroutineType(types: !13)
67+
!13 = !{null}
68+
!14 = !DILocation(line: 8, column: 16, scope: !11)
69+
!15 = !DILocation(line: 9, column: 1, scope: !11)

0 commit comments

Comments
 (0)