mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 04:38:24 +00:00
[PBQP] Callee saved regs should have a higher cost than scratch regs
Registers are not all equal. Some are not allocatable (infinite cost), some have to be preserved but can be used, and some others are just free to use. Ensure there is a cost hierarchy reflecting this fact, so that the allocator will favor scratch registers over callee-saved registers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221293 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -479,6 +479,15 @@ void RegAllocPBQP::findVRegIntervalsToAlloc(const MachineFunction &MF,
|
||||
}
|
||||
}
|
||||
|
||||
static bool isACalleeSavedRegister(unsigned reg, const TargetRegisterInfo &TRI,
|
||||
const MachineFunction &MF) {
|
||||
const MCPhysReg *CSR = TRI.getCalleeSavedRegs(&MF);
|
||||
for (unsigned i = 0; CSR[i] != 0; ++i)
|
||||
if (TRI.regsOverlap(reg, CSR[i]))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void RegAllocPBQP::initializeGraph(PBQPRAGraph &G) {
|
||||
MachineFunction &MF = G.getMetadata().MF;
|
||||
|
||||
@ -523,6 +532,13 @@ void RegAllocPBQP::initializeGraph(PBQPRAGraph &G) {
|
||||
}
|
||||
|
||||
PBQPRAGraph::RawVector NodeCosts(VRegAllowed.size() + 1, 0);
|
||||
|
||||
// Tweak cost of callee saved registers, as using then force spilling and
|
||||
// restoring them. This would only happen in the prologue / epilogue though.
|
||||
for (unsigned i = 0; i != VRegAllowed.size(); ++i)
|
||||
if (isACalleeSavedRegister(VRegAllowed[i], TRI, MF))
|
||||
NodeCosts[1 + i] += 1.0;
|
||||
|
||||
PBQPRAGraph::NodeId NId = G.addNode(std::move(NodeCosts));
|
||||
G.getNodeMetadata(NId).setVReg(VReg);
|
||||
G.getNodeMetadata(NId).setAllowedRegs(
|
||||
|
Reference in New Issue
Block a user