Skip to content

Commit d6bd311

Browse files
committed
Use a smallvector for inactiveCounts and initialize it lazily
instead of init'ing it maximally to zeros on entry. getFreePhysReg is pretty hot and only a few elements are typically used. This speeds up linscan by 5% on 176.gcc. llvm-svn: 47631
1 parent dc1b011 commit d6bd311

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

llvm/lib/CodeGen/RegAllocLinearScan.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur)
839839
/// getFreePhysReg - return a free physical register for this virtual register
840840
/// interval if we have one, otherwise return 0.
841841
unsigned RALinScan::getFreePhysReg(LiveInterval *cur) {
842-
std::vector<unsigned> inactiveCounts(tri_->getNumRegs(), 0);
842+
SmallVector<unsigned, 256> inactiveCounts;
843843
unsigned MaxInactiveCount = 0;
844844

845845
const TargetRegisterClass *RC = reginfo_->getRegClass(cur->reg);
@@ -856,6 +856,8 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) {
856856
const TargetRegisterClass *RegRC = reginfo_->getRegClass(reg);
857857
if (RelatedRegClasses.getLeaderValue(RegRC) == RCLeader) {
858858
reg = vrm_->getPhys(reg);
859+
if (inactiveCounts.size() <= reg)
860+
inactiveCounts.resize(reg+1);
859861
++inactiveCounts[reg];
860862
MaxInactiveCount = std::max(MaxInactiveCount, inactiveCounts[reg]);
861863
}
@@ -882,10 +884,13 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) {
882884
for (; I != E; ++I)
883885
if (prt_->isRegAvail(*I)) {
884886
FreeReg = *I;
885-
FreeRegInactiveCount = inactiveCounts[FreeReg];
887+
if (FreeReg < inactiveCounts.size())
888+
FreeRegInactiveCount = inactiveCounts[FreeReg];
889+
else
890+
FreeRegInactiveCount = 0;
886891
break;
887892
}
888-
893+
889894
// If there are no free regs, or if this reg has the max inactive count,
890895
// return this register.
891896
if (FreeReg == 0 || FreeRegInactiveCount == MaxInactiveCount) return FreeReg;
@@ -896,7 +901,8 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) {
896901
// reevaluated now.
897902
for (; I != E; ++I) {
898903
unsigned Reg = *I;
899-
if (prt_->isRegAvail(Reg) && FreeRegInactiveCount < inactiveCounts[Reg]) {
904+
if (prt_->isRegAvail(Reg) && Reg < inactiveCounts.size() &&
905+
FreeRegInactiveCount < inactiveCounts[Reg]) {
900906
FreeReg = Reg;
901907
FreeRegInactiveCount = inactiveCounts[Reg];
902908
if (FreeRegInactiveCount == MaxInactiveCount)

0 commit comments

Comments
 (0)