#include "PhysRegTracker.h"
#include "VirtRegMap.h"
#include <algorithm>
+#include <cmath>
#include <iostream>
using namespace llvm;
std::auto_ptr<PhysRegTracker> prt_;
std::auto_ptr<VirtRegMap> vrm_;
+ std::auto_ptr<Spiller> spiller_;
typedef std::vector<float> SpillWeights;
SpillWeights spillWeights_;
void RA::releaseMemory()
{
unhandled_.clear();
+ fixed_.clear();
active_.clear();
inactive_.clear();
- fixed_.clear();
handled_.clear();
}
li_ = &getAnalysis<LiveIntervals>();
if (!prt_.get()) prt_.reset(new PhysRegTracker(*mri_));
vrm_.reset(new VirtRegMap(*mf_));
+ if (!spiller_.get()) spiller_.reset(createSpiller());
initIntervalSets(li_->getIntervals());
linearScan();
- eliminateVirtRegs(*mf_, *vrm_);
+ spiller_->runOnMachineFunction(*mf_, *vrm_);
return true;
}
DEBUG(printIntervals("active", active_.begin(), active_.end()));
DEBUG(printIntervals("inactive", inactive_.begin(), inactive_.end()));
- while (!unhandled_.empty() || !fixed_.empty()) {
+ while (!unhandled_.empty()) {
// pick the interval with the earliest start point
- IntervalPtrs::value_type cur;
- if (fixed_.empty()) {
- cur = unhandled_.front();
- unhandled_.pop_front();
- }
- else if (unhandled_.empty()) {
- cur = fixed_.front();
- fixed_.pop_front();
- }
- else if (unhandled_.front()->start() < fixed_.front()->start()) {
- cur = unhandled_.front();
- unhandled_.pop_front();
- }
- else {
- cur = fixed_.front();
- fixed_.pop_front();
- }
+ IntervalPtrs::value_type cur = unhandled_.front();
+ unhandled_.pop_front();
DEBUG(std::cerr << "\n*** CURRENT ***: " << *cur << '\n');
for (LiveIntervals::Intervals::iterator i = li.begin(), e = li.end();
i != e; ++i) {
+ unhandled_.push_back(&*i);
if (MRegisterInfo::isPhysicalRegister(i->reg))
fixed_.push_back(&*i);
- else
- unhandled_.push_back(&*i);
}
}
DEBUG(std::cerr << "\tassigning stack slot at interval "<< *cur << ":\n");
- float minWeight = std::numeric_limits<float>::infinity();
+ float minWeight = HUGE_VAL;
unsigned minReg = 0;
const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(cur->reg);
for (TargetRegisterClass::iterator i = rc->allocation_order_begin(*mf_);
if (cur->weight <= minWeight) {
DEBUG(std::cerr << "\t\t\tspilling(c): " << *cur << '\n';);
int slot = vrm_->assignVirt2StackSlot(cur->reg);
- li_->updateSpilledInterval(*cur, slot);
+ li_->updateSpilledInterval(*cur, *vrm_, slot);
// if we didn't eliminate the interval find where to add it
// back to unhandled. We need to scan since unhandled are
DEBUG(std::cerr << "\t\t\tspilling(a): " << **i << '\n');
earliestStart = std::min(earliestStart, (*i)->start());
int slot = vrm_->assignVirt2StackSlot((*i)->reg);
- li_->updateSpilledInterval(**i, slot);
+ li_->updateSpilledInterval(**i, *vrm_, slot);
}
}
for (IntervalPtrs::iterator i = inactive_.begin();
DEBUG(std::cerr << "\t\t\tspilling(i): " << **i << '\n');
earliestStart = std::min(earliestStart, (*i)->start());
int slot = vrm_->assignVirt2StackSlot((*i)->reg);
- li_->updateSpilledInterval(**i, slot);
+ li_->updateSpilledInterval(**i, *vrm_, slot);
}
}
DEBUG(std::cerr << "\t\trolling back to: " << earliestStart << '\n');
// scan handled in reverse order and undo each one, restoring the
- // state of unhandled and fixed
+ // state of unhandled
while (!handled_.empty()) {
IntervalPtrs::value_type i = handled_.back();
// if this interval starts before t we are done
if ((it = find(active_.begin(), active_.end(), i)) != active_.end()) {
active_.erase(it);
if (MRegisterInfo::isPhysicalRegister(i->reg)) {
- fixed_.push_front(i);
prt_->delRegUse(i->reg);
+ unhandled_.push_front(i);
}
else {
prt_->delRegUse(vrm_->getPhys(i->reg));
- vrm_->clearVirtReg(i->reg);
+ vrm_->clearVirt(i->reg);
if (i->spilled()) {
if (!i->empty()) {
IntervalPtrs::iterator it = unhandled_.begin();
else if ((it = find(inactive_.begin(), inactive_.end(), i)) != inactive_.end()) {
inactive_.erase(it);
if (MRegisterInfo::isPhysicalRegister(i->reg))
- fixed_.push_front(i);
+ unhandled_.push_front(i);
else {
- vrm_->clearVirtReg(i->reg);
+ vrm_->clearVirt(i->reg);
if (i->spilled()) {
if (!i->empty()) {
IntervalPtrs::iterator it = unhandled_.begin();
}
}
else {
- if (MRegisterInfo::isPhysicalRegister(i->reg))
- fixed_.push_front(i);
- else {
- vrm_->clearVirtReg(i->reg);
- unhandled_.push_front(i);
- }
+ if (MRegisterInfo::isVirtualRegister(i->reg))
+ vrm_->clearVirt(i->reg);
+ unhandled_.push_front(i);
}
}