Skip to content

Commit ff42e63

Browse files
Address feedback
1 parent dc4a7c9 commit ff42e63

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,21 @@ 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;
369+
370+
void onEviction(Register RegBeingEvicted) const {
371+
// If we cannot find the virtual register in the map, we just assume it has
372+
// not been evicted before and thus has a value of zero (which is what the
373+
// subscript operator returns by default).
374+
++VirtRegEvictionCounts[RegBeingEvicted.id()];
375+
}
376+
377+
unsigned getEvictionCount(Register Reg) const {
378+
auto EvictionCountIt = VirtRegEvictionCounts.find(Reg.id());
379+
if (EvictionCountIt != VirtRegEvictionCounts.end()) {
380+
return EvictionCountIt->second;
381+
}
382+
return 0;
383+
}
372384
};
373385

374386
#define _DECL_FEATURES(type, name, shape, _) \
@@ -661,11 +673,8 @@ bool MLEvictAdvisor::loadInterferenceFeatures(
661673
// large amount of compile time being spent in regalloc. If we hit the
662674
// threshold, prevent the range from being evicted. We still let the
663675
// range through if it is urgent as we are required to produce an
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).
668-
if (VirtRegEvictionCounts[Intf->reg().id()] > MaxEvictionCount && !Urgent)
676+
// eviction if the candidate is not spillable.
677+
if (getEvictionCount(Intf->reg()) > MaxEvictionCount && !Urgent)
669678
return false;
670679

671680
// Only evict older cascades or live ranges without a cascade.
@@ -686,22 +695,6 @@ bool MLEvictAdvisor::loadInterferenceFeatures(
686695
return true;
687696
}
688697

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-
705698
MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
706699
const LiveInterval &VirtReg, const AllocationOrder &Order,
707700
uint8_t CostPerUseLimit, const SmallVirtRegSet &FixedRegisters) const {
@@ -831,7 +824,17 @@ MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
831824
// Update information about how many times the virtual registers being
832825
// evicted have been evicted so that we can prevent the model from evicting
833826
// the same ranges continually and eating compile time.
834-
incrementEvictionCount(Regs, VirtReg, CandidatePos);
827+
if (CandidatePos == CandidateVirtRegPos) {
828+
onEviction(VirtReg.reg());
829+
} else {
830+
for (MCRegUnit Unit : TRI->regunits(Regs[CandidatePos].first)) {
831+
LiveIntervalUnion::Query &Q = Matrix->query(VirtReg, Unit);
832+
const auto &IFIntervals = Q.interferingVRegs(EvictInterferenceCutoff);
833+
for (const LiveInterval *Intf : reverse(IFIntervals)) {
834+
onEviction(Intf->reg());
835+
}
836+
}
837+
}
835838

836839
return Regs[CandidatePos].first;
837840
}

0 commit comments

Comments
 (0)