14 #ifndef LLVM_CODEGEN_REGISTERPRESSURE_H 15 #define LLVM_CODEGEN_REGISTERPRESSURE_H 34 class MachineFunction;
36 class MachineRegisterInfo;
37 class RegisterClassInfo;
44 : RegUnit(RegUnit), LaneMask(LaneMask) {}
116 assert(isValid() &&
"invalid PressureChange");
130 return PSetID == RHS.PSetID && UnitInc == RHS.UnitInc;
145 enum { MaxPSets = 16 };
151 iterator nonconst_begin() {
return &PressureChanges[0]; }
152 iterator nonconst_end() {
return &PressureChanges[MaxPSets]; }
160 void addPressureChange(
unsigned RegUnit,
bool IsDec,
209 void init(
unsigned N);
212 assert(Idx < Size &&
"PressureDiff index out of bounds");
213 return PDiffArray[Idx];
262 struct IndexMaskPair {
266 IndexMaskPair(
unsigned Index,
LaneBitmask LaneMask)
269 unsigned getSparseSetIndex()
const {
276 unsigned NumRegUnits;
278 unsigned getSparseIndexFromReg(
unsigned Reg)
const {
281 assert(Reg < NumRegUnits);
285 unsigned getRegFromSparseIndex(
unsigned SparseIndex)
const {
286 if (SparseIndex >= NumRegUnits)
296 unsigned SparseIndex = getSparseIndexFromReg(Reg);
306 unsigned SparseIndex = getSparseIndexFromReg(Pair.
RegUnit);
307 auto InsertRes = Regs.
insert(IndexMaskPair(SparseIndex, Pair.
LaneMask));
308 if (!InsertRes.second) {
310 InsertRes.first->LaneMask |= Pair.
LaneMask;
319 unsigned SparseIndex = getSparseIndexFromReg(Pair.
RegUnit);
332 template<
typename ContainerT>
334 for (
const IndexMaskPair &
P : Regs) {
335 unsigned Reg = getRegFromSparseIndex(
P.Index);
336 if (
P.LaneMask.any())
373 bool RequireIntervals;
376 bool TrackUntiedDefs =
false;
379 bool TrackLaneMasks =
false;
387 std::vector<unsigned> CurrSetPressure;
395 std::vector<unsigned> LiveThruPressure;
406 bool TrackLaneMasks,
bool TrackUntiedDefs);
433 void recedeSkipDebugValues();
452 LiveThruPressure.assign(PressureSet.
begin(), PressureSet.
end());
465 return CurrSetPressure;
468 bool isTopClosed()
const;
469 bool isBottomClosed()
const;
494 void getMaxDownwardPressureDelta(
const MachineInstr *MI,
507 return getMaxDownwardPressureDelta(MI, Delta, CriticalPSets,
510 assert(isBottomClosed() &&
"Uninitialized pressure tracker");
511 return getMaxUpwardPressureDelta(MI,
nullptr, Delta, CriticalPSets,
517 std::vector<unsigned> &PressureResult,
518 std::vector<unsigned> &MaxPressureResult);
522 std::vector<unsigned> &PressureResult,
523 std::vector<unsigned> &MaxPressureResult);
526 std::vector<unsigned> &PressureResult,
527 std::vector<unsigned> &MaxPressureResult) {
529 return getUpwardPressure(MI, PressureResult, MaxPressureResult);
531 assert(isBottomClosed() &&
"Uninitialized pressure tracker");
532 return getDownwardPressure(MI, PressureResult, MaxPressureResult);
536 return UntiedDefs.
count(VirtReg);
553 void decreaseRegPressure(
unsigned RegUnit,
LaneBitmask PreviousMask,
574 #endif // LLVM_CODEGEN_REGISTERPRESSURE_H A common definition of LaneBitmask for use in TableGen and CodeGen.
void getPressureAfterInst(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
static unsigned virtReg2Index(unsigned Reg)
Convert a virtual register number to a 0-based index.
This class represents lattice values for constants.
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
RegisterMaskPair(unsigned RegUnit, LaneBitmask LaneMask)
unsigned RegUnit
Virtual register or register unit.
SmallVector< RegisterMaskPair, 8 > DeadDefs
List of virtual registers and register units defined by the instruction but dead. ...
unsigned const TargetRegisterInfo * TRI
block Block Frequency true
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
static LaneBitmask getLiveLanesAt(const LiveIntervals &LIS, const MachineRegisterInfo &MRI, bool TrackLaneMasks, unsigned RegUnit, SlotIndex Pos)
Base class for register pressure results.
SlotIndex TopIdx
Record the boundary of the region being tracked.
const RegisterPressure & getPressure() const
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise. ...
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...
MachineBasicBlock::const_iterator getPos() const
Get the MI position corresponding to this register pressure.
static constexpr LaneBitmask getNone()
size_type size() const
size - Returns the number of elements in the set.
LaneBitmask contains(unsigned Reg) 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)...
List of registers defined and used by a machine instruction.
void appendTo(ContainerT &To) const
PressureDiff & operator[](unsigned Idx)
const_iterator end() const
SmallVector< RegisterMaskPair, 8 > LiveOutRegs
SmallVector< RegisterMaskPair, 8 > Uses
List of virtual registers and register units read by the instruction.
unsigned getPSetOrMax() const
initializer< Ty > init(const Ty &Val)
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
unsigned const MachineRegisterInfo * MRI
PressureChange CurrentMax
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx...
typename DenseT::iterator iterator
ArrayRef< unsigned > getLiveThru() const
typename DenseT::const_iterator const_iterator
RegisterPressure computed within a region of instructions delimited by TopPos and BottomPos...
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...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool operator==(const PressureChange &RHS) const
const_iterator end() const
bool hasUntiedDef(unsigned VirtReg) 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...
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.
Align max(MaybeAlign Lhs, Align Rhs)
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...
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...
PressureChange(unsigned id)
const PressureDiff & operator[](unsigned Idx) const
RegPressureTracker(RegionPressure &rp)
bool operator==(const RegPressureDelta &RHS) const
PressureChange CriticalMax
static void clear(coro::Shape &Shape)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
bool operator!=(const RegPressureDelta &RHS) const
Representation of each machine instruction.
void dumpRegSetPressure(ArrayRef< unsigned > SetPressure, const TargetRegisterInfo *TRI)
RegPressureTracker(IntervalPressure &rp)
iterator find(const KeyT &Key)
find - Find an element by its key.
Capture a change in pressure for a single pressure set.
Store the effects of a change in pressure on things that MI scheduler cares about.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const_iterator begin() 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.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void setPos(MachineBasicBlock::const_iterator Pos)
bool operator==(uint64_t V1, const APInt &V2)
RegisterPressure & getPressure()
Get the resulting register pressure over the traversed region.
MachineBasicBlock::const_iterator BottomPos
SlotIndex - An opaque wrapper around machine indexes.