diff options
author | Arnaud A. de Grandmaison <arnaud.degrandmaison@arm.com> | 2014-11-04 20:51:29 +0000 |
---|---|---|
committer | Arnaud A. de Grandmaison <arnaud.degrandmaison@arm.com> | 2014-11-04 20:51:29 +0000 |
commit | a11cab31209a6bb20e3dd35d6396071b504ab4ee (patch) | |
tree | 72da5f64d421a08e20c4a010292c918597d1cf02 /llvm/lib/CodeGen | |
parent | 829dd81377abfd0c02257ebd10d31bb0b1377815 (diff) | |
download | bcm5719-llvm-a11cab31209a6bb20e3dd35d6396071b504ab4ee.tar.gz bcm5719-llvm-a11cab31209a6bb20e3dd35d6396071b504ab4ee.zip |
[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.
llvm-svn: 221293
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/RegAllocPBQP.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/RegAllocPBQP.cpp b/llvm/lib/CodeGen/RegAllocPBQP.cpp index fa45dd23654..eb7e563352a 100644 --- a/llvm/lib/CodeGen/RegAllocPBQP.cpp +++ b/llvm/lib/CodeGen/RegAllocPBQP.cpp @@ -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( |