Currently, the custom SGPR spill lowering pass spills SGPRs into physical VGPR lanes and the remaining VGPRs are used by regalloc for vector regclass allocation. This imposes many restrictions that we ended up with unsuccessful SGPR spilling when there won't be enough VGPRs and we are forced to spill the leftover into memory during PEI. The custom spill handling during PEI has many edge cases and often breaks the compiler time to time. This patch implements spilling SGPRs into virtual VGPR lanes. Since we now split the register allocation for SGPRs and VGPRs, the virtual registers introduced for the spill lanes would get allocated automatically in the subsequent regalloc invocation for VGPRs. Spill to virtual registers will always be successful, even in the high-pressure situations, and hence it avoids most of the edge cases during PEI. We are now left with only the custom SGPR spills during PEI for special registers like the frame pointer which isn an unproblematic case. This patch also implements the whole wave spills which might occur if RA spills any live range of virtual registers involved in the whole wave operations. Earlier, we had been hand-picking registers for such machine operands. But now with SGPR spills into virtual VGPR lanes, we are exposing them to the allocator. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D124196
93 lines
3.9 KiB
C++
93 lines
3.9 KiB
C++
//===--------------------- SIFrameLowering.h --------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_SIFRAMELOWERING_H
|
|
#define LLVM_LIB_TARGET_AMDGPU_SIFRAMELOWERING_H
|
|
|
|
#include "AMDGPUFrameLowering.h"
|
|
#include "SIRegisterInfo.h"
|
|
|
|
namespace llvm {
|
|
|
|
class SIFrameLowering final : public AMDGPUFrameLowering {
|
|
public:
|
|
SIFrameLowering(StackDirection D, Align StackAl, int LAO,
|
|
Align TransAl = Align(1))
|
|
: AMDGPUFrameLowering(D, StackAl, LAO, TransAl) {}
|
|
~SIFrameLowering() override = default;
|
|
|
|
void emitEntryFunctionPrologue(MachineFunction &MF,
|
|
MachineBasicBlock &MBB) const;
|
|
void emitPrologue(MachineFunction &MF,
|
|
MachineBasicBlock &MBB) const override;
|
|
void emitEpilogue(MachineFunction &MF,
|
|
MachineBasicBlock &MBB) const override;
|
|
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
|
|
Register &FrameReg) const override;
|
|
|
|
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
|
|
RegScavenger *RS = nullptr) const override;
|
|
void determineCalleeSavesSGPR(MachineFunction &MF, BitVector &SavedRegs,
|
|
RegScavenger *RS = nullptr) const;
|
|
void determinePrologEpilogSGPRSaves(MachineFunction &MF, BitVector &SavedRegs,
|
|
bool NeedExecCopyReservedReg) const;
|
|
void emitCSRSpillStores(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator MBBI, DebugLoc &DL,
|
|
LivePhysRegs &LiveRegs, Register FrameReg,
|
|
Register FramePtrRegScratchCopy) const;
|
|
void emitCSRSpillRestores(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator MBBI, DebugLoc &DL,
|
|
LivePhysRegs &LiveRegs, Register FrameReg,
|
|
Register FramePtrRegScratchCopy) const;
|
|
bool
|
|
assignCalleeSavedSpillSlots(MachineFunction &MF,
|
|
const TargetRegisterInfo *TRI,
|
|
std::vector<CalleeSavedInfo> &CSI) const override;
|
|
|
|
bool allocateScavengingFrameIndexesNearIncomingSP(
|
|
const MachineFunction &MF) const override;
|
|
|
|
bool isSupportedStackID(TargetStackID::Value ID) const override;
|
|
|
|
void processFunctionBeforeFrameFinalized(
|
|
MachineFunction &MF,
|
|
RegScavenger *RS = nullptr) const override;
|
|
|
|
void processFunctionBeforeFrameIndicesReplaced(
|
|
MachineFunction &MF, RegScavenger *RS = nullptr) const override;
|
|
|
|
MachineBasicBlock::iterator
|
|
eliminateCallFramePseudoInstr(MachineFunction &MF,
|
|
MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator MI) const override;
|
|
|
|
private:
|
|
void emitEntryFunctionFlatScratchInit(MachineFunction &MF,
|
|
MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator I,
|
|
const DebugLoc &DL,
|
|
Register ScratchWaveOffsetReg) const;
|
|
|
|
Register getEntryFunctionReservedScratchRsrcReg(MachineFunction &MF) const;
|
|
|
|
void emitEntryFunctionScratchRsrcRegSetup(
|
|
MachineFunction &MF, MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator I, const DebugLoc &DL,
|
|
Register PreloadedPrivateBufferReg, Register ScratchRsrcReg,
|
|
Register ScratchWaveOffsetReg) const;
|
|
|
|
public:
|
|
bool hasFP(const MachineFunction &MF) const override;
|
|
|
|
bool requiresStackPointerReference(const MachineFunction &MF) const;
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_LIB_TARGET_AMDGPU_SIFRAMELOWERING_H
|