Skip to content

Commit 91c5663

Browse files
vmaksimoFreddyLeaf
authored andcommitted
Support translation of DIModule (intel#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 Original commit: KhronosGroup/SPIRV-LLVM-Translator@6a0368f
1 parent c6f720f commit 91c5663

File tree

5 files changed

+87
-5
lines changed

5 files changed

+87
-5
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

+22-3
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
}
@@ -1257,15 +1258,33 @@ LLVMToSPIRVDbgTran::transDbgImportedEntry(const DIImportedEntity *IE) {
12571258
SPIRVEntry *LLVMToSPIRVDbgTran::transDbgModule(const DIModule *Module) {
12581259
using namespace SPIRVDebug::Operand::ModuleINTEL;
12591260
SPIRVWordVec Ops(OperandCount);
1261+
// The difference in translation of NonSemantic Debug Info and
1262+
// SPV_INTEL_debug_module extension is that extension allows Line and IsDecl
1263+
// operands to be Literals, when the non-OpenCL Debug Info allows only IDs to
1264+
// the constant values.
1265+
bool IsNonSemanticDI =
1266+
(BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100);
12601267
Ops[NameIdx] = BM->getString(Module->getName().str())->getId();
12611268
Ops[SourceIdx] = getSource(Module->getFile())->getId();
1262-
Ops[LineIdx] = Module->getLineNo();
1269+
if (IsNonSemanticDI) {
1270+
ConstantInt *Line = getUInt(M, Module->getLineNo());
1271+
Ops[LineIdx] = SPIRVWriter->transValue(Line, nullptr)->getId();
1272+
} else {
1273+
Ops[LineIdx] = Module->getLineNo();
1274+
}
12631275
Ops[ParentIdx] = getScope(Module->getScope())->getId();
12641276
Ops[ConfigMacrosIdx] =
12651277
BM->getString(Module->getConfigurationMacros().str())->getId();
12661278
Ops[IncludePathIdx] = BM->getString(Module->getIncludePath().str())->getId();
12671279
Ops[ApiNotesIdx] = BM->getString(Module->getAPINotesFile().str())->getId();
1268-
Ops[IsDeclIdx] = Module->getIsDecl();
1280+
if (IsNonSemanticDI) {
1281+
ConstantInt *IsDecl = getUInt(M, Module->getIsDecl());
1282+
Ops[IsDeclIdx] = SPIRVWriter->transValue(IsDecl, nullptr)->getId();
1283+
} else {
1284+
Ops[IsDeclIdx] = Module->getIsDecl();
1285+
}
1286+
if (IsNonSemanticDI)
1287+
return BM->addDebugInfo(SPIRVDebug::Module, getVoidTy(), Ops);
12691288
BM->addExtension(ExtensionID::SPV_INTEL_debug_module);
12701289
BM->addCapability(spv::CapabilityDebugInfoModuleINTEL);
12711290
return BM->addDebugInfo(SPIRVDebug::ModuleINTEL, getVoidTy(), Ops);

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -1000,14 +1000,22 @@ DINode *SPIRVToLLVMDbgTran::transModule(const SPIRVExtInst *DebugInst) {
10001000
using namespace SPIRVDebug::Operand::ModuleINTEL;
10011001
const SPIRVWordVec &Ops = DebugInst->getArguments();
10021002
assert(Ops.size() >= OperandCount && "Invalid number of operands");
1003+
bool IsNonSemanticDI =
1004+
(DebugInst->getExtSetKind() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100);
10031005
DIScope *Scope = getScope(BM->getEntry(Ops[ParentIdx]));
1004-
unsigned Line = Ops[LineIdx];
1006+
auto GetInt = [&](SPIRVId Id) -> ConstantInt * {
1007+
auto *V = BM->get<SPIRVValue>(Id);
1008+
return cast<ConstantInt>(SPIRVReader->transValue(V, nullptr, nullptr));
1009+
};
1010+
unsigned Line =
1011+
IsNonSemanticDI ? GetInt(Ops[LineIdx])->getZExtValue() : Ops[LineIdx];
10051012
DIFile *File = getFile(Ops[SourceIdx]);
10061013
StringRef Name = getString(Ops[NameIdx]);
10071014
StringRef ConfigMacros = getString(Ops[ConfigMacrosIdx]);
10081015
StringRef IncludePath = getString(Ops[IncludePathIdx]);
10091016
StringRef ApiNotes = getString(Ops[ApiNotesIdx]);
1010-
bool IsDecl = Ops[IsDeclIdx];
1017+
bool IsDecl =
1018+
IsNonSemanticDI ? GetInt(Ops[IsDeclIdx])->getZExtValue() : Ops[IsDeclIdx];
10111019

10121020
return Builder.createModule(Scope, Name, ConfigMacros, IncludePath, ApiNotes,
10131021
File, Line, IsDecl);
@@ -1115,6 +1123,7 @@ MDNode *SPIRVToLLVMDbgTran::transDebugInstImpl(const SPIRVExtInst *DebugInst) {
11151123
case SPIRVDebug::ImportedEntity:
11161124
return transImportedEntry(DebugInst);
11171125

1126+
case SPIRVDebug::Module:
11181127
case SPIRVDebug::ModuleINTEL:
11191128
return transModule(DebugInst);
11201129

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

+1
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
};

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

+1
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
}
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 -emit-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)