[Mesa-dev] [PATCH] ra: Add ra_set_node_reg()

Tom Stellard tstellar at gmail.com
Tue Apr 19 23:09:46 PDT 2011


This function makes it possible to include input / payload registers in
the interference graph.
---
 src/mesa/program/register_allocate.c |   21 ++++++++++++++++++---
 src/mesa/program/register_allocate.h |    1 +
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/mesa/program/register_allocate.c b/src/mesa/program/register_allocate.c
index 95a9bde..40df95b 100644
--- a/src/mesa/program/register_allocate.c
+++ b/src/mesa/program/register_allocate.c
@@ -37,6 +37,8 @@
 #include "main/mtypes.h"
 #include "register_allocate.h"
 
+#define NO_REG ~0
+
 struct ra_reg {
    GLboolean *conflicts;
    unsigned int *conflict_list;
@@ -227,7 +229,7 @@ ra_alloc_interference_graph(struct ra_regs *regs, unsigned int count)
       g->nodes[i].adjacency_list = ralloc_array(g, unsigned int, count);
       g->nodes[i].adjacency_count = 0;
       ra_add_node_adjacency(g, i, i);
-      g->nodes[i].reg = ~0;
+      g->nodes[i].reg = NO_REG;
    }
 
    return g;
@@ -287,7 +289,7 @@ ra_simplify(struct ra_graph *g)
       progress = GL_FALSE;
 
       for (i = g->count - 1; i >= 0; i--) {
-	 if (g->nodes[i].in_stack)
+	 if (g->nodes[i].in_stack || g->nodes[i].reg != NO_REG)
 	    continue;
 
 	 if (pq_test(g, i)) {
@@ -367,7 +369,7 @@ ra_optimistic_color(struct ra_graph *g)
    unsigned int i;
 
    for (i = 0; i < g->count; i++) {
-      if (g->nodes[i].in_stack)
+      if (g->nodes[i].in_stack || g->nodes[i].reg != NO_REG)
 	 continue;
 
       g->stack[g->stack_count] = i;
@@ -391,6 +393,19 @@ ra_get_node_reg(struct ra_graph *g, unsigned int n)
    return g->nodes[n].reg;
 }
 
+/**
+ * This function allows a user to manually assign a register to a node.  This
+ * is useful for nodes that belong to register classes that contain a very small
+ * number of registers that are not likely to be allocated if they end up at
+ * the bottom of the stack.
+ */
+void
+ra_set_node_reg(struct ra_graph *g, unsigned int n, unsigned int reg)
+{
+   g->nodes[n].reg = reg;
+   g->nodes[n].in_stack = GL_FALSE;
+}
+
 static float
 ra_get_spill_benefit(struct ra_graph *g, unsigned int n)
 {
diff --git a/src/mesa/program/register_allocate.h b/src/mesa/program/register_allocate.h
index 198b89f..5b95833 100644
--- a/src/mesa/program/register_allocate.h
+++ b/src/mesa/program/register_allocate.h
@@ -65,6 +65,7 @@ GLboolean ra_select(struct ra_graph *g);
 GLboolean ra_allocate_no_spills(struct ra_graph *g);
 
 unsigned int ra_get_node_reg(struct ra_graph *g, unsigned int n);
+void ra_set_node_reg(struct ra_graph * g, unsigned int n, unsigned int reg);
 void ra_set_node_spill_cost(struct ra_graph *g, unsigned int n, float cost);
 int ra_get_best_spill_node(struct ra_graph *g);
 /** @} */
-- 
1.7.3.4



More information about the mesa-dev mailing list