[Mlir-commits] [mlir] [MLIR][LLVM] Improve inlining debug information (PR #123520)
Tobias Gysi
llvmlistbot at llvm.org
Sun Jan 19 09:17:19 PST 2025
https://github.com/gysit created https://github.com/llvm/llvm-project/pull/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.
>From f3d6693d581adaf2a2b6abee5368b3789cf3a603 Mon Sep 17 00:00:00 2001
From: Tobias Gysi <tobias.gysi at nextsilicon.com>
Date: Sun, 19 Jan 2025 17:57:32 +0100
Subject: [PATCH] [MLIR][LLVM] Improve inlining debug information
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.
---
.../Transforms/InlinerInterfaceImpl.cpp | 6 +++---
.../Dialect/LLVMIR/inlining-debuginfo.mlir | 21 +++++++++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
create mode 100644 mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
index 79dd3e30696482..aab8d037cd8d21 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
@@ -643,9 +643,9 @@ static Value handleByValArgument(OpBuilder &builder, Operation *callable,
return argument;
}
uint64_t targetAlignment = std::max(requestedAlignment, minimumAlignment);
- return handleByValArgumentInit(builder, func.getLoc(), argument, elementType,
- dataLayout.getTypeSize(elementType),
- targetAlignment);
+ return handleByValArgumentInit(
+ builder, argument.getLoc(), argument, elementType,
+ dataLayout.getTypeSize(elementType), targetAlignment);
}
namespace {
diff --git a/mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir b/mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir
new file mode 100644
index 00000000000000..10b06d987e4498
--- /dev/null
+++ b/mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir
@@ -0,0 +1,21 @@
+// RUN: mlir-opt %s -inline -mlir-print-debuginfo | FileCheck %s
+
+llvm.func @foo() -> !llvm.ptr
+
+llvm.func @with_byval_arg(%ptr : !llvm.ptr { llvm.byval = f64 }) {
+ llvm.return
+}
+
+// CHECK-LABEL: llvm.func @test_byval
+llvm.func @test_byval() {
+ // CHECK: %[[COPY:.+]] = llvm.alloca %{{.+}} x f64
+ // CHECK-SAME: loc(#[[LOC:.+]])
+ // CHECK: %[[ORIG:.+]] = llvm.call @foo() : () -> !llvm.ptr loc(#[[LOC]])
+ %0 = llvm.call @foo() : () -> !llvm.ptr loc("inlining-debuginfo.mlir":14:2)
+ // CHECK: "llvm.intr.memcpy"(%[[COPY]], %[[ORIG]]
+ // CHECK-SAME: loc(#[[LOC]])
+ llvm.call @with_byval_arg(%0) : (!llvm.ptr) -> ()
+ llvm.return
+}
+
+// CHECK: #[[LOC]] = loc("inlining-debuginfo.mlir":14:2)
\ No newline at end of file
More information about the Mlir-commits
mailing list