[llvm] [RemoveDIs] Fix removeRedundantDdbgInstrs utils for dbg.declares (PR #74102)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 01:42:26 PST 2023
https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/74102
>From 48dbd6b74bab9f923efa587a8e5b1cd7e87eb958 Mon Sep 17 00:00:00 2001
From: OCHyams <orlando.hyams at sony.com>
Date: Fri, 24 Nov 2023 16:47:06 +0000
Subject: [PATCH 1/2] [RemoveDIs] Fix removeRedundantDdbgInstrs utils for
dbg.declares
The intrinsic variants of these functions don't do anything to
dbg.declares so the non-instruction variants should too.
Tested in llvm/test/DebugInfo/duplicate_dbgvalue.ll, which has
`--try-experimental-debuginfo-iterators` added in #73504.
---
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index ccee97025e3c3..1c6b4986c0342 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -387,6 +387,8 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
SmallDenseSet<DebugVariable> VariableSet;
for (auto &I : reverse(*BB)) {
for (DPValue &DPV : reverse(I.getDbgValueRange())) {
+ if (DPV.getType() == DPValue::LocationType::Declare)
+ continue;
DebugVariable Key(DPV.getVariable(), DPV.getExpression(),
DPV.getDebugLoc()->getInlinedAt());
auto R = VariableSet.insert(Key);
@@ -478,6 +480,8 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
VariableMap;
for (auto &I : *BB) {
for (DPValue &DPV : I.getDbgValueRange()) {
+ if (DPV.getType() == DPValue::LocationType::Declare)
+ continue;
DebugVariable Key(DPV.getVariable(), std::nullopt,
DPV.getDebugLoc()->getInlinedAt());
auto VMI = VariableMap.find(Key);
>From b15fd617fd5d30c6d8170ba2c0a4d495b21c5798 Mon Sep 17 00:00:00 2001
From: OCHyams <orlando.hyams at sony.com>
Date: Mon, 11 Dec 2023 09:42:02 +0000
Subject: [PATCH 2/2] Fix non-identical output from
DPValuesRemoveRedundantDbgInstrsUsingBackwardScan, add comments
---
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 1c6b4986c0342..529468b0e9240 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -387,8 +387,18 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
SmallDenseSet<DebugVariable> VariableSet;
for (auto &I : reverse(*BB)) {
for (DPValue &DPV : reverse(I.getDbgValueRange())) {
- if (DPV.getType() == DPValue::LocationType::Declare)
+ // Skip declare-type records, as the debug intrinsic method only works
+ // on dbg.value intrinsics.
+ if (DPV.getType() == DPValue::LocationType::Declare) {
+ // The debug intrinsic method treats dbg.declares are "non-debug"
+ // instructions (i.e., a break in a consecutive range of debug
+ // intrinsics). Emulate that to create identical outputs. See
+ // "Possible improvements" above.
+ // FIXME: Delete the line below.
+ VariableSet.clear();
continue;
+ }
+
DebugVariable Key(DPV.getVariable(), DPV.getExpression(),
DPV.getDebugLoc()->getInlinedAt());
auto R = VariableSet.insert(Key);
More information about the llvm-commits
mailing list