Skip to content

Commit 02d37bb

Browse files
authored
[DebugInfo] Add Target Function optional parameter to DebugFunction (#1853)
It's being added in KhronosGroup/SPIRV-Registry#186 In DWARF it's used in 'trampoline' functions generated for Fortran external function calls.
1 parent f7e68fb commit 02d37bb

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,16 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgFunction(const DISubprogram *Func) {
991991

992992
if (DISubprogram *FuncDecl = Func->getDeclaration())
993993
Ops.push_back(transDbgEntry(FuncDecl)->getId());
994-
else
994+
else {
995995
Ops.push_back(getDebugInfoNoneId());
996+
if (BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100) {
997+
// Translate targetFuncName mostly for Fortran trampoline function if it
998+
// is the case
999+
StringRef TargetFunc = Func->getTargetFuncName();
1000+
if (!TargetFunc.empty())
1001+
Ops.push_back(BM->getString(TargetFunc.str())->getId());
1002+
}
1003+
}
9961004

9971005
DebugFunc = BM->addDebugInfo(SPIRVDebug::Function, getVoidTy(), Ops);
9981006
MDMap.insert(std::make_pair(Func, DebugFunc));

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,18 @@ DINode *SPIRVToLLVMDbgTran::transFunction(const SPIRVExtInst *DebugInst) {
611611
!IsDefinition)
612612
DIS = Builder.createMethod(Scope, Name, LinkageName, File, LineNo, Ty, 0, 0,
613613
nullptr, Flags, SPFlags, TParamsArray);
614-
else
614+
else {
615+
// Create targetFuncName mostly for Fortran trampoline function if it is
616+
// the case
617+
StringRef TargetFunction;
618+
if (Ops.size() > TargetFunctionNameIdx) {
619+
TargetFunction = getString(Ops[TargetFunctionNameIdx]);
620+
}
615621
DIS = Builder.createFunction(Scope, Name, LinkageName, File, LineNo, Ty,
616-
ScopeLine, Flags, SPFlags, TParamsArray, FD);
622+
ScopeLine, Flags, SPFlags, TParamsArray, FD,
623+
/*ThrownTypes*/ nullptr,
624+
/*Annotations*/ nullptr, TargetFunction);
625+
}
617626
DebugInstCache[DebugInst] = DIS;
618627
SPIRVId RealFuncId = Ops[FunctionIdIdx];
619628
FuncMap[RealFuncId] = DIS;

lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ enum {
514514
ScopeLineIdx = 8,
515515
FunctionIdIdx = 9,
516516
DeclarationIdx = 10,
517+
TargetFunctionNameIdx = 11,
517518
MinOperandCount = 10
518519
};
519520
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv -spirv-text %t.bc -o %t.spt --spirv-debug-info-version=nonsemantic-kernel-100
3+
; RUN: FileCheck < %t.spt %s -check-prefix=CHECK-SPIRV
4+
; RUN: llvm-spirv -to-binary %t.spt -o %t.spv
5+
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
8+
; RUN: FileCheck < %t.rev.ll %s -check-prefix=CHECK-LLVM
9+
10+
; CHECK-SPIRV-DAG: ExtInstImport [[#EISId:]] "NonSemantic.Kernel.DebugInfo.100"
11+
; CHECK-SPIRV-DAG: String [[#Func:]] "foo_wrapper"
12+
; CHECK-SPIRV-DAG: String [[#TargetFunc:]] "_Z3foov"
13+
14+
; CHECK-SPIRV-DAG: ExtInst [[#]] [[#DebugNone:]] [[#]] DebugInfoNone
15+
; CHECK-SPIRV-DAG: ExtInst [[#]] [[#]] [[#]] DebugFunction [[#Func]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#DebugNone]] [[#TargetFunc]]
16+
17+
; CHECK-LLVM: define spir_func void @_Z11foo_wrapperv() {{.*}} !dbg ![[#DbgSubProg:]] {
18+
; CHECK-LLVM: ![[#DbgSubProg]] = distinct !DISubprogram(name: "foo_wrapper", linkageName: "_Z11foo_wrapperv", scope: null, file: ![[#]], line: 3, type: ![[#]], scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: ![[#]], templateParams: ![[#]], retainedNodes: ![[#]], targetFuncName: "_Z3foov")
19+
20+
; ModuleID = 'example.bc'
21+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
22+
target triple = "spir64-unknown-unknown"
23+
24+
define spir_func void @_Z11foo_wrapperv() !dbg !10 {
25+
call void @_Z3foov(), !dbg !15
26+
ret void, !dbg !16
27+
}
28+
29+
declare spir_func void @_Z3foov()
30+
31+
define spir_func void @_Z3boov() !dbg !17 {
32+
call void @_Z11foo_wrapperv(), !dbg !18
33+
ret void, !dbg !19
34+
}
35+
36+
!llvm.dbg.cu = !{!0}
37+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
38+
!llvm.ident = !{!9}
39+
40+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0 (https://github.com/llvm/llvm-project.git 88bd2601c013e349fa907b3f878312a94e16e9f6)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
41+
!1 = !DIFile(filename: "/app/example.cpp", directory: "/app")
42+
!2 = !{i32 7, !"Dwarf Version", i32 4}
43+
!3 = !{i32 2, !"Debug Info Version", i32 3}
44+
!4 = !{i32 1, !"wchar_size", i32 4}
45+
!5 = !{i32 8, !"PIC Level", i32 2}
46+
!6 = !{i32 7, !"PIE Level", i32 2}
47+
!7 = !{i32 7, !"uwtable", i32 2}
48+
!8 = !{i32 7, !"frame-pointer", i32 2}
49+
!9 = !{!"clang version 17.0.0 (https://github.com/llvm/llvm-project.git 88bd2601c013e349fa907b3f878312a94e16e9f6)"}
50+
!10 = distinct !DISubprogram(name: "foo_wrapper", linkageName: "_Z11foo_wrapperv", scope: !11, file: !11, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14, targetFuncName: "_Z3foov")
51+
!11 = !DIFile(filename: "example.cpp", directory: "/app")
52+
!12 = !DISubroutineType(types: !13)
53+
!13 = !{null}
54+
!14 = !{}
55+
!15 = !DILocation(line: 4, column: 5, scope: !10)
56+
!16 = !DILocation(line: 5, column: 1, scope: !10)
57+
!17 = distinct !DISubprogram(name: "boo", linkageName: "_Z3boov", scope: !11, file: !11, line: 7, type: !12, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
58+
!18 = !DILocation(line: 8, column: 5, scope: !17)
59+
!19 = !DILocation(line: 9, column: 1, scope: !17)

0 commit comments

Comments
 (0)