@@ -366,6 +366,9 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
366366 mutable DenseMap<RegID, LIFeatureComponents> CachedFeatures;
367367
368368 mutable std::unordered_map<unsigned , unsigned > VirtRegEvictionCounts;
369+ void incrementEvictionCount (const CandidateRegList &Regs,
370+ const LiveInterval &VirtReg,
371+ size_t CandidatePosition) const ;
369372};
370373
371374#define _DECL_FEATURES (type, name, shape, _ ) \
@@ -658,7 +661,10 @@ bool MLEvictAdvisor::loadInterferenceFeatures(
658661 // large amount of compile time being spent in regalloc. If we hit the
659662 // threshold, prevent the range from being evicted. We still let the
660663 // range through if it is urgent as we are required to produce an
661- // eviction if the candidate is not spillable.
664+ // eviction if the candidate is not spillable. If we cannot find the
665+ // virtual register in the map, we just assume it has not been evicted
666+ // before and thus has a value of zero (which is what the subscript
667+ // operator returns by default).
662668 if (VirtRegEvictionCounts[Intf->reg ().id ()] > MaxEvictionCount && !Urgent)
663669 return false ;
664670
@@ -680,6 +686,22 @@ bool MLEvictAdvisor::loadInterferenceFeatures(
680686 return true ;
681687}
682688
689+ void MLEvictAdvisor::incrementEvictionCount (const CandidateRegList &Regs,
690+ const LiveInterval &VirtReg,
691+ size_t CandidatePosition) const {
692+ if (CandidatePosition == CandidateVirtRegPos) {
693+ VirtRegEvictionCounts[VirtReg.reg ()] += 1 ;
694+ } else {
695+ for (MCRegUnit Unit : TRI->regunits (Regs[CandidatePosition].first )) {
696+ LiveIntervalUnion::Query &Q = Matrix->query (VirtReg, Unit);
697+ const auto &IFIntervals = Q.interferingVRegs (EvictInterferenceCutoff);
698+ for (const LiveInterval *Intf : reverse (IFIntervals)) {
699+ VirtRegEvictionCounts[Intf->reg ()] += 1 ;
700+ }
701+ }
702+ }
703+ }
704+
683705MCRegister MLEvictAdvisor::tryFindEvictionCandidate (
684706 const LiveInterval &VirtReg, const AllocationOrder &Order,
685707 uint8_t CostPerUseLimit, const SmallVirtRegSet &FixedRegisters) const {
@@ -807,18 +829,9 @@ MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
807829 (void )ValidPosLimit;
808830
809831 // Update information about how many times the virtual registers being
810- // evicted have been evicted.
811- if (CandidatePos == CandidateVirtRegPos) {
812- VirtRegEvictionCounts[VirtReg.reg ()] += 1 ;
813- } else {
814- for (MCRegUnit Unit : TRI->regunits (Regs[CandidatePos].first )) {
815- LiveIntervalUnion::Query &Q = Matrix->query (VirtReg, Unit);
816- const auto &IFIntervals = Q.interferingVRegs (EvictInterferenceCutoff);
817- for (const LiveInterval *Intf : reverse (IFIntervals)) {
818- VirtRegEvictionCounts[Intf->reg ()] += 1 ;
819- }
820- }
821- }
832+ // evicted have been evicted so that we can prevent the model from evicting
833+ // the same ranges continually and eating compile time.
834+ incrementEvictionCount (Regs, VirtReg, CandidatePos);
822835
823836 return Regs[CandidatePos].first ;
824837}
0 commit comments