17#ifndef LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H
18#define LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H
36 const char *Names[] = {
"SGPR",
"VGPR",
"AGPR",
"AVGPR"};
61 if (UnifiedVGPRFile) {
79 return alignTo(NumArchVGPRs + NumAVGPRs,
99 unsigned DynamicVGPRBlockSize)
const {
100 return std::min(ST.getOccupancyWithNumSGPRs(
getSGPRNum()),
101 ST.getOccupancyWithNumVGPRs(
getVGPRNum(ST.hasGFX90AInsts()),
102 DynamicVGPRBlockSize));
111 unsigned DynamicVGPRBlockSize)
const {
113 O.getOccupancy(ST, DynamicVGPRBlockSize);
129 unsigned MaxOccupancy = std::numeric_limits<unsigned>::max())
const;
134 return !(*
this == O);
138 for (
unsigned I = 0;
I < ValueArraySize; ++
I)
139 Value[
I] +=
RHS.Value[
I];
144 for (
unsigned I = 0;
I < ValueArraySize; ++
I)
145 Value[
I] -=
RHS.Value[
I];
158 static constexpr unsigned ValueArraySize =
TOTAL_KINDS * 2;
162 std::array<unsigned, ValueArraySize>
Value;
171 unsigned DynamicVGPRBlockSize);
176 for (
unsigned I = 0;
I < GCNRegPressure::ValueArraySize; ++
I)
177 Res.Value[
I] = std::max(P1.Value[
I], P2.Value[
I]);
220 void setTarget(
unsigned NumSGPRs,
unsigned NumVGPRs);
238#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
240 OS <<
"Actual/Target: " <<
Target.RP.getSGPRNum() <<
'/' <<
Target.MaxSGPRs
241 <<
" SGPRs, " <<
Target.RP.getArchVGPRNum() <<
'/' <<
Target.MaxVGPRs
242 <<
" ArchVGPRs, " <<
Target.RP.getAGPRNum() <<
'/' <<
Target.MaxVGPRs
245 if (
Target.MaxUnifiedVGPRs) {
246 OS <<
", " <<
Target.RP.getVGPRNum(
true) <<
'/' <<
Target.MaxUnifiedVGPRs
247 <<
" VGPRs (unified)";
255 const bool UnifiedRF;
266 unsigned MaxUnifiedVGPRs;
269 : MF(MF), UnifiedRF(MF.getSubtarget<
GCNSubtarget>().hasGFX90AInsts()),
315 const MachineRegisterInfo &
MRI,
335 reset(
MBB.getParent()->getRegInfo(), MBBLastSlot);
340 reset(
MI.getMF()->getRegInfo(),
LIS.getInstructionIndex(
MI).getDeadSlot());
400 bool UseInternalIterator =
true);
409 bool UseInternalIterator =
true);
441 const LiveIntervals &LIS,
442 const MachineRegisterInfo &
MRI,
446 const MachineRegisterInfo &
MRI,
454template <
typename Range>
455DenseMap<MachineInstr*, GCNRPTracker::LiveRegSet>
457 std::vector<SlotIndex> Indexes;
458 Indexes.reserve(std::distance(R.begin(), R.end()));
461 auto SI = SII.getInstructionIndex(*
I);
462 Indexes.push_back(After ?
SI.getDeadSlot() :
SI.getBaseIndex());
466 auto &
MRI = (*R.begin())->getParent()->getParent()->getRegInfo();
469 for (
unsigned I = 0,
E =
MRI.getNumVirtRegs();
I !=
E; ++
I) {
475 if (!LI.findIndexesLiveAt(Indexes, std::back_inserter(LiveIdxs)))
477 if (!LI.hasSubRanges()) {
478 for (
auto SI : LiveIdxs)
479 LiveRegMap[SII.getInstructionFromIndex(
SI)][
Reg] =
480 MRI.getMaxLaneMaskForVReg(
Reg);
482 for (
const auto &S : LI.subranges()) {
485 S.findIndexesLiveAt(LiveIdxs, std::back_inserter(SRLiveIdxs));
486 for (
auto SI : SRLiveIdxs)
487 LiveRegMap[SII.getInstructionFromIndex(
SI)][
Reg] |= S.LaneMask;
496 MI.getParent()->getParent()->getRegInfo());
502 MI.getParent()->getParent()->getRegInfo());
505template <
typename Range>
517Printable
print(
const GCNRegPressure &RP,
const GCNSubtarget *ST =
nullptr,
518 unsigned DynamicVGPRBlockSize = 0);
521 const MachineRegisterInfo &
MRI);
525 const TargetRegisterInfo *
TRI, StringRef Pfx =
" ");
545 const MachineLoopInfo *MLI);
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
Register const TargetRegisterInfo * TRI
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
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),...
GCNRegPressure moveMaxPressure()
return MaxPressure and clear it.
bool advanceBeforeNext(MachineInstr *MI=nullptr, bool UseInternalIterator=true)
Move to the state right before the next MI or after the end of MBB.
bool advance(MachineInstr *MI=nullptr, bool UseInternalIterator=true)
Move to the state at the next MI.
GCNRegPressure bumpDownwardPressure(const MachineInstr *MI, const SIRegisterInfo *TRI) const
Mostly copy/paste from CodeGen/RegisterPressure.cpp Calculate the impact MI will have on CurPressure ...
MachineBasicBlock::const_iterator getNext() const
GCNDownwardRPTracker(const LiveIntervals &LIS_)
bool reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)
Reset tracker to the point before the MI filling LiveRegs upon this point using LIS.
void advanceToNext(MachineInstr *MI=nullptr, bool UseInternalIterator=true)
Move to the state at the MI, advanceBeforeNext has to be called first.
GCNRPTarget(const MachineFunction &MF, const GCNRegPressure &RP)
Sets up the target such that the register pressure starting at RP does not show register spilling on ...
bool isSaveBeneficial(Register Reg) const
Determines whether saving virtual register Reg will be beneficial towards achieving the RP target.
void saveReg(Register Reg, LaneBitmask Mask, const MachineRegisterInfo &MRI)
Saves virtual register Reg with lanemask Mask.
bool satisfied() const
Whether the current RP is at or below the defined pressure target.
void setRP(const GCNRegPressure &NewRP)
const GCNRegPressure & getCurrentRP() const
void setTarget(unsigned NumSGPRs, unsigned NumVGPRs)
Changes the target (same semantics as constructor).
friend raw_ostream & operator<<(raw_ostream &OS, const GCNRPTarget &Target)
GCNRegPressure getPressure() const
const decltype(LiveRegs) & getLiveRegs() const
const MachineInstr * LastTrackedMI
decltype(LiveRegs) moveLiveRegs()
GCNRegPressure CurPressure
DenseMap< unsigned, LaneBitmask > LiveRegSet
GCNRPTracker(const LiveIntervals &LIS_)
GCNRegPressure MaxPressure
void reset(const MachineInstr &MI, const LiveRegSet *LiveRegsCopy, bool After)
LaneBitmask getLastUsedLanes(Register RegUnit, SlotIndex Pos) const
Mostly copy/paste from CodeGen/RegisterPressure.cpp.
void bumpDeadDefs(ArrayRef< VRegMaskOrUnit > DeadDefs)
Mostly copy/paste from CodeGen/RegisterPressure.cpp.
const MachineInstr * getLastTrackedMI() const
const MachineRegisterInfo * MRI
const LiveIntervals & LIS
GCNUpwardRPTracker(const LiveIntervals &LIS_)
GCNRegPressure getMaxPressureAndReset()
void reset(const MachineRegisterInfo &MRI, SlotIndex SI)
reset tracker at the specified slot index SI.
void recede(const MachineInstr &MI)
Move to the state of RP just before the MI .
const GCNRegPressure & getMaxPressure() const
void reset(const MachineBasicBlock &MBB)
reset tracker to the end of the MBB.
bool isValid() const
returns whether the tracker's state after receding MI corresponds to reported by LIS.
void reset(const MachineInstr &MI)
reset tracker to the point just after MI (in program order).
bool hasInterval(Register Reg) const
SlotIndexes * getSlotIndexes() const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
LiveInterval & getInterval(Register Reg)
A set of live virtual registers and physical register units.
MachineInstrBundleIterator< const MachineInstr > const_iterator
MachineFunctionPass(char &ID)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Simple wrapper around std::function<void(raw_ostream&)>.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Target - Wrapper for Target specific information.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned getArchVGPRAllocGranule()
For subtargets with a unified VGPR file and mixed ArchVGPR/AGPR usage, returns the allocation granule...
This is an optimization pass for GlobalISel generic memory operations.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LaneBitmask getLiveLaneMask(unsigned Reg, SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI, LaneBitmask LaneMaskFilter=LaneBitmask::getAll())
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
GCNRPTracker::LiveRegSet getLiveRegs(SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI, GCNRegPressure::RegKind RegKind=GCNRegPressure::TOTAL_KINDS)
GCNRegPressure getRegPressure(const MachineRegisterInfo &MRI, Range &&LiveRegs)
GCNRPTracker::LiveRegSet getLiveRegsAfter(const MachineInstr &MI, const LiveIntervals &LIS)
void sort(IteratorTy Start, IteratorTy End)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
DenseMap< MachineInstr *, GCNRPTracker::LiveRegSet > getLiveRegMap(Range &&R, bool After, LiveIntervals &LIS)
creates a map MachineInstr -> LiveRegSet R - range of iterators on instructions After - upon entry or...
APInt operator+(APInt a, const APInt &b)
GCNRPTracker::LiveRegSet getLiveRegsBefore(const MachineInstr &MI, const LiveIntervals &LIS)
LLVM_ABI void dumpMaxRegPressure(MachineFunction &MF, GCNRegPressure::RegKind Kind, LiveIntervals &LIS, const MachineLoopInfo *MLI)
Printable reportMismatch(const GCNRPTracker::LiveRegSet &LISLR, const GCNRPTracker::LiveRegSet &TrackedL, const TargetRegisterInfo *TRI, StringRef Pfx=" ")
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
static RegKind getRegKind(unsigned Reg, const MachineRegisterInfo &MRI)
static constexpr const char * getName(RegKind Kind)
bool operator!=(const GCNRegPressure &O) const
GCNRegPressure & operator+=(const GCNRegPressure &RHS)
unsigned getNumRegs(RegKind Kind) const
unsigned getVGPRTuplesWeight() const
GCNRegPressure & operator-=(const GCNRegPressure &RHS)
unsigned getVGPRNum(bool UnifiedVGPRFile) const
friend Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST, unsigned DynamicVGPRBlockSize)
unsigned getOccupancy(const GCNSubtarget &ST, unsigned DynamicVGPRBlockSize) const
friend GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
void inc(unsigned Reg, LaneBitmask PrevMask, LaneBitmask NewMask, const MachineRegisterInfo &MRI)
bool higherOccupancy(const GCNSubtarget &ST, const GCNRegPressure &O, unsigned DynamicVGPRBlockSize) const
unsigned getArchVGPRNum() const
unsigned getAGPRNum() const
unsigned getSGPRNum() const
unsigned getSGPRTuplesWeight() const
bool operator==(const GCNRegPressure &O) const
static unsigned getUnifiedVGPRNum(unsigned NumArchVGPRs, unsigned NumAGPRs, unsigned NumAVGPRs)
Returns the aggregated VGPR pressure, assuming NumArchVGPRs ArchVGPRs NumAGPRs AGPRS,...
unsigned getAVGPRNum() const
bool less(const MachineFunction &MF, const GCNRegPressure &O, unsigned MaxOccupancy=std::numeric_limits< unsigned >::max()) const
Compares this GCNRegpressure to O, returning true if this is less.
static constexpr LaneBitmask getAll()
static constexpr LaneBitmask getNone()