[llvm] [CodeGen] Preserve LiveStack analysis in StackSlotColoring pass (PR #94967)
Vikash Gupta via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 07:30:21 PDT 2024
https://github.com/vg0204 updated https://github.com/llvm/llvm-project/pull/94967
>From e13e0f881dbec891d4f57ae63649e8aa32d14773 Mon Sep 17 00:00:00 2001
From: vg0204 <Vikash.Gupta at amd.com>
Date: Mon, 10 Jun 2024 17:07:35 +0530
Subject: [PATCH] [CodeGen] Preserve LiveStack analysis in StackSlotColoring
pass
For some target architectures, stack slot coloring pass may be invoked
multiple times. It can occur due to the split of RA pass, opening up
the opportunity to optimize stack slots usage at each RA invocation.
In order to achieve that if we could keep stack analysis alive
uptil the invocation of the RA pass for the last time, it will save
up the overhead of recomputing live stack analysis after each RA.
This requires it to be preserved at stack slot coloring pass which
basically optimizes stack slots, but not makes the needed updates
in live stack results. This has been achieved here.
---
llvm/lib/CodeGen/StackSlotColoring.cpp | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp
index 9fdc8a338b52a..7bf966b21ebc1 100644
--- a/llvm/lib/CodeGen/StackSlotColoring.cpp
+++ b/llvm/lib/CodeGen/StackSlotColoring.cpp
@@ -149,6 +149,7 @@ namespace {
AU.addRequired<SlotIndexes>();
AU.addPreserved<SlotIndexes>();
AU.addRequired<LiveStacks>();
+ AU.addPreserved<LiveStacks>();
AU.addRequired<MachineBlockFrequencyInfo>();
AU.addPreserved<MachineBlockFrequencyInfo>();
AU.addPreservedID(MachineDominatorsID);
@@ -411,6 +412,23 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
}
}
+ // In order to preserve LiveStack analysis, the live ranges for dead spill
+ // stack slots would be merged with the live range of those stack slots that
+ // now share the spill object of the mentioned dead stack slot.
+ for (unsigned SS = 0, SE = SlotMapping.size(); SS != SE; ++SS) {
+ int NewFI = SlotMapping[SS];
+ if (SlotMapping[SS] == -1 || (NewFI == (int)SS)) {
+ continue;
+ }
+
+ LiveRange &lrToUpdateInto =
+ static_cast<LiveRange &>(LS->getInterval(NewFI));
+ const LiveRange &lrToUpdateFrom =
+ static_cast<LiveRange &>(LS->getInterval((int)SS));
+ lrToUpdateInto.MergeSegmentsInAsValue(lrToUpdateFrom,
+ lrToUpdateInto.getValNumInfo(0));
+ }
+
return true;
}
More information about the llvm-commits
mailing list