Skip to content

Commit d0c9e70

Browse files
authored
[MLIR][LLVM] Improve inlining debug information (#123520)
This commit improves the debug information for `alloca` and `memcpy` operations generated by the LLVM dialect inlining interface. When inlining by value parameters, the inliner creates `alloca` and `memcpy` operations. This revision sets the location of these created operations to the respective argument locations instead of the function location. This change enables users to better identify the source code location of the copied variables.
1 parent c0055ec commit d0c9e70

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,9 @@ static Value handleByValArgument(OpBuilder &builder, Operation *callable,
643643
return argument;
644644
}
645645
uint64_t targetAlignment = std::max(requestedAlignment, minimumAlignment);
646-
return handleByValArgumentInit(builder, func.getLoc(), argument, elementType,
647-
dataLayout.getTypeSize(elementType),
648-
targetAlignment);
646+
return handleByValArgumentInit(
647+
builder, argument.getLoc(), argument, elementType,
648+
dataLayout.getTypeSize(elementType), targetAlignment);
649649
}
650650

651651
namespace {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: mlir-opt %s -inline -mlir-print-debuginfo | FileCheck %s
2+
3+
llvm.func @foo() -> !llvm.ptr
4+
5+
llvm.func @with_byval_arg(%ptr : !llvm.ptr { llvm.byval = f64 }) {
6+
llvm.return
7+
}
8+
9+
// CHECK-LABEL: llvm.func @test_byval
10+
llvm.func @test_byval() {
11+
// CHECK: %[[COPY:.+]] = llvm.alloca %{{.+}} x f64
12+
// CHECK-SAME: loc(#[[LOC:.+]])
13+
// CHECK: %[[ORIG:.+]] = llvm.call @foo() : () -> !llvm.ptr loc(#[[LOC]])
14+
%0 = llvm.call @foo() : () -> !llvm.ptr loc("inlining-debuginfo.mlir":14:2)
15+
// CHECK: "llvm.intr.memcpy"(%[[COPY]], %[[ORIG]]
16+
// CHECK-SAME: loc(#[[LOC]])
17+
llvm.call @with_byval_arg(%0) : (!llvm.ptr) -> ()
18+
llvm.return
19+
}
20+
21+
// CHECK: #[[LOC]] = loc("inlining-debuginfo.mlir":14:2)

0 commit comments

Comments
 (0)