From: Jason Ekstrand Date: Fri, 29 May 2020 20:44:10 +0000 (-0500) Subject: spirv: Refactor vtn_push_ssa X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dbb4a24413d8f3af246a2ef7530ef036613ea1e4;p=mesa.git spirv: Refactor vtn_push_ssa We rename it to vtn_push_ssa_value, move it to spirv_to_nir, and remove the unnecessary type parameter. Reviewed-by: Caio Marcelo de Oliveira Filho Part-of: --- diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index e0a92bcf76a..fa09f0d64d2 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -302,6 +302,23 @@ vtn_ssa_value(struct vtn_builder *b, uint32_t value_id) } } +struct vtn_value * +vtn_push_ssa_value(struct vtn_builder *b, uint32_t value_id, + struct vtn_ssa_value *ssa) +{ + struct vtn_type *type = vtn_get_value_type(b, value_id); + + struct vtn_value *val; + if (type->base_type == vtn_base_type_pointer) { + val = vtn_push_pointer(b, value_id, vtn_pointer_from_ssa(b, ssa->def, type)); + } else { + val = vtn_push_value(b, value_id, vtn_value_type_ssa); + val->ssa = ssa; + } + + return val; +} + nir_ssa_def * vtn_get_nir_ssa(struct vtn_builder *b, uint32_t value_id) { @@ -323,7 +340,7 @@ vtn_push_nir_ssa(struct vtn_builder *b, uint32_t value_id, nir_ssa_def *def) "Mismatch between NIR and SPIR-V type."); struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, type->type); ssa->def = def; - return vtn_push_ssa(b, value_id, type, ssa); + return vtn_push_ssa_value(b, value_id, ssa); } static char * @@ -3606,7 +3623,7 @@ vtn_handle_composite(struct vtn_builder *b, SpvOp opcode, vtn_fail_with_opcode("unknown composite operation", opcode); } - vtn_push_ssa(b, w[2], type, ssa); + vtn_push_ssa_value(b, w[2], ssa); } static void @@ -4733,11 +4750,10 @@ vtn_handle_select(struct vtn_builder *b, SpvOp opcode, vtn_fail("Result type of OpSelect must be a scalar, composite, or pointer"); } - struct vtn_type *res_type = vtn_get_type(b, w[1]); - struct vtn_ssa_value *ssa = vtn_nir_select(b, - vtn_ssa_value(b, w[3]), vtn_ssa_value(b, w[4]), vtn_ssa_value(b, w[5])); - - vtn_push_ssa(b, w[2], res_type, ssa); + vtn_push_ssa_value(b, w[2], + vtn_nir_select(b, vtn_ssa_value(b, w[3]), + vtn_ssa_value(b, w[4]), + vtn_ssa_value(b, w[5]))); } static void diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c index e97362a9dca..72922464633 100644 --- a/src/compiler/spirv/vtn_cfg.c +++ b/src/compiler/spirv/vtn_cfg.c @@ -185,7 +185,6 @@ void vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode, const uint32_t *w, unsigned count) { - struct vtn_type *res_type = vtn_get_type(b, w[1]); struct vtn_function *vtn_callee = vtn_value(b, w[3], vtn_value_type_function)->func; struct nir_function *callee = vtn_callee->impl->function; @@ -238,7 +237,7 @@ vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode, if (ret_type->base_type == vtn_base_type_void) { vtn_push_value(b, w[2], vtn_value_type_undef); } else { - vtn_push_ssa(b, w[2], res_type, vtn_local_load(b, ret_deref, 0)); + vtn_push_ssa_value(b, w[2], vtn_local_load(b, ret_deref, 0)); } } @@ -351,7 +350,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode, /* We're a regular SSA value. */ struct vtn_ssa_value *value = vtn_create_ssa_value(b, type->type); vtn_ssa_value_load_function_param(b, value, type, &b->func_param_idx); - vtn_push_ssa(b, w[2], type, value); + vtn_push_ssa_value(b, w[2], value); } break; } @@ -988,8 +987,8 @@ vtn_handle_phis_first_pass(struct vtn_builder *b, SpvOp opcode, nir_local_variable_create(b->nb.impl, type->type, "phi"); _mesa_hash_table_insert(b->phi_table, w, phi_var); - vtn_push_ssa(b, w[2], type, - vtn_local_load(b, nir_build_deref_var(&b->nb, phi_var), 0)); + vtn_push_ssa_value(b, w[2], + vtn_local_load(b, nir_build_deref_var(&b->nb, phi_var), 0)); return true; } diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index 1e90316aec2..ea30cb68ddd 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -784,6 +784,8 @@ vtn_get_type(struct vtn_builder *b, uint32_t value_id) } struct vtn_ssa_value *vtn_ssa_value(struct vtn_builder *b, uint32_t value_id); +struct vtn_value *vtn_push_ssa_value(struct vtn_builder *b, uint32_t value_id, + struct vtn_ssa_value *ssa); nir_ssa_def *vtn_get_nir_ssa(struct vtn_builder *b, uint32_t value_id); struct vtn_value *vtn_push_nir_ssa(struct vtn_builder *b, uint32_t value_id, @@ -793,9 +795,6 @@ struct vtn_value *vtn_push_pointer(struct vtn_builder *b, uint32_t value_id, struct vtn_pointer *ptr); -struct vtn_value *vtn_push_ssa(struct vtn_builder *b, uint32_t value_id, - struct vtn_type *type, struct vtn_ssa_value *ssa); - void vtn_copy_value(struct vtn_builder *b, uint32_t src_value_id, uint32_t dst_value_id); diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index 6de66a41d1a..01e95d54b74 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -76,20 +76,6 @@ vtn_push_pointer(struct vtn_builder *b, uint32_t value_id, return val; } -struct vtn_value * -vtn_push_ssa(struct vtn_builder *b, uint32_t value_id, - struct vtn_type *type, struct vtn_ssa_value *ssa) -{ - struct vtn_value *val; - if (type->base_type == vtn_base_type_pointer) { - val = vtn_push_pointer(b, value_id, vtn_pointer_from_ssa(b, ssa->def, type)); - } else { - val = vtn_push_value(b, value_id, vtn_value_type_ssa); - val->ssa = ssa; - } - return val; -} - void vtn_copy_value(struct vtn_builder *b, uint32_t src_value_id, uint32_t dst_value_id) @@ -2621,7 +2607,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, } } - vtn_push_ssa(b, w[2], res_type, vtn_variable_load(b, src)); + vtn_push_ssa_value(b, w[2], vtn_variable_load(b, src)); break; }