34#define DEBUG_TYPE "regalloc"
38 cl::desc(
"Limit all regclasses to N registers"));
49 if (STI.getRegisterInfo() != TRI) {
50 TRI = STI.getRegisterInfo();
58 bool CSRChanged =
true;
61 size_t LastSize = LastCalleeSavedRegs.size();
62 for (
unsigned I = 0;; ++
I) {
64 CSRChanged =
I != LastSize;
71 if (CSR[
I] != LastCalleeSavedRegs[
I]) {
80 LastCalleeSavedRegs.clear();
83 CalleeSavedAliases.assign(TRI->
getNumRegs(), 0);
86 CalleeSavedAliases[*AI] = *
I;
87 LastCalleeSavedRegs.push_back(*
I);
98 CSRHintsForAllocOrder[*AI] = STI.ignoreCSRForAllocationOrder(mf, *AI);
99 if (IgnoreCSRForAllocOrder.
size() != CSRHintsForAllocOrder.
size() ||
100 IgnoreCSRForAllocOrder != CSRHintsForAllocOrder) {
102 IgnoreCSRForAllocOrder = CSRHintsForAllocOrder;
109 if (Reserved.
size() != RR.
size() || RR != Reserved) {
117 PSetLimits.reset(
new unsigned[NumPSets]);
118 std::fill(&PSetLimits[0], &PSetLimits[NumPSets], 0);
127 assert(RC &&
"no register class given");
128 RCInfo &RCI = RegClass[RC->
getID()];
139 uint8_t MinCost = uint8_t(~0u);
140 uint8_t LastCost = uint8_t(~0u);
141 unsigned LastCostChange = 0;
146 for (
unsigned PhysReg : RawOrder) {
148 if (Reserved.
test(PhysReg))
150 uint8_t
Cost = RegCosts[PhysReg];
151 MinCost = std::min(MinCost,
Cost);
153 if (CalleeSavedAliases[PhysReg] &&
154 !STI.ignoreCSRForAllocationOrder(*MF, PhysReg))
158 if (
Cost != LastCost)
160 RCI.Order[
N++] = PhysReg;
164 RCI.NumRegs =
N + CSRAlias.
size();
165 assert(RCI.NumRegs <= NumRegs &&
"Allocation order larger than regclass");
168 for (
unsigned i = 0, e = CSRAlias.
size(); i != e; ++i) {
169 unsigned PhysReg = CSRAlias[i];
170 uint8_t
Cost = RegCosts[PhysReg];
171 if (
Cost != LastCost)
173 RCI.Order[
N++] = PhysReg;
185 RCI.ProperSubClass =
true;
187 RCI.MinCost = MinCost;
188 RCI.LastCostChange = LastCostChange;
192 for (
unsigned I = 0;
I != RCI.NumRegs; ++
I)
194 dbgs() << (RCI.ProperSubClass ?
" ] (sub-class)\n" :
" ]\n");
206 unsigned NumRCUnits = 0;
209 for (; *PSetID != -1; ++PSetID) {
210 if ((
unsigned)*PSetID ==
Idx)
219 if (!RC || NUnits > NumRCUnits) {
224 assert(RC &&
"Failed to find register class");
232 if (NAllocatableRegs == 0)
233 return RegPressureSetLimit;
234 unsigned NReserved = RC->
getNumRegs() - NAllocatableRegs;
unsigned const MachineRegisterInfo * MRI
This file implements the BitVector class.
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
static cl::opt< unsigned > StressRA("stress-regalloc", cl::Hidden, cl::init(0), cl::value_desc("N"), cl::desc("Limit all regclasses to N registers"))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool test(unsigned Idx) const
size_type size() const
size - Returns the number of bits in this bitvector.
MCRegAliasIterator enumerates all registers aliasing Reg.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const
getNumAllocatableRegs - Returns the number of actually allocatable registers in RC in the current fun...
void runOnMachineFunction(const MachineFunction &MF)
runOnFunction - Prepare to answer questions about MF.
unsigned computePSetLimit(unsigned Idx) const
This is not accurate because two overlapping register sets may have some nonoverlapping reserved regi...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getNumRegs() const
Return the number of registers in this class.
unsigned getID() const
Return the register class ID number.
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF) const
Returns the preferred order for allocating registers from this register class in MF.
virtual unsigned getNumRegPressureSets() const =0
Get the number of dimensions of register pressure.
iterator_range< regclass_iterator > regclasses() const
ArrayRef< uint8_t > getRegisterCosts(const MachineFunction &MF) const
Get a list of cost values for all registers that correspond to the index returned by RegisterCostTabl...
unsigned getNumRegClasses() const
virtual const int * getRegClassPressureSets(const TargetRegisterClass *RC) const =0
Get the dimensions of register pressure impacted by this register class.
virtual const RegClassWeight & getRegClassWeight(const TargetRegisterClass *RC) const =0
Get the weight in units of pressure for this register class.
virtual const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &) const
Returns the largest super class of RC that is legal to use in the current sub-target and has the same...
virtual unsigned getRegPressureSetLimit(const MachineFunction &MF, unsigned Idx) const =0
Get the register unit pressure limit for this dimension.
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.