35 #define DEBUG_TYPE "si-lower-sgpr-spills" 42 "amdgpu-spill-vgpr-to-agpr",
43 cl::desc(
"Enable spilling VGPRs to AGPRs"),
80 "SI lower SGPR spill instructions",
false,
false)
100 unsigned Reg = CS.getReg();
112 LIS->InsertMachineInstrInMaps(Inst);
113 LIS->removeAllRegUnitsForPhysReg(Reg);
121 std::vector<CalleeSavedInfo> &CSI,
135 unsigned Reg = CI.getReg();
140 "loadRegFromStackSlot didn't insert any code!");
155 void SILowerSGPRSpills::calculateSaveRestoreBlocks(
MachineFunction &MF) {
170 if (!RestoreBlock->succ_empty() || RestoreBlock->isReturnBlock())
176 SaveBlocks.push_back(&MF.
front());
178 if (MBB.isEHFuncletEntry())
179 SaveBlocks.push_back(&MBB);
180 if (MBB.isReturnBlock())
181 RestoreBlocks.push_back(&MBB);
195 TFI->determineCalleeSavesSGPR(MF, SavedRegs, RS);
203 std::vector<CalleeSavedInfo> CSI;
206 for (
unsigned I = 0; CSRegs[
I]; ++
I) {
207 unsigned Reg = CSRegs[
I];
208 if (SavedRegs.
test(Reg)) {
236 VRM = getAnalysisIfAvailable<VirtRegMap>();
238 assert(SaveBlocks.empty() && RestoreBlocks.empty());
242 calculateSaveRestoreBlocks(MF);
243 bool HasCSRs = spillCalleeSavedRegs(MF);
248 RestoreBlocks.clear();
255 && EnableSpillVGPRToAGPR;
257 bool MadeChange =
false;
259 const bool SpillToAGPR = EnableSpillVGPRToAGPR && ST.
hasMAIInsts();
263 if ((TRI->spillSGPRToVGPR() && (HasCSRs || FuncInfo->
hasSpilledSGPRs())) ||
272 for (
auto I = MBB.begin(),
E = MBB.end(); I !=
E; I = Next) {
276 if (SpillToAGPR && TII->isVGPRSpill(MI)) {
280 AMDGPU::OpName::vaddr);
283 TII->getNamedOperand(MI, AMDGPU::OpName::vdata)->getReg();
285 TRI->isAGPR(MRI, VReg))) {
291 if (!TII->isSGPRSpill(MI))
294 int FI = TII->getNamedOperand(MI, AMDGPU::OpName::addr)->getIndex();
297 bool Spilled = TRI->eliminateSGPRToVGPRSpillFrameIndex(MI, FI,
nullptr);
299 assert(Spilled &&
"failed to spill SGPR to VGPR when allocated");
306 MBB.addLiveIn(SSpill.VGPR);
314 MBB.sortUniqueLiveIns();
321 RestoreBlocks.clear();
bool allocateVGPRSpillToAGPR(MachineFunction &MF, int FI, bool isAGPRtoVGPR)
Reserve AGPRs or VGPRs to support spilling for FrameIndex FI.
AMDGPU specific subclass of TargetSubtarget.
void setCalleeSavedInfoValid(bool v)
This class represents lattice values for constants.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool test(unsigned Idx) const
const SIInstrInfo * getInstrInfo() const override
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
unsigned const TargetRegisterInfo * TRI
bool hasSpilledVGPRs() const
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
MachineInstrSpan provides an interface to get an iteration range containing the instruction it was in...
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class...
#define INITIALIZE_PASS_DEPENDENCY(depName)
ArrayRef< MCPhysReg > getAGPRSpillVGPRs() const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
MachineBasicBlock * getRestorePoint() const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
SlotIndex InsertMachineInstrInMaps(MachineInstr &MI)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const =0
This method must be overriden to eliminate abstract frame indices from instructions which may use the...
virtual const TargetInstrInfo * getInstrInfo() const
bool allocateSGPRSpillToVGPR(MachineFunction &MF, int FI)
Reserve a slice of a VGPR to support spilling for FrameIndex FI.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
TargetInstrInfo - Interface to description of machine instruction set.
initializer< Ty > init(const Ty &Val)
unsigned const MachineRegisterInfo * MRI
void removeAllRegUnitsForPhysReg(unsigned Reg)
Remove associated live ranges for the register units associated with Reg.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static void insertCSRRestores(MachineBasicBlock &RestoreBlock, std::vector< CalleeSavedInfo > &CSI, LiveIntervals *LIS)
Insert restore code for the callee-saved registers used in the function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const SIFrameLowering * getFrameLowering() const override
Represent the analysis usage information of a pass.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
static void insertCSRSaves(MachineBasicBlock &SaveBlock, ArrayRef< CalleeSavedInfo > CSI, LiveIntervals *LIS)
Insert restore code for the callee-saved registers used in the function.
ArrayRef< SGPRSpillVGPRCSR > getSGPRSpillVGPRs() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
bool hasSpilledSGPRs() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Information about stack frame layout on the target.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
void setPreservesAll()
Set by analyses that do not transform their input at all.
char & SILowerSGPRSpillsID
virtual void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
Store the specified register of the given register class to the specified stack frame index...
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void push_back(MachineInstr *MI)
virtual const TargetFrameLowering * getFrameLowering() const
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
uint8_t getStackID(int ObjectIdx) const
MachineBasicBlock * getSavePoint() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
INITIALIZE_PASS_BEGIN(SILowerSGPRSpills, DEBUG_TYPE, "SI lower SGPR spill instructions", false, false) INITIALIZE_PASS_END(SILowerSGPRSpills
inst_range instructions(Function *F)
ArrayRef< MCPhysReg > getVGPRSpillAGPRs() const
const MachineOperand & getOperand(unsigned i) const
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
Load the specified register of the given register class from the specified stack frame index...
Wrapper class representing virtual and physical registers.
MachineBasicBlock::iterator begin()
const SIRegisterInfo * getRegisterInfo() const override