diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp index fb4682232303..492a92a4d8a3 100644 --- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp @@ -1298,3 +1298,34 @@ bool SIRegisterInfo::shouldCoalesce(MachineInstr *MI, return NewSize <= DstSize || NewSize <= SrcSize; } + +unsigned SIRegisterInfo::getRegPressureLimit(const TargetRegisterClass *RC, + MachineFunction &MF) const { + + const SISubtarget &ST = MF.getSubtarget(); + const SIMachineFunctionInfo *MFI = MF.getInfo(); + + unsigned Occupancy = ST.getOccupancyWithLocalMemSize(MFI->getLDSSize(), + *MF.getFunction()); + switch (RC->getID()) { + default: + return AMDGPURegisterInfo::getRegPressureLimit(RC, MF); + case AMDGPU::VGPR_32RegClassID: + return std::min(ST.getMaxNumVGPRs(Occupancy), ST.getMaxNumVGPRs(MF)); + case AMDGPU::SGPR_32RegClassID: + return std::min(ST.getMaxNumSGPRs(Occupancy, true), ST.getMaxNumSGPRs(MF)); + } +} + +unsigned SIRegisterInfo::getRegPressureSetLimit(const MachineFunction &MF, + unsigned Idx) const { + if (Idx == getVGPRPressureSet()) + return getRegPressureLimit(&AMDGPU::VGPR_32RegClass, + const_cast(MF)); + + if (Idx == getSGPRPressureSet()) + return getRegPressureLimit(&AMDGPU::SGPR_32RegClass, + const_cast(MF)); + + return AMDGPURegisterInfo::getRegPressureSetLimit(MF, Idx); +} diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.h b/llvm/lib/Target/AMDGPU/SIRegisterInfo.h index c75a45268573..4330e6106815 100644 --- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.h +++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.h @@ -205,6 +205,12 @@ public: unsigned DstSubReg, const TargetRegisterClass *NewRC) const override; + unsigned getRegPressureLimit(const TargetRegisterClass *RC, + MachineFunction &MF) const override; + + unsigned getRegPressureSetLimit(const MachineFunction &MF, + unsigned Idx) const override; + private: void buildSpillLoadStore(MachineBasicBlock::iterator MI, unsigned LoadStoreOp,