"llvm/lib/git@repo.hca.bsc.es:rferrer/llvm-epi-0.8.git" did not exist on "a618e13c8390040521e3bd55cfd072d3afd3f7d0"
Newer
Older
}
Evan Cheng
committed
}
}
// If folding is not possible / failed, then tell the spiller to issue a
// load / rematerialization for us.
nI.removeRange(index.getLoadIndex(), index.getDefIndex());
vrm.addRestorePoint(VReg, MI);
Id = RestoreMBBs.find_next(Id);
// Finalize intervals: add kills, finalize spill weights, and filter out
// dead intervals.
std::vector<LiveInterval*> RetNewLIs;
for (unsigned i = 0, e = NewLIs.size(); i != e; ++i) {
LiveInterval *LI = NewLIs[i];
if (!LI->empty()) {
if (!AddedKill.count(LI)) {
LiveRange *LR = &LI->ranges[LI->ranges.size()-1];
MachineInstr *LastUse = getInstructionFromIndex(LastUseIdx);
int UseIdx = LastUse->findRegisterUseOperandIdx(LI->reg, false);
if (!LastUse->isRegTiedToDefOperand(UseIdx)) {
LastUse->getOperand(UseIdx).setIsKill();
vrm.addKillPoint(LI->reg, LastUseIdx);
Evan Cheng
committed
}
RetNewLIs.push_back(LI);
}
}
Evan Cheng
committed
handleSpilledImpDefs(li, vrm, rc, RetNewLIs);
Jakob Stoklund Olesen
committed
normalizeSpillWeights(RetNewLIs);
Evan Cheng
committed
/// hasAllocatableSuperReg - Return true if the specified physical register has
/// any super register that's allocatable.
bool LiveIntervals::hasAllocatableSuperReg(unsigned Reg) const {
for (const unsigned* AS = tri_->getSuperRegisters(Reg); *AS; ++AS)
if (allocatableRegs_[*AS] && hasInterval(*AS))
return true;
return false;
}
/// getRepresentativeReg - Find the largest super register of the specified
/// physical register.
unsigned LiveIntervals::getRepresentativeReg(unsigned Reg) const {
// Find the largest super-register that is allocatable.
Evan Cheng
committed
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
unsigned BestReg = Reg;
for (const unsigned* AS = tri_->getSuperRegisters(Reg); *AS; ++AS) {
unsigned SuperReg = *AS;
if (!hasAllocatableSuperReg(SuperReg) && hasInterval(SuperReg)) {
BestReg = SuperReg;
break;
}
}
return BestReg;
}
/// getNumConflictsWithPhysReg - Return the number of uses and defs of the
/// specified interval that conflicts with the specified physical register.
unsigned LiveIntervals::getNumConflictsWithPhysReg(const LiveInterval &li,
unsigned PhysReg) const {
unsigned NumConflicts = 0;
const LiveInterval &pli = getInterval(getRepresentativeReg(PhysReg));
for (MachineRegisterInfo::reg_iterator I = mri_->reg_begin(li.reg),
E = mri_->reg_end(); I != E; ++I) {
MachineOperand &O = I.getOperand();
MachineInstr *MI = O.getParent();
if (MI->isDebugValue())
continue;
Evan Cheng
committed
if (pli.liveAt(Index))
++NumConflicts;
}
return NumConflicts;
}
/// spillPhysRegAroundRegDefsUses - Spill the specified physical register
/// around all defs and uses of the specified interval. Return true if it
/// was able to cut its interval.
bool LiveIntervals::spillPhysRegAroundRegDefsUses(const LiveInterval &li,
Evan Cheng
committed
unsigned PhysReg, VirtRegMap &vrm) {
unsigned SpillReg = getRepresentativeReg(PhysReg);
Jakob Stoklund Olesen
committed
DEBUG(dbgs() << "spillPhysRegAroundRegDefsUses " << tri_->getName(PhysReg)
<< " represented by " << tri_->getName(SpillReg) << '\n');
Evan Cheng
committed
for (const unsigned *AS = tri_->getAliasSet(PhysReg); *AS; ++AS)
// If there are registers which alias PhysReg, but which are not a
// sub-register of the chosen representative super register. Assert
// since we can't handle it yet.
assert(*AS == SpillReg || !allocatableRegs_[*AS] || !hasInterval(*AS) ||
Evan Cheng
committed
tri_->isSuperRegister(*AS, SpillReg));
Evan Cheng
committed
SmallVector<unsigned, 4> PRegs;
if (hasInterval(SpillReg))
PRegs.push_back(SpillReg);
Jakob Stoklund Olesen
committed
for (const unsigned *SR = tri_->getSubRegisters(SpillReg); *SR; ++SR)
if (hasInterval(*SR))
PRegs.push_back(*SR);
DEBUG({
dbgs() << "Trying to spill:";
for (unsigned i = 0, e = PRegs.size(); i != e; ++i)
dbgs() << ' ' << tri_->getName(PRegs[i]);
dbgs() << '\n';
});
Evan Cheng
committed
Evan Cheng
committed
SmallPtrSet<MachineInstr*, 8> SeenMIs;
for (MachineRegisterInfo::reg_iterator I = mri_->reg_begin(li.reg),
E = mri_->reg_end(); I != E; ++I) {
MachineOperand &O = I.getOperand();
MachineInstr *MI = O.getParent();
if (MI->isDebugValue() || SeenMIs.count(MI))
Evan Cheng
committed
continue;
SeenMIs.insert(MI);
Jakob Stoklund Olesen
committed
bool LiveReg = false;
Evan Cheng
committed
for (unsigned i = 0, e = PRegs.size(); i != e; ++i) {
unsigned PReg = PRegs[i];
LiveInterval &pli = getInterval(PReg);
if (!pli.liveAt(Index))
continue;
Jakob Stoklund Olesen
committed
LiveReg = true;
SlotIndex StartIdx = Index.getLoadIndex();
SlotIndex EndIdx = Index.getNextIndex().getBaseIndex();
Jakob Stoklund Olesen
committed
if (!pli.isInOneLiveRange(StartIdx, EndIdx)) {
std::string msg;
raw_string_ostream Msg(msg);
Msg << "Ran out of registers during register allocation!";
if (MI->isInlineAsm()) {
Msg << "\nPlease check your inline asm statement for invalid "
Evan Cheng
committed
<< "constraints:\n";
report_fatal_error(Msg.str());
Jakob Stoklund Olesen
committed
pli.removeRange(StartIdx, EndIdx);
LiveReg = true;
Evan Cheng
committed
}
Jakob Stoklund Olesen
committed
if (!LiveReg)
continue;
DEBUG(dbgs() << "Emergency spill around " << Index << '\t' << *MI);
vrm.addEmergencySpill(SpillReg, MI);
Cut = true;
Evan Cheng
committed
}
Evan Cheng
committed
}
Owen Anderson
committed
LiveRange LiveIntervals::addLiveRangeToEndOfBlock(unsigned reg,
MachineInstr* startInst) {
Owen Anderson
committed
LiveInterval& Interval = getOrCreateInterval(reg);
VNInfo* VN = Interval.getNextValue(
SlotIndex(getInstructionIndex(startInst).getDefIndex()),
startInst, getVNInfoAllocator());
LiveRange LR(
SlotIndex(getInstructionIndex(startInst).getDefIndex()),
getMBBEndIdx(startInst->getParent()), VN);
Owen Anderson
committed
Interval.addRange(LR);
Owen Anderson
committed
return LR;
}