diff --git a/lib/CodeGen/RegAllocLinearScan.cpp b/lib/CodeGen/RegAllocLinearScan.cpp index 9a358faea01..18a3db81500 100644 --- a/lib/CodeGen/RegAllocLinearScan.cpp +++ b/lib/CodeGen/RegAllocLinearScan.cpp @@ -29,7 +29,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/Compiler.h" #include -#include #include #include #include @@ -138,14 +137,14 @@ namespace { template void printIntervals(const char* const str, ItTy i, ItTy e) const { - if (str) std::cerr << str << " intervals:\n"; + if (str) DOUT << str << " intervals:\n"; for (; i != e; ++i) { - std::cerr << "\t" << *i->first << " -> "; + DOUT << "\t" << *i->first << " -> "; unsigned reg = i->first->reg; if (MRegisterInfo::isVirtualRegister(reg)) { reg = vrm_->getPhys(reg); } - std::cerr << mri_->getName(reg) << '\n'; + DOUT << mri_->getName(reg) << '\n'; } } }; @@ -243,9 +242,8 @@ void RA::initIntervalSets() void RA::linearScan() { // linear scan algorithm - DEBUG(std::cerr << "********** LINEAR SCAN **********\n"); - DEBUG(std::cerr << "********** Function: " - << mf_->getFunction()->getName() << '\n'); + DOUT << "********** LINEAR SCAN **********\n"; + DOUT << "********** Function: " << mf_->getFunction()->getName() << '\n'; // DEBUG(printIntervals("unhandled", unhandled_.begin(), unhandled_.end())); DEBUG(printIntervals("fixed", fixed_.begin(), fixed_.end())); @@ -257,7 +255,7 @@ void RA::linearScan() LiveInterval* cur = unhandled_.top(); unhandled_.pop(); ++numIterations; - DEBUG(std::cerr << "\n*** CURRENT ***: " << *cur << '\n'); + DOUT << "\n*** CURRENT ***: " << *cur << '\n'; processActiveIntervals(cur->beginNumber()); processInactiveIntervals(cur->beginNumber()); @@ -280,7 +278,7 @@ void RA::linearScan() for (IntervalPtrs::reverse_iterator i = active_.rbegin(); i != active_.rend(); ) { unsigned reg = i->first->reg; - DEBUG(std::cerr << "\tinterval " << *i->first << " expired\n"); + DOUT << "\tinterval " << *i->first << " expired\n"; assert(MRegisterInfo::isVirtualRegister(reg) && "Can only allocate virtual registers!"); reg = vrm_->getPhys(reg); @@ -291,18 +289,18 @@ void RA::linearScan() // expire any remaining inactive intervals for (IntervalPtrs::reverse_iterator i = inactive_.rbegin(); i != inactive_.rend(); ) { - DEBUG(std::cerr << "\tinterval " << *i->first << " expired\n"); + DOUT << "\tinterval " << *i->first << " expired\n"; i = IntervalPtrs::reverse_iterator(inactive_.erase(i.base()-1)); } - DEBUG(std::cerr << *vrm_); + DOUT << *vrm_; } /// processActiveIntervals - expire old intervals and move non-overlapping ones /// to the inactive list. void RA::processActiveIntervals(unsigned CurPoint) { - DEBUG(std::cerr << "\tprocessing active intervals:\n"); + DOUT << "\tprocessing active intervals:\n"; for (unsigned i = 0, e = active_.size(); i != e; ++i) { LiveInterval *Interval = active_[i].first; @@ -312,7 +310,7 @@ void RA::processActiveIntervals(unsigned CurPoint) IntervalPos = Interval->advanceTo(IntervalPos, CurPoint); if (IntervalPos == Interval->end()) { // Remove expired intervals. - DEBUG(std::cerr << "\t\tinterval " << *Interval << " expired\n"); + DOUT << "\t\tinterval " << *Interval << " expired\n"; assert(MRegisterInfo::isVirtualRegister(reg) && "Can only allocate virtual registers!"); reg = vrm_->getPhys(reg); @@ -325,7 +323,7 @@ void RA::processActiveIntervals(unsigned CurPoint) } else if (IntervalPos->start > CurPoint) { // Move inactive intervals to inactive list. - DEBUG(std::cerr << "\t\tinterval " << *Interval << " inactive\n"); + DOUT << "\t\tinterval " << *Interval << " inactive\n"; assert(MRegisterInfo::isVirtualRegister(reg) && "Can only allocate virtual registers!"); reg = vrm_->getPhys(reg); @@ -348,7 +346,7 @@ void RA::processActiveIntervals(unsigned CurPoint) /// ones to the active list. void RA::processInactiveIntervals(unsigned CurPoint) { - DEBUG(std::cerr << "\tprocessing inactive intervals:\n"); + DOUT << "\tprocessing inactive intervals:\n"; for (unsigned i = 0, e = inactive_.size(); i != e; ++i) { LiveInterval *Interval = inactive_[i].first; @@ -358,7 +356,7 @@ void RA::processInactiveIntervals(unsigned CurPoint) IntervalPos = Interval->advanceTo(IntervalPos, CurPoint); if (IntervalPos == Interval->end()) { // remove expired intervals. - DEBUG(std::cerr << "\t\tinterval " << *Interval << " expired\n"); + DOUT << "\t\tinterval " << *Interval << " expired\n"; // Pop off the end of the list. inactive_[i] = inactive_.back(); @@ -366,7 +364,7 @@ void RA::processInactiveIntervals(unsigned CurPoint) --i; --e; } else if (IntervalPos->start <= CurPoint) { // move re-activated intervals in active list - DEBUG(std::cerr << "\t\tinterval " << *Interval << " active\n"); + DOUT << "\t\tinterval " << *Interval << " active\n"; assert(MRegisterInfo::isVirtualRegister(reg) && "Can only allocate virtual registers!"); reg = vrm_->getPhys(reg); @@ -416,7 +414,7 @@ static void RevertVectorIteratorsTo(RA::IntervalPtrs &V, unsigned Point) { /// spill. void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) { - DEBUG(std::cerr << "\tallocating current interval: "); + DOUT << "\tallocating current interval: "; PhysRegTracker backupPrt = *prt_; @@ -516,14 +514,14 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) // the free physical register and add this interval to the active // list. if (physReg) { - DEBUG(std::cerr << mri_->getName(physReg) << '\n'); + DOUT << mri_->getName(physReg) << '\n'; vrm_->assignVirt2Phys(cur->reg, physReg); prt_->addRegUse(physReg); active_.push_back(std::make_pair(cur, cur->begin())); handled_.push_back(cur); return; } - DEBUG(std::cerr << "no free registers\n"); + DOUT << "no free registers\n"; // Compile the spill weights into an array that is better for scanning. std::vector SpillWeights(mri_->getNumRegs(), 0.0); @@ -541,7 +539,7 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) updateSpillWeights(SpillWeights, reg, i->first->weight, mri_); } - DEBUG(std::cerr << "\tassigning stack slot at interval "<< *cur << ":\n"); + DOUT << "\tassigning stack slot at interval "<< *cur << ":\n"; // Find a register to spill. float minWeight = HUGE_VALF; @@ -575,14 +573,14 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) minReg = *RC->allocation_order_begin(*mf_); } - DEBUG(std::cerr << "\t\tregister with min weight: " - << mri_->getName(minReg) << " (" << minWeight << ")\n"); + DOUT << "\t\tregister with min weight: " + << mri_->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 // linearscan. if (cur->weight != HUGE_VALF && cur->weight <= minWeight) { - DEBUG(std::cerr << "\t\t\tspilling(c): " << *cur << '\n';); + DOUT << "\t\t\tspilling(c): " << *cur << '\n'; int slot = vrm_->assignVirt2StackSlot(cur->reg); std::vector added = li_->addIntervalsForSpills(*cur, *vrm_, slot); @@ -634,7 +632,7 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) if (//MRegisterInfo::isVirtualRegister(reg) && toSpill[vrm_->getPhys(reg)] && cur->overlapsFrom(*i->first, i->second)) { - DEBUG(std::cerr << "\t\t\tspilling(a): " << *i->first << '\n'); + DOUT << "\t\t\tspilling(a): " << *i->first << '\n'; earliestStart = std::min(earliestStart, i->first->beginNumber()); int slot = vrm_->assignVirt2StackSlot(i->first->reg); std::vector newIs = @@ -648,7 +646,7 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) if (//MRegisterInfo::isVirtualRegister(reg) && toSpill[vrm_->getPhys(reg)] && cur->overlapsFrom(*i->first, i->second-1)) { - DEBUG(std::cerr << "\t\t\tspilling(i): " << *i->first << '\n'); + DOUT << "\t\t\tspilling(i): " << *i->first << '\n'; earliestStart = std::min(earliestStart, i->first->beginNumber()); int slot = vrm_->assignVirt2StackSlot(reg); std::vector newIs = @@ -658,7 +656,7 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) } } - DEBUG(std::cerr << "\t\trolling back to: " << earliestStart << '\n'); + DOUT << "\t\trolling back to: " << earliestStart << '\n'; // Scan handled in reverse order up to the earliest start of a // spilled live interval and undo each one, restoring the state of @@ -668,7 +666,7 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) // If this interval starts before t we are done. if (i->beginNumber() < earliestStart) break; - DEBUG(std::cerr << "\t\t\tundo changes for: " << *i << '\n'); + DOUT << "\t\t\tundo changes for: " << *i << '\n'; handled_.pop_back(); // When undoing a live interval allocation we must know if it is active or @@ -708,7 +706,7 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) LiveInterval *HI = handled_[i]; if (!HI->expiredAt(earliestStart) && HI->expiredAt(cur->beginNumber())) { - DEBUG(std::cerr << "\t\t\tundo changes for: " << *HI << '\n'); + DOUT << "\t\t\tundo changes for: " << *HI << '\n'; active_.push_back(std::make_pair(HI, HI->begin())); assert(!MRegisterInfo::isPhysicalRegister(HI->reg)); prt_->addRegUse(vrm_->getPhys(HI->reg));