From 7aabf5901bd5e5316dd58a40be2a869d24bbfa5a Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Tue, 2 May 2023 14:39:37 +0200 Subject: [PATCH] [PATCH 45/79] [DebugInfo] Fix missing 2nd operand for DebugImportedEntity (#1983) 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 | 20 +++++++++----- lib/SPIRV/SPIRVToLLVMDbgTran.cpp | 26 +++++++++++-------- lib/SPIRV/libSPIRV/SPIRV.debug.h | 18 ++++++++++++- .../NonSemantic/Shader200/DIModule.ll | 2 +- test/DebugInfo/omit-empty.ll | 2 +- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp index 6e5b81d..946aa71 100644 --- a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp +++ b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp @@ -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(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); } diff --git a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp index 46e0daf..3279009 100644 --- a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp +++ b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp @@ -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(BM->get(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(BM->get(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) { diff --git a/lib/SPIRV/libSPIRV/SPIRV.debug.h b/lib/SPIRV/libSPIRV/SPIRV.debug.h index cd181fa..7ddba0a 100644 --- a/lib/SPIRV/libSPIRV/SPIRV.debug.h +++ b/lib/SPIRV/libSPIRV/SPIRV.debug.h @@ -843,6 +843,9 @@ static std::map 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 { diff --git a/test/DebugInfo/NonSemantic/Shader200/DIModule.ll b/test/DebugInfo/NonSemantic/Shader200/DIModule.ll index fb83dfc..e413c42 100644 --- a/test/DebugInfo/NonSemantic/Shader200/DIModule.ll +++ b/test/DebugInfo/NonSemantic/Shader200/DIModule.ll @@ -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} diff --git a/test/DebugInfo/omit-empty.ll b/test/DebugInfo/omit-empty.ll index 42d0a1c..edb7dd8 100644 --- a/test/DebugInfo/omit-empty.ll +++ b/test/DebugInfo/omit-empty.ll @@ -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} -- 2.30.2