[Mesa-dev] [PATCH 1/4] nir/instr_set: Add an allow_loads field

Pohjolainen, Topi topi.pohjolainen at intel.com
Tue Oct 27 05:33:50 PDT 2015


On Tue, Oct 27, 2015 at 10:28:58AM +0100, Iago Toral Quiroga wrote:
> We need this so we can configure different behaviors for passes that
> cannot deal with side-effectful instructions (CSE) and passes that can
> (we will add a load-combine pass shortly).
> 
> For now, when allow_loads is true, we let the instruction set rewrite
> SSBO loads.
> ---
>  src/glsl/nir/nir_instr_set.c | 51 ++++++++++++++++++++++++++++----------------
>  src/glsl/nir/nir_instr_set.h | 20 ++++++++++++-----
>  src/glsl/nir/nir_opt_cse.c   |  4 ++--
>  3 files changed, 50 insertions(+), 25 deletions(-)
> 
> diff --git a/src/glsl/nir/nir_instr_set.c b/src/glsl/nir/nir_instr_set.c
> index d3f939f..583618f 100644
> --- a/src/glsl/nir/nir_instr_set.c
> +++ b/src/glsl/nir/nir_instr_set.c
> @@ -398,6 +398,13 @@ dest_is_ssa(nir_dest *dest, void *data)
>     return dest->is_ssa;
>  }
>  
> +static bool
> +is_load(nir_intrinsic_instr *instr)
> +{
> +   return instr->intrinsic == nir_intrinsic_load_ssbo ||
> +          instr->intrinsic == nir_intrinsic_load_ssbo_indirect;
> +}
> +
>  /* This function determines if uses of an instruction can safely be rewritten
>   * to use another identical instruction instead. Note that this function must
>   * be kept in sync with hash_instr() and nir_instrs_equal() -- only
> @@ -406,7 +413,7 @@ dest_is_ssa(nir_dest *dest, void *data)
>   */
>  
>  static bool
> -instr_can_rewrite(nir_instr *instr)
> +instr_can_rewrite(nir_instr *instr, bool allow_loads)
>  {
>     /* We only handle SSA. */
>     if (!nir_foreach_dest(instr, dest_is_ssa, NULL) ||
> @@ -428,11 +435,15 @@ instr_can_rewrite(nir_instr *instr)
>        return true;
>     }
>     case nir_instr_type_intrinsic: {
> +      nir_intrinsic_instr *intrinsic = nir_instr_as_intrinsic(instr);
>        const nir_intrinsic_info *info =
> -         &nir_intrinsic_infos[nir_instr_as_intrinsic(instr)->intrinsic];
> -      return (info->flags & NIR_INTRINSIC_CAN_ELIMINATE) &&
> -             (info->flags & NIR_INTRINSIC_CAN_REORDER) &&
> -             info->num_variables == 0; /* not implemented yet */
> +         &nir_intrinsic_infos[intrinsic->intrinsic];
> +      bool can_eliminate_and_reorder =
> +         (info->flags & NIR_INTRINSIC_CAN_ELIMINATE) &&
> +         (info->flags & NIR_INTRINSIC_CAN_REORDER) &&
> +         info->num_variables == 0; /* not implemented yet */
> +      return can_eliminate_and_reorder ?
> +         true: allow_loads && is_load(intrinsic);

Isn't this just?

         return can_eliminate_and_reorder ||
                (allow_loads && is_load(intrinsic));


More information about the mesa-dev mailing list