[Mesa-dev] [RFC 9/9] SQUASH: nir: Update various components for the new list-based use/def sets

Jason Ekstrand jason at jlekstrand.net
Fri Apr 24 16:32:06 PDT 2015


---
 src/glsl/nir/nir_from_ssa.c             | 11 +++++------
 src/glsl/nir/nir_lower_locals_to_regs.c | 14 ++++++--------
 src/glsl/nir/nir_lower_to_source_mods.c | 20 ++++++++++++--------
 src/glsl/nir/nir_lower_vars_to_ssa.c    |  3 ++-
 src/glsl/nir/nir_opt_gcm.c              | 14 ++++++--------
 src/glsl/nir/nir_opt_global_to_local.c  | 13 ++++++-------
 src/glsl/nir/nir_opt_peephole_ffma.c    |  9 ++++-----
 src/glsl/nir/nir_opt_peephole_select.c  | 10 ++++------
 src/glsl/nir/nir_to_ssa.c               | 19 ++++++++++---------
 9 files changed, 55 insertions(+), 58 deletions(-)

diff --git a/src/glsl/nir/nir_from_ssa.c b/src/glsl/nir/nir_from_ssa.c
index 5e7deca..436ecd6 100644
--- a/src/glsl/nir/nir_from_ssa.c
+++ b/src/glsl/nir/nir_from_ssa.c
@@ -345,6 +345,7 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
 
          nir_parallel_copy_entry *entry = rzalloc(state->dead_ctx,
                                                   nir_parallel_copy_entry);
+         entry->src.parent_instr = &pcopy->instr;
          nir_ssa_dest_init(&pcopy->instr, &entry->dest,
                            phi->dest.ssa.num_components, src->src.ssa->name);
          exec_list_push_tail(&pcopy->entries, &entry->node);
@@ -358,6 +359,7 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
 
       nir_parallel_copy_entry *entry = rzalloc(state->dead_ctx,
                                                nir_parallel_copy_entry);
+      entry->src.parent_instr = &block_pcopy->instr;
       nir_ssa_dest_init(&block_pcopy->instr, &entry->dest,
                         phi->dest.ssa.num_components, phi->dest.ssa.name);
       exec_list_push_tail(&block_pcopy->entries, &entry->node);
@@ -503,7 +505,7 @@ rewrite_ssa_def(nir_ssa_def *def, void *void_state)
    }
 
    nir_ssa_def_rewrite_uses(def, nir_src_for_reg(reg), state->mem_ctx);
-   assert(def->uses->entries == 0 && def->if_uses->entries == 0);
+   assert(nir_list_is_empty(&def->uses) && nir_list_is_empty(&def->if_uses));
 
    if (def->parent_instr->type == nir_instr_type_ssa_undef)
       return true;
@@ -515,12 +517,9 @@ rewrite_ssa_def(nir_ssa_def *def, void *void_state)
     */
    nir_dest *dest = exec_node_data(nir_dest, def, ssa);
 
-   _mesa_set_destroy(dest->ssa.uses, NULL);
-   _mesa_set_destroy(dest->ssa.if_uses, NULL);
-
    *dest = nir_dest_for_reg(reg);
-
-   _mesa_set_add(reg->defs, state->instr);
+   dest->reg.parent_instr = state->instr;
+   nir_list_push_tail(&reg->defs, &dest->reg.def_link);
 
    return true;
 }
