34#define DEBUG_TYPE "regalloc"
38 cl::desc(
"Limit all regclasses to N registers"));
50 if (STI.getRegisterInfo() != TRI || Reverse != Rev) {
52 TRI = STI.getRegisterInfo();
53 RegClass.reset(
new RCInfo[TRI->getNumRegClasses()]);
60 bool CSRChanged =
true;
63 size_t LastSize = LastCalleeSavedRegs.size();
64 for (
unsigned I = 0;; ++
I) {
66 CSRChanged =
I != LastSize;
73 if (CSR[
I] != LastCalleeSavedRegs[
I]) {
82 LastCalleeSavedRegs.clear();
85 CalleeSavedAliases.assign(TRI->getNumRegUnits(), 0);
88 CalleeSavedAliases[U] = *
I;
89 LastCalleeSavedRegs.push_back(*
I);
97 BitVector CSRHintsForAllocOrder(TRI->getNumRegs());
100 CSRHintsForAllocOrder[(*AI).id()] =
101 STI.ignoreCSRForAllocationOrder(mf, *AI);
102 if (IgnoreCSRForAllocOrder != CSRHintsForAllocOrder) {
104 IgnoreCSRForAllocOrder = CSRHintsForAllocOrder;
107 RegCosts = TRI->getRegisterCosts(*MF);
110 const BitVector &RR = MF->getRegInfo().getReservedRegs();
111 if (RR != Reserved) {
118 unsigned NumPSets = TRI->getNumRegPressureSets();
119 PSetLimits.reset(
new unsigned[NumPSets]);
120 std::fill(&PSetLimits[0], &PSetLimits[NumPSets], 0);
129 assert(RC &&
"no register class given");
130 RCInfo &RCI = RegClass[RC->
getID()];
143 unsigned LastCostChange = 0;
148 std::vector<MCPhysReg> ReverseOrder;
153 for (
unsigned PhysReg : RawOrder) {
157 uint8_t Cost = RegCosts[PhysReg];
158 MinCost = std::min(MinCost, Cost);
161 !STI.ignoreCSRForAllocationOrder(*MF, PhysReg))
165 if (Cost != LastCost)
167 RCI.Order[
N++] = PhysReg;
171 RCI.NumRegs =
N + CSRAlias.
size();
172 assert(RCI.NumRegs <= NumRegs &&
"Allocation order larger than regclass");
175 for (
unsigned PhysReg : CSRAlias) {
176 uint8_t
Cost = RegCosts[PhysReg];
177 if (
Cost != LastCost)
179 RCI.Order[
N++] = PhysReg;
188 if (
const TargetRegisterClass *Super =
189 TRI->getLargestLegalSuperClass(RC, *MF))
191 RCI.ProperSubClass =
true;
193 RCI.MinCost = MinCost;
194 RCI.LastCostChange = LastCostChange;
197 dbgs() <<
"AllocationOrder(" << TRI->getRegClassName(RC) <<
") = [";
198 for (
unsigned I = 0;
I != RCI.NumRegs; ++
I)
200 dbgs() << (RCI.ProperSubClass ?
" ] (sub-class)\n" :
" ]\n");
212 unsigned NumRCUnits = 0;
214 const int *PSetID = TRI->getRegClassPressureSets(
C);
215 for (; *PSetID != -1; ++PSetID) {
216 if ((
unsigned)*PSetID == Idx)
224 unsigned NUnits = TRI->getRegClassWeight(
C).WeightLimit;
225 if (!RC || NUnits > NumRCUnits) {
230 assert(RC &&
"Failed to find register class");
233 unsigned RegPressureSetLimit = TRI->getRegPressureSetLimit(*MF, Idx);
238 if (NAllocatableRegs == 0)
239 return RegPressureSetLimit;
240 unsigned NReserved = RC->
getNumRegs() - NAllocatableRegs;
241 return RegPressureSetLimit - TRI->getRegClassWeight(RC).RegWeight * NReserved;
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the BitVector class.
static cl::opt< unsigned > StressRA("stress-regalloc", cl::Hidden, cl::init(0), cl::value_desc("N"), cl::desc("Limit all regclasses to N registers"))
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
MCRegAliasIterator enumerates all registers aliasing Reg.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const
getNumAllocatableRegs - Returns the number of actually allocatable registers in RC in the current fun...
LLVM_ABI void runOnMachineFunction(const MachineFunction &MF, bool Rev=false)
runOnFunction - Prepare to answer questions about MF.
MCRegister getLastCalleeSavedAlias(MCRegister PhysReg) const
getLastCalleeSavedAlias - Returns the last callee saved register that overlaps PhysReg,...
LLVM_ABI RegisterClassInfo()
LLVM_ABI 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, bool Rev=false) const
Returns the preferred order for allocating registers from this register class in MF.
@ 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.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned MCRegUnit
Register units are used to compute register aliasing.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI 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.