[llvm] 9a2798c - [CodeGen][NFC] Hoist budget check out of loop

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 00:28:56 PDT 2022


Author: Max Kazantsev
Date: 2022-04-05T14:20:42+07:00
New Revision: 9a2798c7a36e3261ac01adb617785da8f1165767

URL: https://github.com/llvm/llvm-project/commit/9a2798c7a36e3261ac01adb617785da8f1165767
DIFF: https://github.com/llvm/llvm-project/commit/9a2798c7a36e3261ac01adb617785da8f1165767.diff

LOG: [CodeGen][NFC] Hoist budget check out of loop

Less computations & early exit if we know for sure that the limit will be exceeded.

Added: 
    

Modified: 
    llvm/lib/CodeGen/RegAllocGreedy.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 3b23a22c14926..365dd890fe701 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -123,7 +123,7 @@ CSRFirstTimeCost("regalloc-csr-first-time-cost",
               cl::desc("Cost for first time use of callee-saved register."),
               cl::init(0), cl::Hidden);
 
-static cl::opt<long> GrowRegionComplexityBudget(
+static cl::opt<unsigned long> GrowRegionComplexityBudget(
     "grow-region-complexity-budget",
     cl::desc("growRegion() does not scale with the number of BB edges, so "
              "limit its budget and bail out once we reach the limit."),
@@ -780,17 +780,18 @@ bool RAGreedy::growRegion(GlobalSplitCandidate &Cand) {
   unsigned Visited = 0;
 #endif
 
-  long Budget = GrowRegionComplexityBudget;
+  unsigned long Budget = GrowRegionComplexityBudget;
   while (true) {
     ArrayRef<unsigned> NewBundles = SpillPlacer->getRecentPositive();
     // Find new through blocks in the periphery of PrefRegBundles.
     for (unsigned Bundle : NewBundles) {
       // Look at all blocks connected to Bundle in the full graph.
       ArrayRef<unsigned> Blocks = Bundles->getBlocks(Bundle);
+      // Limit compilation time by bailing out after we use all our budget.
+      if (Blocks.size() >= Budget)
+        return false;
+      Budget -= Blocks.size();
       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);


        


More information about the llvm-commits mailing list