if (TargetRegisterInfo::isVirtualRegister(reg)) {
reg = vrm_->getPhys(reg);
}
- DOUT << tri_->getPrintableName(reg) << '\n';
+ DOUT << tri_->getName(reg) << '\n';
}
}
};
// Try to coalesce.
if (!li_->conflictsWithPhysRegDef(cur, *vrm_, SrcReg)) {
- DOUT << "Coalescing: " << cur << " -> " << tri_->getPrintableName(SrcReg)
+ DOUT << "Coalescing: " << cur << " -> " << tri_->getName(SrcReg)
<< '\n';
vrm_->clearVirt(cur.reg);
vrm_->assignVirt2Phys(cur.reg, SrcReg);
// the free physical register and add this interval to the active
// list.
if (physReg) {
- DOUT << tri_->getPrintableName(physReg) << '\n';
+ DOUT << tri_->getName(physReg) << '\n';
vrm_->assignVirt2Phys(cur->reg, physReg);
prt_->addRegUse(physReg);
active_.push_back(std::make_pair(cur, cur->begin()));
}
// All registers must have inf weight. Just grab one!
- if (!minReg)
+ if (!minReg) {
+ if (active_.size() == 0) {
+ // FIXME: All the registers are occupied by fixed intervals.
+ cerr << "Register allocator ran out of registers!\n";
+ abort();
+ }
minReg = *RC->allocation_order_begin(*mf_);
+ }
}
DOUT << "\t\tregister with min weight: "
- << tri_->getPrintableName(minReg) << " (" << minWeight << ")\n";
+ << tri_->getName(minReg) << " (" << minWeight << ")\n";
// if the current has the minimum weight, we need to spill it and
// add any added intervals back to unhandled, and restart
/// getFreePhysReg - return a free physical register for this virtual register
/// interval if we have one, otherwise return 0.
unsigned RALinScan::getFreePhysReg(LiveInterval *cur) {
- std::vector<unsigned> inactiveCounts(tri_->getNumRegs(), 0);
+ SmallVector<unsigned, 256> inactiveCounts;
unsigned MaxInactiveCount = 0;
const TargetRegisterClass *RC = reginfo_->getRegClass(cur->reg);
const TargetRegisterClass *RegRC = reginfo_->getRegClass(reg);
if (RelatedRegClasses.getLeaderValue(RegRC) == RCLeader) {
reg = vrm_->getPhys(reg);
+ if (inactiveCounts.size() <= reg)
+ inactiveCounts.resize(reg+1);
++inactiveCounts[reg];
MaxInactiveCount = std::max(MaxInactiveCount, inactiveCounts[reg]);
}
if (cur->preference) {
if (prt_->isRegAvail(cur->preference)) {
DOUT << "\t\tassigned the preferred register: "
- << tri_->getPrintableName(cur->preference) << "\n";
+ << tri_->getName(cur->preference) << "\n";
return cur->preference;
} else
DOUT << "\t\tunable to assign the preferred register: "
- << tri_->getPrintableName(cur->preference) << "\n";
+ << tri_->getName(cur->preference) << "\n";
}
// Scan for the first available register.
for (; I != E; ++I)
if (prt_->isRegAvail(*I)) {
FreeReg = *I;
- FreeRegInactiveCount = inactiveCounts[FreeReg];
+ if (FreeReg < inactiveCounts.size())
+ FreeRegInactiveCount = inactiveCounts[FreeReg];
+ else
+ FreeRegInactiveCount = 0;
break;
}
-
+
// If there are no free regs, or if this reg has the max inactive count,
// return this register.
if (FreeReg == 0 || FreeRegInactiveCount == MaxInactiveCount) return FreeReg;
// reevaluated now.
for (; I != E; ++I) {
unsigned Reg = *I;
- if (prt_->isRegAvail(Reg) && FreeRegInactiveCount < inactiveCounts[Reg]) {
+ if (prt_->isRegAvail(Reg) && Reg < inactiveCounts.size() &&
+ FreeRegInactiveCount < inactiveCounts[Reg]) {
FreeReg = Reg;
FreeRegInactiveCount = inactiveCounts[Reg];
if (FreeRegInactiveCount == MaxInactiveCount)