@@ -400,6 +400,8 @@ class RAGreedy : public MachineFunctionPass,
400
400
typedef SmallVector<HintInfo, 4 > HintsInfo;
401
401
BlockFrequency getBrokenHintFreq (const HintsInfo &, unsigned );
402
402
void collectHintInfo (unsigned , HintsInfo &);
403
+
404
+ bool isUnusedCalleeSavedReg (unsigned PhysReg) const ;
403
405
};
404
406
} // end anonymous namespace
405
407
@@ -816,6 +818,16 @@ void RAGreedy::evictInterference(LiveInterval &VirtReg, unsigned PhysReg,
816
818
}
817
819
}
818
820
821
+ // / Returns true if the given \p PhysReg is a callee saved register and has not
822
+ // / been used for allocation yet.
823
+ bool RAGreedy::isUnusedCalleeSavedReg (unsigned PhysReg) const {
824
+ unsigned CSR = RegClassInfo.getLastCalleeSavedAlias (PhysReg);
825
+ if (CSR == 0 )
826
+ return false ;
827
+
828
+ return !Matrix->isPhysRegUsed (PhysReg);
829
+ }
830
+
819
831
// / tryEvict - Try to evict all interferences for a physreg.
820
832
// / @param VirtReg Currently unassigned virtual register.
821
833
// / @param Order Physregs to try.
@@ -861,13 +873,12 @@ unsigned RAGreedy::tryEvict(LiveInterval &VirtReg,
861
873
continue ;
862
874
// The first use of a callee-saved register in a function has cost 1.
863
875
// Don't start using a CSR when the CostPerUseLimit is low.
864
- if (CostPerUseLimit == 1 )
865
- if (unsigned CSR = RegClassInfo.getLastCalleeSavedAlias (PhysReg))
866
- if (!MRI->isPhysRegUsed (CSR)) {
867
- DEBUG (dbgs () << PrintReg (PhysReg, TRI) << " would clobber CSR "
868
- << PrintReg (CSR, TRI) << ' \n ' );
869
- continue ;
870
- }
876
+ if (CostPerUseLimit == 1 && isUnusedCalleeSavedReg (PhysReg)) {
877
+ DEBUG (dbgs () << PrintReg (PhysReg, TRI) << " would clobber CSR "
878
+ << PrintReg (RegClassInfo.getLastCalleeSavedAlias (PhysReg), TRI)
879
+ << ' \n ' );
880
+ continue ;
881
+ }
871
882
872
883
if (!canEvictInterference (VirtReg, PhysReg, false , BestCost))
873
884
continue ;
@@ -1348,9 +1359,8 @@ unsigned RAGreedy::calculateRegionSplitCost(LiveInterval &VirtReg,
1348
1359
unsigned BestCand = NoCand;
1349
1360
Order.rewind ();
1350
1361
while (unsigned PhysReg = Order.next ()) {
1351
- if (unsigned CSR = RegClassInfo.getLastCalleeSavedAlias (PhysReg))
1352
- if (IgnoreCSR && !MRI->isPhysRegUsed (CSR))
1353
- continue ;
1362
+ if (IgnoreCSR && isUnusedCalleeSavedReg (PhysReg))
1363
+ continue ;
1354
1364
1355
1365
// Discard bad candidates before we run out of interference cache cursors.
1356
1366
// This will only affect register classes with a lot of registers (>32).
@@ -2134,7 +2144,8 @@ unsigned RAGreedy::tryLastChanceRecoloring(LiveInterval &VirtReg,
2134
2144
unsigned ItVirtReg = (*It)->reg ;
2135
2145
if (VRM->hasPhys (ItVirtReg))
2136
2146
Matrix->unassign (**It);
2137
- Matrix->assign (**It, VirtRegToPhysReg[ItVirtReg]);
2147
+ unsigned ItPhysReg = VirtRegToPhysReg[ItVirtReg];
2148
+ Matrix->assign (**It, ItPhysReg);
2138
2149
}
2139
2150
}
2140
2151
@@ -2441,16 +2452,11 @@ unsigned RAGreedy::selectOrSplitImpl(LiveInterval &VirtReg,
2441
2452
// First try assigning a free register.
2442
2453
AllocationOrder Order (VirtReg.reg , *VRM, RegClassInfo);
2443
2454
if (unsigned PhysReg = tryAssign (VirtReg, Order, NewVRegs)) {
2444
- // We check other options if we are using a CSR for the first time.
2445
- bool CSRFirstUse = false ;
2446
- if (unsigned CSR = RegClassInfo.getLastCalleeSavedAlias (PhysReg))
2447
- if (!MRI->isPhysRegUsed (CSR))
2448
- CSRFirstUse = true ;
2449
-
2450
2455
// When NewVRegs is not empty, we may have made decisions such as evicting
2451
2456
// a virtual register, go with the earlier decisions and use the physical
2452
2457
// register.
2453
- if (CSRCost.getFrequency () && CSRFirstUse && NewVRegs.empty ()) {
2458
+ if (CSRCost.getFrequency () && isUnusedCalleeSavedReg (PhysReg) &&
2459
+ NewVRegs.empty ()) {
2454
2460
unsigned CSRReg = tryAssignCSRFirstTime (VirtReg, Order, PhysReg,
2455
2461
CostPerUseLimit, NewVRegs);
2456
2462
if (CSRReg || !NewVRegs.empty ())
0 commit comments