diff --git a/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp --- a/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp +++ b/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp @@ -294,7 +294,7 @@ FixedRegisters); } - const LIFeatureComponents + const LIFeatureComponents & getLIFeatureComponents(const LiveInterval &LI) const; // Hold on to a default advisor for: @@ -310,6 +310,9 @@ // This could be static and shared, but its initialization is non-trivial. std::bitset DoNotNormalize; const float InitialQSize; + + using RegID = unsigned; + mutable DenseMap CachedFeatures; }; // =================================== @@ -692,9 +695,15 @@ return Regs[CandidatePos].first; } -const LIFeatureComponents +const LIFeatureComponents & MLEvictAdvisor::getLIFeatureComponents(const LiveInterval &LI) const { - LIFeatureComponents Ret; + RegID ID = LI.reg().id(); + LIFeatureComponents Empty; + auto I = CachedFeatures.insert(std::make_pair(ID, Empty)); + LIFeatureComponents &Ret = I.first->getSecond(); + if (!I.second) + return Ret; + SmallPtrSet Visited; const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); @@ -775,7 +784,7 @@ if (LI.endIndex() > EndSI) EndSI = LI.endIndex(); - const LIFeatureComponents LIFC = getLIFeatureComponents(LI); + const LIFeatureComponents &LIFC = getLIFeatureComponents(LI); NrBrokenHints += VRM->hasPreferredPhys(LI.reg()); NrDefsAndUses += LIFC.NrDefsAndUses;