[llvm] [CodeGen] Preserve LiveStack analysis in StackSlotColoring pass (PR #94967)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 09:32:53 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-regalloc

Author: Vikash Gupta (vg0204)

<details>
<summary>Changes</summary>

This PR originated as a follow-up requirement from #<!-- -->93668.

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 after each RA invocation.

In order to achieve that if we could keep livestack analysis alive uptil the invocation of the RA pass for the last time in pipeline, it would save up the overhead of recomputing live stack analysis after each RA. Thus, livestack result 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 in this patch.

---
Full diff: https://github.com/llvm/llvm-project/pull/94967.diff


1 Files Affected:

- (modified) llvm/lib/CodeGen/StackSlotColoring.cpp (+18) 


``````````diff
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;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/94967


More information about the llvm-commits mailing list