15 #ifndef LLVM_CODEGEN_REGISTERPRESSURE_H
16 #define LLVM_CODEGEN_REGISTERPRESSURE_H
26 class RegisterClassInfo;
34 : RegUnit(RegUnit), LaneMask(LaneMask) {}
99 assert(
id < UINT16_MAX &&
"PSetID overflow.");
116 return PSetID == RHS.PSetID && UnitInc == RHS.UnitInc;
133 enum { MaxPSets = 16 };
138 iterator nonconst_begin() {
return &PressureChanges[0]; }
139 iterator nonconst_end() {
return &PressureChanges[MaxPSets]; }
194 void init(
unsigned N);
197 assert(Idx < Size &&
"PressureDiff index out of bounds");
198 return PDiffArray[Idx];
245 struct IndexMaskPair {
249 IndexMaskPair(
unsigned Index,
LaneBitmask LaneMask)
250 : Index(Index), LaneMask(LaneMask) {}
252 unsigned getSparseSetIndex()
const {
259 unsigned NumRegUnits;
261 unsigned getSparseIndexFromReg(
unsigned Reg)
const {
264 assert(Reg < NumRegUnits);
267 unsigned getRegFromSparseIndex(
unsigned SparseIndex)
const {
268 if (SparseIndex >= NumRegUnits)
278 unsigned SparseIndex = getSparseIndexFromReg(Reg);
288 unsigned SparseIndex = getSparseIndexFromReg(Pair.
RegUnit);
289 auto InsertRes = Regs.
insert(IndexMaskPair(SparseIndex, Pair.
LaneMask));
290 if (!InsertRes.second) {
292 InsertRes.first->LaneMask |= Pair.
LaneMask;
301 unsigned SparseIndex = getSparseIndexFromReg(Pair.
RegUnit);
314 template<
typename ContainerT>
316 for (
const IndexMaskPair &
P : Regs) {
317 unsigned Reg = getRegFromSparseIndex(
P.Index);
318 if (
P.LaneMask.any())
355 bool RequireIntervals;
358 bool TrackUntiedDefs;
369 std::vector<unsigned> CurrSetPressure;
377 std::vector<unsigned> LiveThruPressure;
381 MF(nullptr), TRI(nullptr), RCI(nullptr), LIS(nullptr), MBB(nullptr), P(rp),
382 RequireIntervals(
true), TrackUntiedDefs(
false), TrackLaneMasks(
false) {}
385 MF(nullptr), TRI(nullptr), RCI(nullptr), LIS(nullptr), MBB(nullptr), P(rp),
386 RequireIntervals(
false), TrackUntiedDefs(
false), TrackLaneMasks(
false) {}
393 bool TrackLaneMasks,
bool TrackUntiedDefs);
439 LiveThruPressure.assign(PressureSet.
begin(), PressureSet.
end());
452 return CurrSetPressure;
504 std::vector<unsigned> &PressureResult,
505 std::vector<unsigned> &MaxPressureResult);
509 std::vector<unsigned> &PressureResult,
510 std::vector<unsigned> &MaxPressureResult);
513 std::vector<unsigned> &PressureResult,
514 std::vector<unsigned> &MaxPressureResult) {
523 return UntiedDefs.count(VirtReg);
557 const TargetRegisterInfo *TRI);
void dump(const TargetRegisterInfo *TRI) const
void addInstruction(unsigned Idx, const RegisterOperands &RegOpers, const MachineRegisterInfo &MRI)
Record pressure difference induced by the given operand list to node with index Idx.
void getPressureAfterInst(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
void detectDeadDefs(const MachineInstr &MI, const LiveIntervals &LIS)
Use liveness information to find dead defs not marked with a dead flag and move them to the DeadDefs ...
void bumpDeadDefs(ArrayRef< RegisterMaskPair > DeadDefs)
static unsigned virtReg2Index(unsigned Reg)
Convert a virtual register number to a 0-based index.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
void addPressureChange(unsigned RegUnit, bool IsDec, const MachineRegisterInfo *MRI)
Add a change in pressure to the pressure diff of a given instruction.
void init(unsigned N)
Initialize an array of N PressureDiffs.
bool operator==(const PressureChange &RHS) const
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
RegisterMaskPair(unsigned RegUnit, LaneBitmask LaneMask)
void decreaseRegPressure(unsigned RegUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)
void appendTo(ContainerT &To) const
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned RegUnit
Virtual register or register unit.
SmallVector< RegisterMaskPair, 8 > DeadDefs
List of virtual registers and register units defined by the instruction but dead. ...
void closeRegion()
Finalize the region boundaries and recored live ins and live outs.
bool isTopClosed() const
Does this pressure result have a valid top position and live ins.
void openBottom(MachineBasicBlock::const_iterator PrevBottom)
If the current bottom is the previous instr (before advancing), open it.
MachineBasicBlock::const_iterator getPos() const
Get the MI position corresponding to this register pressure.
void discoverLiveInOrOut(RegisterMaskPair Pair, SmallVectorImpl< RegisterMaskPair > &LiveInOrOut)
void recede(SmallVectorImpl< RegisterMaskPair > *LiveUses=nullptr)
Recede across the previous instruction.
Base class for register pressure results.
void discoverLiveIn(RegisterMaskPair Pair)
Add Reg to the live in set and increase max pressure.
SlotIndex TopIdx
Record the boundary of the region being tracked.
void closeBottom()
Set the boundary for the bottom of the region and summarize live outs.
void openBottom(SlotIndex PrevBottom)
If the current bottom is not greater than the previous index, open it.
MachineBasicBlock::const_iterator TopPos
Record the boundary of the region being tracked.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
const_iterator end() const
Reg
All possible values of the reg field in the ModR/M byte.
SlotIndex getCurrSlot() const
Get the SlotIndex for the first nondebug instruction including or after the current position...
const_iterator end() const
void openTop(SlotIndex NextTop)
If the current top is not less than or equal to the next index, open it.
Function Alias Analysis false
bool hasUntiedDef(unsigned VirtReg) const
SmallVector< RegisterMaskPair, 8 > LiveInRegs
List of live in virtual registers or physical register units.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void collect(const MachineInstr &MI, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, bool TrackLaneMasks, bool IgnoreDead)
Analyze the given instruction MI and fill in the Uses, Defs and DeadDefs list based on the MachineOpe...
List of registers defined and used by a machine instruction.
void increaseRegPressure(unsigned RegUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)
PressureDiff & operator[](unsigned Idx)
void recedeSkipDebugValues()
Recede until we find an instruction which is not a DebugValue.
LaneBitmask getLiveLanesAt(unsigned RegUnit, SlotIndex Pos) const
void init(const MachineRegisterInfo &MRI)
SmallVector< RegisterMaskPair, 8 > LiveOutRegs
void addLiveRegs(ArrayRef< RegisterMaskPair > Regs)
Force liveness of virtual registers or physical register units.
void getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction top-down.
SmallVector< RegisterMaskPair, 8 > Uses
List of virtual registers and register units read by the instruction.
LaneBitmask getLiveThroughAt(unsigned RegUnit, SlotIndex Pos) const
ArrayRef< unsigned > getLiveThru() const
unsigned const MachineRegisterInfo * MRI
size_type size() const
size - Returns the number of elements in the set.
PressureChange CurrentMax
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx...
bool operator!=(const RegPressureDelta &RHS) const
bool operator==(const RegPressureDelta &RHS) const
void bumpDownwardPressure(const MachineInstr *MI)
Record the downward impact of a single instruction on current register pressure.
RegisterPressure computed within a region of instructions delimited by TopPos and BottomPos...
void openTop(MachineBasicBlock::const_iterator PrevTop)
If the current top is the previous instruction (before receding), open it.
Track the current register pressure at some position in the instruction stream, and remember the high...
List of PressureChanges in order of increasing, unique PSetID.
A set of live virtual registers and physical register units.
SmallVector< RegisterMaskPair, 8 > Defs
List of virtual registers and register units defined by the instruction which are not dead...
void discoverLiveOut(RegisterMaskPair Pair)
Add Reg to the live out set and increase max pressure.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
void initLiveThru(const RegPressureTracker &RPTracker)
Initialize the LiveThru pressure set based on the untied defs found in RPTracker. ...
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.
void adjustLaneLiveness(const LiveIntervals &LIS, const MachineRegisterInfo &MRI, SlotIndex Pos, MachineInstr *AddFlagsMI=nullptr)
Use liveness information to find out which uses/defs are partially undefined/dead and adjust the Regi...
void advance()
Advance across the current instruction.
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
const RegisterPressure & getPressure() const
LaneBitmask erase(RegisterMaskPair Pair)
Clears the Pair.LaneMask lanes of Pair.Reg (mark them as dead).
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static LaneBitmask getNone()
void getMaxPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Find the pressure set with the most change beyond its pressure limit after traversing this instructio...
LaneBitmask getLastUsedLanes(unsigned RegUnit, SlotIndex Pos) const
void reset()
Clear the result so it can be used for another round of pressure tracking.
PressureChange(unsigned id)
RegPressureTracker(RegionPressure &rp)
PressureChange CriticalMax
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
LaneBitmask contains(unsigned Reg) const
void closeTop()
Set the boundary for the top of the region and summarize live ins.
Representation of each machine instruction.
void dumpRegSetPressure(ArrayRef< unsigned > SetPressure, const TargetRegisterInfo *TRI)
RegPressureTracker(IntervalPressure &rp)
LLVM_DUMP_METHOD void dump(const TargetRegisterInfo &TRI) const
iterator find(const KeyT &Key)
find - Find an element by its key.
Capture a change in pressure for a single pressure set.
void getMaxUpwardPressureDelta(const MachineInstr *MI, PressureDiff *PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction bottom-up.
void getUpwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction bottom-up.
const_iterator begin() const
bool isBottomClosed() const
Does this pressure result have a valid bottom position and live outs.
void init(const MachineFunction *mf, const RegisterClassInfo *rci, const LiveIntervals *lis, const MachineBasicBlock *mbb, MachineBasicBlock::const_iterator pos, bool TrackLaneMasks, bool TrackUntiedDefs)
Setup the RegPressureTracker.
void bumpUpwardPressure(const MachineInstr *MI)
Record the upward impact of a single instruction on current register pressure.
unsigned getPSetOrMax() const
const std::vector< unsigned > & getRegSetPressureAtPos() const
Get the register set pressure at the current position, which may be less than the pressure across the...
Store the effects of a change in pressure on things that MI scheduler cares about.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const PressureChange * const_iterator
const PressureDiff & operator[](unsigned Idx) const
void initLiveThru(ArrayRef< unsigned > PressureSet)
Copy an existing live thru pressure result.
LaneBitmask insert(RegisterMaskPair Pair)
Mark the Pair.LaneMask lanes of Pair.Reg as live.
void reset()
Clear the result so it can be used for another round of pressure tracking.
void getDownwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction top-down.
void setPos(MachineBasicBlock::const_iterator Pos)
RegisterPressure & getPressure()
Get the resulting register pressure over the traversed region.
MachineBasicBlock::const_iterator BottomPos
SlotIndex - An opaque wrapper around machine indexes.
void getUpwardPressureDelta(const MachineInstr *MI, PressureDiff &PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit) const
This is the fast version of querying register pressure that does not directly depend on current liven...