31
31
32
32
#define DEBUG_TYPE " regalloc"
33
33
34
+ #include " LiveRangeEdit.h"
34
35
#include " RenderMachineFunction.h"
36
+ #include " Spiller.h"
35
37
#include " Splitter.h"
36
38
#include " VirtRegMap.h"
37
39
#include " VirtRegRewriter.h"
@@ -132,6 +134,7 @@ class RegAllocPBQP : public MachineFunctionPass {
132
134
MachineRegisterInfo *mri;
133
135
RenderMachineFunction *rmf;
134
136
137
+ std::auto_ptr<Spiller> spiller;
135
138
LiveIntervals *lis;
136
139
LiveStacks *lss;
137
140
VirtRegMap *vrm;
@@ -141,10 +144,6 @@ class RegAllocPBQP : public MachineFunctionPass {
141
144
// / \brief Finds the initial set of vreg intervals to allocate.
142
145
void findVRegIntervalsToAlloc ();
143
146
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
-
148
147
// / \brief Given a solved PBQP problem maps this solution back to a register
149
148
// / assignment.
150
149
bool mapPBQPToRegAlloc (const PBQPRAProblem &problem,
@@ -488,29 +487,6 @@ void RegAllocPBQP::findVRegIntervalsToAlloc() {
488
487
}
489
488
}
490
489
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
-
514
490
bool RegAllocPBQP::mapPBQPToRegAlloc (const PBQPRAProblem &problem,
515
491
const PBQP::Solution &solution) {
516
492
// Set to true if we have any spills
@@ -535,22 +511,16 @@ bool RegAllocPBQP::mapPBQPToRegAlloc(const PBQPRAProblem &problem,
535
511
vrm->assignVirt2Phys (vreg, preg);
536
512
} else if (problem.isSpillOption (vreg, alloc)) {
537
513
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
+
547
518
DEBUG (dbgs () << " VREG " << vreg << " -> SPILLED (Cost: "
548
- << oldWeight << " , New vregs: " );
519
+ << LRE. getParent (). weight << " , New vregs: " );
549
520
550
521
// Copy any newly inserted live intervals into the list of regs to
551
522
// 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 ();
554
524
itr != end; ++itr) {
555
525
assert (!(*itr)->empty () && " Empty spill range." );
556
526
DEBUG (dbgs () << (*itr)->reg << " " );
@@ -560,7 +530,7 @@ bool RegAllocPBQP::mapPBQPToRegAlloc(const PBQPRAProblem &problem,
560
530
DEBUG (dbgs () << " )\n " );
561
531
562
532
// We need another round if spill intervals were added.
563
- anotherRoundNeeded |= !newSpills .empty ();
533
+ anotherRoundNeeded |= !LRE .empty ();
564
534
} else {
565
535
assert (false && " Unknown allocation option." );
566
536
}
@@ -650,6 +620,7 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
650
620
rmf = &getAnalysis<RenderMachineFunction>();
651
621
652
622
vrm = &getAnalysis<VirtRegMap>();
623
+ spiller.reset (createInlineSpiller (*this , MF, *vrm));
653
624
654
625
655
626
DEBUG (dbgs () << " PBQP Register Allocating for " << mf->getFunction ()->getName () << " \n " );
0 commit comments