#include <stdbool.h>
#include <stdlib.h>
+#include "blob.h"
#include "ralloc.h"
#include "main/macros.h"
#include "util/bitset.h"
}
}
+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)
{
struct ra_class;
struct ra_regs;
+struct blob;
+struct blob_reader;
+
/* @{
* Register set setup.
*
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.