[Mesa-dev] [PATCH 125/133] nir/lower_variables: Use a real dominance DFS for variable renaming

Jason Ekstrand jason at jlekstrand.net
Mon Dec 15 22:13:08 PST 2014


Previously, we were just iterating over the program "in order" which
kind-of approximates a DFS, but not really.  In particular, we got the
following case wrong:

loop {
   a = 3;
   if (foo) {
      a = 5;
   } else {
      break;
   }
   use(a);
}

where use(a) would get 3 instead of 5 because of premature popping of the
SSA def stack.  Now, since we do an actaul DFS, we should evaluate use(a)
immediately after a = 5 and we should be ok.
---
 src/glsl/nir/nir_lower_variables.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/glsl/nir/nir_lower_variables.c b/src/glsl/nir/nir_lower_variables.c
index eff7d5d..16157b3 100644
--- a/src/glsl/nir/nir_lower_variables.c
+++ b/src/glsl/nir/nir_lower_variables.c
@@ -730,10 +730,8 @@ add_phi_sources(nir_block *block, nir_block *pred,
 }
 
 static bool
-lower_deref_to_ssa_block(nir_block *block, void *void_state)
+rename_variables_block(nir_block *block, struct lower_variables_state *state)
 {
-   struct lower_variables_state *state = void_state;
-
    nir_foreach_instr_safe(block, instr) {
       if (instr->type == nir_instr_type_phi) {
          nir_phi_instr *phi = nir_instr_as_phi(instr);
@@ -862,6 +860,9 @@ lower_deref_to_ssa_block(nir_block *block, void *void_state)
    if (block->successors[1])
       add_phi_sources(block->successors[1], block, state);
 
+   for (unsigned i = 0; i < block->num_dom_children; ++i)
+      rename_variables_block(block->dom_children[i], state);
+
    return true;
 }
 
@@ -1001,7 +1002,7 @@ nir_lower_variables_impl(nir_function_impl *impl)
    nir_metadata_require(impl, nir_metadata_dominance);
 
    insert_phi_nodes(&state);
-   nir_foreach_block(impl, lower_deref_to_ssa_block, &state);
+   rename_variables_block(impl->start_block, &state);
 
    nir_metadata_preserve(impl, nir_metadata_block_index |
                                nir_metadata_dominance);
-- 
2.2.0



More information about the mesa-dev mailing list