[PATCH 19/79] [Backport to 15][DebugInfo] Add Target Function optional parameter...
authorDmitry Sidorov <dmitry.sidorov@intel.com>
Thu, 23 Feb 2023 18:11:30 +0000 (19:11 +0100)
committerAndreas Beckmann <anbe@debian.org>
Thu, 8 Feb 2024 21:48:18 +0000 (22:48 +0100)
It's being added in
KhronosGroup/SPIRV-Registry#186

In DWARF it's used in 'trampoline' functions generated for Fortran external function calls.

Gbp-Pq: Name 0019-Backport-to-15-DebugInfo-Add-Target-Function-optiona.patch

lib/SPIRV/LLVMToSPIRVDbgTran.cpp
lib/SPIRV/SPIRVToLLVMDbgTran.cpp
lib/SPIRV/libSPIRV/SPIRV.debug.h
test/DebugInfo/NonSemanticKernel100/DebugInfoTargetFunction.ll [new file with mode: 0644]

index d6da1a82bab414b76292c175dbb86394588630e0..6985665d07190ee605e844784557b641d879fea5 100644 (file)
@@ -988,8 +988,16 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgFunction(const DISubprogram *Func) {
 
     if (DISubprogram *FuncDecl = Func->getDeclaration())
       Ops.push_back(transDbgEntry(FuncDecl)->getId());
-    else
+    else {
       Ops.push_back(getDebugInfoNoneId());
+      if (BM->getDebugInfoEIS() == SPIRVEIS_NonSemantic_Kernel_DebugInfo_100) {
+        // Translate targetFuncName mostly for Fortran trampoline function if it
+        // is the case
+        StringRef TargetFunc = Func->getTargetFuncName();
+        if (!TargetFunc.empty())
+          Ops.push_back(BM->getString(TargetFunc.str())->getId());
+      }
+    }
 
     DebugFunc = BM->addDebugInfo(SPIRVDebug::Function, getVoidTy(), Ops);
     MDMap.insert(std::make_pair(Func, DebugFunc));
index 94c3616f0dee753954e90bdad1e41d00594bc163..b9e1679b42616fdeaf3ee5ba1002fd2b145749a1 100644 (file)
@@ -609,9 +609,18 @@ DINode *SPIRVToLLVMDbgTran::transFunction(const SPIRVExtInst *DebugInst) {
       !IsDefinition)
     DIS = Builder.createMethod(Scope, Name, LinkageName, File, LineNo, Ty, 0, 0,
                                nullptr, Flags, SPFlags, TParamsArray);
-  else
+  else {
+    // Create targetFuncName mostly for Fortran trampoline function if it is
+    // the case
+    StringRef TargetFunction;
+    if (Ops.size() > TargetFunctionNameIdx) {
+      TargetFunction = getString(Ops[TargetFunctionNameIdx]);
+    }
     DIS = Builder.createFunction(Scope, Name, LinkageName, File, LineNo, Ty,
-                                 ScopeLine, Flags, SPFlags, TParamsArray, FD);
+                                 ScopeLine, Flags, SPFlags, TParamsArray, FD,
+                                 /*ThrownTypes*/ nullptr,
+                                 /*Annotations*/ nullptr, TargetFunction);
+  }
   DebugInstCache[DebugInst] = DIS;
   SPIRVId RealFuncId = Ops[FunctionIdIdx];
   FuncMap[RealFuncId] = DIS;
index 007783cbf982b37b8d177b428acab64d865f207a..dcebe6eac624c349da5688de64033e12a5b67657 100644 (file)
@@ -513,6 +513,7 @@ enum {
   ScopeLineIdx    = 8,
   FunctionIdIdx   = 9,
   DeclarationIdx  = 10,
+  TargetFunctionNameIdx  = 11,
   MinOperandCount = 10
 };
 }
diff --git a/test/DebugInfo/NonSemanticKernel100/DebugInfoTargetFunction.ll b/test/DebugInfo/NonSemanticKernel100/DebugInfoTargetFunction.ll
new file mode 100644 (file)
index 0000000..25d5330
--- /dev/null
@@ -0,0 +1,59 @@
+; RUN: llvm-as %s -o %t.bc
+; RUN: llvm-spirv -spirv-text %t.bc -o %t.spt --spirv-debug-info-version=nonsemantic-kernel-100
+; RUN: FileCheck < %t.spt %s -check-prefix=CHECK-SPIRV
+; RUN: llvm-spirv -to-binary %t.spt -o %t.spv
+
+; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
+; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
+; RUN: FileCheck < %t.rev.ll %s -check-prefix=CHECK-LLVM
+
+; CHECK-SPIRV-DAG: ExtInstImport [[#EISId:]] "NonSemantic.Kernel.DebugInfo.100"
+; CHECK-SPIRV-DAG: String [[#Func:]] "foo_wrapper"
+; CHECK-SPIRV-DAG: String [[#TargetFunc:]] "_Z3foov"
+
+; CHECK-SPIRV-DAG: ExtInst [[#]] [[#DebugNone:]] [[#]] DebugInfoNone
+; CHECK-SPIRV-DAG: ExtInst [[#]] [[#]] [[#]] DebugFunction [[#Func]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#DebugNone]] [[#TargetFunc]]
+
+; CHECK-LLVM: define spir_func void @_Z11foo_wrapperv() {{.*}} !dbg ![[#DbgSubProg:]] {
+; 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")
+
+; ModuleID = 'example.bc'
+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"
+target triple = "spir64-unknown-unknown"
+
+define spir_func void @_Z11foo_wrapperv() !dbg !10 {
+  call void @_Z3foov(), !dbg !15
+  ret void, !dbg !16
+}
+
+declare spir_func void @_Z3foov()
+
+define spir_func void @_Z3boov() !dbg !17 {
+  call void @_Z11foo_wrapperv(), !dbg !18
+  ret void, !dbg !19
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
+!llvm.ident = !{!9}
+
+!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)
+!1 = !DIFile(filename: "/app/example.cpp", directory: "/app")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 8, !"PIC Level", i32 2}
+!6 = !{i32 7, !"PIE Level", i32 2}
+!7 = !{i32 7, !"uwtable", i32 2}
+!8 = !{i32 7, !"frame-pointer", i32 2}
+!9 = !{!"clang version 17.0.0 (https://github.com/llvm/llvm-project.git 88bd2601c013e349fa907b3f878312a94e16e9f6)"}
+!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")
+!11 = !DIFile(filename: "example.cpp", directory: "/app")
+!12 = !DISubroutineType(types: !13)
+!13 = !{null}
+!14 = !{}
+!15 = !DILocation(line: 4, column: 5, scope: !10)
+!16 = !DILocation(line: 5, column: 1, scope: !10)
+!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)
+!18 = !DILocation(line: 8, column: 5, scope: !17)
+!19 = !DILocation(line: 9, column: 1, scope: !17)