Skip to content

[RemoveDIs] Fix removeRedundantDdbgInstrs utils for dbg.declares #74102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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