-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[TRI] Remove reserved registers in getRegPressureSetLimit #118787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: users/wangpc-pp/spr/main.tri-remove-reserved-registers-in-getregpressuresetlimit
Are you sure you want to change the base?
Changes from 1 commit
2ec06c7
fae615d
723597a
5adec35
9737ec8
538b48d
f5de3e9
47c3275
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1327,47 +1327,6 @@ class HighRegisterPressureDetector { | |
void computePressureSetLimit(const RegisterClassInfo &RCI) { | ||
for (unsigned PSet = 0; PSet < PSetNum; PSet++) | ||
PressureSetLimit[PSet] = TRI->getRegPressureSetLimit(MF, PSet); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @kasuga-fj! What do you think about this part? I just removed the code below as it seems to be unnecessary now. Related patch: #74807 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I think just removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for caring. I dared to replace it from |
||
// We assume fixed registers, such as stack pointer, are already in use. | ||
// Therefore subtracting the weight of the fixed registers from the limit of | ||
// each pressure set in advance. | ||
SmallDenseSet<Register, 8> FixedRegs; | ||
for (const TargetRegisterClass *TRC : TRI->regclasses()) { | ||
for (const MCPhysReg Reg : *TRC) | ||
if (isFixedRegister(Reg)) | ||
FixedRegs.insert(Reg); | ||
} | ||
|
||
LLVM_DEBUG({ | ||
for (auto Reg : FixedRegs) { | ||
dbgs() << printReg(Reg, TRI, 0, &MRI) << ": ["; | ||
for (MCRegUnit Unit : TRI->regunits(Reg)) { | ||
const int *Sets = TRI->getRegUnitPressureSets(Unit); | ||
for (; *Sets != -1; Sets++) { | ||
dbgs() << TRI->getRegPressureSetName(*Sets) << ", "; | ||
} | ||
} | ||
dbgs() << "]\n"; | ||
} | ||
}); | ||
|
||
for (auto Reg : FixedRegs) { | ||
LLVM_DEBUG(dbgs() << "fixed register: " << printReg(Reg, TRI, 0, &MRI) | ||
<< "\n"); | ||
for (MCRegUnit Unit : TRI->regunits(Reg)) { | ||
auto PSetIter = MRI.getPressureSets(Unit); | ||
unsigned Weight = PSetIter.getWeight(); | ||
for (; PSetIter.isValid(); ++PSetIter) { | ||
unsigned &Limit = PressureSetLimit[*PSetIter]; | ||
assert( | ||
Limit >= Weight && | ||
"register pressure limit must be greater than or equal weight"); | ||
Limit -= Weight; | ||
LLVM_DEBUG(dbgs() << "PSet=" << *PSetIter << " Limit=" << Limit | ||
<< " (decreased by " << Weight << ")\n"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// There are two patterns of last-use. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,6 +674,50 @@ TargetRegisterInfo::prependOffsetExpression(const DIExpression *Expr, | |
PrependFlags & DIExpression::EntryValue); | ||
} | ||
|
||
unsigned TargetRegisterInfo::getRegPressureSetLimit(const MachineFunction &MF, | ||
wangpc-pp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unsigned Idx) const { | ||
const TargetRegisterClass *RC = nullptr; | ||
unsigned NumRCUnits = 0; | ||
for (const TargetRegisterClass *C : regclasses()) { | ||
const int *PSetID = getRegClassPressureSets(C); | ||
for (; *PSetID != -1; ++PSetID) { | ||
if ((unsigned)*PSetID == Idx) | ||
break; | ||
} | ||
if (*PSetID == -1) | ||
continue; | ||
|
||
// Found a register class that counts against this pressure set. | ||
// For efficiency, only compute the set order for the largest set. | ||
unsigned NUnits = getRegClassWeight(C).WeightLimit; | ||
if (!RC || NUnits > NumRCUnits) { | ||
RC = C; | ||
NumRCUnits = NUnits; | ||
} | ||
} | ||
assert(RC && "Failed to find register class"); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason we drop the call to
It looks like this is related to what is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason why we need a // ...
compute(RC);
unsigned NAllocatableRegs = getNumAllocatableRegs(RC);
// ...
unsigned NReserved = RC->getNumRegs() - NAllocatableRegs; unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const {
return get(RC).NumRegs;
} The logic of calculating // FIXME: Once targets reserve registers instead of removing them from the
// allocation order, we can simply use begin/end here.
ArrayRef<MCPhysReg> RawOrder = RC->getRawAllocationOrder(*MF);
for (unsigned PhysReg : RawOrder) {
// Remove reserved registers from the allocation order.
if (Reserved.test(PhysReg))
continue;
uint8_t Cost = RegCosts[PhysReg];
MinCost = std::min(MinCost, Cost);
if (getLastCalleeSavedAlias(PhysReg) &&
!STI.ignoreCSRForAllocationOrder(*MF, PhysReg))
// PhysReg aliases a CSR, save it for later.
CSRAlias.push_back(PhysReg);
else {
if (Cost != LastCost)
LastCostChange = N;
RCI.Order[N++] = PhysReg;
LastCost = Cost;
}
}
RCI.NumRegs = N + CSRAlias.size();
|
||
unsigned NReserved = 0; | ||
const BitVector Reserved = MF.getRegInfo().getReservedRegs(); | ||
lenary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (unsigned PhysReg : RC->getRawAllocationOrder(MF)) | ||
wangpc-pp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (Reserved.test(PhysReg)) | ||
NReserved++; | ||
|
||
unsigned NAllocatableRegs = RC->getNumRegs() - NReserved; | ||
unsigned RegPressureSetLimit = getRawRegPressureSetLimit(MF, Idx); | ||
// If all the regs are reserved, return raw RegPressureSetLimit. | ||
// One example is VRSAVERC in PowerPC. | ||
// Avoid returning zero, RegisterClassInfo::getRegPressureSetLimit(Idx) | ||
// assumes this returns non-zero value. | ||
if (NAllocatableRegs == 0) { | ||
LLVM_DEBUG({ | ||
dbgs() << "All registers of " << getRegClassName(RC) << " are reserved!"; | ||
}); | ||
wangpc-pp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return RegPressureSetLimit; | ||
} | ||
return RegPressureSetLimit - getRegClassWeight(RC).RegWeight * NReserved; | ||
} | ||
|
||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||
LLVM_DUMP_METHOD | ||
void TargetRegisterInfo::dumpReg(Register Reg, unsigned SubRegIndex, | ||
|
Uh oh!
There was an error while loading. Please reload this page.