diff options
author | Chris Lattner <sabre@nondot.org> | 2008-02-26 22:08:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-02-26 22:08:41 +0000 |
commit | d6bd31150697932439d4b1a1ad421481750da4d6 (patch) | |
tree | 91607a290aed5eefb6748f7dbc348129a4ca853c /llvm/lib/CodeGen/RegAllocLinearScan.cpp | |
parent | dc1b0114edb46c8f8f53670dc035f900f2f61f21 (diff) | |
download | bcm5719-llvm-d6bd31150697932439d4b1a1ad421481750da4d6.tar.gz bcm5719-llvm-d6bd31150697932439d4b1a1ad421481750da4d6.zip |
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
Diffstat (limited to 'llvm/lib/CodeGen/RegAllocLinearScan.cpp')
-rw-r--r-- | llvm/lib/CodeGen/RegAllocLinearScan.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/RegAllocLinearScan.cpp b/llvm/lib/CodeGen/RegAllocLinearScan.cpp index dd3ea7d0a23..d43cc19683c 100644 --- a/llvm/lib/CodeGen/RegAllocLinearScan.cpp +++ b/llvm/lib/CodeGen/RegAllocLinearScan.cpp @@ -839,7 +839,7 @@ void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur) /// getFreePhysReg - return a free physical register for this virtual register /// interval if we have one, otherwise return 0. unsigned RALinScan::getFreePhysReg(LiveInterval *cur) { - std::vector<unsigned> inactiveCounts(tri_->getNumRegs(), 0); + SmallVector<unsigned, 256> inactiveCounts; unsigned MaxInactiveCount = 0; const TargetRegisterClass *RC = reginfo_->getRegClass(cur->reg); @@ -856,6 +856,8 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) { const TargetRegisterClass *RegRC = reginfo_->getRegClass(reg); if (RelatedRegClasses.getLeaderValue(RegRC) == RCLeader) { reg = vrm_->getPhys(reg); + if (inactiveCounts.size() <= reg) + inactiveCounts.resize(reg+1); ++inactiveCounts[reg]; MaxInactiveCount = std::max(MaxInactiveCount, inactiveCounts[reg]); } @@ -882,10 +884,13 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) { for (; I != E; ++I) if (prt_->isRegAvail(*I)) { FreeReg = *I; - FreeRegInactiveCount = inactiveCounts[FreeReg]; + if (FreeReg < inactiveCounts.size()) + FreeRegInactiveCount = inactiveCounts[FreeReg]; + else + FreeRegInactiveCount = 0; break; } - + // If there are no free regs, or if this reg has the max inactive count, // return this register. if (FreeReg == 0 || FreeRegInactiveCount == MaxInactiveCount) return FreeReg; @@ -896,7 +901,8 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) { // reevaluated now. for (; I != E; ++I) { unsigned Reg = *I; - if (prt_->isRegAvail(Reg) && FreeRegInactiveCount < inactiveCounts[Reg]) { + if (prt_->isRegAvail(Reg) && Reg < inactiveCounts.size() && + FreeRegInactiveCount < inactiveCounts[Reg]) { FreeReg = Reg; FreeRegInactiveCount = inactiveCounts[Reg]; if (FreeRegInactiveCount == MaxInactiveCount) |