From 5ecbcc207c14a81f3ce006579854307997d26821 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 30 Nov 2021 19:34:59 -0500 Subject: [PATCH] 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. --- .../include/llvm/CodeGen/RegisterScavenging.h | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/llvm/include/llvm/CodeGen/RegisterScavenging.h b/llvm/include/llvm/CodeGen/RegisterScavenging.h index 218e05f6eb6b..1f0cd273bf61 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);