Improve debugging output. Remove unneeded virtReg->0 mapping when

virtReg lives on the stack. Now a virtual register has an entry in the
virtual->physical map or the virtual->stack slot map but never in
both.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10958 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alkis Evlogimenos 2004-01-22 19:24:43 +00:00
parent 1075ecd32f
commit ce50115006

View File

@ -152,13 +152,18 @@ namespace {
memcpy(regUse_, regUseBackup_, sizeof(regUseBackup_)); memcpy(regUse_, regUseBackup_, sizeof(regUseBackup_));
} }
void printVirt2PhysMap() const { void printVirtRegAssignment() const {
std::cerr << "allocated registers:\n"; std::cerr << "register assignment:\n";
for (Virt2PhysMap::const_iterator for (Virt2PhysMap::const_iterator
i = v2pMap_.begin(), e = v2pMap_.end(); i != e; ++i) { i = v2pMap_.begin(), e = v2pMap_.end(); i != e; ++i) {
assert(i->second != 0);
std::cerr << '[' << i->first << ',' std::cerr << '[' << i->first << ','
<< mri_->getName(i->second) << "]\n"; << mri_->getName(i->second) << "]\n";
} }
for (Virt2StackSlotMap::const_iterator
i = v2ssMap_.begin(), e = v2ssMap_.end(); i != e; ++i) {
std::cerr << '[' << i->first << ",ss#" << i->second << "]\n";
}
std::cerr << '\n'; std::cerr << '\n';
} }
@ -320,7 +325,7 @@ bool RA::runOnMachineFunction(MachineFunction &fn) {
inactive_.clear(); inactive_.clear();
DEBUG(std::cerr << "finished register allocation\n"); DEBUG(std::cerr << "finished register allocation\n");
DEBUG(printVirt2PhysMap()); DEBUG(printVirtRegAssignment());
DEBUG(std::cerr << "Rewrite machine code:\n"); DEBUG(std::cerr << "Rewrite machine code:\n");
for (currentMbb_ = mf_->begin(); currentMbb_ != mf_->end(); ++currentMbb_) { for (currentMbb_ = mf_->begin(); currentMbb_ != mf_->end(); ++currentMbb_) {
@ -341,11 +346,11 @@ bool RA::runOnMachineFunction(MachineFunction &fn) {
MachineOperand& op = (*currentInstr_)->getOperand(i); MachineOperand& op = (*currentInstr_)->getOperand(i);
if (op.isVirtualRegister()) { if (op.isVirtualRegister()) {
unsigned virtReg = op.getAllocatedRegNum(); unsigned virtReg = op.getAllocatedRegNum();
unsigned physReg = v2pMap_[virtReg]; Virt2PhysMap::const_iterator it = v2pMap_.find(virtReg);
if (physReg) { if (it != v2pMap_.end()) {
DEBUG(std::cerr << "\t\t\t%reg" << virtReg DEBUG(std::cerr << "\t\t\t%reg" << it->second
<< " -> " << mri_->getName(physReg) << '\n'); << " -> " << mri_->getName(it->second) << '\n');
(*currentInstr_)->SetMachineOperandReg(i, physReg); (*currentInstr_)->SetMachineOperandReg(i, it->second);
} }
} }
} }
@ -357,8 +362,12 @@ bool RA::runOnMachineFunction(MachineFunction &fn) {
MachineOperand& op = (*currentInstr_)->getOperand(i); MachineOperand& op = (*currentInstr_)->getOperand(i);
if (op.isVirtualRegister() && op.isUse() && !op.isDef()) { if (op.isVirtualRegister() && op.isUse() && !op.isDef()) {
unsigned virtReg = op.getAllocatedRegNum(); unsigned virtReg = op.getAllocatedRegNum();
unsigned physReg = v2pMap_[virtReg]; unsigned physReg = 0;
if (!physReg) { Virt2PhysMap::const_iterator it = v2pMap_.find(virtReg);
if (it != v2pMap_.end()) {
physReg = it->second;
}
else {
physReg = getFreeTempPhysReg(virtReg); physReg = getFreeTempPhysReg(virtReg);
loadVirt2PhysReg(virtReg, physReg); loadVirt2PhysReg(virtReg, physReg);
tempUseOperands_.push_back(virtReg); tempUseOperands_.push_back(virtReg);
@ -380,8 +389,12 @@ bool RA::runOnMachineFunction(MachineFunction &fn) {
MachineOperand& op = (*currentInstr_)->getOperand(i); MachineOperand& op = (*currentInstr_)->getOperand(i);
if (op.isVirtualRegister() && op.isDef()) { if (op.isVirtualRegister() && op.isDef()) {
unsigned virtReg = op.getAllocatedRegNum(); unsigned virtReg = op.getAllocatedRegNum();
unsigned physReg = v2pMap_[virtReg]; unsigned physReg = 0;
if (!physReg) { Virt2PhysMap::const_iterator it = v2pMap_.find(virtReg);
if (it != v2pMap_.end()) {
physReg = it->second;
}
else {
physReg = getFreeTempPhysReg(virtReg); physReg = getFreeTempPhysReg(virtReg);
} }
if (op.isUse()) { // def and use if (op.isUse()) { // def and use
@ -563,6 +576,8 @@ void RA::assignStackSlotAtInterval(IntervalPtrs::value_type cur)
minReg = reg; minReg = reg;
} }
} }
DEBUG(std::cerr << "\t\t\tregister with min weight: "
<< mri_->getName(minReg) << " (" << minWeight << ")\n");
if (cur->weight < minWeight) { if (cur->weight < minWeight) {
restoreRegUse(); restoreRegUse();
@ -570,7 +585,6 @@ void RA::assignStackSlotAtInterval(IntervalPtrs::value_type cur)
assignVirt2StackSlot(cur->reg); assignVirt2StackSlot(cur->reg);
} }
else { else {
DEBUG(std::cerr << "\t\t\t\tfreeing: " << mri_->getName(minReg) << '\n');
std::set<unsigned> toSpill; std::set<unsigned> toSpill;
toSpill.insert(minReg); toSpill.insert(minReg);
for (const unsigned* as = mri_->getAliasSet(minReg); *as; ++as) for (const unsigned* as = mri_->getAliasSet(minReg); *as; ++as)
@ -674,7 +688,9 @@ unsigned RA::getFreeTempPhysReg(unsigned virtReg)
void RA::assignVirt2PhysReg(unsigned virtReg, unsigned physReg) void RA::assignVirt2PhysReg(unsigned virtReg, unsigned physReg)
{ {
v2pMap_[virtReg] = physReg; bool inserted = v2pMap_.insert(std::make_pair(virtReg, physReg)).second;
assert(inserted && "attempting to assign a virt->phys mapping to an "
"already mapped register");
markPhysRegNotFree(physReg); markPhysRegNotFree(physReg);
} }
@ -685,8 +701,7 @@ void RA::clearVirtReg(unsigned virtReg)
"attempting to clear a not allocated virtual register"); "attempting to clear a not allocated virtual register");
unsigned physReg = it->second; unsigned physReg = it->second;
markPhysRegFree(physReg); markPhysRegFree(physReg);
v2pMap_[virtReg] = 0; // this marks that this virtual register v2pMap_.erase(it);
// lives on the stack
DEBUG(std::cerr << "\t\t\tcleared register " << mri_->getName(physReg) DEBUG(std::cerr << "\t\t\tcleared register " << mri_->getName(physReg)
<< "\n"); << "\n");
} }
@ -704,10 +719,6 @@ void RA::assignVirt2StackSlot(unsigned virtReg)
if (v2pMap_.find(virtReg) != v2pMap_.end()) { if (v2pMap_.find(virtReg) != v2pMap_.end()) {
clearVirtReg(virtReg); clearVirtReg(virtReg);
} }
else {
v2pMap_[virtReg] = 0; // this marks that this virtual register
// lives on the stack
}
} }
int RA::getStackSlot(unsigned virtReg) int RA::getStackSlot(unsigned virtReg)