nir/spirv: Add a helper for pushing SSA values
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
This commit is contained in:
@@ -1379,6 +1379,7 @@ static void
|
|||||||
vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
|
vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
|
||||||
const uint32_t *w, unsigned count)
|
const uint32_t *w, unsigned count)
|
||||||
{
|
{
|
||||||
|
struct vtn_type *res_type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
||||||
struct nir_function *callee =
|
struct nir_function *callee =
|
||||||
vtn_value(b, w[3], vtn_value_type_function)->func->impl->function;
|
vtn_value(b, w[3], vtn_value_type_function)->func->impl->function;
|
||||||
|
|
||||||
@@ -1402,6 +1403,7 @@ vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
nir_variable *out_tmp = NULL;
|
nir_variable *out_tmp = NULL;
|
||||||
|
assert(res_type->type == callee->return_type);
|
||||||
if (!glsl_type_is_void(callee->return_type)) {
|
if (!glsl_type_is_void(callee->return_type)) {
|
||||||
out_tmp = nir_local_variable_create(b->impl, callee->return_type,
|
out_tmp = nir_local_variable_create(b->impl, callee->return_type,
|
||||||
"out_tmp");
|
"out_tmp");
|
||||||
@@ -1413,8 +1415,7 @@ vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
|
|||||||
if (glsl_type_is_void(callee->return_type)) {
|
if (glsl_type_is_void(callee->return_type)) {
|
||||||
vtn_push_value(b, w[2], vtn_value_type_undef);
|
vtn_push_value(b, w[2], vtn_value_type_undef);
|
||||||
} else {
|
} else {
|
||||||
struct vtn_value *retval = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
vtn_push_ssa(b, w[2], res_type, vtn_local_load(b, call->return_deref));
|
||||||
retval->ssa = vtn_local_load(b, call->return_deref);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -112,12 +112,12 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
|
|||||||
val->pointer = vtn_pointer_for_variable(b, vtn_var, type);
|
val->pointer = vtn_pointer_for_variable(b, vtn_var, type);
|
||||||
} else {
|
} else {
|
||||||
/* We're a regular SSA value. */
|
/* We're a regular SSA value. */
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
struct vtn_ssa_value *param_ssa =
|
||||||
|
vtn_local_load(b, nir_deref_var_create(b, param));
|
||||||
|
struct vtn_value *val = vtn_push_ssa(b, w[2], type, param_ssa);
|
||||||
|
|
||||||
/* Name the parameter so it shows up nicely in NIR */
|
/* Name the parameter so it shows up nicely in NIR */
|
||||||
param->name = ralloc_strdup(param, val->name);
|
param->name = ralloc_strdup(param, val->name);
|
||||||
|
|
||||||
val->ssa = vtn_local_load(b, nir_deref_var_create(b, param));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -504,14 +504,13 @@ vtn_handle_phis_first_pass(struct vtn_builder *b, SpvOp opcode,
|
|||||||
* algorithm all over again. It's easier if we just let
|
* algorithm all over again. It's easier if we just let
|
||||||
* lower_vars_to_ssa do that for us instead of repeating it here.
|
* lower_vars_to_ssa do that for us instead of repeating it here.
|
||||||
*/
|
*/
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
|
||||||
|
|
||||||
struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
||||||
nir_variable *phi_var =
|
nir_variable *phi_var =
|
||||||
nir_local_variable_create(b->nb.impl, type->type, "phi");
|
nir_local_variable_create(b->nb.impl, type->type, "phi");
|
||||||
_mesa_hash_table_insert(b->phi_table, w, phi_var);
|
_mesa_hash_table_insert(b->phi_table, w, phi_var);
|
||||||
|
|
||||||
val->ssa = vtn_local_load(b, nir_deref_var_create(b, phi_var));
|
vtn_push_ssa(b, w[2], type,
|
||||||
|
vtn_local_load(b, nir_deref_var_create(b, phi_var)));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -513,6 +513,15 @@ vtn_push_value(struct vtn_builder *b, uint32_t value_id,
|
|||||||
return &b->values[value_id];
|
return &b->values[value_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline 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 = vtn_push_value(b, value_id, vtn_value_type_ssa);
|
||||||
|
val->ssa = ssa;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct vtn_value *
|
static inline struct vtn_value *
|
||||||
vtn_untyped_value(struct vtn_builder *b, uint32_t value_id)
|
vtn_untyped_value(struct vtn_builder *b, uint32_t value_id)
|
||||||
{
|
{
|
||||||
|
@@ -1774,6 +1774,8 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case SpvOpLoad: {
|
case SpvOpLoad: {
|
||||||
|
struct vtn_type *res_type =
|
||||||
|
vtn_value(b, w[1], vtn_value_type_type)->type;
|
||||||
struct vtn_pointer *src =
|
struct vtn_pointer *src =
|
||||||
vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
|
vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
|
||||||
|
|
||||||
@@ -1783,8 +1785,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
vtn_push_ssa(b, w[2], res_type, vtn_variable_load(b, src));
|
||||||
val->ssa = vtn_variable_load(b, src);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user