35#define DEBUG_TYPE "regalloc"
39 cl::desc(
"Limit all regclasses to N registers"));
51 if (STI.getRegisterInfo() != TRI || Reverse != Rev) {
53 TRI = STI.getRegisterInfo();
54 RegClass.reset(
new RCInfo[TRI->getNumRegClasses()]);
61 bool CSRChanged =
true;
64 size_t LastSize = LastCalleeSavedRegs.size();
65 for (
unsigned I = 0;; ++
I) {
67 CSRChanged =
I != LastSize;
74 if (CSR[
I] != LastCalleeSavedRegs[
I]) {
83 LastCalleeSavedRegs.clear();
86 CalleeSavedAliases.assign(TRI->getNumRegUnits(), 0);
88 for (MCRegUnit U : TRI->regunits(*
I))
89 CalleeSavedAliases[
static_cast<unsigned>(U)] = *
I;
90 LastCalleeSavedRegs.push_back(*
I);
99 STI.getCSRAllocationOrderMask(mf, CSRHintsForAllocOrder);
100 if (IgnoreCSRForAllocOrder != CSRHintsForAllocOrder) {
102 IgnoreCSRForAllocOrder = std::move(CSRHintsForAllocOrder);
105 RegCosts = TRI->getRegisterCosts(*MF);
108 const BitVector &RR = MF->getRegInfo().getReservedRegs();
109 if (RR != Reserved) {
116 unsigned NumPSets = TRI->getNumRegPressureSets();
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()];
140 unsigned LastCostChange = 0;
150 MinCost = std::min(MinCost,
Cost);
153 (IgnoreCSRForAllocOrder.
empty() ||
154 !IgnoreCSRForAllocOrder.
test(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 PhysReg : CSRAlias) {
169 uint8_t
Cost = RegCosts[PhysReg];
170 if (
Cost != LastCost)
172 RCI.Order[
N++] = PhysReg;
182 TRI->getLargestLegalSuperClass(RC, *MF))
184 RCI.ProperSubClass =
true;
186 RCI.MinCost = MinCost;
187 RCI.LastCostChange = LastCostChange;
190 dbgs() <<
"AllocationOrder(" << TRI->getRegClassName(RC) <<
") = [";
191 for (
unsigned I = 0;
I != RCI.NumRegs; ++
I)
193 dbgs() << (RCI.ProperSubClass ?
" ] (sub-class)\n" :
" ]\n");
205 assert(RC &&
"Failed to find register class");
208 unsigned RegPressureSetLimit = TRI->getRegPressureSetLimit(*MF, Idx);
213 if (NAllocatableRegs == 0)
214 return RegPressureSetLimit;
215 unsigned NReserved = RC->
getNumRegs() - NAllocatableRegs;
216 return RegPressureSetLimit - TRI->getRegClassWeight(RC).RegWeight * NReserved;
220 "machine-register-class-info",
221 "Machine Register Class Info Analysis",
true,
true)
241 RCI.runOnMachineFunction(MF);
245void 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.
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.
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...