Skip to content

Commit 5c2368b

Browse files
vmaksimoDmitry Sidorov
authored andcommitted
[Backport to 14][DebugInfo] Support translation of DIModule (#1878)
This entity represents a module in the programming language, for example a Fortran module. Spec: KhronosGroup/SPIRV-Registry#186 The implementation is the same as for SPV_INTEL_debug_module extension. Spec for extension: https://github.com/intel/llvm/blob/sycl/sycl/doc/design/spirv-extensions/SPV_INTEL_debug_module.asciidoc
1 parent 70e9de0 commit 5c2368b

5 files changed

Lines changed: 87 additions & 5 deletions

File tree

lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgEntryImpl(const MDNode *MDN) {
360360
return transDbgImportedEntry(cast<DIImportedEntity>(DIEntry));
361361

362362
case dwarf::DW_TAG_module: {
363-
if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_debug_module))
363+
if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_debug_module) ||
364+
BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100)
364365
return transDbgModule(cast<DIModule>(DIEntry));
365366
return getDebugInfoNone();
366367
}
@@ -1251,15 +1252,33 @@ LLVMToSPIRVDbgTran::transDbgImportedEntry(const DIImportedEntity *IE) {
12511252
SPIRVEntry *LLVMToSPIRVDbgTran::transDbgModule(const DIModule *Module) {
12521253
using namespace SPIRVDebug::Operand::ModuleINTEL;
12531254
SPIRVWordVec Ops(OperandCount);
1255+
// The difference in translation of NonSemantic Debug Info and
1256+
// SPV_INTEL_debug_module extension is that extension allows Line and IsDecl
1257+
// operands to be Literals, when the non-OpenCL Debug Info allows only IDs to
1258+
// the constant values.
1259+
bool IsNonSemanticDI =
1260+
(BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100);
12541261
Ops[NameIdx] = BM->getString(Module->getName().str())->getId();
12551262
Ops[SourceIdx] = getSource(Module->getFile())->getId();
1256-
Ops[LineIdx] = Module->getLineNo();
1263+
if (IsNonSemanticDI) {
1264+
ConstantInt *Line = getUInt(M, Module->getLineNo());
1265+
Ops[LineIdx] = SPIRVWriter->transValue(Line, nullptr)->getId();
1266+
} else {
1267+
Ops[LineIdx] = Module->getLineNo();
1268+
}
12571269
Ops[ParentIdx] = getScope(Module->getScope())->getId();
12581270
Ops[ConfigMacrosIdx] =
12591271
BM->getString(Module->getConfigurationMacros().str())->getId();
12601272
Ops[IncludePathIdx] = BM->getString(Module->getIncludePath().str())->getId();
12611273
Ops[ApiNotesIdx] = BM->getString(Module->getAPINotesFile().str())->getId();
1262-
Ops[IsDeclIdx] = Module->getIsDecl();
1274+
if (IsNonSemanticDI) {
1275+
ConstantInt *IsDecl = getUInt(M, Module->getIsDecl());
1276+
Ops[IsDeclIdx] = SPIRVWriter->transValue(IsDecl, nullptr)->getId();
1277+
} else {
1278+
Ops[IsDeclIdx] = Module->getIsDecl();
1279+
}
1280+
if (IsNonSemanticDI)
1281+
return BM->addDebugInfo(SPIRVDebug::Module, getVoidTy(), Ops);
12631282
BM->addExtension(ExtensionID::SPV_INTEL_debug_module);
12641283
BM->addCapability(spv::CapabilityDebugInfoModuleINTEL);
12651284
return BM->addDebugInfo(SPIRVDebug::ModuleINTEL, getVoidTy(), Ops);

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,14 +994,22 @@ DINode *SPIRVToLLVMDbgTran::transModule(const SPIRVExtInst *DebugInst) {
994994
using namespace SPIRVDebug::Operand::ModuleINTEL;
995995
const SPIRVWordVec &Ops = DebugInst->getArguments();
996996
assert(Ops.size() >= OperandCount && "Invalid number of operands");
997+
bool IsNonSemanticDI =
998+
(DebugInst->getExtSetKind() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100);
997999
DIScope *Scope = getScope(BM->getEntry(Ops[ParentIdx]));
998-
unsigned Line = Ops[LineIdx];
1000+
auto GetInt = [&](SPIRVId Id) -> ConstantInt * {
1001+
auto *V = BM->get<SPIRVValue>(Id);
1002+
return cast<ConstantInt>(SPIRVReader->transValue(V, nullptr, nullptr));
1003+
};
1004+
unsigned Line =
1005+
IsNonSemanticDI ? GetInt(Ops[LineIdx])->getZExtValue() : Ops[LineIdx];
9991006
DIFile *File = getFile(Ops[SourceIdx]);
10001007
StringRef Name = getString(Ops[NameIdx]);
10011008
StringRef ConfigMacros = getString(Ops[ConfigMacrosIdx]);
10021009
StringRef IncludePath = getString(Ops[IncludePathIdx]);
10031010
StringRef ApiNotes = getString(Ops[ApiNotesIdx]);
1004-
bool IsDecl = Ops[IsDeclIdx];
1011+
bool IsDecl =
1012+
IsNonSemanticDI ? GetInt(Ops[IsDeclIdx])->getZExtValue() : Ops[IsDeclIdx];
10051013

10061014
return Builder.createModule(Scope, Name, ConfigMacros, IncludePath, ApiNotes,
10071015
File, Line, IsDecl);
@@ -1109,6 +1117,7 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
11091117
case SPIRVDebug::ImportedEntity:
11101118
return transImportedEntry(DebugInst);
11111119

1120+
case SPIRVDebug::Module:
11121121
case SPIRVDebug::ModuleINTEL:
11131122
return transModule(DebugInst);
11141123

lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum Instruction {
5353
ModuleINTEL = 36,
5454
InstCount = 37,
5555
TypeSubrange = 110,
56+
Module = 200,
5657
TypeArrayDynamic = 202,
5758
TypeString = 203
5859
};

lib/SPIRV/libSPIRV/SPIRVExtInst.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ template <> inline void SPIRVMap<SPIRVDebugExtOpKind, std::string>::init() {
257257
add(SPIRVDebug::InlinedAt, "DebugInlinedAt");
258258
add(SPIRVDebug::ImportedEntity, "DebugImportedEntity");
259259
add(SPIRVDebug::ModuleINTEL, "DebugModuleINTEL");
260+
add(SPIRVDebug::Module, "DebugModule");
260261
add(SPIRVDebug::Expression, "DebugExpression");
261262
add(SPIRVDebug::Operation, "DebugOperation");
262263
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; ModuleID = '/Volumes/Data/apple-internal/llvm/tools/clang/test/Modules/debug-info-moduleimport.m'
2+
; RUN: llvm-as < %s -o %t.bc
3+
; RUN: llvm-spirv --spirv-debug-info-version=nonsemantic-kernel-100 %t.bc -o %t.spv
4+
; RUN: llvm-spirv -r --opaque-pointers %t.spv -o - | llvm-dis -o %t.ll
5+
6+
; RUN: llc -mtriple=x86_64-apple-macosx %t.ll -accel-tables=Dwarf -o %t -filetype=obj
7+
; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
8+
; RUN: llvm-dwarfdump -verify %t
9+
10+
; RUN: llvm-spirv --spirv-debug-info-version=nonsemantic-kernel-100 %t.bc -spirv-text -o %t.spt
11+
; RUN: FileCheck %s --input-file %t.spt --check-prefix CHECK-SPIRV
12+
13+
; CHECK: DW_TAG_compile_unit
14+
; CHECK-NOT: DW_TAG
15+
; CHECK: DW_TAG_module
16+
; CHECK-NEXT: DW_AT_name {{.*}}"DebugModule"
17+
; CHECK-NEXT: DW_AT_LLVM_config_macros {{.*}}"-DMODULES=0"
18+
; CHECK-NEXT: DW_AT_LLVM_include_path {{.*}}"/llvm/tools/clang/test/Modules/Inputs"
19+
; CHECK-NEXT: DW_AT_LLVM_apinotes {{.*}}"m.apinotes"
20+
21+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
22+
target triple = "spir64-unknown-unknown"
23+
24+
; CHECK-SPIRV-DAG: ExtInstImport [[#EISId:]] "NonSemantic.Kernel.DebugInfo.100"
25+
; CHECK-SPIRV: String [[#FileName:]] "/llvm/tools/clang/test/Modules/<stdin>"
26+
; CHECK-SPIRV: String [[#EmptyStr:]] ""
27+
; CHECK-SPIRV: String [[#Name:]] "DebugModule"
28+
; CHECK-SPIRV: String [[#Defines:]] "-DMODULES=0"
29+
; CHECK-SPIRV: String [[#IncludePath:]] "/llvm/tools/clang/test/Modules/Inputs"
30+
; CHECK-SPIRV: String [[#ApiNotes:]] "m.apinotes"
31+
; CHECK-SPIRV: TypeInt [[#TypeInt32:]] 32 0
32+
; CHECK-SPIRV: Constant [[#TypeInt32]] [[#Constant0:]] 0
33+
34+
; CHECK-SPIRV: ExtInst [[#]] [[#Source:]] [[#]] DebugSource [[#FileName]]
35+
; CHECK-SPIRV: ExtInst [[#]] [[#Parent:]] [[#]] DebugCompileUnit 65536 4
36+
; CHECK-SPIRV: ExtInst [[#]] [[#SourceEmpty:]] [[#]] DebugSource [[#EmptyStr]]
37+
; CHECK-SPIRV: ExtInst [[#]] [[#Module:]] [[#]] DebugModule [[#Name]] [[#SourceEmpty]] [[#Constant0]] [[#Parent]] [[#Defines]] [[#IncludePath]] [[#ApiNotes]] [[#Constant0]]
38+
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] DebugImportedEntity [[#]] [[#]] [[#]] [[#Source]] [[#Module]]
39+
40+
!llvm.dbg.cu = !{!0}
41+
!llvm.module.flags = !{!6, !7}
42+
!llvm.ident = !{!8}
43+
44+
!0 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !1, producer: "LLVM version 3.7.0", isOptimized: false, runtimeVersion: 2, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !3, sysroot: "/")
45+
!1 = !DIFile(filename: "/llvm/tools/clang/test/Modules/<stdin>", directory: "/")
46+
!2 = !{}
47+
!3 = !{!4}
48+
!4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: !5, file: !1, line: 5)
49+
!5 = !DIModule(scope: null, name: "DebugModule", configMacros: "-DMODULES=0", includePath: "/llvm/tools/clang/test/Modules/Inputs", apinotes: "m.apinotes")
50+
!6 = !{i32 2, !"Dwarf Version", i32 4}
51+
!7 = !{i32 2, !"Debug Info Version", i32 3}
52+
!8 = !{!"LLVM version 3.7.0"}

0 commit comments

Comments
 (0)