From 878a8daca6bfc856308dda7d265964d93feb05ae Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 24 Aug 2020 09:51:04 -0500 Subject: [PATCH] nir: Add alignment information to cast derefs Reviewed-by: Jesse Natalie Reviewed-by: Boris Brezillon Part-of: --- src/compiler/nir/nir.h | 2 ++ src/compiler/nir/nir_clone.c | 2 ++ src/compiler/nir/nir_instr_set.c | 6 +++++- src/compiler/nir/nir_serialize.c | 4 ++++ src/compiler/nir/nir_validate.c | 6 ++++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index f6f667bcdcb..16733fd5e50 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1462,6 +1462,8 @@ typedef struct { struct { unsigned ptr_stride; + unsigned align_mul; + unsigned align_offset; } cast; }; diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index 05689b097a8..d090a7cf160 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -339,6 +339,8 @@ clone_deref_instr(clone_state *state, const nir_deref_instr *deref) case nir_deref_type_cast: nderef->cast.ptr_stride = deref->cast.ptr_stride; + nderef->cast.align_mul = deref->cast.align_mul; + nderef->cast.align_offset = deref->cast.align_offset; break; default: diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c index 5e280a1e3e0..63f01872d72 100644 --- a/src/compiler/nir/nir_instr_set.c +++ b/src/compiler/nir/nir_instr_set.c @@ -172,6 +172,8 @@ hash_deref(uint32_t hash, const nir_deref_instr *instr) case nir_deref_type_cast: hash = HASH(hash, instr->cast.ptr_stride); + hash = HASH(hash, instr->cast.align_mul); + hash = HASH(hash, instr->cast.align_offset); break; case nir_deref_type_var: @@ -619,7 +621,9 @@ nir_instrs_equal(const nir_instr *instr1, const nir_instr *instr2) break; case nir_deref_type_cast: - if (deref1->cast.ptr_stride != deref2->cast.ptr_stride) + if (deref1->cast.ptr_stride != deref2->cast.ptr_stride || + deref1->cast.align_mul != deref2->cast.align_mul || + deref1->cast.align_offset != deref2->cast.align_offset) return false; break; diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c index 2a0e5180787..64319886cd9 100644 --- a/src/compiler/nir/nir_serialize.c +++ b/src/compiler/nir/nir_serialize.c @@ -1037,6 +1037,8 @@ write_deref(write_ctx *ctx, const nir_deref_instr *deref) case nir_deref_type_cast: write_src(ctx, &deref->parent); blob_write_uint32(ctx->blob, deref->cast.ptr_stride); + blob_write_uint32(ctx->blob, deref->cast.align_mul); + blob_write_uint32(ctx->blob, deref->cast.align_offset); if (!header.deref.cast_type_same_as_last) { encode_type_to_blob(ctx->blob, deref->type); ctx->last_type = deref->type; @@ -1101,6 +1103,8 @@ read_deref(read_ctx *ctx, union packed_instr header) case nir_deref_type_cast: read_src(ctx, &deref->parent, &deref->instr); deref->cast.ptr_stride = blob_read_uint32(ctx->blob); + deref->cast.align_mul = blob_read_uint32(ctx->blob); + deref->cast.align_offset = blob_read_uint32(ctx->blob); if (header.deref.cast_type_same_as_last) { deref->type = ctx->last_type; } else { diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c index 11e9841e178..b7622cd06a9 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -418,6 +418,12 @@ validate_deref_instr(nir_deref_instr *instr, validate_state *state) /* We just validate that the type and mode are there */ validate_assert(state, instr->mode); validate_assert(state, instr->type); + if (instr->cast.align_mul > 0) { + validate_assert(state, util_is_power_of_two_nonzero(instr->cast.align_mul)); + validate_assert(state, instr->cast.align_offset < instr->cast.align_mul); + } else { + validate_assert(state, instr->cast.align_offset == 0); + } } else { /* We require the parent to be SSA. This may be lifted in the future */ validate_assert(state, instr->parent.is_ssa); -- 2.30.2