[llvm] [LiveDebugValues] Generalize approach to find stack units, NFC (PR #124862)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 28 16:12:05 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-debuginfo
Author: Emma Pilkington (epilk)
<details>
<summary>Changes</summary>
On x86_64 this produces an identical set of stack units, however on other targets (e.g. AMDGPU) this can significantly improve compile time performance. Fixes SWDEV-508735.
---
Full diff: https://github.com/llvm/llvm-project/pull/124862.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp (+23-21)
``````````diff
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 2510b77c6d5be4..bd8d64fbb6c50f 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -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;
+ for (auto Pair : AllSlotsBySize) {
+ unsigned Start = Pair.first.second;
+ unsigned End = Start + Pair.first.first;
+ if (End > SlotCoverage.size()) {
+ SlotCoverage.resize(End, false);
+ ThisSlot.resize(End, false);
+ }
+
+ ThisSlot.reset();
+ ThisSlot.set(Start, End);
+
+ if (!SlotCoverage.anyCommon(ThisSlot)) {
+ SlotCoverage |= ThisSlot;
+ Slots.push_back(Pair.second);
+ }
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/124862
More information about the llvm-commits
mailing list