From: LU-JOHN <111294400+LU-JOHN@users.noreply.github.com> Date: Fri, 9 Jun 2023 09:23:38 +0000 (-0500) Subject: [PATCH 59/79] Only generate BuildIdentifier if non-semantic debug is enabled (#2040) X-Git-Tag: archive/raspbian/15.0.1-1+rpi1^2^2~26 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=53e001f86385ad57781cf1993a64965a1041a7a3;p=spirv-llvm-translator-15.git [PATCH 59/79] Only generate BuildIdentifier if non-semantic debug is enabled (#2040) Only generate BuildIdentifier and StoragePath if non-semantic debug is enabled Gbp-Pq: Name 0059-Only-generate-BuildIdentifier-if-non-semantic-debug-.patch --- diff --git a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp index 821eafd..757fd8e 100644 --- a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp +++ b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp @@ -556,7 +556,8 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgCompileUnit(const DICompileUnit *CU) { Ops[DWARFVersionIdx] = M->getDwarfVersion(); Ops[SourceIdx] = getSource(CU)->getId(); - generateBuildIdentifierAndStoragePath(CU); + if (isNonSemanticDebugInfo()) + generateBuildIdentifierAndStoragePath(CU); auto DwarfLang = static_cast(CU->getSourceLanguage()); diff --git a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp index 42026b6..42d6924 100644 --- a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp +++ b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp @@ -211,30 +211,31 @@ SPIRVToLLVMDbgTran::transCompilationUnit(const SPIRVExtInst *DebugInst, BuilderMap[DebugInst->getId()] = std::make_unique(*M); - if (DebugInst->getExtSetKind() == SPIRVEIS_NonSemantic_Shader_DebugInfo_100) { - return BuilderMap[DebugInst->getId()]->createCompileUnit( - SourceLang, getFile(Ops[SourceIdx]), CompilerVersion, false, Flags, 0); - } - if (DebugInst->getExtSetKind() == SPIRVEIS_NonSemantic_Shader_DebugInfo_200) { - StringRef Producer = getString(Ops[ProducerIdx]); - return BuilderMap[DebugInst->getId()]->createCompileUnit( - SourceLang, getFile(Ops[SourceIdx]), Producer, false, Flags, 0); - } - // TODO: Remove this workaround once we switch to NonSemantic.Shader.* debug - // info by default - auto Producer = findModuleProducer(); assert(BuilderMap.size() != 0 && "No debug compile units"); - if (BuilderMap.size()==1) + if (isNonSemanticDebugInfo(DebugInst->getExtSetKind())) { // Only initialize once - setBuildIdentifierAndStoragePath(); + if (BuilderMap.size() == 1) + setBuildIdentifierAndStoragePath(); + + // This assertion is a guard/reminder to update the Producer argument to + // createCompileUnit() if a new DebugInfo type is ever created + assert(DebugInst->getExtSetKind() == + SPIRVEIS_NonSemantic_Shader_DebugInfo_100 || + DebugInst->getExtSetKind() == + SPIRVEIS_NonSemantic_Shader_DebugInfo_200); - if (!StoragePath.empty()) { return BuilderMap[DebugInst->getId()]->createCompileUnit( - SourceLang, getFile(Ops[SourceIdx]), Producer, false, "", 0, - StoragePath, DICompileUnit::DebugEmissionKind::FullDebug, - BuildIdentifier); + SourceLang, getFile(Ops[SourceIdx]), + DebugInst->getExtSetKind() == SPIRVEIS_NonSemantic_Shader_DebugInfo_100 + ? CompilerVersion + : getString(Ops[ProducerIdx]), + false, Flags, 0, StoragePath, + DICompileUnit::DebugEmissionKind::FullDebug, BuildIdentifier); } + // TODO: Remove this workaround once we switch to NonSemantic.Shader.* debug + // info by default + auto Producer = findModuleProducer(); return BuilderMap[DebugInst->getId()]->createCompileUnit( SourceLang, getFile(Ops[SourceIdx]), Producer, false, Flags, 0); } diff --git a/test/DebugInfo/DebugInfoProducer.ll b/test/DebugInfo/DebugInfoProducer.ll index fa5536f..6fc0537 100644 --- a/test/DebugInfo/DebugInfoProducer.ll +++ b/test/DebugInfo/DebugInfoProducer.ll @@ -43,6 +43,8 @@ attributes #0 = { noinline norecurse nounwind optnone "correctly-rounded-divide- ; CHECK-LLVM-SAME: producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)" ; CHECK-LLVM-NOT: producer: "spirv" ; CHECK-SPIRV: ModuleProcessed "Debug info producer: clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)" +; CHECK-SPIRV-NOT: DebugBuildIdentifier +; CHECK-SPIRV-NOT: DebugStoragePath !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) !1 = !DIFile(filename: "", directory: "oneAPI") diff --git a/test/DebugInfo/NonSemantic/DebugInfoProducer.ll b/test/DebugInfo/NonSemantic/DebugInfoProducer.ll index dfe1c8c..a48e651 100644 --- a/test/DebugInfo/NonSemantic/DebugInfoProducer.ll +++ b/test/DebugInfo/NonSemantic/DebugInfoProducer.ll @@ -56,10 +56,14 @@ attributes #0 = { noinline norecurse nounwind optnone "correctly-rounded-divide- ; CHECK-LLVM-100-SAME: flags: "-O2" ; CHECK-SPIRV-200: String [[#ProducerId:]] "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)" +; CHECK-SPIRV-200: DebugBuildIdentifier [[#]] [[#]] +; CHECK-SPIRV-200: DebugStoragePath [[#]] ; CHECK-SPIRV-200: DebugCompilationUnit [[#]] [[#]] [[#]] [[#]] [[#ProducerId]] ; CHECK-SPIRV-200: DebugEntryPoint [[#]] [[#]] [[#ProducerId]] [[#]] {{$}} ; CHECK-SPIRV-100: String [[#ProducerId:]] "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 16a50c9e642fd085e5ceb68c403b71b5b2e0607c)" +; CHECK-SPIRV-100: DebugBuildIdentifier [[#]] [[#]] +; CHECK-SPIRV-100: DebugStoragePath [[#]] ; CHECK-SPIRV-100-NOT: DebugCompilationUnit [[#]] [[#]] [[#]] [[#]] [[#ProducerId]] {{$}} ; CHECK-SPIRV-100: DebugEntryPoint [[#]] [[#]] [[#ProducerId]] [[#]] {{$}} diff --git a/test/DebugInfo/NonSemantic/Shader200/storagePath_dwo.ll b/test/DebugInfo/NonSemantic/Shader200/storagePath_dwo.ll new file mode 100644 index 0000000..273cee6 --- /dev/null +++ b/test/DebugInfo/NonSemantic/Shader200/storagePath_dwo.ll @@ -0,0 +1,33 @@ +; Test checks that dwoId and splitDebugFilename is preserved from LLVM IR to spirv +; and spirv to LLVM IR translation. + +; RUN: llvm-as %s -o %t.bc +; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -spirv-text -o - | FileCheck %s --check-prefix CHECK-SPIRV +; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-200 -o %t.spv +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc +; RUN: llvm-dis %t.rev.bc -o %t.rev.ll +; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM + +; CHECK-SPIRV: String [[#stringA_id:]] "11111" +; CHECK-SPIRV: String [[#stringA_sf:]] "debugA_info.dwo" +; CHECK-SPIRV: [[#buildID_A:]] [[#]] DebugBuildIdentifier [[#stringA_id]] +; CHECK-SPIRV: [[#storageID_A:]] [[#]] DebugStoragePath [[#stringA_sf]] + +; CHECK-LLVM: !DICompileUnit +; CHECK-LLVM-SAME: splitDebugFilename: "debugA_info.dwo" +; CHECK-LLVM-SAME: dwoId: 11111 +; CHECK-LLVM: !DICompileUnit +; CHECK-LLVM-SAME: splitDebugFilename: "debugA_info.dwo" +; CHECK-LLVM-SAME: dwoId: 11111 + +!llvm.dbg.cu = !{!7, !0} +!llvm.module.flags = !{!3, !4} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Clang", isOptimized: false, runtimeVersion: 2, splitDebugFilename: "debugA_info.dwo", emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, dwoId: 11111) +!1 = !DIFile(filename: "", directory: "/") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!6} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Clang", isOptimized: false, runtimeVersion: 2, splitDebugFilename: "debugA_info.dwo", dwoId: 11111, emissionKind: FullDebug, retainedTypes: !5) diff --git a/test/DebugInfo/storagePath_dwo.ll b/test/DebugInfo/storagePath_dwo.ll deleted file mode 100644 index 1cbb0ab..0000000 --- a/test/DebugInfo/storagePath_dwo.ll +++ /dev/null @@ -1,33 +0,0 @@ -; Test checks that dwoId and splitDebugFilename is preserved from LLVM IR to spirv -; and spirv to LLVM IR translation. - -; RUN: llvm-as %s -o %t.bc -; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix CHECK-SPIRV -; RUN: llvm-spirv %t.bc -o %t.spv -; RUN: llvm-spirv -r %t.spv -o %t.rev.bc -; RUN: llvm-dis %t.rev.bc -o %t.rev.ll -; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM - -; CHECK-SPIRV: String [[#stringA_id:]] "11111" -; CHECK-SPIRV: String [[#stringA_sf:]] "debugA_info.dwo" -; CHECK-SPIRV: [[#buildID_A:]] [[#]] DebugBuildIdentifier [[#stringA_id]] -; CHECK-SPIRV: [[#storageID_A:]] [[#]] DebugStoragePath [[#stringA_sf]] - -; CHECK-LLVM: !DICompileUnit -; CHECK-LLVM-SAME: splitDebugFilename: "debugA_info.dwo" -; CHECK-LLVM-SAME: dwoId: 11111 -; CHECK-LLVM: !DICompileUnit -; CHECK-LLVM-SAME: splitDebugFilename: "debugA_info.dwo" -; CHECK-LLVM-SAME: dwoId: 11111 - -!llvm.dbg.cu = !{!7, !0} -!llvm.module.flags = !{!3, !4} - -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Clang", isOptimized: false, runtimeVersion: 2, splitDebugFilename: "debugA_info.dwo", emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, dwoId: 11111) -!1 = !DIFile(filename: "", directory: "/") -!2 = !{} -!3 = !{i32 2, !"Dwarf Version", i32 4} -!4 = !{i32 2, !"Debug Info Version", i32 3} -!5 = !{!6} -!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) -!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Clang", isOptimized: false, runtimeVersion: 2, splitDebugFilename: "debugA_info.dwo", dwoId: 11111, emissionKind: FullDebug, retainedTypes: !5)