[llvm] e093109 - [InstrRef][NFC] Avoid another DenseMap, use a sorted vector (#99051)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 17 05:56:48 PDT 2024
Author: Jeremy Morse
Date: 2024-07-17T13:56:44+01:00
New Revision: e093109e4a1551de13a1219275d62e9c7ee3146f
URL: https://github.com/llvm/llvm-project/commit/e093109e4a1551de13a1219275d62e9c7ee3146f
DIFF: https://github.com/llvm/llvm-project/commit/e093109e4a1551de13a1219275d62e9c7ee3146f.diff
LOG: [InstrRef][NFC] Avoid another DenseMap, use a sorted vector (#99051)
When resolving value-numbers to specific machine locations in the final
stages of LiveDebugValues, we've been producing a DenseMap containing
all the value-numbers we're interested in. However we never modify the
map keys as they're all pre-known. Thus, this is a suitable collection
to switch to a sorted vector that gets searched, rather than a DenseMap
that gets probed. The overall operation of LiveDebugValues isn't
affected at all.
Added:
Modified:
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index bde8cc4a89715..247258a1ff553 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -316,6 +316,13 @@ class TransferTracker {
bool isBest() const { return getQuality() == LocationQuality::Best; }
};
+ using ValueLocPair = std::pair<ValueIDNum, LocationAndQuality>;
+
+ static inline bool ValueToLocSort(const ValueLocPair &A,
+ const ValueLocPair &B) {
+ return A.first < B.first;
+ };
+
// Returns the LocationQuality for the location L iff the quality of L is
// is strictly greater than the provided minimum quality.
std::optional<LocationQuality>
@@ -344,7 +351,7 @@ class TransferTracker {
/// \p DbgOpStore is the map containing the DbgOpID->DbgOp mapping needed to
/// determine the values used by Value.
void loadVarInloc(MachineBasicBlock &MBB, DbgOpIDMap &DbgOpStore,
- const DenseMap<ValueIDNum, LocationAndQuality> &ValueToLoc,
+ const SmallVectorImpl<ValueLocPair> &ValueToLoc,
DebugVariable Var, DbgValue Value) {
SmallVector<DbgOp> DbgOps;
SmallVector<ResolvedDbgOp> ResolvedDbgOps;
@@ -373,9 +380,17 @@ class TransferTracker {
continue;
}
- // If the value has no location, we can't make a variable location.
+ // Search for the desired ValueIDNum, to examine the best location found
+ // for it. Use an empty ValueLocPair to search for an entry in ValueToLoc.
const ValueIDNum &Num = Op.ID;
- auto ValuesPreferredLoc = ValueToLoc.find(Num);
+ ValueLocPair Probe(Num, LocationAndQuality());
+ auto ValuesPreferredLoc = std::lower_bound(
+ ValueToLoc.begin(), ValueToLoc.end(), Probe, ValueToLocSort);
+
+ // There must be a legitimate entry found for Num.
+ assert(ValuesPreferredLoc != ValueToLoc.end() &&
+ ValuesPreferredLoc->first == Num);
+
if (ValuesPreferredLoc->second.isIllegal()) {
// If it's a def that occurs in this block, register it as a
// use-before-def to be resolved as we step through the block.
@@ -439,8 +454,9 @@ class TransferTracker {
UseBeforeDefs.clear();
UseBeforeDefVariables.clear();
- // Map of the preferred location for each value.
- DenseMap<ValueIDNum, LocationAndQuality> ValueToLoc;
+ // Mapping of the preferred locations for each value. Collected into this
+ // vector then sorted for easy searching.
+ SmallVector<ValueLocPair, 16> ValueToLoc;
// Initialized the preferred-location map with illegal locations, to be
// filled in later.
@@ -448,8 +464,10 @@ class TransferTracker {
if (VLoc.second.Kind == DbgValue::Def)
for (DbgOpID OpID : VLoc.second.getDbgOpIDs())
if (!OpID.ID.IsConst)
- ValueToLoc.insert({DbgOpStore.find(OpID).ID, LocationAndQuality()});
+ ValueToLoc.push_back(
+ {DbgOpStore.find(OpID).ID, LocationAndQuality()});
+ llvm::sort(ValueToLoc, ValueToLocSort);
ActiveMLocs.reserve(VLocs.size());
ActiveVLocs.reserve(VLocs.size());
@@ -464,8 +482,10 @@ class TransferTracker {
VarLocs.push_back(VNum);
// Is there a variable that wants a location for this value? If not, skip.
- auto VIt = ValueToLoc.find(VNum);
- if (VIt == ValueToLoc.end())
+ ValueLocPair Probe(VNum, LocationAndQuality());
+ auto VIt = std::lower_bound(ValueToLoc.begin(), ValueToLoc.end(), Probe,
+ ValueToLocSort);
+ if (VIt == ValueToLoc.end() || VIt->first != VNum)
continue;
auto &Previous = VIt->second;
More information about the llvm-commits
mailing list