[Mesa-dev] [PATCH 06/11] nir: rework force_unroll_array_access()
Thomas Helland
thomashelland90 at gmail.com
Wed Dec 5 06:55:23 UTC 2018
Den tir. 20. nov. 2018 kl. 09:15 skrev Timothy Arceri <tarceri at itsqueeze.com>:
>
> Here we rework force_unroll_array_access() so that we can reused
> the induction variable detection in a following patch.
> ---
> src/compiler/nir/nir_loop_analyze.c | 49 ++++++++++++++++++++---------
> 1 file changed, 35 insertions(+), 14 deletions(-)
>
> diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c
> index 700d1fe552..a103a22afd 100644
> --- a/src/compiler/nir/nir_loop_analyze.c
> +++ b/src/compiler/nir/nir_loop_analyze.c
> @@ -350,6 +350,38 @@ find_loop_terminators(loop_info_state *state)
> return success;
> }
>
> +/* This function looks for an array access within a loop that use an induction
> + * variable for the array index. If found it returns the size of the array,
> + * otherwise 0 is returned.
> + */
> +static unsigned
> +find_array_access_via_induction(loop_info_state *state,
> + nir_deref_instr *deref,
> + nir_loop_variable **array_index_out)
Maybe make a small comment about the last parameter?
I guess it's quite obvious, but I'd rather have too much
handholding than too little =)
> +{
> + for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {
> + if (d->deref_type != nir_deref_type_array)
> + continue;
> +
> + assert(d->arr.index.is_ssa);
> + nir_loop_variable *array_index = get_loop_var(d->arr.index.ssa, state);
> +
> + if (array_index->type != basic_induction)
> + continue;
> +
> + if (array_index_out)
> + *array_index_out = array_index;
> +
> + nir_deref_instr *parent = nir_deref_instr_parent(d);
> + assert(glsl_type_is_array(parent->type) ||
> + glsl_type_is_matrix(parent->type));
Maybe use glsl_type_is_array_or_matrix() ?
With (or without) that this patchs looks good and is:
Reviewed-by: Thomas Helland <thomashelland90 at gmail.com>
> +
> + return glsl_get_length(parent->type);
> + }
> +
> + return 0;
> +}
> +
> static int32_t
> get_iteration(nir_op cond_op, nir_const_value *initial, nir_const_value *step,
> nir_const_value *limit)
> @@ -626,20 +658,9 @@ find_trip_count(loop_info_state *state)
> static bool
> force_unroll_array_access(loop_info_state *state, nir_deref_instr *deref)
> {
> - for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {
> - if (d->deref_type != nir_deref_type_array)
> - continue;
> -
> - assert(d->arr.index.is_ssa);
> - nir_loop_variable *array_index = get_loop_var(d->arr.index.ssa, state);
> -
> - if (array_index->type != basic_induction)
> - continue;
> -
> - nir_deref_instr *parent = nir_deref_instr_parent(d);
> - assert(glsl_type_is_array(parent->type) ||
> - glsl_type_is_matrix(parent->type));
> - if (glsl_get_length(parent->type) == state->loop->info->max_trip_count)
> + unsigned array_size = find_array_access_via_induction(state, deref, NULL);
> + if (array_size) {
> + if (array_size == state->loop->info->max_trip_count)
> return true;
>
> if (deref->mode & state->indirect_mask)
> --
> 2.19.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list