[RemoveDIs][NFC] Clean up BasicBlockUtils now intrinsics are gone (#154326)
A couple of minor readability changes now that we're not supporting both intrinsics and records.
This commit is contained in:
parent
174135863f
commit
6c9352530a
@ -377,15 +377,12 @@ bool llvm::MergeBlockSuccessorsIntoGivenBlocks(
|
|||||||
///
|
///
|
||||||
/// Possible improvements:
|
/// Possible improvements:
|
||||||
/// - Check fully overlapping fragments and not only identical fragments.
|
/// - Check fully overlapping fragments and not only identical fragments.
|
||||||
static bool
|
static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
|
||||||
DbgVariableRecordsRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
|
|
||||||
SmallVector<DbgVariableRecord *, 8> ToBeRemoved;
|
SmallVector<DbgVariableRecord *, 8> ToBeRemoved;
|
||||||
SmallDenseSet<DebugVariable> VariableSet;
|
SmallDenseSet<DebugVariable> VariableSet;
|
||||||
for (auto &I : reverse(*BB)) {
|
for (auto &I : reverse(*BB)) {
|
||||||
for (DbgVariableRecord &DR :
|
for (DbgVariableRecord &DVR :
|
||||||
reverse(filterDbgVars(I.getDbgRecordRange()))) {
|
reverse(filterDbgVars(I.getDbgRecordRange()))) {
|
||||||
DbgVariableRecord &DVR = cast<DbgVariableRecord>(DR);
|
|
||||||
|
|
||||||
DebugVariable Key(DVR.getVariable(), DVR.getExpression(),
|
DebugVariable Key(DVR.getVariable(), DVR.getExpression(),
|
||||||
DVR.getDebugLoc()->getInlinedAt());
|
DVR.getDebugLoc()->getInlinedAt());
|
||||||
auto R = VariableSet.insert(Key);
|
auto R = VariableSet.insert(Key);
|
||||||
@ -416,10 +413,6 @@ DbgVariableRecordsRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
|
|||||||
return !ToBeRemoved.empty();
|
return !ToBeRemoved.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
|
|
||||||
return DbgVariableRecordsRemoveRedundantDbgInstrsUsingBackwardScan(BB);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove redundant dbg.value instructions using a forward scan. This can
|
/// Remove redundant dbg.value instructions using a forward scan. This can
|
||||||
/// remove a dbg.value instruction that is redundant due to indicating that a
|
/// remove a dbg.value instruction that is redundant due to indicating that a
|
||||||
/// variable has the same value as already being indicated by an earlier
|
/// variable has the same value as already being indicated by an earlier
|
||||||
@ -439,14 +432,14 @@ static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) {
|
|||||||
///
|
///
|
||||||
/// Possible improvements:
|
/// Possible improvements:
|
||||||
/// - Keep track of non-overlapping fragments.
|
/// - Keep track of non-overlapping fragments.
|
||||||
static bool
|
static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
|
||||||
DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
|
bool RemovedAny = false;
|
||||||
SmallVector<DbgVariableRecord *, 8> ToBeRemoved;
|
|
||||||
SmallDenseMap<DebugVariable,
|
SmallDenseMap<DebugVariable,
|
||||||
std::pair<SmallVector<Value *, 4>, DIExpression *>, 4>
|
std::pair<SmallVector<Value *, 4>, DIExpression *>, 4>
|
||||||
VariableMap;
|
VariableMap;
|
||||||
for (auto &I : *BB) {
|
for (auto &I : *BB) {
|
||||||
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
|
for (DbgVariableRecord &DVR :
|
||||||
|
make_early_inc_range(filterDbgVars(I.getDbgRecordRange()))) {
|
||||||
if (DVR.getType() == DbgVariableRecord::LocationType::Declare)
|
if (DVR.getType() == DbgVariableRecord::LocationType::Declare)
|
||||||
continue;
|
continue;
|
||||||
DebugVariable Key(DVR.getVariable(), std::nullopt,
|
DebugVariable Key(DVR.getVariable(), std::nullopt,
|
||||||
@ -472,55 +465,12 @@ DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
|
|||||||
if (!IsDbgValueKind)
|
if (!IsDbgValueKind)
|
||||||
continue;
|
continue;
|
||||||
// Found an identical mapping. Remember the instruction for later removal.
|
// Found an identical mapping. Remember the instruction for later removal.
|
||||||
ToBeRemoved.push_back(&DVR);
|
DVR.eraseFromParent();
|
||||||
|
RemovedAny = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto *DVR : ToBeRemoved)
|
return RemovedAny;
|
||||||
DVR->eraseFromParent();
|
|
||||||
|
|
||||||
return !ToBeRemoved.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
DbgVariableRecordsRemoveUndefDbgAssignsFromEntryBlock(BasicBlock *BB) {
|
|
||||||
assert(BB->isEntryBlock() && "expected entry block");
|
|
||||||
SmallVector<DbgVariableRecord *, 8> ToBeRemoved;
|
|
||||||
DenseSet<DebugVariable> SeenDefForAggregate;
|
|
||||||
// Returns the DebugVariable for DVI with no fragment info.
|
|
||||||
auto GetAggregateVariable = [](const DbgVariableRecord &DVR) {
|
|
||||||
return DebugVariable(DVR.getVariable(), std::nullopt,
|
|
||||||
DVR.getDebugLoc().getInlinedAt());
|
|
||||||
};
|
|
||||||
|
|
||||||
// Remove undef dbg.assign intrinsics that are encountered before
|
|
||||||
// any non-undef intrinsics from the entry block.
|
|
||||||
for (auto &I : *BB) {
|
|
||||||
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
|
|
||||||
if (!DVR.isDbgValue() && !DVR.isDbgAssign())
|
|
||||||
continue;
|
|
||||||
bool IsDbgValueKind =
|
|
||||||
(DVR.isDbgValue() || at::getAssignmentInsts(&DVR).empty());
|
|
||||||
DebugVariable Aggregate = GetAggregateVariable(DVR);
|
|
||||||
if (!SeenDefForAggregate.contains(Aggregate)) {
|
|
||||||
bool IsKill = DVR.isKillLocation() && IsDbgValueKind;
|
|
||||||
if (!IsKill) {
|
|
||||||
SeenDefForAggregate.insert(Aggregate);
|
|
||||||
} else if (DVR.isDbgAssign()) {
|
|
||||||
ToBeRemoved.push_back(&DVR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (DbgVariableRecord *DVR : ToBeRemoved)
|
|
||||||
DVR->eraseFromParent();
|
|
||||||
|
|
||||||
return !ToBeRemoved.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
|
|
||||||
return DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BB);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove redundant undef dbg.assign intrinsic from an entry block using a
|
/// Remove redundant undef dbg.assign intrinsic from an entry block using a
|
||||||
@ -543,7 +493,34 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
|
|||||||
/// Possible improvements:
|
/// Possible improvements:
|
||||||
/// - Keep track of non-overlapping fragments.
|
/// - Keep track of non-overlapping fragments.
|
||||||
static bool removeUndefDbgAssignsFromEntryBlock(BasicBlock *BB) {
|
static bool removeUndefDbgAssignsFromEntryBlock(BasicBlock *BB) {
|
||||||
return DbgVariableRecordsRemoveUndefDbgAssignsFromEntryBlock(BB);
|
assert(BB->isEntryBlock() && "expected entry block");
|
||||||
|
bool RemovedAny = false;
|
||||||
|
DenseSet<DebugVariableAggregate> SeenDefForAggregate;
|
||||||
|
|
||||||
|
// Remove undef dbg.assign intrinsics that are encountered before
|
||||||
|
// any non-undef intrinsics from the entry block.
|
||||||
|
for (auto &I : *BB) {
|
||||||
|
for (DbgVariableRecord &DVR :
|
||||||
|
make_early_inc_range(filterDbgVars(I.getDbgRecordRange()))) {
|
||||||
|
if (!DVR.isDbgValue() && !DVR.isDbgAssign())
|
||||||
|
continue;
|
||||||
|
bool IsDbgValueKind =
|
||||||
|
(DVR.isDbgValue() || at::getAssignmentInsts(&DVR).empty());
|
||||||
|
|
||||||
|
DebugVariableAggregate Aggregate(&DVR);
|
||||||
|
if (!SeenDefForAggregate.contains(Aggregate)) {
|
||||||
|
bool IsKill = DVR.isKillLocation() && IsDbgValueKind;
|
||||||
|
if (!IsKill) {
|
||||||
|
SeenDefForAggregate.insert(Aggregate);
|
||||||
|
} else if (DVR.isDbgAssign()) {
|
||||||
|
DVR.eraseFromParent();
|
||||||
|
RemovedAny = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RemovedAny;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool llvm::RemoveRedundantDbgInstrs(BasicBlock *BB) {
|
bool llvm::RemoveRedundantDbgInstrs(BasicBlock *BB) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user