[Mesa-dev] [PATCH 155/133] nir/vars_to_ssa: Refactor get_deref_node

Connor Abbott cwabbott0 at gmail.com
Wed Jan 14 14:09:37 PST 2015


Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>

On Wed, Jan 14, 2015 at 5:02 PM, Jason Ekstrand <jason at jlekstrand.net> wrote:
> This refactor allows you to more easily get the deref node associated with
> a given variable.  We then use that new functionality in the
> deref_may_be_aliased function instead of creating a 1-element deref chain.
> ---
>  src/glsl/nir/nir_lower_vars_to_ssa.c | 48 +++++++++++++++++++-----------------
>  1 file changed, 26 insertions(+), 22 deletions(-)
>
> diff --git a/src/glsl/nir/nir_lower_vars_to_ssa.c b/src/glsl/nir/nir_lower_vars_to_ssa.c
> index 0f2391a..00a9b08 100644
> --- a/src/glsl/nir/nir_lower_vars_to_ssa.c
> +++ b/src/glsl/nir/nir_lower_vars_to_ssa.c
> @@ -192,6 +192,27 @@ deref_node_create(struct deref_node *parent,
>     return node;
>  }
>
> +/* Returns the deref node associated with the given variable.  This will be
> + * the root of the tree representing all of the derefs of the given variable.
> + */
> +static struct deref_node *
> +get_deref_node_for_var(nir_variable *var, struct lower_variables_state *state)
> +{
> +   struct deref_node *node;
> +
> +   uint32_t var_hash = _mesa_hash_pointer(var);
> +   struct hash_entry *var_entry =
> +      _mesa_hash_table_search(state->deref_var_nodes, var_hash, var);
> +
> +   if (var_entry) {
> +      return var_entry->data;
> +   } else {
> +      node = deref_node_create(NULL, var->type, state->dead_ctx);
> +      _mesa_hash_table_insert(state->deref_var_nodes, var_hash, var, node);
> +      return node;
> +   }
> +}
> +
>  /* Gets the deref_node for the given deref chain and creates it if it
>   * doesn't yet exist.  If the deref is fully-qualified and direct and
>   * add_to_direct_deref_nodes is true, it will be added to the hash table of
> @@ -203,19 +224,9 @@ get_deref_node(nir_deref_var *deref, bool add_to_direct_deref_nodes,
>  {
>     bool is_direct = true;
>
> -   struct deref_node *node;
> -
> -   uint32_t var_hash = _mesa_hash_pointer(deref->var);
> -   struct hash_entry *var_entry =
> -      _mesa_hash_table_search(state->deref_var_nodes, var_hash, deref->var);
> -
> -   if (var_entry) {
> -      node = var_entry->data;
> -   } else {
> -      node = deref_node_create(NULL, deref->deref.type, state->dead_ctx);
> -      _mesa_hash_table_insert(state->deref_var_nodes,
> -                              var_hash, deref->var, node);
> -   }
> +   /* Start at the base of the chain. */
> +   struct deref_node *node = get_deref_node_for_var(deref->var, state);
> +   assert(deref->deref.type == node->type);
>
>     for (nir_deref *tail = deref->deref.child; tail; tail = tail->child) {
>        switch (tail->deref_type) {
> @@ -417,15 +428,8 @@ static bool
>  deref_may_be_aliased(nir_deref_var *deref,
>                       struct lower_variables_state *state)
>  {
> -   nir_deref_var var_deref = *deref;
> -   var_deref.deref.child = NULL;
> -   struct deref_node *node = get_deref_node(&var_deref, false, state);
> -
> -   /* An invalid dereference can't be aliased. */
> -   if (node == NULL)
> -      return false;
> -
> -   return deref_may_be_aliased_node(node, &deref->deref, state);
> +   return deref_may_be_aliased_node(get_deref_node_for_var(deref->var, state),
> +                                    &deref->deref, state);
>  }
>
>  static void
> --
> 2.2.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list