diff --git a/src/glsl/nir/nir_lower_locals_to_regs.c b/src/glsl/nir/nir_lower_locals_to_regs.c
index bc6a3d3..b1ba4c5 100644
--- a/src/glsl/nir/nir_lower_locals_to_regs.c
+++ b/src/glsl/nir/nir_lower_locals_to_regs.c
@@ -269,18 +269,16 @@ lower_locals_to_regs_block(nir_block *block, void *void_state)
 static nir_block *
 compute_reg_usedef_lca(nir_register *reg)
 {
-   struct set_entry *entry;
    nir_block *lca = NULL;
 
-   set_foreach(reg->defs, entry)
-      lca = nir_dominance_lca(lca, ((nir_instr *)entry->key)->block);
+   nir_list_foreach(nir_dest, def_dest, reg.def_link, &reg->defs)
+      lca = nir_dominance_lca(lca, def_dest->reg.parent_instr->block);
 
-   set_foreach(reg->uses, entry)
-      lca = nir_dominance_lca(lca, ((nir_instr *)entry->key)->block);
+   nir_list_foreach(nir_src, use_src, use_link, &reg->uses)
+      lca = nir_dominance_lca(lca, use_src->parent_instr->block);
 
-   set_foreach(reg->if_uses, entry) {
-      nir_if *if_stmt = (nir_if *)entry->key;
-      nir_cf_node *prev_node = nir_cf_node_prev(&if_stmt->cf_node);
+   nir_list_foreach(nir_src, use_src, use_link, &reg->if_uses) {
+      nir_cf_node *prev_node = nir_cf_node_prev(&use_src->parent_if->cf_node);
       assert(prev_node->type == nir_cf_node_block);
       lca = nir_dominance_lca(lca, nir_cf_node_as_block(prev_node));
    }
diff --git a/src/glsl/nir/nir_lower_to_source_mods.c b/src/glsl/nir/nir_lower_to_source_mods.c
index 7b4a0f6..33a2a27 100644
--- a/src/glsl/nir/nir_lower_to_source_mods.c
+++ b/src/glsl/nir/nir_lower_to_source_mods.c
@@ -88,8 +88,8 @@ nir_lower_to_source_mods_block(nir_block *block, void *state)
             alu->src[i].swizzle[j] = parent->src[0].swizzle[alu->src[i].swizzle[j]];
          }
 
-         if (parent->dest.dest.ssa.uses->entries == 0 &&
-             parent->dest.dest.ssa.if_uses->entries == 0)
+         if (nir_list_is_empty(&parent->dest.dest.ssa.uses) &&
+             nir_list_is_empty(&parent->dest.dest.ssa.if_uses))
             nir_instr_remove(&parent->instr);
       }
 
@@ -131,13 +131,13 @@ nir_lower_to_source_mods_block(nir_block *block, void *state)
       if (nir_op_infos[alu->op].output_type != nir_type_float)
          continue;
 
-      if (alu->dest.dest.ssa.if_uses->entries != 0)
+      if (!nir_list_is_empty(&alu->dest.dest.ssa.if_uses))
          continue;
 
       bool all_children_are_sat = true;
