[PATCH] D118707: [nfc][regalloc] Make the max inference cutoff configurable

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 1 08:27:37 PST 2022


mtrofin created this revision.
mtrofin added reviewers: qcolombet, MatzeB, wenlei, yundiqian, davidxl.
Herald added a subscriber: hiraditya.
mtrofin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Added a flag to make configurable the number of interferences after
which we 'bail out' and treat a set of intervals as un-evictable. Also
using it on the ML side, as it turns out to be a good control for
compile-time.

With this configurable, we can do a bit of trial and error and see if
bumping it has any effect on heuristic/policy quality.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118707

Files:
  llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
  llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp


Index: llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp
+++ llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp
@@ -42,6 +42,14 @@
              "may be compile time intensive"),
     cl::init(false));
 
+cl::opt<unsigned> EvictInterferenceCutoff(
+    "regalloc-eviction-max-interference-cutoff", cl::Hidden,
+    cl::desc("Number of interferences after which we declare "
+             "an interference unevictable and bail out. This "
+             "is a compilation cost-saving consideration. To "
+             "disable, pass a very large number."),
+    cl::init(10));
+
 #define DEBUG_TYPE "regalloc"
 #ifdef LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL
 #define LLVM_HAVE_TF_AOT
@@ -195,8 +203,8 @@
   for (MCRegUnitIterator Units(PhysReg, TRI); Units.isValid(); ++Units) {
     LiveIntervalUnion::Query &Q = Matrix->query(VirtReg, *Units);
     // If there is 10 or more interferences, chances are one is heavier.
-    const auto &Interferences = Q.interferingVRegs(10);
-    if (Interferences.size() >= 10)
+    const auto &Interferences = Q.interferingVRegs(EvictInterferenceCutoff);
+    if (Interferences.size() >= EvictInterferenceCutoff)
       return false;
 
     // Check if any interfering live range is heavier than MaxWeight.
Index: llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
===================================================================
--- llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
+++ llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
@@ -58,6 +58,8 @@
     "regalloc-model", cl::Hidden,
     cl::desc("The model being trained for register allocation eviction"));
 
+extern cl::opt<unsigned> EvictInterferenceCutoff;
+
 #endif // #ifdef LLVM_HAVE_TF_API
 
 /// The score injection pass.
@@ -544,9 +546,11 @@
     LiveIntervalUnion::Query &Q = Matrix->query(VirtReg, *Units);
     // Different from the default heuristic, we don't make any assumptions about
     // what having more than 10 results in the query may mean.
-    const auto &IFIntervals = Q.interferingVRegs();
+    const auto &IFIntervals = Q.interferingVRegs(EvictInterferenceCutoff);
     if (IFIntervals.empty() && InterferingIntervals.empty())
       continue;
+    if (IFIntervals.size() >= EvictInterferenceCutoff)
+      return false;
     InterferingIntervals.append(IFIntervals.begin(), IFIntervals.end());
     for (LiveInterval *Intf : reverse(IFIntervals)) {
       assert(Register::isVirtualRegister(Intf->reg()) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118707.404946.patch
Type: text/x-patch
Size: 2517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220201/1401d3f1/attachment.bin>


More information about the llvm-commits mailing list