Newer
Older
DEBUG(dbgs() << "PBQP Register Allocating for " << mf->getFunction()->getName() << "\n");
Lang Hames
committed
// Allocator main loop:
// * Map current regalloc problem to a PBQP problem
// * Solve the PBQP problem
// * Map the solution back to a register allocation
// * Spill if necessary
// This process is continued till no more spills are generated.
Lang Hames
committed
// Find the vreg intervals in need of allocation.
findVRegIntervalsToAlloc();
Lang Hames
committed
// If there are non-empty intervals allocate them using pbqp.
Lang Hames
committed
if (!vregsToAlloc.empty()) {
Lang Hames
committed
bool pbqpAllocComplete = false;
unsigned round = 0;
Lang Hames
committed
if (!pbqpBuilder) {
while (!pbqpAllocComplete) {
DEBUG(dbgs() << " PBQP Regalloc round " << round << ":\n");
Lang Hames
committed
Lang Hames
committed
PBQP::Graph problem = constructPBQPProblem();
PBQP::Solution solution =
PBQP::HeuristicSolver<PBQP::Heuristics::Briggs>::solve(problem);
Lang Hames
committed
pbqpAllocComplete = mapPBQPToRegAlloc(solution);
Lang Hames
committed
++round;
}
} else {
while (!pbqpAllocComplete) {
DEBUG(dbgs() << " PBQP Regalloc round " << round << ":\n");
std::auto_ptr<PBQPRAProblem> problem =
builder->build(mf, lis, vregsToAlloc);
PBQP::Solution solution =
HeuristicSolver<Briggs>::solve(problem->getGraph());
pbqpAllocComplete = mapPBQPToRegAlloc2(*problem, solution);
++round;
}
Lang Hames
committed
}
}
Lang Hames
committed
// Finalise allocation, allocate empty ranges.
finalizeAlloc();
rmf->renderMachineFunction("After PBQP register allocation.", vrm);
Lang Hames
committed
vregsToAlloc.clear();
emptyIntervalVRegs.clear();
Lang Hames
committed
li2Node.clear();
node2LI.clear();
allowedSets.clear();
DEBUG(dbgs() << "Post alloc VirtRegMap:\n" << *vrm << "\n");
Lang Hames
committed
// Run rewriter
std::auto_ptr<VirtRegRewriter> rewriter(createVirtRegRewriter());
rewriter->runOnMachineFunction(*mf, *vrm, lis);
Lang Hames
committed
}
Lang Hames
committed
FunctionPass* createPBQPRegisterAllocator() {
return new RegAllocPBQP(std::auto_ptr<PBQPBuilder>(new PBQPBuilder()));
}
Lang Hames
committed
}
#undef DEBUG_TYPE