#include "nir_control_flow.h"
#include "util/u_dynarray.h"
+#define MAX_OBJECT_IDS (1 << 30)
+
typedef struct {
size_t blob_offset;
nir_ssa_def *src;
struct hash_table *remap_table;
/* the next index to assign to a NIR in-memory object */
- uintptr_t next_idx;
+ uint32_t next_idx;
/* Array of write_phi_fixup structs representing phi sources that need to
* be resolved in the second pass.
struct blob_reader *blob;
/* the next index to assign to a NIR in-memory object */
- uintptr_t next_idx;
+ uint32_t next_idx;
/* The length of the index -> object table */
- uintptr_t idx_table_len;
+ uint32_t idx_table_len;
/* map from index to deserialized pointer */
void **idx_table;
static void
write_add_object(write_ctx *ctx, const void *obj)
{
- uintptr_t index = ctx->next_idx++;
- _mesa_hash_table_insert(ctx->remap_table, obj, (void *) index);
+ uint32_t index = ctx->next_idx++;
+ assert(index != MAX_OBJECT_IDS);
+ _mesa_hash_table_insert(ctx->remap_table, obj, (void *)(uintptr_t) index);
}
-static uintptr_t
+static uint32_t
write_lookup_object(write_ctx *ctx, const void *obj)
{
struct hash_entry *entry = _mesa_hash_table_search(ctx->remap_table, obj);
assert(entry);
- return (uintptr_t) entry->data;
+ return (uint32_t)(uintptr_t) entry->data;
}
static void
write_object(write_ctx *ctx, const void *obj)
{
- blob_write_intptr(ctx->blob, write_lookup_object(ctx, obj));
+ blob_write_uint32(ctx->blob, write_lookup_object(ctx, obj));
}
static void
}
static void *
-read_lookup_object(read_ctx *ctx, uintptr_t idx)
+read_lookup_object(read_ctx *ctx, uint32_t idx)
{
assert(idx < ctx->idx_table_len);
return ctx->idx_table[idx];
static void *
read_object(read_ctx *ctx)
{
- return read_lookup_object(ctx, blob_read_intptr(ctx->blob));
+ return read_lookup_object(ctx, blob_read_uint32(ctx->blob));
}
static void
* address space would've been exhausted allocating the remap table!
*/
if (src->is_ssa) {
- uintptr_t idx = write_lookup_object(ctx, src->ssa) << 2;
+ uint32_t idx = write_lookup_object(ctx, src->ssa) << 2;
idx |= 1;
- blob_write_intptr(ctx->blob, idx);
+ blob_write_uint32(ctx->blob, idx);
} else {
- uintptr_t idx = write_lookup_object(ctx, src->reg.reg) << 2;
+ uint32_t idx = write_lookup_object(ctx, src->reg.reg) << 2;
if (src->reg.indirect)
idx |= 2;
- blob_write_intptr(ctx->blob, idx);
+ blob_write_uint32(ctx->blob, idx);
blob_write_uint32(ctx->blob, src->reg.base_offset);
if (src->reg.indirect) {
write_src(ctx, src->reg.indirect);
static void
read_src(read_ctx *ctx, nir_src *src, void *mem_ctx)
{
- uintptr_t val = blob_read_intptr(ctx->blob);
- uintptr_t idx = val >> 2;
+ uint32_t val = blob_read_uint32(ctx->blob);
+ uint32_t idx = val >> 2;
src->is_ssa = val & 0x1;
if (src->is_ssa) {
src->ssa = read_lookup_object(ctx, idx);
if (dst->ssa.name)
blob_write_string(ctx->blob, dst->ssa.name);
} else {
- blob_write_intptr(ctx->blob, write_lookup_object(ctx, dst->reg.reg));
+ blob_write_uint32(ctx->blob, write_lookup_object(ctx, dst->reg.reg));
blob_write_uint32(ctx->blob, dst->reg.base_offset);
if (dst->reg.indirect)
write_src(ctx, dst->reg.indirect);
write_phi(write_ctx *ctx, const nir_phi_instr *phi)
{
/* Phi nodes are special, since they may reference SSA definitions and
- * basic blocks that don't exist yet. We leave two empty uintptr_t's here,
+ * basic blocks that don't exist yet. We leave two empty uint32_t's here,
* and then store enough information so that a later fixup pass can fill
* them in correctly.
*/
nir_foreach_phi_src(src, phi) {
assert(src->src.is_ssa);
- size_t blob_offset = blob_reserve_intptr(ctx->blob);
- ASSERTED size_t blob_offset2 = blob_reserve_intptr(ctx->blob);
- assert(blob_offset + sizeof(uintptr_t) == blob_offset2);
+ size_t blob_offset = blob_reserve_uint32(ctx->blob);
+ ASSERTED size_t blob_offset2 = blob_reserve_uint32(ctx->blob);
+ assert(blob_offset + sizeof(uint32_t) == blob_offset2);
write_phi_fixup fixup = {
.blob_offset = blob_offset,
.src = src->src.ssa,
write_fixup_phis(write_ctx *ctx)
{
util_dynarray_foreach(&ctx->phi_fixups, write_phi_fixup, fixup) {
- uintptr_t *blob_ptr = (uintptr_t *)(ctx->blob->data + fixup->blob_offset);
+ uint32_t *blob_ptr = (uint32_t *)(ctx->blob->data + fixup->blob_offset);
blob_ptr[0] = write_lookup_object(ctx, fixup->src);
blob_ptr[1] = write_lookup_object(ctx, fixup->block);
}
nir_phi_src *src = ralloc(phi, nir_phi_src);
src->src.is_ssa = true;
- src->src.ssa = (nir_ssa_def *) blob_read_intptr(ctx->blob);
- src->pred = (nir_block *) blob_read_intptr(ctx->blob);
+ src->src.ssa = (nir_ssa_def *)(uintptr_t) blob_read_uint32(ctx->blob);
+ src->pred = (nir_block *)(uintptr_t) blob_read_uint32(ctx->blob);
/* Since we're not letting nir_insert_instr handle use/def stuff for us,
* we have to set the parent_instr manually. It doesn't really matter
static void
write_call(write_ctx *ctx, const nir_call_instr *call)
{
- blob_write_intptr(ctx->blob, write_lookup_object(ctx, call->callee));
+ blob_write_uint32(ctx->blob, write_lookup_object(ctx, call->callee));
for (unsigned i = 0; i < call->num_params; i++)
write_src(ctx, &call->params[i]);
ctx.nir = nir;
util_dynarray_init(&ctx.phi_fixups, NULL);
- size_t idx_size_offset = blob_reserve_intptr(blob);
+ size_t idx_size_offset = blob_reserve_uint32(blob);
struct shader_info info = nir->info;
uint32_t strings = 0;
if (nir->constant_data_size > 0)
blob_write_bytes(blob, nir->constant_data, nir->constant_data_size);
- *(uintptr_t *)(blob->data + idx_size_offset) = ctx.next_idx;
+ *(uint32_t *)(blob->data + idx_size_offset) = ctx.next_idx;
_mesa_hash_table_destroy(ctx.remap_table, NULL);
util_dynarray_fini(&ctx.phi_fixups);
read_ctx ctx;
ctx.blob = blob;
list_inithead(&ctx.phi_srcs);
- ctx.idx_table_len = blob_read_intptr(blob);
+ ctx.idx_table_len = blob_read_uint32(blob);
ctx.idx_table = calloc(ctx.idx_table_len, sizeof(uintptr_t));
ctx.next_idx = 0;