aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorAlkis Evlogimenos <alkis@evlogimenos.com>2004-09-02 21:24:33 +0000
committerAlkis Evlogimenos <alkis@evlogimenos.com>2004-09-02 21:24:33 +0000
commit70619fae28414db54e00be2f9052a66cd245a9c8 (patch)
tree1875eeeaf956c81eb1932946afe7497bb858ba61 /lib/CodeGen
parent84f5bcb0139789010eb4a4509fddf811def8794e (diff)
Change the way we choose a free register: instead of picking the first
free allocatable register, we prefer the a free one with the most uses of inactive intervals. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16148 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/RegAllocIterativeScan.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/CodeGen/RegAllocIterativeScan.cpp b/lib/CodeGen/RegAllocIterativeScan.cpp
index 26fa7b7655..4cdcc1d4dd 100644
--- a/lib/CodeGen/RegAllocIterativeScan.cpp
+++ b/lib/CodeGen/RegAllocIterativeScan.cpp
@@ -463,17 +463,28 @@ void RA::assignRegOrSpillAtInterval(IntervalPtrs::value_type cur)
}
-unsigned RA::getFreePhysReg(IntervalPtrs::value_type cur)
+unsigned RA::getFreePhysReg(LiveInterval* cur)
{
+ std::vector<unsigned> inactiveCounts(mri_->getNumRegs(), 0);
+ for (IntervalPtrs::iterator i = inactive_.begin(), e = inactive_.end();
+ i != e; ++i) {
+ unsigned reg = (*i)->reg;
+ if (MRegisterInfo::isVirtualRegister(reg))
+ reg = vrm_->getPhys(reg);
+ ++inactiveCounts[reg];
+ }
+
const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(cur->reg);
+ unsigned freeReg = 0;
for (TargetRegisterClass::iterator i = rc->allocation_order_begin(*mf_);
i != rc->allocation_order_end(*mf_); ++i) {
unsigned reg = *i;
- if (prt_->isRegAvail(reg))
- return reg;
+ if (prt_->isRegAvail(reg) &&
+ (!freeReg || inactiveCounts[freeReg] < inactiveCounts[reg]))
+ freeReg = reg;
}
- return 0;
+ return freeReg;
}
FunctionPass* llvm::createIterativeScanRegisterAllocator() {