[PATCH] D120752: [RegAlloc] Add a complexity limit in growRegion() to cap compilation time.

Vasileios Porpodas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 1 10:25:56 PST 2022


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

growRegion() does not scale in code with BBs with a very large number of edges.
In such code growRegion() becomes a compile-time bottleneck, consuming 60% of
the total compilation time.
This patch adds a limit to the time spent in growRegion(). We bail out once
the limit is reached.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120752

Files:
  llvm/lib/CodeGen/RegAllocGreedy.cpp


Index: llvm/lib/CodeGen/RegAllocGreedy.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -133,6 +133,12 @@
              "candidate when choosing the best split candidate."),
     cl::init(false));
 
+static cl::opt<long> GrowRegionComplexityBudget(
+    "grow-region-complexity-budget",
+    cl::desc("growRegion() does not scale, so limit its budget. "
+             "Bail out if we explore this many edges."),
+    cl::init(10000), cl::Hidden);
+
 static RegisterRegAlloc greedyRegAlloc("greedy", "greedy register allocator",
                                        createGreedyRegisterAllocator);
 
@@ -784,6 +790,7 @@
   unsigned Visited = 0;
 #endif
 
+  long Budget = GrowRegionComplexityBudget;
   while (true) {
     ArrayRef<unsigned> NewBundles = SpillPlacer->getRecentPositive();
     // Find new through blocks in the periphery of PrefRegBundles.
@@ -791,6 +798,9 @@
       // Look at all blocks connected to Bundle in the full graph.
       ArrayRef<unsigned> Blocks = Bundles->getBlocks(Bundle);
       for (unsigned Block : Blocks) {
+        // Limit compilation time by bailing out after we use all our budget.
+        if (Budget-- == 0)
+          return false;
         if (!Todo.test(Block))
           continue;
         Todo.reset(Block);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120752.412159.patch
Type: text/x-patch
Size: 1368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220301/f53ec018/attachment.bin>


More information about the llvm-commits mailing list