util/ra: spiff out select_reg_callback
authorRob Clark <robdclark@chromium.org>
Fri, 28 Feb 2020 18:06:54 +0000 (10:06 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 10 Mar 2020 16:01:39 +0000 (16:01 +0000)
Add a parameter so the callback can know which node it is selecting a
register for.  And remove the graph parameter, as it is unused by
existing users, and somewhat unnecessary (ie. the callback data could
be used instead).

And add a comment so $future_me remembers how this works.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4071>

src/broadcom/compiler/vir_register_allocate.c
src/gallium/drivers/vc4/vc4_register_allocate.c
src/util/register_allocate.c
src/util/register_allocate.h

index 623cc22cefad74390ce88a9284ae52dad50d059e..d88a8df1141d6f7622c8a421f068eac981750f9b 100644 (file)
@@ -309,7 +309,7 @@ struct v3d_ra_select_callback_data {
 };
 
 static unsigned int
-v3d_ra_select_callback(struct ra_graph *g, BITSET_WORD *regs, void *data)
+v3d_ra_select_callback(unsigned int n, BITSET_WORD *regs, void *data)
 {
         struct v3d_ra_select_callback_data *v3d_ra = data;
         int r5 = ACC_INDEX + 5;
index 1d860ea058ee208c271c94950acc62f9bbe3e2d7..53faf1ae77974a27b6fc30145b38237008629f40 100644 (file)
@@ -208,7 +208,7 @@ struct vc4_ra_select_callback_data {
 };
 
 static unsigned int
-vc4_ra_select_callback(struct ra_graph *g, BITSET_WORD *regs, void *data)
+vc4_ra_select_callback(unsigned int n, BITSET_WORD *regs, void *data)
 {
         struct vc4_ra_select_callback_data *vc4_ra = data;
 
index 85453d2529021dba62847e3b7608ea8009acd2c4..56517b5161cd834b817cffe42b1e8310ba984ea5 100644 (file)
@@ -171,8 +171,7 @@ struct ra_graph {
 
    unsigned int alloc; /**< count of nodes allocated. */
 
-   unsigned int (*select_reg_callback)(struct ra_graph *g, BITSET_WORD *regs,
-                                       void *data);
+   ra_select_reg_callback select_reg_callback;
    void *select_reg_callback_data;
 
    /* Temporary data for the algorithm to scratch around in */
@@ -565,9 +564,7 @@ ra_resize_interference_graph(struct ra_graph *g, unsigned int count)
 }
 
 void ra_set_select_reg_callback(struct ra_graph *g,
-                                unsigned int (*callback)(struct ra_graph *g,
-                                                         BITSET_WORD *regs,
-                                                         void *data),
+                                ra_select_reg_callback callback,
                                 void *data)
 {
    g->select_reg_callback = callback;
@@ -868,7 +865,7 @@ ra_select(struct ra_graph *g)
             return false;
          }
 
-         r = g->select_reg_callback(g, select_regs, g->select_reg_callback_data);
+         r = g->select_reg_callback(n, select_regs, g->select_reg_callback_data);
       } else {
          /* Find the lowest-numbered reg which is not used by a member
           * of the graph adjacent to us.
index fcd4d9394e041ef77214496aa9ef47ac16b294f7..7d8459b1eff09fb3913afd4951e02a94524f53de 100644 (file)
@@ -83,10 +83,28 @@ void ra_resize_interference_graph(struct ra_graph *g, unsigned int count);
 void ra_set_node_class(struct ra_graph *g, unsigned int n, unsigned int c);
 unsigned int ra_get_node_class(struct ra_graph *g, unsigned int n);
 unsigned int ra_add_node(struct ra_graph *g, unsigned int c);
+
+/** @{ Register selection callback.
+ *
+ * The register allocator can use either one of two built-in register
+ * selection behaviors (ie. lowest-available or round-robin), or the
+ * user can implement it's own selection policy by setting an register
+ * selection callback.  The parameters to the callback are:
+ *
+ *  - n       the graph node, ie. the virtual variable to select a
+ *            register for
+ *  - regs    bitset of available registers to choose; this bitset
+ *            contains *all* registers, but registers of different
+ *            classes will not have their corresponding bit set.
+ *  - data    callback data specified in ra_set_select_reg_callback()
+ */
+typedef unsigned int (*ra_select_reg_callback)(
+      unsigned int n,        /* virtual variable to choose a physical reg for */
+      BITSET_WORD *regs,     /* available physical regs to choose from */
+      void *data);
+
 void ra_set_select_reg_callback(struct ra_graph *g,
-                                unsigned int (*callback)(struct ra_graph *g,
-                                                         BITSET_WORD *regs,
-                                                         void *data),
+                                ra_select_reg_callback callback,
                                 void *data);
 void ra_add_node_interference(struct ra_graph *g,
                               unsigned int n1, unsigned int n2);