Skip to content

Commit 1646ff6

Browse files
authored
[DebugInfo] Add module producer info for NonSemantic.Shader.DebugInfo.200 (#1968)
Keep existing W/A for other debug info specs, except NonSemantic.Shader.DebugInfo.100
1 parent a4cdee9 commit 1646ff6

File tree

4 files changed

+106
-5
lines changed

4 files changed

+106
-5
lines changed

lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ SPIRVId LLVMToSPIRVDbgTran::getDebugInfoNoneId() {
540540

541541
SPIRVEntry *LLVMToSPIRVDbgTran::transDbgCompileUnit(const DICompileUnit *CU) {
542542
using namespace SPIRVDebug::Operand::CompilationUnit;
543-
SPIRVWordVec Ops(OperandCount);
543+
SPIRVWordVec Ops(MinOperandCount);
544544
Ops[SPIRVDebugInfoVersionIdx] = SPIRVDebug::DebugInfoVersion;
545545
Ops[DWARFVersionIdx] = M->getDwarfVersion();
546546
Ops[SourceIdx] = getSource(CU)->getId();
@@ -553,7 +553,17 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgCompileUnit(const DICompileUnit *CU) {
553553
if (isNonSemanticDebugInfo())
554554
transformToConstant(
555555
Ops, {SPIRVDebugInfoVersionIdx, DWARFVersionIdx, LanguageIdx});
556-
BM->addModuleProcessed(SPIRVDebug::ProducerPrefix + CU->getProducer().str());
556+
557+
if (isNonSemanticDebugInfo()) {
558+
if (BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) {
559+
Ops.push_back(BM->getString(CU->getProducer().str())->getId());
560+
}
561+
} else {
562+
// TODO: Remove this workaround once we switch to NonSemantic.Shader.* debug
563+
// info by default
564+
BM->addModuleProcessed(SPIRVDebug::ProducerPrefix +
565+
CU->getProducer().str());
566+
}
557567
// Cache CU in a member.
558568
SPIRVCUMap[CU] = static_cast<SPIRVExtInst *>(
559569
BM->addDebugInfo(SPIRVDebug::CompilationUnit, getVoidTy(), Ops));

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ SPIRVToLLVMDbgTran::transCompilationUnit(const SPIRVExtInst *DebugInst) {
156156
const SPIRVWordVec &Ops = DebugInst->getArguments();
157157

158158
using namespace SPIRVDebug::Operand::CompilationUnit;
159-
assert(Ops.size() == OperandCount && "Invalid number of operands");
159+
assert(Ops.size() >= MinOperandCount && "Invalid number of operands");
160160
// We must preserve only one Dwarf version module level metadata
161161
// UpgradeDebugInfo from llvm/lib/IR/AutoUpgrade.cpp has already done all
162162
// work for us during linking stage leaving a single Dwarf version in the
@@ -172,8 +172,21 @@ SPIRVToLLVMDbgTran::transCompilationUnit(const SPIRVExtInst *DebugInst) {
172172
SourceLang = convertSPIRVSourceLangToDWARFNonSemanticDbgInfo(SourceLang);
173173
else
174174
SourceLang = convertSPIRVSourceLangToDWARF(SourceLang);
175-
auto Producer = findModuleProducer();
175+
176176
BuilderMap[DebugInst->getId()] = std::make_unique<DIBuilder>(*M);
177+
178+
if (DebugInst->getExtSetKind() == SPIRVEIS_NonSemantic_Shader_DebugInfo_100) {
179+
return BuilderMap[DebugInst->getId()]->createCompileUnit(
180+
SourceLang, getFile(Ops[SourceIdx]), "spirv", false, "", 0);
181+
}
182+
if (DebugInst->getExtSetKind() == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) {
183+
StringRef Producer = getString(Ops[ProducerIdx]);
184+
return BuilderMap[DebugInst->getId()]->createCompileUnit(
185+
SourceLang, getFile(Ops[SourceIdx]), Producer, false, "", 0);
186+
}
187+
// TODO: Remove this workaround once we switch to NonSemantic.Shader.* debug
188+
// info by default
189+
auto Producer = findModuleProducer();
177190
return BuilderMap[DebugInst->getId()]->createCompileUnit(
178191
SourceLang, getFile(Ops[SourceIdx]), Producer, false, "", 0);
179192
}

lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ enum {
290290
DWARFVersionIdx = 1,
291291
SourceIdx = 2,
292292
LanguageIdx = 3,
293-
OperandCount = 4
293+
// For NonSemantic.Shader.DebugInfo.200
294+
ProducerIdx = 4,
295+
MinOperandCount = 4
294296
};
295297
}
296298

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
; Test checks debug info of producer is preserved from LLVM IR to spirv
2+
; and spirv to LLVM IR translation.
3+
4+
; Original .cpp source:
5+
;
6+
; int main() {
7+
; return 0;
8+
; }
9+
10+
; Command line:
11+
; ./clang -cc1 -debug-info-kind=standalone -v s.cpp -S -emit-llvm -triple spir
12+
13+
; RUN: llvm-as %s -o %t.bc
14+
; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -spirv-text -o - | FileCheck %s --check-prefix CHECK-SPIRV-200
15+
; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -o %t.spv
16+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc
17+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
18+
; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM-200
19+
20+
; Check that we don't produce "producer" info for NonSemantic.Shader.DebugInfo.100 as it's not specification conformant
21+
; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-100 -spirv-text -o %t.spt
22+
; RUN: FileCheck %s --input-file %t.spt --check-prefix CHECK-SPIRV-100
23+
; RUN: llvm-spirv -spirv-text -r -emit-opaque-pointers %t.spt -o %t.rev.bc
24+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix CHECK-LLVM-100
25+
26+
; ModuleID = 's.bc'
27+
source_filename = "s.cpp"
28+
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
29+
target triple = "spir"
30+
31+
; Function Attrs: noinline norecurse nounwind optnone
32+
define i32 @main() #0 !dbg !8 {
33+
entry:
34+
%retval = alloca i32, align 4
35+
store i32 0, i32* %retval, align 4
36+
ret i32 0, !dbg !13
37+
}
38+
39+
attributes #0 = { noinline norecurse nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
40+
41+
!llvm.dbg.cu = !{!0}
42+
!llvm.module.flags = !{!3, !4, !5, !6}
43+
!opencl.used.extensions = !{!2}
44+
!opencl.used.optional.core.features = !{!2}
45+
!opencl.compiler.options = !{!2}
46+
!llvm.ident = !{!7}
47+
48+
; CHECK-LLVM-200: !DICompileUnit
49+
; CHECK-LLVM-200-SAME: producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)"
50+
; CHECK-LLVM-200-NOT: producer: "spirv"
51+
52+
; CHECK-LLVM-100: !DICompileUnit
53+
; CHECK-LLVM-100-SAME: producer: "spirv"
54+
; CHECK-LLVM-100-NOT: producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)"
55+
56+
; CHECK-SPIRV-200: String [[#ProducerId:]] "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)"
57+
; CHECK-SPIRV-200: DebugCompilationUnit [[#]] [[#]] [[#]] [[#]] [[#ProducerId]]
58+
59+
; CHECK-SPIRV-100-NOT: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)"
60+
; CHECK-SPIRV-100-NOT: DebugCompilationUnit [[#]] [[#]] [[#]] [[#]] [[#]] {{$}}
61+
62+
63+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
64+
!1 = !DIFile(filename: "<stdin>", directory: "oneAPI")
65+
!2 = !{}
66+
!3 = !{i32 2, !"Debug Info Version", i32 3}
67+
!4 = !{i32 1, !"wchar_size", i32 4}
68+
!5 = !{i32 1, !"ThinLTO", i32 0}
69+
!6 = !{i32 1, !"EnableSplitLTOUnit", i32 1}
70+
!7 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)"}
71+
!8 = distinct !DISubprogram(name: "main", scope: !9, file: !9, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
72+
!9 = !DIFile(filename: "s.cpp", directory: "C:\\")
73+
!10 = !DISubroutineType(types: !11)
74+
!11 = !{!12}
75+
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
76+
!13 = !DILocation(line: 2, column: 2, scope: !8)

0 commit comments

Comments
 (0)