Skip to content

Commit 91a33ad

Browse files
committed
[nfc][mlgo][regalloc] Cache live interval feature components
Lazily cache the feature components of a LiveInterval. Differential Revision: https://reviews.llvm.org/D118674
1 parent 877c84a commit 91a33ad

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
294294
FixedRegisters);
295295
}
296296

297-
const LIFeatureComponents
297+
const LIFeatureComponents &
298298
getLIFeatureComponents(const LiveInterval &LI) const;
299299

300300
// Hold on to a default advisor for:
@@ -310,6 +310,9 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
310310
// This could be static and shared, but its initialization is non-trivial.
311311
std::bitset<FeatureIDs::FeatureCount> DoNotNormalize;
312312
const float InitialQSize;
313+
314+
using RegID = unsigned;
315+
mutable DenseMap<RegID, LIFeatureComponents> CachedFeatures;
313316
};
314317

315318
// ===================================
@@ -692,9 +695,15 @@ MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
692695
return Regs[CandidatePos].first;
693696
}
694697

695-
const LIFeatureComponents
698+
const LIFeatureComponents &
696699
MLEvictAdvisor::getLIFeatureComponents(const LiveInterval &LI) const {
697-
LIFeatureComponents Ret;
700+
RegID ID = LI.reg().id();
701+
LIFeatureComponents Empty;
702+
auto I = CachedFeatures.insert(std::make_pair(ID, Empty));
703+
LIFeatureComponents &Ret = I.first->getSecond();
704+
if (!I.second)
705+
return Ret;
706+
698707
SmallPtrSet<MachineInstr *, 8> Visited;
699708
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
700709

@@ -775,7 +784,7 @@ void MLEvictAdvisor::extractFeatures(
775784

776785
if (LI.endIndex() > EndSI)
777786
EndSI = LI.endIndex();
778-
const LIFeatureComponents LIFC = getLIFeatureComponents(LI);
787+
const LIFeatureComponents &LIFC = getLIFeatureComponents(LI);
779788
NrBrokenHints += VRM->hasPreferredPhys(LI.reg());
780789

781790
NrDefsAndUses += LIFC.NrDefsAndUses;

0 commit comments

Comments
 (0)