From 47ebb50cab3bfd41000f517e83ad0bac57fc4085 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Sat, 30 May 2020 12:27:54 -0500 Subject: [PATCH] spirv: Hand-roll fewer vtn_ssa_value creations Previously, we created our vtn_ssa_value in _vtn_variable_load_store manually as we did the recursive load/store. Instead, we now create the SSA value before calling into the recursive function. This is a tiny bit less efficient but it removes a case of hand-rolling vtn_ssa_value creation. For symmetry, we make _vtn_block_load_store assume the value is already created. Finally, we remove a trivial hand-rolled case in vtn_composite_extract. Reviewed-by: Caio Marcelo de Oliveira Filho Part-of: --- src/compiler/spirv/spirv_to_nir.c | 5 +++-- src/compiler/spirv/vtn_variables.c | 15 ++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index bdb0e333130..53e082a6bd7 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -3485,8 +3485,9 @@ vtn_composite_extract(struct vtn_builder *b, struct vtn_ssa_value *src, * vector to extract. */ - struct vtn_ssa_value *ret = rzalloc(b, struct vtn_ssa_value); - ret->type = glsl_scalar_type(glsl_get_base_type(cur->type)); + const struct glsl_type *scalar_type = + glsl_scalar_type(glsl_get_base_type(cur->type)); + struct vtn_ssa_value *ret = vtn_create_ssa_value(b, scalar_type); ret->def = nir_channel(&b->nb, cur->def, indices[i]); return ret; } else { diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index 01e95d54b74..d2e9f07ebfe 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -872,9 +872,6 @@ _vtn_block_load_store(struct vtn_builder *b, nir_intrinsic_op op, bool load, struct vtn_type *type, enum gl_access_qualifier access, struct vtn_ssa_value **inout) { - if (load && *inout == NULL) - *inout = vtn_create_ssa_value(b, type->type); - enum glsl_base_type base_type = glsl_get_base_type(type->type); switch (base_type) { case GLSL_TYPE_UINT: @@ -1029,7 +1026,7 @@ vtn_block_load(struct vtn_builder *b, struct vtn_pointer *src) nir_ssa_def *offset, *index = NULL; offset = vtn_pointer_to_offset(b, src, &index); - struct vtn_ssa_value *value = NULL; + struct vtn_ssa_value *value = vtn_create_ssa_value(b, src->type->type); _vtn_block_load_store(b, op, true, index, offset, access_offset, access_size, src->type, src->access, &value); @@ -1093,7 +1090,6 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load, * deref. */ if (load) { - *inout = vtn_create_ssa_value(b, ptr->type->type); (*inout)->def = nir_load_deref_with_access(&b->nb, deref, ptr->type->access | access); } else { @@ -1115,13 +1111,6 @@ _vtn_variable_load_store(struct vtn_builder *b, bool load, case GLSL_TYPE_ARRAY: case GLSL_TYPE_STRUCT: { unsigned elems = glsl_get_length(ptr->type->type); - if (load) { - vtn_assert(*inout == NULL); - *inout = rzalloc(b, struct vtn_ssa_value); - (*inout)->type = ptr->type->type; - (*inout)->elems = rzalloc_array(b, struct vtn_ssa_value *, elems); - } - struct vtn_access_chain chain = { .length = 1, .link = { @@ -1148,7 +1137,7 @@ vtn_variable_load(struct vtn_builder *b, struct vtn_pointer *src) if (vtn_pointer_uses_ssa_offset(b, src)) { return vtn_block_load(b, src); } else { - struct vtn_ssa_value *val = NULL; + struct vtn_ssa_value *val = vtn_create_ssa_value(b, src->type->type); _vtn_variable_load_store(b, true, src, src->access, &val); return val; } -- 2.30.2