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 return Reserved == MF->getRegInfo().getReservedRegs();
127 assert(MF && TRI && RegClass &&
128 "RegisterClassInfo must be initialized before updating reserved regs");
129 assert(ReservedInput.
size() == Reserved.size() &&
130 "Reserved register bit vectors must have the same size");
131 if (ReservedInput == Reserved)
135 bool OnlyNewReservations = Reserved.subsetOf(ReservedInput);
137 Reserved = ReservedInput;
140 std::fill_n(PSetLimits.get(), TRI->getNumRegPressureSets(), 0);
144 if (!OnlyNewReservations ||
StressRA) {
150 RCInfo &Info = RegClass[RC.getID()];
156 unsigned NewNumRegs = 0;
159 unsigned LastCostChange = 0;
161 for (
unsigned I = 0;
I != Info.NumRegs; ++
I) {
163 if (Reserved.test(PhysReg))
167 MinCost = std::min(MinCost,
Cost);
168 if (
Cost != LastCost)
169 LastCostChange = NewNumRegs;
171 Info.Order[NewNumRegs++] = PhysReg;
175 Info.NumRegs = NewNumRegs;
176 Info.MinCost = MinCost;
177 Info.LastCostChange = LastCostChange;
179 Info.ProperSubClass =
false;
181 TRI->getLargestLegalSuperClass(&RC, *MF))
183 Info.ProperSubClass =
true;
191 assert(RC &&
"no register class given");
192 RCInfo &RCI = RegClass[RC->
getID()];
204 unsigned LastCostChange = 0;
214 MinCost = std::min(MinCost,
Cost);
217 (IgnoreCSRForAllocOrder.
empty() ||
218 !IgnoreCSRForAllocOrder.
test(PhysReg)))
222 if (
Cost != LastCost)
224 RCI.Order[
N++] = PhysReg;
228 RCI.NumRegs =
N + CSRAlias.
size();
229 assert(RCI.NumRegs <= NumRegs &&
"Allocation order larger than regclass");
232 for (
unsigned PhysReg : CSRAlias) {
233 uint8_t
Cost = RegCosts[PhysReg];
234 if (
Cost != LastCost)
236 RCI.Order[
N++] = PhysReg;
246 TRI->getLargestLegalSuperClass(RC, *MF))
248 RCI.ProperSubClass =
true;
250 RCI.MinCost = MinCost;
251 RCI.LastCostChange = LastCostChange;
254 dbgs() <<
"AllocationOrder(" << TRI->getRegClassName(RC) <<
") = [";
255 for (
unsigned I = 0;
I != RCI.NumRegs; ++
I)
257 dbgs() << (RCI.ProperSubClass ?
" ] (sub-class)\n" :
" ]\n");
269 assert(RC &&
"Failed to find register class");
271 unsigned RegPressureSetLimit = TRI->getRegPressureSetLimit(*MF, Idx);
276 if (NAllocatableRegs == 0)
277 return RegPressureSetLimit;
278 unsigned NReserved = RC->
getNumRegs() - NAllocatableRegs;
279 unsigned ReservedRegWeight = TRI->getRegClassWeight(RC).RegWeight * NReserved;
284 if (ReservedRegWeight >= RegPressureSetLimit)
285 return RegPressureSetLimit;
286 return RegPressureSetLimit - ReservedRegWeight;
290 "machine-register-class-info",
291 "Machine Register Class Info Analysis",
true,
true)
311 RCI.runOnMachineFunction(MF);
315void 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)
MachineRegisterInfo & MRI
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,...
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 bool hasCurrentReservedRegs() const
Whether the cached information was filtered by MRI's frozen reserved registers, i....
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...