-      struct set_entry *entry;
-      set_foreach(alu->dest.dest.ssa.uses, entry) {
-         const nir_instr *child = entry->key;
+      nir_list_foreach(nir_src, child_src, use_link, &alu->dest.dest.ssa.uses) {
+         assert(child_src->is_ssa);
+         nir_instr *child = child_src->parent_instr;
          if (child->type != nir_instr_type_alu) {
             all_children_are_sat = false;
             continue;
@@ -161,8 +161,12 @@ nir_lower_to_source_mods_block(nir_block *block, void *state)
 
       alu->dest.saturate = true;
 
-      set_foreach(alu->dest.dest.ssa.uses, entry) {
-         nir_alu_instr *child_alu = nir_instr_as_alu((nir_instr *)entry->key);
+      nir_list_foreach(nir_src, child_src, use_link, &alu->dest.dest.ssa.uses) {
+         assert(child_src->is_ssa);
+         nir_instr *child = child_src->parent_instr;
+         assert(child->type == nir_instr_type_alu);
+         nir_alu_instr *child_alu = nir_instr_as_alu(child);
+
          child_alu->op = nir_op_fmov;
          child_alu->dest.saturate = false;
          /* We could propagate the dest of our instruction to the
diff --git a/src/glsl/nir/nir_lower_vars_to_ssa.c b/src/glsl/nir/nir_lower_vars_to_ssa.c
index bb60f46..4710c34 100644
--- a/src/glsl/nir/nir_lower_vars_to_ssa.c
+++ b/src/glsl/nir/nir_lower_vars_to_ssa.c
@@ -567,10 +567,11 @@ add_phi_sources(nir_block *block, nir_block *pred,
 
       nir_phi_src *src = ralloc(phi, nir_phi_src);
       src->pred = pred;
+      src->src.parent_instr = &phi->instr;
       src->src.is_ssa = true;
       src->src.ssa = get_ssa_def_for_block(node, pred, state);
 
-      _mesa_set_add(src->src.ssa->uses, instr);
+      nir_list_push_tail(&src->src.ssa->uses, &src->src.use_link);
 
       exec_list_push_tail(&phi->srcs, &src->node);
    }
diff --git a/src/glsl/nir/nir_opt_gcm.c b/src/glsl/nir/nir_opt_gcm.c
index b4f5fd3..db60370 100644
--- a/src/glsl/nir/nir_opt_gcm.c
+++ b/src/glsl/nir/nir_opt_gcm.c
@@ -279,9 +279,8 @@ gcm_schedule_late_def(nir_ssa_def *def, void *void_state)
 
    nir_block *lca = NULL;
 
-   struct set_entry *entry;
-   set_foreach(def->uses, entry) {
-      nir_instr *use_instr = (nir_instr *)entry->key;
+   nir_list_foreach(nir_src, use_src, use_link, &def->uses) {
+      nir_instr *use_instr = use_src->parent_instr;
 
       gcm_schedule_late_instr(use_instr, state);
 
@@ -304,8 +303,8 @@ gcm_schedule_late_def(nir_ssa_def *def, void *void_state)
       }
    }
 
-   set_foreach(def->if_uses, entry) {
-      nir_if *if_stmt = (nir_if *)entry->key;
+   nir_list_foreach(nir_src, use_src, use_link, &def->if_uses) {
+      nir_if *if_stmt = use_src->parent_if;
 
       /* For if statements, we consider the block to be the one immediately
        * preceding the if CF node.
@@ -377,9 +376,8 @@ gcm_place_instr(nir_instr *instr, struct gcm_state *state);
 static bool
 gcm_place_instr_def(nir_ssa_def *def, void *state)
 {
-   struct set_entry *entry;
-   set_foreach(def->uses, entry)
-      gcm_place_instr((nir_instr *)entry->key, state);
+   nir_list_foreach(nir_src, use_src, use_link, &def->uses)
+      gcm_place_instr(use_src->parent_instr, state);
 
    return false;
 }
diff --git a/src/glsl/nir/nir_opt_global_to_local.c b/src/glsl/nir/nir_opt_global_to_local.c
index 00db37b..d5a79ff 100644
--- a/src/glsl/nir/nir_opt_global_to_local.c
+++ b/src/glsl/nir/nir_opt_global_to_local.c
@@ -34,9 +34,8 @@ global_to_local(nir_register *reg)
 
    assert(reg->is_global);
 
-   struct set_entry *entry;
-   set_foreach(reg->defs, entry) {
-      nir_instr *instr = (nir_instr *) entry->key;
+   nir_list_foreach(nir_dest, def_dest, reg.def_link, &reg->defs) {
+      nir_instr *instr = def_dest->reg.parent_instr;
       nir_function_impl *instr_impl =
          nir_cf_node_get_function(&instr->block->cf_node);
       if (impl != NULL) {
@@ -47,8 +46,8 @@ global_to_local(nir_register *reg)
       }
    }
 
-   set_foreach(reg->uses, entry) {
-      nir_instr *instr = (nir_instr *) entry->key;
+   nir_list_foreach(nir_src, use_src, use_link, &reg->uses) {
+      nir_instr *instr = use_src->parent_instr;
       nir_function_impl *instr_impl =
          nir_cf_node_get_function(&instr->block->cf_node);
       if (impl != NULL) {
@@ -59,8 +58,8 @@ global_to_local(nir_register *reg)
       }
    }
 
-   set_foreach(reg->if_uses, entry) {
-      nir_if *if_stmt = (nir_if *) entry->key;
+   nir_list_foreach(nir_src, use_src, use_link, &reg->if_uses) {
+      nir_if *if_stmt = use_src->parent_if;
       nir_function_impl *if_impl = nir_cf_node_get_function(&if_stmt->cf_node);
       if (impl != NULL) {
          if (impl != if_impl)
diff --git a/src/glsl/nir/nir_opt_peephole_ffma.c b/src/glsl/nir/nir_opt_peephole_ffma.c
index 9d5646f..3b05953 100644
--- a/src/glsl/nir/nir_opt_peephole_ffma.c
+++ b/src/glsl/nir/nir_opt_peephole_ffma.c
@@ -41,12 +41,11 @@ struct peephole_ffma_state {
 static inline bool
 are_all_uses_fadd(nir_ssa_def *def)
 {
-   if (def->if_uses->entries > 0)
+   if (!nir_list_is_empty(&def->if_uses))
       return false;
 
-   struct set_entry *use_iter;
-   set_foreach(def->uses, use_iter) {
-      nir_instr *use_instr = (nir_instr *)use_iter->key;
+   nir_list_foreach(nir_src, use_src, use_link, &def->uses) {
+      nir_instr *use_instr = use_src->parent_instr;
 
       if (use_instr->type != nir_instr_type_alu)
          return false;
@@ -220,7 +219,7 @@ nir_opt_peephole_ffma_block(nir_block *block, void *void_state)
                                state->mem_ctx);
 
       nir_instr_insert_before(&add->instr, &ffma->instr);
-      assert(add->dest.dest.ssa.uses->entries == 0);
+      assert(nir_list_is_empty(&add->dest.dest.ssa.uses));
       nir_instr_remove(&add->instr);
 
       state->progress = true;
diff --git a/src/glsl/nir/nir_opt_peephole_select.c b/src/glsl/nir/nir_opt_peephole_select.c
index f400cfd..ad15e0a 100644
--- a/src/glsl/nir/nir_opt_peephole_select.c
+++ b/src/glsl/nir/nir_opt_peephole_select.c
@@ -98,15 +98,13 @@ block_check_for_allowed_instrs(nir_block *block)
             return false;
 
          /* It cannot have any if-uses */
-         if (mov->dest.dest.ssa.if_uses->entries != 0)
+         if (!nir_list_is_empty(&mov->dest.dest.ssa.if_uses))
             return false;
 
          /* The only uses of this definition must be phi's in the successor */
-         struct set_entry *entry;
-         set_foreach(mov->dest.dest.ssa.uses, entry) {
-            const nir_instr *dest_instr = entry->key;
-            if (dest_instr->type != nir_instr_type_phi ||
-                dest_instr->block != block->successors[0])
+         nir_list_foreach(nir_src, use, use_link, &mov->dest.dest.ssa.uses) {
+            if (use->parent_instr->type != nir_instr_type_phi ||
+                use->parent_instr->block != block->successors[0])
                return false;
          }
          break;
diff --git a/src/glsl/nir/nir_to_ssa.c b/src/glsl/nir/nir_to_ssa.c
index 53ff547..aafe06c 100644
--- a/src/glsl/nir/nir_to_ssa.c
+++ b/src/glsl/nir/nir_to_ssa.c
@@ -89,9 +89,8 @@ insert_phi_nodes(nir_function_impl *impl)
       w_start = w_end = 0;
       iter_count++;
 
-      struct set_entry *entry;
-      set_foreach(reg->defs, entry) {
-         nir_instr *def = (nir_instr *) entry->key;
+      nir_list_foreach(nir_dest, dest, reg.def_link, &reg->defs) {
+         nir_instr *def = dest->reg.parent_instr;
          if (work[def->block->index] < iter_count)
             W[w_end++] = def->block;
          work[def->block->index] = iter_count;
@@ -99,6 +98,7 @@ insert_phi_nodes(nir_function_impl *impl)
 
       while (w_start != w_end) {
          nir_block *cur = W[w_start++];
+         struct set_entry *entry;
          set_foreach(cur->dom_frontier, entry) {
             nir_block *next = (nir_block *) entry->key;
 
@@ -190,13 +190,12 @@ rewrite_use(nir_src *src, void *_state)
    if (state->states[index].stack == NULL)
       return true;
 
-   src->is_ssa = true;
-   src->ssa = get_ssa_src(src->reg.reg, state);
-
+   nir_ssa_def *def = get_ssa_src(src->reg.reg, state);
    if (state->parent_instr)
-      _mesa_set_add(src->ssa->uses, state->parent_instr);
+      nir_instr_rewrite_src(state->parent_instr, src, nir_src_for_ssa(def));
    else
-      _mesa_set_add(src->ssa->if_uses, state->parent_if);
+      nir_if_rewrite_condition(state->parent_if, nir_src_for_ssa(def));
+
    return true;
 }
 
@@ -219,6 +218,7 @@ rewrite_def_forwards(nir_dest *dest, void *_state)
       name = ralloc_asprintf(state->mem_ctx, "%s_%u", dest->reg.reg->name,
                              state->states[index].num_defs);
 
+   nir_link_remove(&dest->reg.def_link);
    nir_ssa_dest_init(state->parent_instr, dest, reg->num_components, name);
 
    /* push our SSA destination on the stack */
@@ -270,6 +270,7 @@ rewrite_alu_instr_forward(nir_alu_instr *instr, rewrite_state *state)
                                 reg->name, state->states[index].num_defs);
 
       instr->dest.write_mask = (1 << num_components) - 1;
+      nir_link_remove(&instr->dest.dest.reg.def_link);
       nir_ssa_dest_init(&instr->instr, &instr->dest.dest, num_components, name);
 
       if (nir_op_infos[instr->op].output_size == 0) {
@@ -484,7 +485,7 @@ init_rewrite_state(nir_function_impl *impl, rewrite_state *state)
           * called after phi nodes are inserted so we can count phi node
           * definitions too.
           */
-         unsigned stack_size = reg->defs->entries;
+         unsigned stack_size = nir_list_length(&reg->defs);
 
          state->states[reg->index].stack = ralloc_array(state->states,
                                                         nir_ssa_def *,
-- 
2.3.6



More information about the mesa-dev mailing list