[llvm] 91a33ad - [nfc][mlgo][regalloc] Cache live interval feature components

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 17:01:53 PST 2022


Author: Mircea Trofin
Date: 2022-02-03T17:01:42-08:00
New Revision: 91a33ad32b41c1f7188375252fec353acc3e8594

URL: https://github.com/llvm/llvm-project/commit/91a33ad32b41c1f7188375252fec353acc3e8594
DIFF: https://github.com/llvm/llvm-project/commit/91a33ad32b41c1f7188375252fec353acc3e8594.diff

LOG: [nfc][mlgo][regalloc] Cache live interval feature components

Lazily cache the feature components of a LiveInterval.

Differential Revision: https://reviews.llvm.org/D118674

Added: 
    

Modified: 
    llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
index 64b14c63c8675..f0893a43e4d00 100644
--- a/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
@@ -294,7 +294,7 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
                                                         FixedRegisters);
   }
 
-  const LIFeatureComponents
+  const LIFeatureComponents &
   getLIFeatureComponents(const LiveInterval &LI) const;
 
   // Hold on to a default advisor for:
@@ -310,6 +310,9 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
   // This could be static and shared, but its initialization is non-trivial.
   std::bitset<FeatureIDs::FeatureCount> DoNotNormalize;
   const float InitialQSize;
+
+  using RegID = unsigned;
+  mutable DenseMap<RegID, LIFeatureComponents> CachedFeatures;
 };
 
 // ===================================
@@ -692,9 +695,15 @@ MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
   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<MachineInstr *, 8> Visited;
   const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
 
@@ -775,7 +784,7 @@ void MLEvictAdvisor::extractFeatures(
 
     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;


        


More information about the llvm-commits mailing list