From a6c1750362ffb5e8c5b5b5232442cd4c49eafdc8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 22 Aug 2005 20:20:42 +0000 Subject: [PATCH] Move some code in the register assignment case that only needs to happen if we spill out of the fast path. The scan of active_ and the calls to updateSpillWeights don't need to happen unless a spill occurs. This reduces debug llc time of kc++ with ppc from 187.3s to 183.2s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22971 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/RegAllocLinearScan.cpp | 43 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/lib/CodeGen/RegAllocLinearScan.cpp b/lib/CodeGen/RegAllocLinearScan.cpp index e85826c0477..ce58e59cb55 100644 --- a/lib/CodeGen/RegAllocLinearScan.cpp +++ b/lib/CodeGen/RegAllocLinearScan.cpp @@ -365,23 +365,11 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) PhysRegTracker backupPrt = *prt_; - std::vector SpillWeights; - SpillWeights.assign(mri_->getNumRegs(), 0.0); - + std::vector > SpillWeightsToAdd; unsigned StartPosition = cur->beginNumber(); - // for each interval in active, update spill weights. - for (IntervalPtrs::const_iterator i = active_.begin(), e = active_.end(); - i != e; ++i) { - unsigned reg = i->first->reg; - assert(MRegisterInfo::isVirtualRegister(reg) && - "Can only allocate virtual registers!"); - reg = vrm_->getPhys(reg); - updateSpillWeights(SpillWeights, reg, i->first->weight, mri_); - } - // for every interval in inactive we overlap with, mark the - // register as not free and update spill weights + // register as not free and update spill weights. for (IntervalPtrs::const_iterator i = inactive_.begin(), e = inactive_.end(); i != e; ++i) { if (cur->overlapsFrom(*i->first, i->second-1)) { @@ -390,7 +378,7 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) "Can only allocate virtual registers!"); reg = vrm_->getPhys(reg); prt_->addRegUse(reg); - updateSpillWeights(SpillWeights, reg, i->first->weight, mri_); + SpillWeightsToAdd.push_back(std::make_pair(reg, i->first->weight)); } } @@ -407,14 +395,19 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) if (cur->overlapsFrom(*I, II)) { unsigned reg = I->reg; prt_->addRegUse(reg); - updateSpillWeights(SpillWeights, reg, I->weight, mri_); + SpillWeightsToAdd.push_back(std::make_pair(reg, I->weight)); } } } + // Using the newly updated prt_ object, which includes conflicts in the + // future, see if there are any registers available. unsigned physReg = getFreePhysReg(cur); - // restore the physical register tracker + + // Restore the physical register tracker, removing information about the + // future. *prt_ = backupPrt; + // if we find a free register, we are done: assign this virtual to // the free physical register and add this interval to the active // list. @@ -428,6 +421,22 @@ void RA::assignRegOrStackSlotAtInterval(LiveInterval* cur) } DEBUG(std::cerr << "no free registers\n"); + // Compile the spill weights into an array that is better for scanning. + std::vector SpillWeights(mri_->getNumRegs(), 0.0); + for (std::vector >::iterator + I = SpillWeightsToAdd.begin(), E = SpillWeightsToAdd.end(); I != E; ++I) + updateSpillWeights(SpillWeights, I->first, I->second, mri_); + + // for each interval in active, update spill weights. + for (IntervalPtrs::const_iterator i = active_.begin(), e = active_.end(); + i != e; ++i) { + unsigned reg = i->first->reg; + assert(MRegisterInfo::isVirtualRegister(reg) && + "Can only allocate virtual registers!"); + reg = vrm_->getPhys(reg); + updateSpillWeights(SpillWeights, reg, i->first->weight, mri_); + } + DEBUG(std::cerr << "\tassigning stack slot at interval "<< *cur << ":\n"); float minWeight = float(HUGE_VAL);