From 53e001f86385ad57781cf1993a64965a1041a7a3 Mon Sep 17 00:00:00 2001 From: LU-JOHN <111294400+LU-JOHN@users.noreply.github.com> Date: Fri, 9 Jun 2023 04:23:38 -0500 Subject: [PATCH] [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 --- lib/SPIRV/LLVMToSPIRVDbgTran.cpp | 3 +- lib/SPIRV/SPIRVToLLVMDbgTran.cpp | 37 ++++++++++--------- test/DebugInfo/DebugInfoProducer.ll | 2 + .../NonSemantic/DebugInfoProducer.ll | 4 ++ .../Shader200}/storagePath_dwo.ll | 4 +- 5 files changed, 29 insertions(+), 21 deletions(-) rename test/DebugInfo/{ => NonSemantic/Shader200}/storagePath_dwo.ll (87%) 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/storagePath_dwo.ll b/test/DebugInfo/NonSemantic/Shader200/storagePath_dwo.ll similarity index 87% rename from test/DebugInfo/storagePath_dwo.ll rename to test/DebugInfo/NonSemantic/Shader200/storagePath_dwo.ll index 1cbb0ab..273cee6 100644 --- a/test/DebugInfo/storagePath_dwo.ll +++ b/test/DebugInfo/NonSemantic/Shader200/storagePath_dwo.ll @@ -2,8 +2,8 @@ ; 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 %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 -- 2.30.2