[PATCH 59/79] Only generate BuildIdentifier if non-semantic debug is enabled (#2040)
authorLU-JOHN <111294400+LU-JOHN@users.noreply.github.com>
Fri, 9 Jun 2023 09:23:38 +0000 (04:23 -0500)
committerAndreas Beckmann <anbe@debian.org>
Thu, 14 Mar 2024 19:01:08 +0000 (20:01 +0100)
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
lib/SPIRV/SPIRVToLLVMDbgTran.cpp
test/DebugInfo/DebugInfoProducer.ll
test/DebugInfo/NonSemantic/DebugInfoProducer.ll
test/DebugInfo/NonSemantic/Shader200/storagePath_dwo.ll [new file with mode: 0644]
test/DebugInfo/storagePath_dwo.ll [deleted file]

index 821eafdba1688eb39355dbc4a8411f7a89ca1546..757fd8ed831927afcb5463735b67db7b517ede01 100644 (file)
@@ -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<llvm::dwarf::SourceLanguage>(CU->getSourceLanguage());
index 42026b6263d8239cf83db809ddacc6523435c67a..42d6924f8d768bbd4894381e4c9cf103bf8ae4b4 100644 (file)
@@ -211,30 +211,31 @@ SPIRVToLLVMDbgTran::transCompilationUnit(const SPIRVExtInst *DebugInst,
 
   BuilderMap[DebugInst->getId()] = std::make_unique<DIBuilder>(*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);
 }
index fa5536fa33870de3e806abb0e677fc1d8dc12461..6fc05370b593c4a5879a2f4a5d5cda3070a5c620 100644 (file)
@@ -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: "<stdin>", directory: "oneAPI")
index dfe1c8ced3ee0269de4bf6aba9685e7c6c6e5f84..a48e651e4134c82cbab61a7ff86e12ed59716d00 100644 (file)
@@ -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 (file)
index 0000000..273cee6
--- /dev/null
@@ -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: "<stdin>", 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 (file)
index 1cbb0ab..0000000
+++ /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: "<stdin>", 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)