@@ -714,28 +714,20 @@ bool RegAllocEvictionAdvisor::isUnusedCalleeSavedReg(MCRegister PhysReg) const {
714
714
return !Matrix->isPhysRegUsed (PhysReg);
715
715
}
716
716
717
- MCRegister DefaultEvictionAdvisor::tryFindEvictionCandidate (
718
- LiveInterval &VirtReg, const AllocationOrder &Order,
719
- uint8_t CostPerUseLimit, const SmallVirtRegSet &FixedRegisters) const {
720
- // Keep track of the cheapest interference seen so far.
721
- EvictionCost BestCost;
722
- BestCost.setMax ();
723
- MCRegister BestPhys;
717
+ Optional<unsigned >
718
+ RegAllocEvictionAdvisor::getOrderLimit (const LiveInterval &VirtReg,
719
+ const AllocationOrder &Order,
720
+ unsigned CostPerUseLimit) const {
724
721
unsigned OrderLimit = Order.getOrder ().size ();
725
722
726
- // When we are just looking for a reduced cost per use, don't break any
727
- // hints, and only evict smaller spill weights.
728
723
if (CostPerUseLimit < uint8_t (~0u )) {
729
- BestCost.BrokenHints = 0 ;
730
- BestCost.MaxWeight = VirtReg.weight ();
731
-
732
724
// Check of any registers in RC are below CostPerUseLimit.
733
725
const TargetRegisterClass *RC = MRI->getRegClass (VirtReg.reg ());
734
726
uint8_t MinCost = RegClassInfo.getMinCost (RC);
735
727
if (MinCost >= CostPerUseLimit) {
736
728
LLVM_DEBUG (dbgs () << TRI->getRegClassName (RC) << " minimum cost = "
737
729
<< MinCost << " , no cheaper registers to be found.\n " );
738
- return 0 ;
730
+ return None ;
739
731
}
740
732
741
733
// It is normal for register classes to have a long tail of registers with
@@ -746,24 +738,50 @@ MCRegister DefaultEvictionAdvisor::tryFindEvictionCandidate(
746
738
<< " regs.\n " );
747
739
}
748
740
}
741
+ return OrderLimit;
742
+ }
743
+
744
+ bool RegAllocEvictionAdvisor::canAllocatePhysReg (unsigned CostPerUseLimit,
745
+ MCRegister PhysReg) const {
746
+ if (RegCosts[PhysReg] >= CostPerUseLimit)
747
+ return false ;
748
+ // The first use of a callee-saved register in a function has cost 1.
749
+ // Don't start using a CSR when the CostPerUseLimit is low.
750
+ if (CostPerUseLimit == 1 && isUnusedCalleeSavedReg (PhysReg)) {
751
+ LLVM_DEBUG (
752
+ dbgs () << printReg (PhysReg, TRI) << " would clobber CSR "
753
+ << printReg (RegClassInfo.getLastCalleeSavedAlias (PhysReg), TRI)
754
+ << ' \n ' );
755
+ return false ;
756
+ }
757
+ return true ;
758
+ }
759
+
760
+ MCRegister DefaultEvictionAdvisor::tryFindEvictionCandidate (
761
+ LiveInterval &VirtReg, const AllocationOrder &Order,
762
+ uint8_t CostPerUseLimit, const SmallVirtRegSet &FixedRegisters) const {
763
+ // Keep track of the cheapest interference seen so far.
764
+ EvictionCost BestCost;
765
+ BestCost.setMax ();
766
+ MCRegister BestPhys;
767
+ auto MaybeOrderLimit = getOrderLimit (VirtReg, Order, CostPerUseLimit);
768
+ if (!MaybeOrderLimit)
769
+ return MCRegister::NoRegister;
770
+ unsigned OrderLimit = *MaybeOrderLimit;
771
+
772
+ // When we are just looking for a reduced cost per use, don't break any
773
+ // hints, and only evict smaller spill weights.
774
+ if (CostPerUseLimit < uint8_t (~0u )) {
775
+ BestCost.BrokenHints = 0 ;
776
+ BestCost.MaxWeight = VirtReg.weight ();
777
+ }
749
778
750
779
for (auto I = Order.begin (), E = Order.getOrderLimitEnd (OrderLimit); I != E;
751
780
++I) {
752
781
MCRegister PhysReg = *I;
753
782
assert (PhysReg);
754
- if (RegCosts[PhysReg] >= CostPerUseLimit)
755
- continue ;
756
- // The first use of a callee-saved register in a function has cost 1.
757
- // Don't start using a CSR when the CostPerUseLimit is low.
758
- if (CostPerUseLimit == 1 && isUnusedCalleeSavedReg (PhysReg)) {
759
- LLVM_DEBUG (
760
- dbgs () << printReg (PhysReg, TRI) << " would clobber CSR "
761
- << printReg (RegClassInfo.getLastCalleeSavedAlias (PhysReg), TRI)
762
- << ' \n ' );
763
- continue ;
764
- }
765
-
766
- if (!canEvictInterferenceBasedOnCost (VirtReg, PhysReg, false , BestCost,
783
+ if (!canAllocatePhysReg (CostPerUseLimit, PhysReg) ||
784
+ !canEvictInterferenceBasedOnCost (VirtReg, PhysReg, false , BestCost,
767
785
FixedRegisters))
768
786
continue ;
769
787
0 commit comments