diff options
author | Jeremy Morse <jeremy.morse@sony.com> | 2023-06-07 12:46:07 +0100 |
---|---|---|
committer | Jeremy Morse <jeremy.morse@sony.com> | 2023-11-21 10:28:19 +0000 |
commit | 6d23aaad4ffdcdda56845e4ca392f09c5795630a (patch) | |
tree | a9964a172dc13c4d160451e01f1db681ac0cc693 /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | |
parent | ef9bcace834e63f25bbbc5e8e2b615f89d85fb2f (diff) | |
download | llvm-6d23aaad4ffdcdda56845e4ca392f09c5795630a.zip llvm-6d23aaad4ffdcdda56845e4ca392f09c5795630a.tar.gz llvm-6d23aaad4ffdcdda56845e4ca392f09c5795630a.tar.bz2 |
[DebugInfo][RemoveDIs] Implement redundant elimination for DPValues (#72284)
This pass steps through a block forwards and backwards, identifying those
variable assignment records that are redundant, and erases them, saving us
a decent wedge of compile-time. This patch re-implements it to use the
replacement for DbgValueInsts, DPValues, in an almost identical way.
Alas the test I've added the try-remove-dis flag to is the only one I've
been able to find that manually runs this pass.
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 05ff4ef..168998f 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -382,7 +382,39 @@ bool llvm::MergeBlockSuccessorsIntoGivenBlocks( /// - Check fully overlapping fragments and not only identical fragments. /// - Support dbg.declare. dbg.label, and possibly other meta instructions being /// part of the sequence of consecutive instructions. +static bool DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) { + SmallVector<DPValue *, 8> ToBeRemoved; + SmallDenseSet<DebugVariable> VariableSet; + for (auto &I : reverse(*BB)) { + for (DPValue &DPV : reverse(I.getDbgValueRange())) { + DebugVariable Key(DPV.getVariable(), DPV.getExpression(), + DPV.getDebugLoc()->getInlinedAt()); + auto R = VariableSet.insert(Key); + // If the same variable fragment is described more than once it is enough + // to keep the last one (i.e. the first found since we for reverse + // iteration). + // FIXME: add assignment tracking support (see parallel implementation + // below). + if (!R.second) + ToBeRemoved.push_back(&DPV); + continue; + } + // Sequence with consecutive dbg.value instrs ended. Clear the map to + // restart identifying redundant instructions if case we find another + // dbg.value sequence. + VariableSet.clear(); + } + + for (auto &DPV : ToBeRemoved) + DPV->eraseFromParent(); + + return !ToBeRemoved.empty(); +} + static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) { + if (BB->IsNewDbgInfoFormat) + return DPValuesRemoveRedundantDbgInstrsUsingBackwardScan(BB); + SmallVector<DbgValueInst *, 8> ToBeRemoved; SmallDenseSet<DebugVariable> VariableSet; for (auto &I : reverse(*BB)) { @@ -440,7 +472,38 @@ static bool removeRedundantDbgInstrsUsingBackwardScan(BasicBlock *BB) { /// /// Possible improvements: /// - Keep track of non-overlapping fragments. +static bool DPValuesRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) { + SmallVector<DPValue *, 8> ToBeRemoved; + DenseMap<DebugVariable, std::pair<SmallVector<Value *, 4>, DIExpression *>> + VariableMap; + for (auto &I : *BB) { + for (DPValue &DPV : I.getDbgValueRange()) { + DebugVariable Key(DPV.getVariable(), std::nullopt, + DPV.getDebugLoc()->getInlinedAt()); + auto VMI = VariableMap.find(Key); + // Update the map if we found a new value/expression describing the + // variable, or if the variable wasn't mapped already. + SmallVector<Value *, 4> Values(DPV.location_ops()); + if (VMI == VariableMap.end() || VMI->second.first != Values || + VMI->second.second != DPV.getExpression()) { + VariableMap[Key] = {Values, DPV.getExpression()}; + continue; + } + // Found an identical mapping. Remember the instruction for later removal. + ToBeRemoved.push_back(&DPV); + } + } + + for (auto *DPV : ToBeRemoved) + DPV->eraseFromParent(); + + return !ToBeRemoved.empty(); +} + static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) { + if (BB->IsNewDbgInfoFormat) + return DPValuesRemoveRedundantDbgInstrsUsingForwardScan(BB); + SmallVector<DbgValueInst *, 8> ToBeRemoved; DenseMap<DebugVariable, std::pair<SmallVector<Value *, 4>, DIExpression *>> VariableMap; |