summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/StackColoring.cpp
diff options
context:
space:
mode:
authormohammed-nurulhoque <96180492+mohammed-nurulhoque@users.noreply.github.com>2023-12-13 12:01:21 +0000
committerGitHub <noreply@github.com>2023-12-13 13:01:21 +0100
commita29457844bf0c4b2eb5c0f3877b6e8ef30cdef52 (patch)
treeaff00f86da198d83c7cb532d65c6846c83559f12 /llvm/lib/CodeGen/StackColoring.cpp
parentea0e9cbdc0592af1dc0284ed73df7a3fb42749ba (diff)
[StackColoring] Delete dead stack slots (#72633)
Deletes slots that have lifetime markers and the lifetime ranges are empty.
Diffstat (limited to 'llvm/lib/CodeGen/StackColoring.cpp')
-rw-r--r--llvm/lib/CodeGen/StackColoring.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index 37f7aa929005..0f298f5c9c09 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -900,6 +900,15 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
unsigned FixedMemOp = 0;
unsigned FixedDbg = 0;
+ // Remove debug information for deleted slots.
+ erase_if(MF->getVariableDbgInfo(), [&](auto &VI) {
+ if (!VI.inStackSlot())
+ return false;
+ int Slot = VI.getStackSlot();
+ return Slot >= 0 && Intervals[Slot]->empty() &&
+ InterestingSlots.test(Slot) && !ConservativeSlots.test(Slot);
+ });
+
// Remap debug information that refers to stack slots.
for (auto &VI : MF->getVariableDbgInfo()) {
if (!VI.Var || !VI.inStackSlot())
@@ -1250,8 +1259,15 @@ bool StackColoring::runOnMachineFunction(MachineFunction &Func) {
// Do not bother looking at empty intervals.
for (unsigned I = 0; I < NumSlots; ++I) {
- if (Intervals[SortedSlots[I]]->empty())
+ int Slot = SortedSlots[I];
+ if (Intervals[Slot]->empty()) {
+ if (InterestingSlots.test(Slot) && !ConservativeSlots.test(Slot)) {
+ RemovedSlots += 1;
+ ReducedSize += MFI->getObjectSize(Slot);
+ MFI->RemoveStackObject(Slot);
+ }
SortedSlots[I] = -1;
+ }
}
// This is a simple greedy algorithm for merging allocas. First, sort the