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);
87 for (MCRegUnit U : TRI->regunits(*
I))
88 CalleeSavedAliases[
static_cast<unsigned>(U)] = *
I;
89 LastCalleeSavedRegs.push_back(*
I);
98 STI.getCSRAllocationOrderMask(mf, CSRHintsForAllocOrder);
99 if (IgnoreCSRForAllocOrder != CSRHintsForAllocOrder) {
101 IgnoreCSRForAllocOrder = std::move(CSRHintsForAllocOrder);
104 RegCosts = TRI->getRegisterCosts(*MF);
107 const BitVector &RR = MF->getRegInfo().getReservedRegs();
108 if (RR != Reserved) {
115 unsigned NumPSets = TRI->getNumRegPressureSets();
116 PSetLimits.reset(
new unsigned[NumPSets]);
117 std::fill(&PSetLimits[0], &PSetLimits[NumPSets], 0);
123 assert(MF && TRI && RegClass &&
124 "RegisterClassInfo must be initialized before updating reserved regs");
125 assert(ReservedInput.
size() == Reserved.size() &&
126 "Reserved register bit vectors must have the same size");
127 if (ReservedInput == Reserved)
131 bool OnlyNewReservations = Reserved.subsetOf(ReservedInput);
133 Reserved = ReservedInput;
136 std::fill_n(PSetLimits.get(), TRI->getNumRegPressureSets(), 0);
140 if (!OnlyNewReservations ||
StressRA) {
146 RCInfo &Info = RegClass[RC.getID()];
152 unsigned NewNumRegs = 0;
155 unsigned LastCostChange = 0;
157 for (
unsigned I = 0;
I != Info.NumRegs; ++
I) {
159 if (Reserved.test(PhysReg))
163 MinCost = std::min(MinCost,
Cost);
164 if (
Cost != LastCost)
165 LastCostChange = NewNumRegs;
167 Info.Order[NewNumRegs++] = PhysReg;
171 Info.NumRegs = NewNumRegs;
172 Info.MinCost = MinCost;
173 Info.LastCostChange = LastCostChange;
175 Info.ProperSubClass =
false;
177 TRI->getLargestLegalSuperClass(&RC, *MF))
179 Info.ProperSubClass =
true;
187 assert(RC &&
"no register class given");
188 RCInfo &RCI = RegClass[RC->
getID()];
200 unsigned LastCostChange = 0;
210 MinCost = std::min(MinCost,
Cost);
213 (IgnoreCSRForAllocOrder.
empty() ||
214 !IgnoreCSRForAllocOrder.
test(PhysReg)))
218 if (
Cost != LastCost)
220 RCI.Order[
N++] = PhysReg;
224 RCI.NumRegs =
N + CSRAlias.
size();
225 assert(RCI.NumRegs <= NumRegs &&
"Allocation order larger than regclass");
228 for (
unsigned PhysReg : CSRAlias) {
229 uint8_t
Cost = RegCosts[PhysReg];
230 if (
Cost != LastCost)
232 RCI.Order[
N++] = PhysReg;
242 TRI->getLargestLegalSuperClass(RC, *MF))
244 RCI.ProperSubClass =
true;
246 RCI.MinCost = MinCost;
247 RCI.LastCostChange = LastCostChange;
250 dbgs() <<
"AllocationOrder(" << TRI->getRegClassName(RC) <<
") = [";
251 for (
unsigned I = 0;
I != RCI.NumRegs; ++
I)
253 dbgs() << (RCI.ProperSubClass ?
" ] (sub-class)\n" :
" ]\n");
265 assert(RC &&
"Failed to find register class");
267 unsigned RegPressureSetLimit = TRI->getRegPressureSetLimit(*MF, Idx);
272 if (NAllocatableRegs == 0)
273 return RegPressureSetLimit;
274 unsigned NReserved = RC->
getNumRegs() - NAllocatableRegs;
275 unsigned ReservedRegWeight = TRI->getRegClassWeight(RC).RegWeight * NReserved;
280 if (ReservedRegWeight >= RegPressureSetLimit)
281 return RegPressureSetLimit;
282 return RegPressureSetLimit - ReservedRegWeight;
286 "machine-register-class-info",
287 "Machine Register Class Info Analysis",
true,
true)
307 RCI.runOnMachineFunction(MF);
311void MachineRegisterClassInfoWrapperPass::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the BitVector class.
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool test(unsigned Idx) const
Returns true if bit Idx is set.
size_type size() const
Returns the number of bits in this bitvector.
bool empty() const
Returns whether there are no bits in this bitvector.
unsigned getID() const
getID() - Return the register class ID number.
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
MachineFunctionPass(char &ID)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
MachineRegisterClassInfoWrapperPass()
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
LLVM_ABI void updateReservedRegs(const BitVector &ReservedInput)
Update cached register class information using ReservedInput, MRI's current reserved-register set.
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...
A global registry used in conjunction with static constructors to make pluggable components (like tar...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void initializeMachineRegisterClassInfoWrapperPassPass(PassRegistry &)
auto reverse_conditionally(ContainerTy &&C, bool ShouldReverse)
Return a range that conditionally reverses C.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
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.
MCRegisterClass TargetRegisterClass
A special type used by analysis passes to provide an address that identifies that particular analysis...