diff options
author | Jason Ekstrand <jason.ekstrand@intel.com> | 2015-01-14 14:00:12 -0800 |
---|---|---|
committer | Jason Ekstrand <jason.ekstrand@intel.com> | 2015-01-15 07:20:24 -0800 |
commit | 700ba5daaf9ec340dc967bbf1ba355470a573b37 (patch) | |
tree | 8f5d3999dafeae9233fa7cd8ec57565528572946 /src | |
parent | 55b5058e69859ba28c2f32de6edf5f0df3c6c28c (diff) |
nir/vars_to_ssa: Refactor get_deref_node
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.
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/glsl/nir/nir_lower_vars_to_ssa.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/glsl/nir/nir_lower_vars_to_ssa.c b/src/glsl/nir/nir_lower_vars_to_ssa.c index 2b40ededc7d..831560cf617 100644 --- a/src/glsl/nir/nir_lower_vars_to_ssa.c +++ b/src/glsl/nir/nir_lower_vars_to_ssa.c @@ -189,6 +189,26 @@ 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; + + struct hash_entry *var_entry = + _mesa_hash_table_search(state->deref_var_nodes, 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, 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 @@ -200,17 +220,9 @@ get_deref_node(nir_deref_var *deref, bool add_to_direct_deref_nodes, { bool is_direct = true; - struct deref_node *node; - - struct hash_entry *var_entry = - _mesa_hash_table_search(state->deref_var_nodes, 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, 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) { @@ -411,15 +423,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 |