[Mesa-dev] [PATCH 13/18] util/register_allocate: Combine the BITSET arrays into a single allocation

Chris Wilson chris at chris-wilson.co.uk
Mon Jul 6 03:33:18 PDT 2015


ralloc's ability to track all pointers belonging to a context and free
them in a single call does not come cheap, and we can reduce the
overhead here by combining the array of BITSETs for a regset into a
single allocation.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Matt Turner <mattst88 at gmail.com>
Cc: Jason Ekstrand <jason.ekstrand at intel.com>
Cc: Martin Peres <martin.peres at linux.intel.com>
---
 src/util/register_allocate.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/util/register_allocate.c b/src/util/register_allocate.c
index 2ad8c3c..f5f7c04 100644
--- a/src/util/register_allocate.c
+++ b/src/util/register_allocate.c
@@ -187,14 +187,18 @@ ra_alloc_reg_set(void *mem_ctx, unsigned int count)
 {
    unsigned int i;
    struct ra_regs *regs;
+   BITSET_WORD *conflicts;
+   int bitset_count = BITSET_WORDS(count);
 
    regs = rzalloc(mem_ctx, struct ra_regs);
    regs->count = count;
    regs->regs = rzalloc_array(regs, struct ra_reg, count);
 
+   conflicts = rzalloc_array(regs->regs, BITSET_WORD, count * bitset_count);
    for (i = 0; i < count; i++) {
-      regs->regs[i].conflicts = rzalloc_array(regs->regs, BITSET_WORD,
-                                              BITSET_WORDS(count));
+      regs->regs[i].conflicts = conflicts;
+      conflicts += bitset_count;
+
       BITSET_SET(regs->regs[i].conflicts, i);
 
       regs->regs[i].conflict_list = ralloc_array(regs->regs, unsigned int, 4);
@@ -379,6 +383,8 @@ ra_alloc_interference_graph(struct ra_regs *regs, unsigned int count)
 {
    struct ra_graph *g;
    unsigned int i;
+   BITSET_WORD *adjacency;
+   int bitset_count = BITSET_WORDS(count);
 
    g = rzalloc(NULL, struct ra_graph);
    g->regs = regs;
@@ -387,9 +393,10 @@ ra_alloc_interference_graph(struct ra_regs *regs, unsigned int count)
 
    g->stack = rzalloc_array(g, unsigned int, count);
 
+   adjacency = rzalloc_array(g, BITSET_WORD, count * bitset_count);
    for (i = 0; i < count; i++) {
-      int bitset_count = BITSET_WORDS(count);
-      g->nodes[i].adjacency = rzalloc_array(g, BITSET_WORD, bitset_count);
+      g->nodes[i].adjacency = adjacency;
+      adjacency += bitset_count;
 
       g->nodes[i].adjacency_list_size = 4;
       g->nodes[i].adjacency_list =
-- 
2.1.4



More information about the mesa-dev mailing list