14#ifndef LLVM_CODEGEN_REGISTERPRESSURE_H
15#define LLVM_CODEGEN_REGISTERPRESSURE_H
36class MachineRegisterInfo;
37class RegisterClassInfo;
110 assert(
id < std::numeric_limits<uint16_t>::max() &&
"PSetID overflow.");
122 return (PSetID - 1) & std::numeric_limits<uint16_t>::max();
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]; }
216 assert(
Idx < Size &&
"PressureDiff index out of bounds");
217 return PDiffArray[
Idx];
266 struct IndexMaskPair {
270 IndexMaskPair(
unsigned Index,
LaneBitmask LaneMask)
271 : Index(Index), LaneMask(LaneMask) {}
273 unsigned getSparseSetIndex()
const {
280 unsigned NumRegUnits = 0u;
282 unsigned getSparseIndexFromReg(
Register Reg)
const {
284 return Reg.virtRegIndex() + NumRegUnits;
289 Register getRegFromSparseIndex(
unsigned SparseIndex)
const {
290 if (SparseIndex >= NumRegUnits)
300 unsigned SparseIndex = getSparseIndexFromReg(
Reg);
310 unsigned SparseIndex = getSparseIndexFromReg(Pair.
RegUnit);
311 auto InsertRes = Regs.
insert(IndexMaskPair(SparseIndex, Pair.
LaneMask));
312 if (!InsertRes.second) {
314 InsertRes.first->LaneMask |= Pair.
LaneMask;
323 unsigned SparseIndex = getSparseIndexFromReg(Pair.
RegUnit);
328 I->LaneMask &= ~Pair.LaneMask;
337 for (
const IndexMaskPair &
P : Regs) {
339 if (
P.LaneMask.any())
376 bool RequireIntervals;
379 bool TrackUntiedDefs =
false;
382 bool TrackLaneMasks =
false;
390 std::vector<unsigned> CurrSetPressure;
398 std::vector<unsigned> LiveThruPressure;
409 bool TrackUntiedDefs);
455 LiveThruPressure.assign(PressureSet.
begin(), PressureSet.
end());
468 return CurrSetPressure;
520 std::vector<unsigned> &PressureResult,
521 std::vector<unsigned> &MaxPressureResult);
525 std::vector<unsigned> &PressureResult,
526 std::vector<unsigned> &MaxPressureResult);
529 std::vector<unsigned> &PressureResult,
530 std::vector<unsigned> &MaxPressureResult) {
539 return UntiedDefs.
count(VirtReg);
574 const TargetRegisterInfo *
TRI);
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
A common definition of LaneBitmask for use in TableGen and CodeGen.
Register const TargetRegisterInfo * TRI
This file defines the SmallVector class.
This file defines the SparseSet class derived from the version described in Briggs,...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A set of live virtual registers and physical register units.
LaneBitmask erase(VRegMaskOrUnit Pair)
Clears the Pair.LaneMask lanes of Pair.Reg (mark them as dead).
LaneBitmask contains(Register Reg) const
LLVM_ABI void init(const MachineRegisterInfo &MRI)
LaneBitmask insert(VRegMaskOrUnit Pair)
Mark the Pair.LaneMask lanes of Pair.Reg as live.
void appendTo(SmallVectorImpl< VRegMaskOrUnit > &To) const
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Capture a change in pressure for a single pressure set.
unsigned getPSetOrMax() const
LLVM_ABI void dump() const
bool operator==(const PressureChange &RHS) const
PressureChange(unsigned id)
List of PressureChanges in order of increasing, unique PSetID.
LLVM_ABI void dump(const TargetRegisterInfo &TRI) const
LLVM_ABI void addPressureChange(Register RegUnit, bool IsDec, const MachineRegisterInfo *MRI)
Add a change in pressure to the pressure diff of a given instruction.
const_iterator end() const
const_iterator begin() const
const PressureDiff & operator[](unsigned Idx) const
PressureDiffs & operator=(const PressureDiffs &other)=delete
PressureDiff & operator[](unsigned Idx)
PressureDiffs(const PressureDiffs &other)=delete
LLVM_ABI void addInstruction(unsigned Idx, const RegisterOperands &RegOpers, const MachineRegisterInfo &MRI)
Record pressure difference induced by the given operand list to node with index Idx.
LLVM_ABI void init(unsigned N)
Initialize an array of N PressureDiffs.
Track the current register pressure at some position in the instruction stream, and remember the high...
LLVM_ABI void closeRegion()
Finalize the region boundaries and recored live ins and live outs.
LLVM_ABI void discoverLiveIn(VRegMaskOrUnit Pair)
Add Reg to the live in set and increase max pressure.
void setPos(MachineBasicBlock::const_iterator Pos)
ArrayRef< unsigned > getLiveThru() const
LLVM_ABI void closeBottom()
Set the boundary for the bottom of the region and summarize live outs.
LLVM_ABI void recede(SmallVectorImpl< VRegMaskOrUnit > *LiveUses=nullptr)
Recede across the previous instruction.
void getPressureAfterInst(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
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...
RegisterPressure & getPressure()
Get the resulting register pressure over the traversed region.
LLVM_ABI void bumpDownwardPressure(const MachineInstr *MI)
Record the downward impact of a single instruction on current register pressure.
LLVM_ABI void addLiveRegs(ArrayRef< VRegMaskOrUnit > Regs)
Force liveness of virtual registers or physical register units.
LLVM_ABI void recedeSkipDebugValues()
Recede until we find an instruction which is not a DebugValue.
LLVM_ABI 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.
LLVM_ABI void initLiveThru(const RegPressureTracker &RPTracker)
Initialize the LiveThru pressure set based on the untied defs found in RPTracker.
LLVM_ABI void bumpDeadDefs(ArrayRef< VRegMaskOrUnit > DeadDefs)
void initLiveThru(ArrayRef< unsigned > PressureSet)
Copy an existing live thru pressure result.
RegPressureTracker(RegionPressure &rp)
RegPressureTracker(IntervalPressure &rp)
LLVM_ABI void dump() const
LLVM_ABI 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.
LLVM_ABI void discoverLiveInOrOut(VRegMaskOrUnit Pair, SmallVectorImpl< VRegMaskOrUnit > &LiveInOrOut)
LLVM_ABI bool isBottomClosed() const
Does this pressure result have a valid bottom position and live outs.
bool hasUntiedDef(Register VirtReg) const
MachineBasicBlock::const_iterator getPos() const
Get the MI position corresponding to this register pressure.
LLVM_ABI void closeTop()
Set the boundary for the top of the region and summarize live ins.
LLVM_ABI LaneBitmask getLiveLanesAt(Register RegUnit, SlotIndex Pos) const
LLVM_ABI void getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction top-down.
const RegisterPressure & getPressure() const
LLVM_ABI void advance()
Advance across the current instruction.
LLVM_ABI bool isTopClosed() const
Does this pressure result have a valid top position and live ins.
LLVM_ABI void bumpUpwardPressure(const MachineInstr *MI)
Record the upward impact of a single instruction on current register pressure.
LLVM_ABI 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.
LLVM_ABI SlotIndex getCurrSlot() const
Get the SlotIndex for the first nondebug instruction including or after the current position.
LLVM_ABI LaneBitmask getLastUsedLanes(Register RegUnit, SlotIndex Pos) 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...
LLVM_ABI 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.
LLVM_ABI LaneBitmask getLiveThroughAt(Register RegUnit, SlotIndex Pos) const
LLVM_ABI void increaseRegPressure(Register RegUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)
LLVM_ABI void discoverLiveOut(VRegMaskOrUnit Pair)
Add Reg to the live out set and increase max pressure.
LLVM_ABI void decreaseRegPressure(Register RegUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)
LLVM_ABI 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...
List of registers defined and used by a machine instruction.
SmallVector< VRegMaskOrUnit, 8 > Defs
List of virtual registers and register units defined by the instruction which are not dead.
LLVM_ABI 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...
SmallVector< VRegMaskOrUnit, 8 > DeadDefs
List of virtual registers and register units defined by the instruction but dead.
LLVM_ABI 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 VReg...
LLVM_ABI 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 ...
SmallVector< VRegMaskOrUnit, 8 > Uses
List of virtual registers and register units read by the instruction.
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
size_type size() const
size - Returns the number of elements in the set.
typename DenseT::iterator iterator
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise.
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
const_iterator end() const
typename DenseT::const_iterator const_iterator
iterator find(const KeyT &Key)
find - Find an element by its key.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void dumpRegSetPressure(ArrayRef< unsigned > SetPressure, const TargetRegisterInfo *TRI)
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx.
LLVM_ABI void reset()
Clear the result so it can be used for another round of pressure tracking.
LLVM_ABI void openBottom(SlotIndex PrevBottom)
If the current bottom is not greater than the previous index, open it.
SlotIndex TopIdx
Record the boundary of the region being tracked.
LLVM_ABI void openTop(SlotIndex NextTop)
If the current top is not less than or equal to the next index, open it.
static constexpr LaneBitmask getNone()
Store the effects of a change in pressure on things that MI scheduler cares about.
PressureChange CriticalMax
PressureChange CurrentMax
RegPressureDelta()=default
bool operator==(const RegPressureDelta &RHS) const
LLVM_ABI void dump() const
bool operator!=(const RegPressureDelta &RHS) const
RegisterPressure computed within a region of instructions delimited by TopPos and BottomPos.
MachineBasicBlock::const_iterator TopPos
Record the boundary of the region being tracked.
MachineBasicBlock::const_iterator BottomPos
LLVM_ABI void openTop(MachineBasicBlock::const_iterator PrevTop)
If the current top is the previous instruction (before receding), open it.
LLVM_ABI void reset()
Clear the result so it can be used for another round of pressure tracking.
LLVM_ABI void openBottom(MachineBasicBlock::const_iterator PrevBottom)
If the current bottom is the previous instr (before advancing), open it.
Base class for register pressure results.
SmallVector< VRegMaskOrUnit, 8 > LiveOutRegs
SmallVector< VRegMaskOrUnit, 8 > LiveInRegs
List of live in virtual registers or physical register units.
LLVM_ABI void dump(const TargetRegisterInfo *TRI) const
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.
VRegMaskOrUnit(Register RegUnit, LaneBitmask LaneMask)
Register RegUnit
Virtual register or register unit.