[PATCH] D115399: RegScavenger: Add function to externally reserve a scavenging index

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 8 14:02:06 PST 2021


arsenm created this revision.
arsenm added reviewers: qcolombet, MatzeB, kparzysz, craig.topper.
Herald added subscribers: arphaman, tpr.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

AMDGPU separately tracks the frame index we use for the emergency
spill slot. In the case where we need to spill SGPRs to memory, we
manually handle the save and restore. In other cases, the scavenger
handles the spills normally.

      

In a future change, I will need to add a second scavenging index in
order to free a second register in case we are spilling to a large
offset and also have to avoid clobbering a condition register
(SCC). In the intersection of these two cases, we will end up
recursively calling eliminateFrameIndex. We need to report to the
scavenger that the first scavenging frame index is unavailable, and
that the register is already used to avoid double spilling to the
scavenging slot (and avoid clobbering the previously evicted register,
and getting the same register for both scavenge calls).

This is really ugly but I don't see a better way without requiring
targets to be far more aware of how the scavenger iterator is
advanced.


https://reviews.llvm.org/D115399

Files:
  llvm/include/llvm/CodeGen/RegisterScavenging.h


Index: llvm/include/llvm/CodeGen/RegisterScavenging.h
===================================================================
--- llvm/include/llvm/CodeGen/RegisterScavenging.h
+++ llvm/include/llvm/CodeGen/RegisterScavenging.h
@@ -70,6 +70,26 @@
 public:
   RegScavenger() = default;
 
+  /// Record that \p Reg is in use at scavenging index \p FI. This is for
+  /// targets which need to directly manage the spilling process, and need to
+  /// update the scavenger's internal state.  It's expected this be called a
+  /// second time with \p Restore set to a non-null value, so that the
+  /// externally inserted restore instruction resets the scavenged slot
+  /// liveness when encountered.
+  void assignRegToScavengingIndex(int FI, Register Reg,
+                                  MachineInstr *Restore = nullptr) {
+    for (ScavengedInfo &Slot : Scavenged) {
+      if (Slot.FrameIndex == FI) {
+        assert(!Slot.Reg || Slot.Reg == Reg);
+        Slot.Reg = Reg;
+        Slot.Restore = Restore;
+        return;
+      }
+    }
+
+    llvm_unreachable("did not find scavenging index");
+  }
+
   /// Start tracking liveness from the begin of basic block \p MBB.
   void enterBasicBlock(MachineBasicBlock &MBB);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115399.392930.patch
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211208/8e78f271/attachment.bin>


More information about the llvm-commits mailing list