Skip to content

Commit 5b69278

Browse files
MrSidimsagainull
authored andcommitted
Fix missing 2nd operand for DebugImportedEntity (intel#1983)
It will be still missing for OpenCL debug info, but for NonSemantic the correct behavior is preserved. Signed-off-by: Sidorov, Dmitry [email protected] Original commit: KhronosGroup/SPIRV-LLVM-Translator@4645b06
1 parent c2d2018 commit 5b69278

File tree

5 files changed

+47
-21
lines changed

5 files changed

+47
-21
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,17 +1422,23 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgExpression(const DIExpression *Expr) {
14221422
SPIRVEntry *
14231423
LLVMToSPIRVDbgTran::transDbgImportedEntry(const DIImportedEntity *IE) {
14241424
using namespace SPIRVDebug::Operand::ImportedEntity;
1425-
SPIRVWordVec Ops(OperandCount);
14261425
auto Tag = static_cast<dwarf::Tag>(IE->getTag());
1426+
// FIXME: 'OpenCL/bugged' version is kept because it's hard to remove it
1427+
// It's W/A for missing 2nd index in OpenCL's implementation
1428+
const SPIRVWord OffsetIdx =
1429+
isNonSemanticDebugInfo() ? OperandCount - NonSemantic::OperandCount : 0;
1430+
SPIRVWordVec Ops(OperandCount - OffsetIdx);
14271431
Ops[NameIdx] = BM->getString(IE->getName().str())->getId();
14281432
Ops[TagIdx] = SPIRV::DbgImportedEntityMap::map(Tag);
1429-
Ops[SourceIdx] = getSource(IE->getFile())->getId();
1430-
Ops[EntityIdx] = transDbgEntry(IE->getEntity())->getId();
1431-
Ops[LineIdx] = IE->getLine();
1432-
Ops[ColumnIdx] = 0; // This version of DIImportedEntity has no column number
1433-
Ops[ParentIdx] = getScope(IE->getScope())->getId();
1433+
Ops[SourceIdx - OffsetIdx] = getSource(IE->getFile())->getId();
1434+
Ops[EntityIdx - OffsetIdx] = transDbgEntry(IE->getEntity())->getId();
1435+
Ops[LineIdx - OffsetIdx] = IE->getLine();
1436+
// This version of DIImportedEntity has no column number
1437+
Ops[ColumnIdx - OffsetIdx] = 0;
1438+
Ops[ParentIdx - OffsetIdx] = getScope(IE->getScope())->getId();
14341439
if (isNonSemanticDebugInfo())
1435-
transformToConstant(Ops, {TagIdx, LineIdx, ColumnIdx});
1440+
transformToConstant(Ops,
1441+
{TagIdx, LineIdx - OffsetIdx, ColumnIdx - OffsetIdx});
14361442
return BM->addDebugInfo(SPIRVDebug::ImportedEntity, getVoidTy(), Ops);
14371443
}
14381444

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,12 +1149,20 @@ MDNode *SPIRVToLLVMDbgTran::transTypeTemplate(const SPIRVExtInst *DebugInst) {
11491149
DINode *SPIRVToLLVMDbgTran::transImportedEntry(const SPIRVExtInst *DebugInst) {
11501150
using namespace SPIRVDebug::Operand::ImportedEntity;
11511151
const SPIRVWordVec &Ops = DebugInst->getArguments();
1152-
assert(Ops.size() >= OperandCount && "Invalid number of operands");
1153-
DIScope *Scope = getScope(BM->getEntry(Ops[ParentIdx]));
1154-
SPIRVWord Line =
1155-
getConstantValueOrLiteral(Ops, LineIdx, DebugInst->getExtSetKind());
1156-
DIFile *File = getFile(Ops[SourceIdx]);
1157-
auto *Entity = transDebugInst<DINode>(BM->get<SPIRVExtInst>(Ops[EntityIdx]));
1152+
// FIXME: 'OpenCL/bugged' version is kept because it's hard to remove it
1153+
// It's W/A for missing 2nd index in OpenCL's implementation
1154+
const SPIRVWord OffsetIdx = isNonSemanticDebugInfo(DebugInst->getExtSetKind())
1155+
? OperandCount - NonSemantic::OperandCount
1156+
: 0;
1157+
1158+
assert(Ops.size() == (OperandCount - OffsetIdx) &&
1159+
"Invalid number of operands");
1160+
DIScope *Scope = getScope(BM->getEntry(Ops[ParentIdx - OffsetIdx]));
1161+
SPIRVWord Line = getConstantValueOrLiteral(Ops, LineIdx - OffsetIdx,
1162+
DebugInst->getExtSetKind());
1163+
DIFile *File = getFile(Ops[SourceIdx - OffsetIdx]);
1164+
auto *Entity =
1165+
transDebugInst<DINode>(BM->get<SPIRVExtInst>(Ops[EntityIdx - OffsetIdx]));
11581166
SPIRVWord Tag =
11591167
getConstantValueOrLiteral(Ops, TagIdx, DebugInst->getExtSetKind());
11601168
if (Tag == SPIRVDebug::ImportedModule) {
@@ -1180,11 +1188,7 @@ DINode *SPIRVToLLVMDbgTran::transImportedEntry(const SPIRVExtInst *DebugInst) {
11801188
return getDIBuilder(DebugInst).createImportedDeclaration(Scope, Entity,
11811189
File, Line, Name);
11821190
}
1183-
// FIXME: uncomment and fix following line, with existing bugs it's reachable.
1184-
// llvm_unreachable("Unexpected kind of imported entity!");
1185-
// Imported entity translation is broken. For example ImportedEntity is
1186-
// missing 2nd parameter.
1187-
return nullptr;
1191+
llvm_unreachable("Unexpected kind of imported entity!");
11881192
}
11891193

11901194
DINode *SPIRVToLLVMDbgTran::transModule(const SPIRVExtInst *DebugInst) {

llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ static std::map<ExpressionOpCode, unsigned> OpCountMap {
843843
}
844844

845845
namespace ImportedEntity {
846+
inline namespace OpenCL {
847+
// it's bugged version, note 2nd index is missing
848+
// FIXME: need to remove it after some graceful period
846849
enum {
847850
NameIdx = 0,
848851
TagIdx = 1,
@@ -853,7 +856,20 @@ enum {
853856
ParentIdx = 7,
854857
OperandCount = 8
855858
};
856-
}
859+
} // namespace OpenCL
860+
namespace NonSemantic {
861+
enum {
862+
NameIdx = 0,
863+
TagIdx = 1,
864+
SourceIdx = 2,
865+
EntityIdx = 3,
866+
LineIdx = 4,
867+
ColumnIdx = 5,
868+
ParentIdx = 6,
869+
OperandCount = 7
870+
};
871+
} // namespace NonSemantic
872+
} // namespace ImportedEntity
857873

858874
namespace ModuleINTEL {
859875
enum {

llvm-spirv/test/DebugInfo/NonSemantic/Shader200/DIModule.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ target triple = "spir64-unknown-unknown"
3737
; CHECK-SPIRV: ExtInst [[#]] [[#Parent:]] [[#]] DebugCompilationUnit [[#Version]] [[#DWARF]]
3838
; CHECK-SPIRV: ExtInst [[#]] [[#SourceEmpty:]] [[#]] DebugSource [[#EmptyStr]]
3939
; CHECK-SPIRV: ExtInst [[#]] [[#Module:]] [[#]] DebugModule [[#Name]] [[#SourceEmpty]] [[#Constant0]] [[#Parent]] [[#Defines]] [[#IncludePath]] [[#ApiNotes]] [[#Constant0]]
40-
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugImportedEntity [[#]] [[#]] [[#]] [[#Source]] [[#Module]]
40+
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugImportedEntity [[#]] [[#]] [[#Source]] [[#Module]]
4141

4242
!llvm.dbg.cu = !{!0}
4343
!llvm.module.flags = !{!6, !7}

llvm-spirv/test/DebugInfo/omit-empty.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ target triple = "spir64-unknown-unknown"
2020
!4 = !{i32 2, !"Debug Info Version", i32 3}
2121
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, imports: !6)
2222
!6 = !{!7}
23-
!7 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !8, entity: !8, file: !1, line: 3)
23+
!7 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !8, entity: !11, file: !1, line: 3)
2424
!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)
2525
!9 = !DISubroutineType(types: !10)
2626
!10 = !{null}

0 commit comments

Comments
 (0)