Skip to content

Commit 11bb63a

Browse files
committed
Switch PBQP to the modern InlineSpiller framework.
It is worth noting that the old spiller would split live ranges around basic blocks. The new spiller doesn't do that. PBQP should do its own live range splitting with SplitEditor::splitSingleBlock() if desired. See RAGreedy::tryBlockSplit(). llvm-svn: 144476
1 parent e7e50e6 commit 11bb63a

File tree

1 file changed

+11
-40
lines changed

1 file changed

+11
-40
lines changed

llvm/lib/CodeGen/RegAllocPBQP.cpp

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
#define DEBUG_TYPE "regalloc"
3333

34+
#include "LiveRangeEdit.h"
3435
#include "RenderMachineFunction.h"
36+
#include "Spiller.h"
3537
#include "Splitter.h"
3638
#include "VirtRegMap.h"
3739
#include "VirtRegRewriter.h"
@@ -132,6 +134,7 @@ class RegAllocPBQP : public MachineFunctionPass {
132134
MachineRegisterInfo *mri;
133135
RenderMachineFunction *rmf;
134136

137+
std::auto_ptr<Spiller> spiller;
135138
LiveIntervals *lis;
136139
LiveStacks *lss;
137140
VirtRegMap *vrm;
@@ -141,10 +144,6 @@ class RegAllocPBQP : public MachineFunctionPass {
141144
/// \brief Finds the initial set of vreg intervals to allocate.
142145
void findVRegIntervalsToAlloc();
143146

144-
/// \brief Adds a stack interval if the given live interval has been
145-
/// spilled. Used to support stack slot coloring.
146-
void addStackInterval(const LiveInterval *spilled,MachineRegisterInfo* mri);
147-
148147
/// \brief Given a solved PBQP problem maps this solution back to a register
149148
/// assignment.
150149
bool mapPBQPToRegAlloc(const PBQPRAProblem &problem,
@@ -488,29 +487,6 @@ void RegAllocPBQP::findVRegIntervalsToAlloc() {
488487
}
489488
}
490489

491-
void RegAllocPBQP::addStackInterval(const LiveInterval *spilled,
492-
MachineRegisterInfo* mri) {
493-
int stackSlot = vrm->getStackSlot(spilled->reg);
494-
495-
if (stackSlot == VirtRegMap::NO_STACK_SLOT) {
496-
return;
497-
}
498-
499-
const TargetRegisterClass *RC = mri->getRegClass(spilled->reg);
500-
LiveInterval &stackInterval = lss->getOrCreateInterval(stackSlot, RC);
501-
502-
VNInfo *vni;
503-
if (stackInterval.getNumValNums() != 0) {
504-
vni = stackInterval.getValNumInfo(0);
505-
} else {
506-
vni = stackInterval.getNextValue(
507-
SlotIndex(), 0, lss->getVNInfoAllocator());
508-
}
509-
510-
LiveInterval &rhsInterval = lis->getInterval(spilled->reg);
511-
stackInterval.MergeRangesInAsValue(rhsInterval, vni);
512-
}
513-
514490
bool RegAllocPBQP::mapPBQPToRegAlloc(const PBQPRAProblem &problem,
515491
const PBQP::Solution &solution) {
516492
// Set to true if we have any spills
@@ -535,22 +511,16 @@ bool RegAllocPBQP::mapPBQPToRegAlloc(const PBQPRAProblem &problem,
535511
vrm->assignVirt2Phys(vreg, preg);
536512
} else if (problem.isSpillOption(vreg, alloc)) {
537513
vregsToAlloc.erase(vreg);
538-
const LiveInterval* spillInterval = &lis->getInterval(vreg);
539-
double oldWeight = spillInterval->weight;
540-
rmf->rememberUseDefs(spillInterval);
541-
std::vector<LiveInterval*> newSpills =
542-
lis->addIntervalsForSpills(*spillInterval, 0, loopInfo, *vrm);
543-
addStackInterval(spillInterval, mri);
544-
rmf->rememberSpills(spillInterval, newSpills);
545-
546-
(void) oldWeight;
514+
SmallVector<LiveInterval*, 8> newSpills;
515+
LiveRangeEdit LRE(lis->getInterval(vreg), newSpills);
516+
spiller->spill(LRE);
517+
547518
DEBUG(dbgs() << "VREG " << vreg << " -> SPILLED (Cost: "
548-
<< oldWeight << ", New vregs: ");
519+
<< LRE.getParent().weight << ", New vregs: ");
549520

550521
// Copy any newly inserted live intervals into the list of regs to
551522
// allocate.
552-
for (std::vector<LiveInterval*>::const_iterator
553-
itr = newSpills.begin(), end = newSpills.end();
523+
for (LiveRangeEdit::iterator itr = LRE.begin(), end = LRE.end();
554524
itr != end; ++itr) {
555525
assert(!(*itr)->empty() && "Empty spill range.");
556526
DEBUG(dbgs() << (*itr)->reg << " ");
@@ -560,7 +530,7 @@ bool RegAllocPBQP::mapPBQPToRegAlloc(const PBQPRAProblem &problem,
560530
DEBUG(dbgs() << ")\n");
561531

562532
// We need another round if spill intervals were added.
563-
anotherRoundNeeded |= !newSpills.empty();
533+
anotherRoundNeeded |= !LRE.empty();
564534
} else {
565535
assert(false && "Unknown allocation option.");
566536
}
@@ -650,6 +620,7 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
650620
rmf = &getAnalysis<RenderMachineFunction>();
651621

652622
vrm = &getAnalysis<VirtRegMap>();
623+
spiller.reset(createInlineSpiller(*this, MF, *vrm));
653624

654625

655626
DEBUG(dbgs() << "PBQP Register Allocating for " << mf->getFunction()->getName() << "\n");

0 commit comments

Comments
 (0)