[llvm] [LiveDebugValues] Generalize approach to find stack units, NFC (PR #124862)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 09:56:48 PST 2025
================
@@ -2514,27 +2514,29 @@ bool InstrRefBasedLDV::mlocJoin(
void InstrRefBasedLDV::findStackIndexInterference(
SmallVectorImpl<unsigned> &Slots) {
- // We could spend a bit of time finding the exact, minimal, set of stack
- // indexes that interfere with each other, much like reg units. Or, we can
- // rely on the fact that:
- // * The smallest / lowest index will interfere with everything at zero
- // offset, which will be the largest set of registers,
- // * Most indexes with non-zero offset will end up being interference units
- // anyway.
- // So just pick those out and return them.
-
- // We can rely on a single-byte stack index existing already, because we
- // initialize them in MLocTracker.
- auto It = MTracker->StackSlotIdxes.find({8, 0});
- assert(It != MTracker->StackSlotIdxes.end());
- Slots.push_back(It->second);
-
- // Find anything that has a non-zero offset and add that too.
- for (auto &Pair : MTracker->StackSlotIdxes) {
- // Is offset zero? If so, ignore.
- if (!Pair.first.second)
- continue;
- Slots.push_back(Pair.second);
+ // Find the exact, minimal, set of stack indexes that interfere with each
+ // other, much like reg units.
+ SmallVector<std::pair<MLocTracker::StackSlotPos, unsigned>> AllSlotsBySize(
+ MTracker->StackSlotIdxes.begin(), MTracker->StackSlotIdxes.end());
+ std::sort(AllSlotsBySize.begin(), AllSlotsBySize.end(),
+ [](auto L, auto R) { return L.first.first < R.first.first; });
+
+ BitVector SlotCoverage, ThisSlot;
----------------
jmorse wrote:
A comment outlining the algorithm will help future readers; "Find the largest slot, then add any further non-overlapping slots in order of size" if I'm reading it right?
https://github.com/llvm/llvm-project/pull/124862
More information about the llvm-commits
mailing list