Skip to content

Commit

Permalink
[RemoveDIs] Fix removeRedundantDdbgInstrs utils for dbg.declares (#74102
Browse files Browse the repository at this point in the history
)

The intrinsic variants of these functions don't do anything to
dbg.declares so the non-instruction variants should ignore them too.

Tested in llvm/test/DebugInfo/duplicate_dbgvalue.ll, which has
`--try-experimental-debuginfo-iterators` added in #73504.

The tests will become "live" once #74090 lands (see for more info).
  • Loading branch information
OCHyams committed Dec 12, 2023
1 parent 5457fab commit 300ac0a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,18 @@ static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
SmallDenseSet<DebugVariable> VariableSet;
for (auto &I : reverse(*BB)) {
for (DPValue &DPV : reverse(I.getDbgValueRange())) {
// 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);
Expand Down Expand Up @@ -478,6 +490,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);
Expand Down

0 comments on commit 300ac0a

Please sign in to comment.