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 <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5278>
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index e0a92bc..fa09f0d 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -302,6 +302,23 @@
}
}
+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 @@
"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_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_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 e97362a..7292246 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -185,7 +185,6 @@
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 @@
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 @@
/* 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 @@
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 1e90316..ea30cb6 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -784,6 +784,8 @@
}
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 @@
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 6de66a4..01e95d5 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -76,20 +76,6 @@
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_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;
}