From c781a243a3d17e7e763515794168d8fa6043f565 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Sun, 3 May 2009 18:32:42 +0000 Subject: In some rare cases, the register allocator can spill registers but end up not utilizing registers at all. The fundamental problem is linearscan's backtracking can end up freeing more than one allocated registers. However, reloads and restores might be folded into uses / defs and freed registers might not be used at all. VirtRegMap keeps track of allocations so it knows what's not used. As a horrible hack, the stack coloring can color spill slots with *free* registers. That is, it replace reload and spills with copies from and to the free register. It unfold instructions that load and store the spill slot and replace them with register using variants. Not yet enabled. This is part 1. More coming. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70787 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/RegAllocPBQP.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/CodeGen/RegAllocPBQP.cpp') diff --git a/lib/CodeGen/RegAllocPBQP.cpp b/lib/CodeGen/RegAllocPBQP.cpp index 748fae4..8cdf4fa 100644 --- a/lib/CodeGen/RegAllocPBQP.cpp +++ b/lib/CodeGen/RegAllocPBQP.cpp @@ -165,7 +165,7 @@ namespace { //! \brief Adds a stack interval if the given live interval has been //! spilled. Used to support stack slot coloring. - void addStackInterval(const LiveInterval *spilled, float &weight); + void addStackInterval(const LiveInterval *spilled,MachineRegisterInfo* mri); //! \brief Given a solved PBQP problem maps this solution back to a register //! assignment. @@ -637,14 +637,15 @@ pbqp* PBQPRegAlloc::constructPBQPProblem() { return solver; } -void PBQPRegAlloc::addStackInterval(const LiveInterval *spilled, float &weight) { +void PBQPRegAlloc::addStackInterval(const LiveInterval *spilled, + MachineRegisterInfo* mri) { int stackSlot = vrm->getStackSlot(spilled->reg); if (stackSlot == VirtRegMap::NO_STACK_SLOT) return; - LiveInterval &stackInterval = lss->getOrCreateInterval(stackSlot); - stackInterval.weight += weight; + const TargetRegisterClass *RC = mri->getRegClass(spilled->reg); + LiveInterval &stackInterval = lss->getOrCreateInterval(stackSlot, RC); VNInfo *vni; if (stackInterval.getNumValNums() != 0) @@ -688,16 +689,13 @@ bool PBQPRegAlloc::mapPBQPToRegAlloc(pbqp *problem) { // of allocation vregIntervalsToAlloc.erase(&lis->getInterval(virtReg)); - float ssWeight; - // Insert spill ranges for this live range const LiveInterval *spillInterval = node2LI[node]; double oldSpillWeight = spillInterval->weight; SmallVector spillIs; std::vector newSpills = - lis->addIntervalsForSpills(*spillInterval, spillIs, loopInfo, *vrm, - ssWeight); - addStackInterval(spillInterval, ssWeight); + lis->addIntervalsForSpills(*spillInterval, spillIs, loopInfo, *vrm); + addStackInterval(spillInterval, mri); DOUT << "VREG " << virtReg << " -> SPILLED (Cost: " << oldSpillWeight << ", New vregs: "; -- cgit v1.1