[Mlir-commits] [mlir] 56b6b45 - [mlir][LLVM] Use `undef` operand instead of removing `llvm.intr.dbg.value`
Markus Böck
llvmlistbot at llvm.org
Thu Jul 6 06:41:56 PDT 2023
Author: Markus Böck
Date: 2023-07-06T15:39:41+02:00
New Revision: 56b6b45472cd2532d60b20c42fb41b7d27b1f956
URL: https://github.com/llvm/llvm-project/commit/56b6b45472cd2532d60b20c42fb41b7d27b1f956
DIFF: https://github.com/llvm/llvm-project/commit/56b6b45472cd2532d60b20c42fb41b7d27b1f956.diff
LOG: [mlir][LLVM] Use `undef` operand instead of removing `llvm.intr.dbg.value`
Jeremy Morse noted in D154451 that LLVM doesn't drop a `dbg.value` when its value is being removed, but rather sets the operand to `undef`. This preserves the debug info and gives allows the debugger to instead inform the user that the variable has been optimized out, rather than not displaying the variable at all.
This patch fixes that mistake done in the previous revision by mirroring that behaviour in MLIR as well.
Differential Revision: https://reviews.llvm.org/D154476
Added:
Modified:
mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
index 241bfdb732dc42..a324712734f53a 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
@@ -263,12 +263,25 @@ DeletionKind LLVM::DbgDeclareOp::removeBlockingUses(
bool LLVM::DbgValueOp::canUsesBeRemoved(
const SmallPtrSetImpl<OpOperand *> &blockingUses,
SmallVectorImpl<OpOperand *> &newBlockingUses) {
- return true;
+ // There is only one operand that we can remove the use of.
+ if (blockingUses.size() != 1)
+ return false;
+
+ return (*blockingUses.begin())->get() == getValue();
}
DeletionKind LLVM::DbgValueOp::removeBlockingUses(
const SmallPtrSetImpl<OpOperand *> &blockingUses, RewriterBase &rewriter) {
- return DeletionKind::Delete;
+ // Rewriter by default is after '*this', but we need it before '*this'.
+ rewriter.setInsertionPoint(*this);
+
+ // Rather than dropping the debug value, replace it with undef to preserve the
+ // debug local variable info. This allows the debugger to inform the user that
+ // the variable has been optimized out.
+ auto undef =
+ rewriter.create<UndefOp>(getValue().getLoc(), getValue().getType());
+ rewriter.updateRootInPlace(*this, [&] { getValueMutable().assign(undef); });
+ return DeletionKind::Keep;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir b/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
index b01fb55653612b..bb96256f3af28f 100644
--- a/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
@@ -76,9 +76,10 @@ llvm.func @double_block_argument_value(%arg0: i64, %arg1: i1) -> i64 {
}
// CHECK-LABEL: llvm.func @always_drop_promoted_declare
+// CHECK: %[[UNDEF:.*]] = llvm.mlir.undef
// CHECK-NOT: = llvm.alloca
// CHECK-NOT: llvm.intr.dbg.declare
-// CHECK-NOT: llvm.intr.dbg.value
+// CHECK: llvm.intr.dbg.value #{{.*}} = %[[UNDEF]]
llvm.func @always_drop_promoted_declare() {
%0 = llvm.mlir.constant(1 : i32) : i32
%1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
More information about the Mlir-commits
mailing list