[llvm] 5ecbcc2 - RegScavenger: Add function to externally reserve a scavenging index

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 2 16:15:56 PST 2022


Author: Matt Arsenault
Date: 2022-02-02T19:15:52-05:00
New Revision: 5ecbcc207c14a81f3ce006579854307997d26821

URL: https://github.com/llvm/llvm-project/commit/5ecbcc207c14a81f3ce006579854307997d26821
DIFF: https://github.com/llvm/llvm-project/commit/5ecbcc207c14a81f3ce006579854307997d26821.diff

LOG: RegScavenger: Add function to externally reserve a scavenging index

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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/RegisterScavenging.h b/llvm/include/llvm/CodeGen/RegisterScavenging.h
index 218e05f6eb6b3..1f0cd273bf618 100644
--- a/llvm/include/llvm/CodeGen/RegisterScavenging.h
+++ b/llvm/include/llvm/CodeGen/RegisterScavenging.h
@@ -70,6 +70,26 @@ class RegScavenger {
 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);
 


        


More information about the llvm-commits mailing list