util/ra: Add a helper for resetting a node's interference
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 7 May 2019 22:16:58 +0000 (17:16 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Tue, 14 May 2019 17:30:22 +0000 (12:30 -0500)
Reviewed-by: Eric Anholt <eric@anholt.net>
src/util/register_allocate.c
src/util/register_allocate.h

index 8c10741870ba9415ca434a09426330d0a496d629..e1138c6a506dbc6048b0dae15dbf15792ba79bba 100644 (file)
@@ -425,6 +425,31 @@ ra_add_node_adjacency(struct ra_graph *g, unsigned int n1, unsigned int n2)
    g->nodes[n1].adjacency_count++;
 }
 
+static void
+ra_node_remove_adjacency(struct ra_graph *g, unsigned int n1, unsigned int n2)
+{
+   BITSET_CLEAR(g->nodes[n1].adjacency, n2);
+
+   assert(n1 != n2);
+
+   int n1_class = g->nodes[n1].class;
+   int n2_class = g->nodes[n2].class;
+   g->nodes[n1].q_total -= g->regs->classes[n1_class]->q[n2_class];
+
+   unsigned int i;
+   for (i = 0; i < g->nodes[n1].adjacency_count; i++) {
+      if (g->nodes[n1].adjacency_list[i] == n2) {
+         memmove(&g->nodes[n1].adjacency_list[i],
+                 &g->nodes[n1].adjacency_list[i + 1],
+                 (g->nodes[n1].adjacency_count - i - 1) *
+                 sizeof(g->nodes[n1].adjacency_list[0]));
+         break;
+      }
+   }
+   assert(i < g->nodes[n1].adjacency_count);
+   g->nodes[n1].adjacency_count--;
+}
+
 static void
 ra_realloc_interference_graph(struct ra_graph *g, unsigned int alloc)
 {
@@ -536,6 +561,17 @@ ra_add_node_interference(struct ra_graph *g,
    }
 }
 
+void
+ra_reset_node_interference(struct ra_graph *g, unsigned int n)
+{
+   for (unsigned int i = 0; i < g->nodes[n].adjacency_count; i++)
+      ra_node_remove_adjacency(g, g->nodes[n].adjacency_list[i], n);
+
+   memset(g->nodes[n].adjacency, 0,
+          BITSET_WORDS(g->count) * sizeof(BITSET_WORD));
+   g->nodes[n].adjacency_count = 0;
+}
+
 static void
 update_pq_info(struct ra_graph *g, unsigned int n)
 {
index 834503ea55baaa5411c3ba9c54a61b833a062e8c..168c6e3535ae4db5110321597329efff60dc9c6c 100644 (file)
@@ -84,6 +84,7 @@ void ra_set_select_reg_callback(struct ra_graph *g,
                                 void *data);
 void ra_add_node_interference(struct ra_graph *g,
                               unsigned int n1, unsigned int n2);
+void ra_reset_node_interference(struct ra_graph *g, unsigned int n);
 /** @} */
 
 /** @{ Graph-coloring register allocation */