intel/fs/ra: Do the spill loop inside RA
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 7 May 2019 23:14:46 +0000 (18:14 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Tue, 14 May 2019 17:30:22 +0000 (12:30 -0500)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/intel/compiler/brw_fs.cpp
src/intel/compiler/brw_fs_reg_allocate.cpp

index f9fbffca7ce50e49798704948a10151a2350747c..c942a35a434278f2897f62ea61867d3cc34e6e3d 100644 (file)
@@ -7279,9 +7279,7 @@ fs_visitor::allocate_registers(unsigned min_dispatch_width, bool allow_spilling)
       /* We should only spill registers on the last scheduling. */
       assert(!spilled_any_registers);
 
-      do {
-         allocated = assign_regs(can_spill, spill_all);
-      } while (!allocated && can_spill && !failed);
+      allocated = assign_regs(can_spill, spill_all);
       if (allocated)
          break;
    }
index 447f49f30a28fdaebb0324674f09b476f2a2a26d..66a92095ab89f0e5cab0cbd00c604b333d329329 100644 (file)
@@ -1051,32 +1051,36 @@ fs_reg_alloc::spill_reg(unsigned spill_reg)
 bool
 fs_reg_alloc::assign_regs(bool allow_spilling, bool spill_all)
 {
-   build_interference_graph(fs->spilled_any_registers);
+   while (1) {
+      build_interference_graph(fs->spilled_any_registers);
+
+      /* Debug of register spilling: Go spill everything. */
+      if (unlikely(spill_all)) {
+         int reg = choose_spill_reg();
+         if (reg != -1) {
+            spill_reg(reg);
+            ralloc_free(g);
+            g = NULL;
+            continue;
+         }
+      }
 
-   /* Debug of register spilling: Go spill everything. */
-   if (unlikely(spill_all)) {
-      int reg = choose_spill_reg();
+      if (ra_allocate(g))
+         break;
 
-      if (reg != -1) {
-         spill_reg(reg);
+      if (!allow_spilling)
          return false;
-      }
-   }
 
-   if (!ra_allocate(g)) {
       /* Failed to allocate registers.  Spill a reg, and the caller will
        * loop back into here to try again.
        */
       int reg = choose_spill_reg();
+      if (reg == -1)
+         return false;
 
-      if (reg == -1) {
-         fs->fail("no register to spill:\n");
-         fs->dump_instructions(NULL);
-      } else if (allow_spilling) {
-         spill_reg(reg);
-      }
-
-      return false;
+      spill_reg(reg);
+      ralloc_free(g);
+      g = NULL;
    }
 
    /* Get the chosen virtual registers for each node, and map virtual
@@ -1109,5 +1113,10 @@ bool
 fs_visitor::assign_regs(bool allow_spilling, bool spill_all)
 {
    fs_reg_alloc alloc(this);
-   return alloc.assign_regs(allow_spilling, spill_all);
+   bool success = alloc.assign_regs(allow_spilling, spill_all);
+   if (!success && allow_spilling) {
+      fail("no register to spill:\n");
+      dump_instructions(NULL);
+   }
+   return success;
 }