aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2019-09-18 14:57:11 -0500
committerMarge Bot <[email protected]>2020-05-13 23:36:44 +0000
commit492d664be06ca538d4e5c1e380ab7966714a12a9 (patch)
treec870d6901fcf9187a205f7c109251ef21be4396e
parent38e68db778439c34ebb876273fcf9139764abc80 (diff)
util/ra: Add [de]serialization support
Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5019>
-rw-r--r--src/util/register_allocate.c63
-rw-r--r--src/util/register_allocate.h6
2 files changed, 69 insertions, 0 deletions
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 <stdbool.h>
#include <stdlib.h>
+#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 = &regs->regs[r];
+ blob_write_bytes(blob, reg->conflicts, BITSET_WORDS(regs->count) *
+ sizeof(BITSET_WORD));
+ assert(util_dynarray_num_elements(&reg->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 = &regs->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.