1818#define LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H
1919
2020#include " GCNSubtarget.h"
21+ #include " SIMachineFunctionInfo.h"
22+ #include " Utils/AMDGPUBaseInfo.h"
2123#include " llvm/CodeGen/LiveIntervals.h"
2224#include " llvm/CodeGen/RegisterPressure.h"
2325#include < algorithm>
@@ -83,12 +85,12 @@ struct GCNRegPressure {
8385 }
8486 unsigned getSGPRTuplesWeight () const { return Value[TOTAL_KINDS + SGPR]; }
8587
86- unsigned getOccupancy ( const GCNSubtarget &ST,
87- unsigned DynamicVGPRBlockSize) const {
88- return std::min (ST. getOccupancyWithNumSGPRs ( getSGPRNum ()),
89- ST. getOccupancyWithNumVGPRs ( getVGPRNum (ST. hasGFX90AInsts ()),
90- DynamicVGPRBlockSize));
91- }
88+ // / Determines the occupancy achievable with the current RP, when \p
89+ // / BalanceVGPRUsage is true on subtargets with non-unified RFs, the
90+ // / occupancy w.r.t. the number of VGPRs is computed as if we will later be
91+ // / able to evenly balance out VGPR usage among ArchVGPR and AGPR banks.
92+ unsigned getOccupancy ( const GCNSubtarget &ST, unsigned DynamicVGPRBlockSize,
93+ bool BalanceVGPRUsage = false ) const ;
9294
9395 void inc (unsigned Reg,
9496 LaneBitmask PrevMask,
@@ -201,22 +203,34 @@ class GCNRPTarget {
201203 GCNRPTarget (unsigned Occupancy, const MachineFunction &MF,
202204 const GCNRegPressure &RP, bool CombineVGPRSavings = false );
203205
206+ // / Changes the target (same semantics as constructor).
207+ void setTarget (unsigned NumSGPRs, unsigned NumVGPRs,
208+ bool CombineVGPRSavings = false );
209+
204210 const GCNRegPressure &getCurrentRP () const { return RP; }
205211
206212 void setRP (const GCNRegPressure &NewRP) { RP = NewRP; }
207213
208214 // / Determines whether saving virtual register \p Reg will be beneficial
209215 // / towards achieving the RP target.
210- bool isSaveBeneficial (Register Reg, const MachineRegisterInfo &MRI ) const ;
216+ bool isSaveBeneficial (Register Reg) const ;
211217
212218 // / Saves virtual register \p Reg with lanemask \p Mask.
213- void saveReg (Register Reg, LaneBitmask Mask, const MachineRegisterInfo &MRI ) {
214- RP.inc (Reg, Mask, LaneBitmask::getNone (), MRI );
219+ void saveReg (Register Reg, LaneBitmask Mask) {
220+ RP.inc (Reg, Mask, LaneBitmask::getNone (), MF. getRegInfo () );
215221 }
216222
217223 // / Whether the current RP is at or below the defined pressure target.
218224 bool satisfied () const ;
219225
226+ // / Computes achievable occupancy with the currently tracked register pressure.
227+ unsigned getOccupancy () const {
228+ return RP.getOccupancy (
229+ MF.getSubtarget <GCNSubtarget>(),
230+ MF.getInfo <SIMachineFunctionInfo>()->getDynamicVGPRBlockSize (),
231+ /* BalanceVGPRUsage=*/ CombineVGPRSavings);
232+ }
233+
220234#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
221235 friend raw_ostream &operator <<(raw_ostream &OS, const GCNRPTarget &Target) {
222236 OS << " Actual/Target: " << Target.RP .getSGPRNum () << ' /' << Target.MaxSGPRs
@@ -236,6 +250,8 @@ class GCNRPTarget {
236250#endif
237251
238252private:
253+ const MachineFunction &MF;
254+
239255 // / Current register pressure.
240256 GCNRegPressure RP;
241257
@@ -248,7 +264,7 @@ class GCNRPTarget {
248264 unsigned MaxUnifiedVGPRs;
249265 // / Whether we consider that the register allocator will be able to swap
250266 // / between ArchVGPRs and AGPRs by copying them to a super register class.
251- // / Concretely, this allows savings in one of the VGPR banks to help toward
267+ // / Concretely, this allows free registers in one VGPR bank to help toward
252268 // / savings in the other VGPR bank.
253269 bool CombineVGPRSavings;
254270
@@ -266,9 +282,6 @@ class GCNRPTarget {
266282 return NumVGPRs > MaxVGPRs || !satisfiesUnifiedTarget () ||
267283 (CombineVGPRSavings && !satisifiesVGPRBanksTarget ());
268284 }
269-
270- void setRegLimits (unsigned MaxSGPRs, unsigned MaxVGPRs,
271- const MachineFunction &MF);
272285};
273286
274287// /////////////////////////////////////////////////////////////////////////////
0 commit comments