[PATCH 45/79] [DebugInfo] Fix missing 2nd operand for DebugImportedEntity (#1983)
authorDmitry Sidorov <dmitry.sidorov@intel.com>
Tue, 2 May 2023 12:39:37 +0000 (14:39 +0200)
committerAndreas Beckmann <anbe@debian.org>
Thu, 8 Feb 2024 21:48:18 +0000 (22:48 +0100)
It will be still missing for OpenCL debug info, but for
NonSemantic the correct behavior is preserved.

Signed-off-by: Sidorov, Dmitry dmitry.sidorov@intel.com
Gbp-Pq: Name 0045-DebugInfo-Fix-missing-2nd-operand-for-DebugImportedE.patch

lib/SPIRV/LLVMToSPIRVDbgTran.cpp
lib/SPIRV/SPIRVToLLVMDbgTran.cpp
lib/SPIRV/libSPIRV/SPIRV.debug.h
test/DebugInfo/NonSemantic/Shader200/DIModule.ll
test/DebugInfo/omit-empty.ll

index 6e5b81dcf1e805afa97e93cddca23e533c63f7ce..946aa71df51c2b3648573429e205a8ed7b80162f 100644 (file)
@@ -1422,17 +1422,23 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgExpression(const DIExpression *Expr) {
 SPIRVEntry *
 LLVMToSPIRVDbgTran::transDbgImportedEntry(const DIImportedEntity *IE) {
   using namespace SPIRVDebug::Operand::ImportedEntity;
-  SPIRVWordVec Ops(OperandCount);
   auto Tag = static_cast<dwarf::Tag>(IE->getTag());
+  // FIXME: 'OpenCL/bugged' version is kept because it's hard to remove it
+  // It's W/A for missing 2nd index in OpenCL's implementation
+  const SPIRVWord OffsetIdx =
+      isNonSemanticDebugInfo() ? OperandCount - NonSemantic::OperandCount : 0;
+  SPIRVWordVec Ops(OperandCount - OffsetIdx);
   Ops[NameIdx] = BM->getString(IE->getName().str())->getId();
   Ops[TagIdx] = SPIRV::DbgImportedEntityMap::map(Tag);
-  Ops[SourceIdx] = getSource(IE->getFile())->getId();
-  Ops[EntityIdx] = transDbgEntry(IE->getEntity())->getId();
-  Ops[LineIdx] = IE->getLine();
-  Ops[ColumnIdx] = 0; // This version of DIImportedEntity has no column number
-  Ops[ParentIdx] = getScope(IE->getScope())->getId();
+  Ops[SourceIdx - OffsetIdx] = getSource(IE->getFile())->getId();
+  Ops[EntityIdx - OffsetIdx] = transDbgEntry(IE->getEntity())->getId();
+  Ops[LineIdx - OffsetIdx] = IE->getLine();
+  // This version of DIImportedEntity has no column number
+  Ops[ColumnIdx - OffsetIdx] = 0;
+  Ops[ParentIdx - OffsetIdx] = getScope(IE->getScope())->getId();
   if (isNonSemanticDebugInfo())
-    transformToConstant(Ops, {TagIdx, LineIdx, ColumnIdx});
+    transformToConstant(Ops,
+                        {TagIdx, LineIdx - OffsetIdx, ColumnIdx - OffsetIdx});
   return BM->addDebugInfo(SPIRVDebug::ImportedEntity, getVoidTy(), Ops);
 }
 
index 46e0daf1565d6a43100e3fca407c0899276e1455..32790095fd389e40da16f12eb240e7c1f84c8e32 100644 (file)
@@ -1149,12 +1149,20 @@ MDNode *SPIRVToLLVMDbgTran::transTypeTemplate(const SPIRVExtInst *DebugInst) {
 DINode *SPIRVToLLVMDbgTran::transImportedEntry(const SPIRVExtInst *DebugInst) {
   using namespace SPIRVDebug::Operand::ImportedEntity;
   const SPIRVWordVec &Ops = DebugInst->getArguments();
-  assert(Ops.size() >= OperandCount && "Invalid number of operands");
-  DIScope *Scope = getScope(BM->getEntry(Ops[ParentIdx]));
-  SPIRVWord Line =
-      getConstantValueOrLiteral(Ops, LineIdx, DebugInst->getExtSetKind());
-  DIFile *File = getFile(Ops[SourceIdx]);
-  auto *Entity = transDebugInst<DINode>(BM->get<SPIRVExtInst>(Ops[EntityIdx]));
+  // FIXME: 'OpenCL/bugged' version is kept because it's hard to remove it
+  // It's W/A for missing 2nd index in OpenCL's implementation
+  const SPIRVWord OffsetIdx = isNonSemanticDebugInfo(DebugInst->getExtSetKind())
+                                  ? OperandCount - NonSemantic::OperandCount
+                                  : 0;
+
+  assert(Ops.size() == (OperandCount - OffsetIdx) &&
+         "Invalid number of operands");
+  DIScope *Scope = getScope(BM->getEntry(Ops[ParentIdx - OffsetIdx]));
+  SPIRVWord Line = getConstantValueOrLiteral(Ops, LineIdx - OffsetIdx,
+                                             DebugInst->getExtSetKind());
+  DIFile *File = getFile(Ops[SourceIdx - OffsetIdx]);
+  auto *Entity =
+      transDebugInst<DINode>(BM->get<SPIRVExtInst>(Ops[EntityIdx - OffsetIdx]));
   SPIRVWord Tag =
       getConstantValueOrLiteral(Ops, TagIdx, DebugInst->getExtSetKind());
   if (Tag == SPIRVDebug::ImportedModule) {
@@ -1180,11 +1188,7 @@ DINode *SPIRVToLLVMDbgTran::transImportedEntry(const SPIRVExtInst *DebugInst) {
     return getDIBuilder(DebugInst).createImportedDeclaration(Scope, Entity,
                                                              File, Line, Name);
   }
-  // FIXME: uncomment and fix following line, with existing bugs it's reachable.
-  // llvm_unreachable("Unexpected kind of imported entity!");
-  // Imported entity translation is broken. For example ImportedEntity is
-  // missing 2nd parameter.
-  return nullptr;
+  llvm_unreachable("Unexpected kind of imported entity!");
 }
 
 DINode *SPIRVToLLVMDbgTran::transModule(const SPIRVExtInst *DebugInst) {
index cd181faa1842fb580166be2dda03260e9f5de675..7ddba0a1507d4470272e88ea4ed608258572f29e 100644 (file)
@@ -843,6 +843,9 @@ static std::map<ExpressionOpCode, unsigned> OpCountMap {
 }
 
 namespace ImportedEntity {
+inline namespace OpenCL {
+// it's bugged version, note 2nd index is missing
+// FIXME: need to remove it after some graceful period
 enum {
   NameIdx      = 0,
   TagIdx       = 1,
@@ -853,7 +856,20 @@ enum {
   ParentIdx    = 7,
   OperandCount = 8
 };
-}
+} // namespace OpenCL
+namespace NonSemantic {
+enum {
+  NameIdx      = 0,
+  TagIdx       = 1,
+  SourceIdx    = 2,
+  EntityIdx    = 3,
+  LineIdx      = 4,
+  ColumnIdx    = 5,
+  ParentIdx    = 6,
+  OperandCount = 7
+};
+} // namespace NonSemantic
+} // namespace ImportedEntity
 
 namespace ModuleINTEL {
 enum {
index fb83dfca0bc1af2f9ae0fd8144d5560d0a9689cf..e413c42e321a739b3012bc4e2caefd8b33f736e1 100644 (file)
@@ -37,7 +37,7 @@ target triple = "spir64-unknown-unknown"
 ; CHECK-SPIRV: ExtInst [[#]] [[#Parent:]] [[#]] DebugCompilationUnit [[#Version]] [[#DWARF]]
 ; CHECK-SPIRV: ExtInst [[#]] [[#SourceEmpty:]] [[#]] DebugSource [[#EmptyStr]]
 ; CHECK-SPIRV: ExtInst [[#]] [[#Module:]] [[#]] DebugModule [[#Name]] [[#SourceEmpty]] [[#Constant0]] [[#Parent]] [[#Defines]] [[#IncludePath]] [[#ApiNotes]] [[#Constant0]]
-; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugImportedEntity [[#]] [[#]] [[#]] [[#Source]] [[#Module]]
+; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugImportedEntity [[#]] [[#]] [[#Source]] [[#Module]]
 
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!6, !7}
index 42d0a1ce7bf8f954d7b40ea4e0a5f0684169c57b..edb7dd8ff41cceb017b53bbc775ade31942f6532 100644 (file)
@@ -20,7 +20,7 @@ target triple = "spir64-unknown-unknown"
 !4 = !{i32 2, !"Debug Info Version", i32 3}
 !5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, imports: !6)
 !6 = !{!7}
-!7 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !8, entity: !8, file: !1, line: 3)
+!7 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !8, entity: !11, file: !1, line: 3)
 !8 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !5, retainedNodes: !2)
 !9 = !DISubroutineType(types: !10)
 !10 = !{null}