From 9040215f5d2894e9a900b0f4b154c617f9a0db27 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 7 May 2019 17:16:58 -0500 Subject: [PATCH] util/ra: Add a helper for resetting a node's interference Reviewed-by: Eric Anholt --- src/util/register_allocate.c | 36 ++++++++++++++++++++++++++++++++++++ src/util/register_allocate.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/util/register_allocate.c b/src/util/register_allocate.c index 8c10741..e1138c6 100644 --- a/src/util/register_allocate.c +++ b/src/util/register_allocate.c @@ -426,6 +426,31 @@ ra_add_node_adjacency(struct ra_graph *g, unsigned int n1, unsigned int n2) } 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) { if (alloc <= g->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) { diff --git a/src/util/register_allocate.h b/src/util/register_allocate.h index 834503e..168c6e3 100644 --- a/src/util/register_allocate.h +++ b/src/util/register_allocate.h @@ -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 */ -- 2.7.4