Skip to content
RegAllocPBQP.cpp 34.8 KiB
Newer Older
Lang Hames's avatar
Lang Hames committed
  DEBUG(dbgs() << "PBQP Register Allocating for " << mf->getFunction()->getName() << "\n");
  // * 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.

  // Find the vreg intervals in need of allocation.
  findVRegIntervalsToAlloc();
  // If there are non-empty intervals allocate them using pbqp.
    if (!pbqpBuilder) {
      while (!pbqpAllocComplete) {
        DEBUG(dbgs() << "  PBQP Regalloc round " << round << ":\n");
        PBQP::Graph problem = constructPBQPProblem();
        PBQP::Solution solution =
          PBQP::HeuristicSolver<PBQP::Heuristics::Briggs>::solve(problem);
        pbqpAllocComplete = mapPBQPToRegAlloc(solution);
        ++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;
      }
  // Finalise allocation, allocate empty ranges.
  finalizeAlloc();
  rmf->renderMachineFunction("After PBQP register allocation.", vrm);

  vregsToAlloc.clear();
  emptyIntervalVRegs.clear();
Lang Hames's avatar
Lang Hames committed
  problemNodes.clear();
David Greene's avatar
David Greene committed
  DEBUG(dbgs() << "Post alloc VirtRegMap:\n" << *vrm << "\n");
  // Run rewriter
  std::auto_ptr<VirtRegRewriter> rewriter(createVirtRegRewriter());

  rewriter->runOnMachineFunction(*mf, *vrm, lis);
Misha Brukman's avatar
Misha Brukman committed
  return true;
FunctionPass* createPBQPRegisterAllocator() {
  return new RegAllocPBQP(std::auto_ptr<PBQPBuilder>(new PBQPBuilder()));