@@ -839,7 +839,7 @@ void RALinScan::assignRegOrStackSlotAtInterval(LiveInterval* cur)
839
839
// / getFreePhysReg - return a free physical register for this virtual register
840
840
// / interval if we have one, otherwise return 0.
841
841
unsigned RALinScan::getFreePhysReg (LiveInterval *cur) {
842
- std::vector <unsigned > inactiveCounts (tri_-> getNumRegs (), 0 ) ;
842
+ SmallVector <unsigned , 256 > inactiveCounts ;
843
843
unsigned MaxInactiveCount = 0 ;
844
844
845
845
const TargetRegisterClass *RC = reginfo_->getRegClass (cur->reg );
@@ -856,6 +856,8 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) {
856
856
const TargetRegisterClass *RegRC = reginfo_->getRegClass (reg);
857
857
if (RelatedRegClasses.getLeaderValue (RegRC) == RCLeader) {
858
858
reg = vrm_->getPhys (reg);
859
+ if (inactiveCounts.size () <= reg)
860
+ inactiveCounts.resize (reg+1 );
859
861
++inactiveCounts[reg];
860
862
MaxInactiveCount = std::max (MaxInactiveCount, inactiveCounts[reg]);
861
863
}
@@ -882,10 +884,13 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) {
882
884
for (; I != E; ++I)
883
885
if (prt_->isRegAvail (*I)) {
884
886
FreeReg = *I;
885
- FreeRegInactiveCount = inactiveCounts[FreeReg];
887
+ if (FreeReg < inactiveCounts.size ())
888
+ FreeRegInactiveCount = inactiveCounts[FreeReg];
889
+ else
890
+ FreeRegInactiveCount = 0 ;
886
891
break ;
887
892
}
888
-
893
+
889
894
// If there are no free regs, or if this reg has the max inactive count,
890
895
// return this register.
891
896
if (FreeReg == 0 || FreeRegInactiveCount == MaxInactiveCount) return FreeReg;
@@ -896,7 +901,8 @@ unsigned RALinScan::getFreePhysReg(LiveInterval *cur) {
896
901
// reevaluated now.
897
902
for (; I != E; ++I) {
898
903
unsigned Reg = *I;
899
- if (prt_->isRegAvail (Reg) && FreeRegInactiveCount < inactiveCounts[Reg]) {
904
+ if (prt_->isRegAvail (Reg) && Reg < inactiveCounts.size () &&
905
+ FreeRegInactiveCount < inactiveCounts[Reg]) {
900
906
FreeReg = Reg;
901
907
FreeRegInactiveCount = inactiveCounts[Reg];
902
908
if (FreeRegInactiveCount == MaxInactiveCount)
0 commit comments