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);
98 BitVector CSRHintsForAllocOrder(TRI->getNumRegs());
101 CSRHintsForAllocOrder[(*AI).id()] =
102 STI.ignoreCSRForAllocationOrder(mf, *AI);
103 if (IgnoreCSRForAllocOrder != CSRHintsForAllocOrder) {
105 IgnoreCSRForAllocOrder = std::move(CSRHintsForAllocOrder);
108 RegCosts = TRI->getRegisterCosts(*MF);
111 const BitVector &RR = MF->getRegInfo().getReservedRegs();
112 if (RR != Reserved) {
119 unsigned NumPSets = TRI->getNumRegPressureSets();
120 PSetLimits.reset(
new unsigned[NumPSets]);
121 std::fill(&PSetLimits[0], &PSetLimits[NumPSets], 0);
130 assert(RC &&
"no register class given");
131 RCInfo &RCI = RegClass[RC->
getID()];
144 unsigned LastCostChange = 0;
154 MinCost = std::min(MinCost,
Cost);
157 !STI.ignoreCSRForAllocationOrder(*MF, PhysReg))
161 if (
Cost != LastCost)
163 RCI.Order[
N++] = PhysReg;
167 RCI.NumRegs =
N + CSRAlias.
size();
168 assert(RCI.NumRegs <= NumRegs &&
"Allocation order larger than regclass");
171 for (
unsigned PhysReg : CSRAlias) {
172 uint8_t
Cost = RegCosts[PhysReg];
173 if (
Cost != LastCost)
175 RCI.Order[
N++] = PhysReg;
185 TRI->getLargestLegalSuperClass(RC, *MF))
187 RCI.ProperSubClass =
true;
189 RCI.MinCost = MinCost;
190 RCI.LastCostChange = LastCostChange;
193 dbgs() <<
"AllocationOrder(" << TRI->getRegClassName(RC) <<
") = [";
194 for (
unsigned I = 0;
I != RCI.NumRegs; ++
I)
196 dbgs() << (RCI.ProperSubClass ?
" ] (sub-class)\n" :
" ]\n");
208 assert(RC &&
"Failed to find register class");
211 unsigned RegPressureSetLimit = TRI->getRegPressureSetLimit(*MF, Idx);
216 if (NAllocatableRegs == 0)
217 return RegPressureSetLimit;
218 unsigned NReserved = RC->
getNumRegs() - NAllocatableRegs;
219 return RegPressureSetLimit - TRI->getRegClassWeight(RC).RegWeight * NReserved;
223 "machine-register-class-info",
224 "Machine Register Class Info Analysis",
true,
true)
244 RCI.runOnMachineFunction(MF);
248void 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),...
MCRegAliasIterator enumerates all registers aliasing Reg.
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...