Skip to content

Commit 18e5055

Browse files
authored
[mlir][LLVM] Improve function debug info import (#69446)
This commit improves the import of function debug info by creating a FileLineColLoc instead of just a NameLoc if possible.
1 parent 00f34ee commit 18e5055

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

mlir/lib/Target/LLVMIR/DebugImporter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ using namespace mlir::LLVM;
2424
using namespace mlir::LLVM::detail;
2525

2626
Location DebugImporter::translateFuncLocation(llvm::Function *func) {
27-
if (!func->getSubprogram())
27+
llvm::DISubprogram *subprogram = func->getSubprogram();
28+
if (!subprogram)
2829
return UnknownLoc::get(context);
2930

3031
// Add a fused location to link the subprogram information.
31-
StringAttr name = StringAttr::get(context, func->getSubprogram()->getName());
32+
StringAttr funcName = StringAttr::get(context, subprogram->getName());
33+
StringAttr fileName = StringAttr::get(context, subprogram->getFilename());
3234
return FusedLocWith<DISubprogramAttr>::get(
33-
{NameLoc::get(name)}, translate(func->getSubprogram()), context);
35+
{NameLoc::get(funcName),
36+
FileLineColLoc::get(fileName, subprogram->getLine(), /*column=*/0)},
37+
translate(subprogram), context);
3438
}
3539

3640
//===----------------------------------------------------------------------===//

mlir/test/Target/LLVMIR/Import/debug-info.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,18 @@ define void @subprogram() !dbg !3 {
222222
define void @func_loc() !dbg !3 {
223223
ret void
224224
}
225-
; CHECK: #[[SP:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #{{.*}}, name = "func_loc", file = #{{.*}}, subprogramFlags = Definition>
226-
; CHECK: loc(fused<#[[SP]]>[
225+
; CHECK-DAG: #[[NAME_LOC:.+]] = loc("func_loc")
226+
; CHECK-DAG: #[[FILE_LOC:.+]] = loc("debug-info.ll":42:0)
227+
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #{{.*}}, name = "func_loc", file = #{{.*}}, line = 42, subprogramFlags = Definition>
228+
229+
; CHECK: loc(fused<#[[SP]]>[#[[NAME_LOC]], #[[FILE_LOC]]]
227230

228231
!llvm.dbg.cu = !{!1}
229232
!llvm.module.flags = !{!0}
230233
!0 = !{i32 2, !"Debug Info Version", i32 3}
231234
!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2)
232235
!2 = !DIFile(filename: "debug-info.ll", directory: "/")
233-
!3 = distinct !DISubprogram(name: "func_loc", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1)
236+
!3 = distinct !DISubprogram(name: "func_loc", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1, line: 42)
234237

235238
; // -----
236239

@@ -538,7 +541,7 @@ define void @noname_subprogram(ptr %arg) !dbg !8 {
538541
; // -----
539542

540543
; CHECK: #[[MODULE:.+]] = #llvm.di_module<
541-
; CHECK-SAME: file = #{{.*}}, scope = #{{.*}}, name = "module",
544+
; CHECK-SAME: file = #{{.*}}, scope = #{{.*}}, name = "module",
542545
; CHECK-SAME: configMacros = "bar", includePath = "/",
543546
; CHECK-SAME: apinotes = "/", line = 42, isDecl = true
544547
; CHECK-SAME: >

0 commit comments

Comments
 (0)