29#define DEBUG_TYPE "si-lower-sgpr-spills"
65char SILowerSGPRSpills::ID = 0;
68 "SI lower SGPR spill instructions",
false,
false)
97 Reg, Reg == RI->getReturnAddressReg(MF) ? MVT::i64 : MVT::i32);
103 const bool IsLiveIn =
MRI.isLiveIn(Reg);
110 Indexes->insertMachineInstrInMaps(Inst);
114 LIS->removeAllRegUnitsForPhysReg(Reg);
138 Reg, Reg == RI->getReturnAddressReg(MF) ? MVT::i64 : MVT::i32);
143 "loadRegFromStackSlot didn't insert any code!");
160void SILowerSGPRSpills::calculateSaveRestoreBlocks(
MachineFunction &MF) {
181 SaveBlocks.push_back(&MF.
front());
184 SaveBlocks.push_back(&
MBB);
186 RestoreBlocks.push_back(&
MBB);
210 TFI->determineCalleeSavesSGPR(MF, SavedRegs, RS);
213 if (!
F.hasFnAttribute(Attribute::Naked)) {
218 std::vector<CalleeSavedInfo> CSI;
221 for (
unsigned I = 0; CSRegs[
I]; ++
I) {
224 if (SavedRegs.
test(Reg)) {
226 TRI->getMinimalPhysRegClass(Reg, MVT::i32);
228 TRI->getSpillAlign(*RC),
true);
239 assert(SaveBlocks.size() == 1 &&
"shrink wrapping not fully implemented");
253 TII =
ST.getInstrInfo();
254 TRI = &
TII->getRegisterInfo();
256 LIS = getAnalysisIfAvailable<LiveIntervals>();
257 Indexes = getAnalysisIfAvailable<SlotIndexes>();
259 assert(SaveBlocks.empty() && RestoreBlocks.empty());
263 calculateSaveRestoreBlocks(MF);
264 bool HasCSRs = spillCalleeSavedRegs(MF);
272 RestoreBlocks.clear();
276 bool MadeChange =
false;
277 bool NewReservedRegs =
false;
281 const bool HasSGPRSpillToVGPR =
TRI->spillSGPRToVGPR() &&
282 (HasCSRs ||
FuncInfo->hasSpilledSGPRs());
283 if (HasSGPRSpillToVGPR) {
295 if (!
TII->isSGPRSpill(
MI))
298 int FI =
TII->getNamedOperand(
MI, AMDGPU::OpName::addr)->getIndex();
300 if (
FuncInfo->allocateSGPRSpillToVGPRLane(MF, FI)) {
301 NewReservedRegs =
true;
302 bool Spilled =
TRI->eliminateSGPRToVGPRSpillFrameIndex(
303 MI, FI,
nullptr, Indexes, LIS);
305 assert(Spilled &&
"failed to spill SGPR to VGPR when allocated");
313 for (
auto Reg :
FuncInfo->getSGPRSpillVGPRs())
322 if (
MI.isDebugValue() &&
MI.getOperand(0).isFI() &&
324 SpillFIs[
MI.getOperand(0).getIndex()]) {
325 MI.getOperand(0).ChangeToRegister(
Register(),
false );
335 FuncInfo->removeDeadFrameIndices(MFI,
false);
341 RestoreBlocks.clear();
345 MRI.freezeReservedRegs(MF);
unsigned const MachineRegisterInfo * MRI
Provides AMDGPU specific target descriptions.
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
typename CallsiteContextGraph< DerivedCCG, FuncTy, CallTy >::FuncInfo FuncInfo
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file declares the machine register scavenger class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void updateLiveness(MachineFunction &MF, ArrayRef< CalleeSavedInfo > CSI)
static void insertCSRRestores(MachineBasicBlock &RestoreBlock, MutableArrayRef< CalleeSavedInfo > CSI, SlotIndexes *Indexes, LiveIntervals *LIS)
Insert restore code for the callee-saved registers used in the function.
SI lower SGPR spill instructions
static void insertCSRSaves(MachineBasicBlock &SaveBlock, ArrayRef< CalleeSavedInfo > CSI, SlotIndexes *Indexes, LiveIntervals *LIS)
Insert spill code for the callee-saved registers used in the function.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool test(unsigned Idx) const
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
Store the specified register of the given register class to the specified stack frame index.
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
Load the specified register of the given register class from the specified stack frame index.
void removeAllRegUnitsForPhysReg(MCRegister Reg)
Remove associated live ranges for the register units associated with Reg.
Wrapper class representing physical registers. Should be passed by value.
void push_back(MachineInstr *MI)
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
void sortUniqueLiveIns()
Sorts and uniques the LiveIns vector.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
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.
MachineBasicBlock * getRestorePoint() const
void setCalleeSavedInfoValid(bool v)
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
uint8_t getStackID(int ObjectIdx) const
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
MachineBasicBlock * getSavePoint() const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
MachineInstrSpan provides an interface to get an iteration range containing the instruction it was in...
MachineBasicBlock::iterator begin()
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Wrapper class representing virtual and physical registers.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
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.
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
char & SILowerSGPRSpillsID
auto reverse(ContainerTy &&C)