[Mlir-commits] [mlir] d0c9e70 - [MLIR][LLVM] Improve inlining debug information (#123520)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jan 20 00:30:32 PST 2025


Author: Tobias Gysi
Date: 2025-01-20T09:30:28+01:00
New Revision: d0c9e70bcc40948821e83eb0ec32e6e15fb0dd4b

URL: https://github.com/llvm/llvm-project/commit/d0c9e70bcc40948821e83eb0ec32e6e15fb0dd4b
DIFF: https://github.com/llvm/llvm-project/commit/d0c9e70bcc40948821e83eb0ec32e6e15fb0dd4b.diff

LOG: [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.

Added: 
    mlir/test/Dialect/LLVMIR/inlining-debuginfo.mlir

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

Removed: 
    


################################################################################
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..97a9f9f0a3d06f
--- /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)


        


More information about the Mlir-commits mailing list