From 492d664be06ca538d4e5c1e380ab7966714a12a9 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 18 Sep 2019 14:57:11 -0500 Subject: [PATCH] util/ra: Add [de]serialization support Reviewed-by: Kenneth Graunke Reviewed-by: Eric Anholt Part-of: --- src/util/register_allocate.c | 63 ++++++++++++++++++++++++++++++++++++ src/util/register_allocate.h | 6 ++++ 2 files changed, 69 insertions(+) diff --git a/src/util/register_allocate.c b/src/util/register_allocate.c index c0cd879c9ca..1d9a074174f 100644 --- a/src/util/register_allocate.c +++ b/src/util/register_allocate.c @@ -73,6 +73,7 @@ #include #include +#include "blob.h" #include "ralloc.h" #include "main/macros.h" #include "util/bitset.h" @@ -421,6 +422,68 @@ ra_set_finalize(struct ra_regs *regs, unsigned int **q_values) } } +void +ra_set_serialize(const struct ra_regs *regs, struct blob *blob) +{ + blob_write_uint32(blob, regs->count); + blob_write_uint32(blob, regs->class_count); + + for (unsigned int r = 0; r < regs->count; r++) { + struct ra_reg *reg = ®s->regs[r]; + blob_write_bytes(blob, reg->conflicts, BITSET_WORDS(regs->count) * + sizeof(BITSET_WORD)); + assert(util_dynarray_num_elements(®->conflict_list, unsigned int) == 0); + } + + for (unsigned int c = 0; c < regs->class_count; c++) { + struct ra_class *class = regs->classes[c]; + blob_write_bytes(blob, class->regs, BITSET_WORDS(regs->count) * + sizeof(BITSET_WORD)); + blob_write_uint32(blob, class->p); + blob_write_bytes(blob, class->q, regs->class_count * sizeof(*class->q)); + } + + blob_write_uint32(blob, regs->round_robin); +} + +struct ra_regs * +ra_set_deserialize(void *mem_ctx, struct blob_reader *blob) +{ + unsigned int reg_count = blob_read_uint32(blob); + unsigned int class_count = blob_read_uint32(blob); + + struct ra_regs *regs = ra_alloc_reg_set(mem_ctx, reg_count, false); + assert(regs->count == reg_count); + + for (unsigned int r = 0; r < reg_count; r++) { + struct ra_reg *reg = ®s->regs[r]; + blob_copy_bytes(blob, reg->conflicts, BITSET_WORDS(reg_count) * + sizeof(BITSET_WORD)); + } + + assert(regs->classes == NULL); + regs->classes = ralloc_array(regs->regs, struct ra_class *, class_count); + regs->class_count = class_count; + + for (unsigned int c = 0; c < class_count; c++) { + struct ra_class *class = rzalloc(regs, struct ra_class); + regs->classes[c] = class; + + class->regs = ralloc_array(class, BITSET_WORD, BITSET_WORDS(reg_count)); + blob_copy_bytes(blob, class->regs, BITSET_WORDS(reg_count) * + sizeof(BITSET_WORD)); + + class->p = blob_read_uint32(blob); + + class->q = ralloc_array(regs->classes[c], unsigned int, class_count); + blob_copy_bytes(blob, class->q, class_count * sizeof(*class->q)); + } + + regs->round_robin = blob_read_uint32(blob); + + return regs; +} + static void ra_add_node_adjacency(struct ra_graph *g, unsigned int n1, unsigned int n2) { diff --git a/src/util/register_allocate.h b/src/util/register_allocate.h index c01f4aee47a..c9170e7762a 100644 --- a/src/util/register_allocate.h +++ b/src/util/register_allocate.h @@ -39,6 +39,9 @@ extern "C" { struct ra_class; struct ra_regs; +struct blob; +struct blob_reader; + /* @{ * Register set setup. * @@ -65,6 +68,9 @@ void ra_class_add_reg(struct ra_regs *regs, unsigned int c, unsigned int reg); void ra_set_num_conflicts(struct ra_regs *regs, unsigned int class_a, unsigned int class_b, unsigned int num_conflicts); void ra_set_finalize(struct ra_regs *regs, unsigned int **conflicts); + +void ra_set_serialize(const struct ra_regs *regs, struct blob *blob); +struct ra_regs *ra_set_deserialize(void *mem_ctx, struct blob_reader *blob); /** @} */ /** @{ Interference graph setup. -- 2.30.2