Newer
Older
CSRegSet restored = BI->second;
CSRegSet spilled;
if (restored.empty())
continue;
DEBUG(errs() << "SAVE[" << getBasicBlockName(MBB) << "] = "
<< stringifyCSRegSet(CSRSave[MBB])
<< " RESTORE[" << getBasicBlockName(MBB) << "] = "
<< stringifyCSRegSet(restored) << "\n");
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
if (CSRSave[MBB].intersects(restored)) {
spilled |= (CSRSave[MBB] & restored);
}
// Walk inverse depth first from MBB to find spills of all
// CSRs restored at MBB:
for (idf_iterator<MachineBasicBlock*> BI = idf_begin(MBB),
BE = idf_end(MBB); BI != BE; ++BI) {
MachineBasicBlock* PBB = *BI;
if (PBB == MBB)
continue;
// Stop when we encounter restores of any CSRs restored at MBB that
// have not yet been seen to be spilled.
if (CSRRestore[PBB].intersects(restored) &&
!spilled.contains(CSRRestore[PBB] & restored))
break;
// Collect the CSRs restored at MBB that are spilled
// at this DF predecessor of MBB.
if (CSRSave[PBB].intersects(restored))
spilled |= (CSRSave[PBB] & restored);
}
if (spilled != restored) {
CSRegSet notSpilled = (restored - spilled);
Daniel Dunbar
committed
DEBUG(errs() << MF->getFunction()->getName() << ": "
<< stringifyCSRegSet(notSpilled)
<< " restored at " << getBasicBlockName(MBB)
<< " are never spilled\n");
}
}
}
// Debugging print methods.
std::string PEI::getBasicBlockName(const MachineBasicBlock* MBB) {
Daniel Dunbar
committed
if (!MBB)
return "";
if (MBB->getBasicBlock())
return MBB->getBasicBlock()->getNameStr();
Daniel Dunbar
committed
name << "_MBB_" << MBB->getNumber();
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
return name.str();
}
std::string PEI::stringifyCSRegSet(const CSRegSet& s) {
const TargetRegisterInfo* TRI = MF->getTarget().getRegisterInfo();
const std::vector<CalleeSavedInfo> CSI =
MF->getFrameInfo()->getCalleeSavedInfo();
std::ostringstream srep;
if (CSI.size() == 0) {
srep << "[]";
return srep.str();
}
srep << "[";
CSRegSet::iterator I = s.begin(), E = s.end();
if (I != E) {
unsigned reg = CSI[*I].getReg();
srep << TRI->getName(reg);
for (++I; I != E; ++I) {
reg = CSI[*I].getReg();
srep << ",";
srep << TRI->getName(reg);
}
}
srep << "]";
return srep.str();
}
void PEI::dumpSet(const CSRegSet& s) {
DEBUG(errs() << stringifyCSRegSet(s) << "\n");
DEBUG({
if (MBB)
errs() << "CSRUsed[" << getBasicBlockName(MBB) << "] = "
<< stringifyCSRegSet(CSRUsed[MBB]) << "\n";
});
}
void PEI::dumpAllUsed() {
for (MachineFunction::iterator MBBI = MF->begin(), MBBE = MF->end();
MBBI != MBBE; ++MBBI) {
MachineBasicBlock* MBB = MBBI;
dumpUsed(MBB);
}
}
void PEI::dumpSets(MachineBasicBlock* MBB) {
DEBUG({
if (MBB)
errs() << getBasicBlockName(MBB) << " | "
<< stringifyCSRegSet(CSRUsed[MBB]) << " | "
<< stringifyCSRegSet(AnticIn[MBB]) << " | "
<< stringifyCSRegSet(AnticOut[MBB]) << " | "
<< stringifyCSRegSet(AvailIn[MBB]) << " | "
<< stringifyCSRegSet(AvailOut[MBB]) << "\n";
});
DEBUG({
if (MBB)
errs() << getBasicBlockName(MBB) << " | "
<< stringifyCSRegSet(CSRUsed[MBB]) << " | "
<< stringifyCSRegSet(AnticIn[MBB]) << " | "
<< stringifyCSRegSet(AnticOut[MBB]) << " | "
<< stringifyCSRegSet(AvailIn[MBB]) << " | "
<< stringifyCSRegSet(AvailOut[MBB]) << " | "
<< stringifyCSRegSet(CSRSave[MBB]) << " | "
<< stringifyCSRegSet(CSRRestore[MBB]) << "\n";
});
}
void PEI::dumpAllSets() {
for (MachineFunction::iterator MBBI = MF->begin(), MBBE = MF->end();
MBBI != MBBE; ++MBBI) {
MachineBasicBlock* MBB = MBBI;
dumpSets1(MBB);
}
}
void PEI::dumpSRSets() {
DEBUG({
for (MachineFunction::iterator MBB = MF->begin(), E = MF->end();
MBB != E; ++MBB) {
if (!CSRSave[MBB].empty()) {
errs() << "SAVE[" << getBasicBlockName(MBB) << "] = "
<< stringifyCSRegSet(CSRSave[MBB]);
if (CSRRestore[MBB].empty())
errs() << '\n';
}
if (!CSRRestore[MBB].empty() && !CSRSave[MBB].empty())
errs() << " "
<< "RESTORE[" << getBasicBlockName(MBB) << "] = "
<< stringifyCSRegSet(CSRRestore[MBB]) << "\n";
}
});