[PATCH] D118674: [nfc][mlgo][regalloc] Cache live interval feature components

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 2 20:08:33 PST 2022


mtrofin updated this revision to Diff 405516.
mtrofin marked an inline comment as done.
mtrofin added a comment.

simplification


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118674/new/

https://reviews.llvm.org/D118674

Files:
  llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp


Index: llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
===================================================================
--- llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
+++ llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
@@ -292,7 +292,7 @@
                                                         FixedRegisters);
   }
 
-  const LIFeatureComponents
+  const LIFeatureComponents &
   getLIFeatureComponents(const LiveInterval &LI) const;
 
   // Hold on to a default advisor for:
@@ -308,6 +308,9 @@
   // 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;
 };
 
 // ===================================
@@ -690,9 +693,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<MachineInstr *, 8> Visited;
   const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
 
@@ -773,7 +782,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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118674.405516.patch
Type: text/x-patch
Size: 1660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220203/dfcd0b3b/attachment.bin>


More information about the llvm-commits mailing list