[Mesa-dev] [PATCH 5/6] nir: Switch the arguments to nir_foreach_use and friends

Jason Ekstrand jason at jlekstrand.net
Wed Apr 27 03:41:49 UTC 2016


This matches the "foreach x in container" pattern found in many other
programming languages.  Generated by the following regular expression:

s/nir_foreach_use(\([^,]*\),\s*\([^,]*\))/nir_foreach_use(\2, \1)/

and similar expressions for nir_foreach_use_safe, etc.
---
 src/compiler/nir/nir.c                                    | 8 ++++----
 src/compiler/nir/nir.h                                    | 8 ++++----
 src/compiler/nir/nir_lower_to_source_mods.c               | 4 ++--
 src/compiler/nir/nir_lower_vec_to_movs.c                  | 2 +-
 src/compiler/nir/nir_move_vec_src_uses_to_dest.c          | 2 +-
 src/compiler/nir/nir_opt_gcm.c                            | 6 +++---
 src/compiler/nir/nir_opt_global_to_local.c                | 4 ++--
 src/compiler/nir/nir_opt_peephole_select.c                | 2 +-
 src/compiler/nir/nir_repair_ssa.c                         | 4 ++--
 src/compiler/nir/nir_validate.c                           | 8 ++++----
 src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c | 2 +-
 src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c     | 2 +-
 12 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index f0c5d59..3fbe56a 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -1419,10 +1419,10 @@ nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src)
 {
    assert(!new_src.is_ssa || def != new_src.ssa);
 
-   nir_foreach_use_safe(def, use_src)
+   nir_foreach_use_safe(use_src, def)
       nir_instr_rewrite_src(use_src->parent_instr, use_src, new_src);
 
-   nir_foreach_if_use_safe(def, use_src)
+   nir_foreach_if_use_safe(use_src, def)
       nir_if_rewrite_condition(use_src->parent_if, new_src);
 }
 
@@ -1462,7 +1462,7 @@ nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_src new_src,
 {
    assert(!new_src.is_ssa || def != new_src.ssa);
 
-   nir_foreach_use_safe(def, use_src) {
+   nir_foreach_use_safe(use_src, def) {
       assert(use_src->parent_instr != def->parent_instr);
       /* Since def already dominates all of its uses, the only way a use can
        * not be dominated by after_me is if it is between def and after_me in
@@ -1472,7 +1472,7 @@ nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_src new_src,
          nir_instr_rewrite_src(use_src->parent_instr, use_src, new_src);
    }
 
-   nir_foreach_if_use_safe(def, use_src)
+   nir_foreach_if_use_safe(use_src, def)
       nir_if_rewrite_condition(use_src->parent_if, new_src);
 }
 
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 1585465..f00b6ed 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -516,16 +516,16 @@ nir_src_init(void)
 
 #define NIR_SRC_INIT nir_src_init()
 
-#define nir_foreach_use(reg_or_ssa_def, src) \
+#define nir_foreach_use(src, reg_or_ssa_def) \
    list_for_each_entry(nir_src, src, &(reg_or_ssa_def)->uses, use_link)
 
-#define nir_foreach_use_safe(reg_or_ssa_def, src) \
+#define nir_foreach_use_safe(src, reg_or_ssa_def) \
    list_for_each_entry_safe(nir_src, src, &(reg_or_ssa_def)->uses, use_link)
 
-#define nir_foreach_if_use(reg_or_ssa_def, src) \
+#define nir_foreach_if_use(src, reg_or_ssa_def) \
    list_for_each_entry(nir_src, src, &(reg_or_ssa_def)->if_uses, use_link)
 
-#define nir_foreach_if_use_safe(reg_or_ssa_def, src) \
+#define nir_foreach_if_use_safe(src, reg_or_ssa_def) \
    list_for_each_entry_safe(nir_src, src, &(reg_or_ssa_def)->if_uses, use_link)
 
 typedef struct {
diff --git a/src/compiler/nir/nir_lower_to_source_mods.c b/src/compiler/nir/nir_lower_to_source_mods.c
index b5f1650..7a1507c 100644
--- a/src/compiler/nir/nir_lower_to_source_mods.c
+++ b/src/compiler/nir/nir_lower_to_source_mods.c
@@ -136,7 +136,7 @@ nir_lower_to_source_mods_block(nir_block *block)
          continue;
 
       bool all_children_are_sat = true;
-      nir_foreach_use(&alu->dest.dest.ssa, child_src) {
+      nir_foreach_use(child_src, &alu->dest.dest.ssa) {
          assert(child_src->is_ssa);
          nir_instr *child = child_src->parent_instr;
          if (child->type != nir_instr_type_alu) {
@@ -162,7 +162,7 @@ nir_lower_to_source_mods_block(nir_block *block)
 
       alu->dest.saturate = true;
 
-      nir_foreach_use(&alu->dest.dest.ssa, child_src) {
+      nir_foreach_use(child_src, &alu->dest.dest.ssa) {
          assert(child_src->is_ssa);
          nir_instr *child = child_src->parent_instr;
          assert(child->type == nir_instr_type_alu);
diff --git a/src/compiler/nir/nir_lower_vec_to_movs.c b/src/compiler/nir/nir_lower_vec_to_movs.c
index 90619c9..b383fb8 100644
--- a/src/compiler/nir/nir_lower_vec_to_movs.c
+++ b/src/compiler/nir/nir_lower_vec_to_movs.c
@@ -131,7 +131,7 @@ try_coalesce(nir_alu_instr *vec, unsigned start_idx, nir_shader *shader)
    /* If we are going to do a reswizzle, then the vecN operation must be the
     * only use of the source value.  We also can't have any source modifiers.
     */
-   nir_foreach_use(vec->src[start_idx].src.ssa, src) {
+   nir_foreach_use(src, vec->src[start_idx].src.ssa) {
       if (src->parent_instr != &vec->instr)
          return 0;
 
diff --git a/src/compiler/nir/nir_move_vec_src_uses_to_dest.c b/src/compiler/nir/nir_move_vec_src_uses_to_dest.c
index 30752a2..7691775 100644
--- a/src/compiler/nir/nir_move_vec_src_uses_to_dest.c
+++ b/src/compiler/nir/nir_move_vec_src_uses_to_dest.c
@@ -121,7 +121,7 @@ move_vec_src_uses_to_dest_block(nir_block *block)
             swizzle[vec->src[j].swizzle[0]] = j;
          }
 
-         nir_foreach_use_safe(vec->src[i].src.ssa, use) {
+         nir_foreach_use_safe(use, vec->src[i].src.ssa) {
             if (use->parent_instr == &vec->instr)
                continue;
 
diff --git a/src/compiler/nir/nir_opt_gcm.c b/src/compiler/nir/nir_opt_gcm.c
index 119b74d..ff079b9 100644
--- a/src/compiler/nir/nir_opt_gcm.c
+++ b/src/compiler/nir/nir_opt_gcm.c
@@ -277,7 +277,7 @@ gcm_schedule_late_def(nir_ssa_def *def, void *void_state)
 
    nir_block *lca = NULL;
 
-   nir_foreach_use(def, use_src) {
+   nir_foreach_use(use_src, def) {
       nir_instr *use_instr = use_src->parent_instr;
 
       gcm_schedule_late_instr(use_instr, state);
@@ -301,7 +301,7 @@ gcm_schedule_late_def(nir_ssa_def *def, void *void_state)
       }
    }
 
-   nir_foreach_if_use(def, use_src) {
+   nir_foreach_if_use(use_src, def) {
       nir_if *if_stmt = use_src->parent_if;
 
       /* For if statements, we consider the block to be the one immediately
@@ -374,7 +374,7 @@ gcm_place_instr(nir_instr *instr, struct gcm_state *state);
 static bool
 gcm_place_instr_def(nir_ssa_def *def, void *state)
 {
-   nir_foreach_use(def, use_src)
+   nir_foreach_use(use_src, def)
       gcm_place_instr(use_src->parent_instr, state);
 
    return false;
diff --git a/src/compiler/nir/nir_opt_global_to_local.c b/src/compiler/nir/nir_opt_global_to_local.c
index bccb45b..3555c7b 100644
--- a/src/compiler/nir/nir_opt_global_to_local.c
+++ b/src/compiler/nir/nir_opt_global_to_local.c
@@ -46,7 +46,7 @@ global_to_local(nir_register *reg)
       }
    }
 
-   nir_foreach_use(reg, use_src) {
+   nir_foreach_use(use_src, reg) {
       nir_instr *instr = use_src->parent_instr;
       nir_function_impl *instr_impl =
          nir_cf_node_get_function(&instr->block->cf_node);
@@ -58,7 +58,7 @@ global_to_local(nir_register *reg)
       }
    }
 
-   nir_foreach_if_use(reg, use_src) {
+   nir_foreach_if_use(use_src, reg) {
       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) {
diff --git a/src/compiler/nir/nir_opt_peephole_select.c b/src/compiler/nir/nir_opt_peephole_select.c
index e06820d..7fcc71e 100644
--- a/src/compiler/nir/nir_opt_peephole_select.c
+++ b/src/compiler/nir/nir_opt_peephole_select.c
@@ -108,7 +108,7 @@ block_check_for_allowed_instrs(nir_block *block)
             return false;
 
          /* The only uses of this definition must be phi's in the successor */
-         nir_foreach_use(&mov->dest.dest.ssa, use) {
+         nir_foreach_use(use, &mov->dest.dest.ssa) {
             if (use->parent_instr->type != nir_instr_type_phi ||
                 use->parent_instr->block != block->successors[0])
                return false;
diff --git a/src/compiler/nir/nir_repair_ssa.c b/src/compiler/nir/nir_repair_ssa.c
index 7dd2397..b4d22d9 100644
--- a/src/compiler/nir/nir_repair_ssa.c
+++ b/src/compiler/nir/nir_repair_ssa.c
@@ -70,7 +70,7 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
    struct repair_ssa_state *state = void_state;
 
    bool is_valid = true;
-   nir_foreach_use(def, src) {
+   nir_foreach_use(src, def) {
       if (!nir_block_dominates(def->parent_instr->block, get_src_block(src))) {
          is_valid = false;
          break;
@@ -90,7 +90,7 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
 
    nir_phi_builder_value_set_block_def(val, def->parent_instr->block, def);
 
-   nir_foreach_use_safe(def, src) {
+   nir_foreach_use_safe(src, def) {
       nir_block *src_block = get_src_block(src);
       if (!nir_block_dominates(def->parent_instr->block, src_block)) {
          nir_instr_rewrite_src(src->parent_instr, src, nir_src_for_ssa(
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index e928c41..53cdbc4 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -852,7 +852,7 @@ postvalidate_reg_decl(nir_register *reg, validate_state *state)
 
    reg_validate_state *reg_state = (reg_validate_state *) entry->data;
 
-   nir_foreach_use(reg, src) {
+   nir_foreach_use(src, reg) {
       struct set_entry *entry = _mesa_set_search(reg_state->uses, src);
       assert(entry);
       _mesa_set_remove(reg_state->uses, entry);
@@ -867,7 +867,7 @@ postvalidate_reg_decl(nir_register *reg, validate_state *state)
       abort();
    }
 
-   nir_foreach_if_use(reg, src) {
+   nir_foreach_if_use(src, reg) {
       struct set_entry *entry = _mesa_set_search(reg_state->if_uses, src);
       assert(entry);
       _mesa_set_remove(reg_state->if_uses, entry);
@@ -924,7 +924,7 @@ postvalidate_ssa_def(nir_ssa_def *def, void *void_state)
    struct hash_entry *entry = _mesa_hash_table_search(state->ssa_defs, def);
    ssa_def_validate_state *def_state = (ssa_def_validate_state *)entry->data;
 
-   nir_foreach_use(def, src) {
+   nir_foreach_use(src, def) {
       struct set_entry *entry = _mesa_set_search(def_state->uses, src);
       assert(entry);
       _mesa_set_remove(def_state->uses, entry);
@@ -939,7 +939,7 @@ postvalidate_ssa_def(nir_ssa_def *def, void *void_state)
       abort();
    }
 
-   nir_foreach_if_use(def, src) {
+   nir_foreach_if_use(src, def) {
       struct set_entry *entry = _mesa_set_search(def_state->if_uses, src);
       assert(entry);
       _mesa_set_remove(def_state->if_uses, entry);
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c b/src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c
index 788d1dd..262f490 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c
@@ -74,7 +74,7 @@ valid_dest(nir_block *block, nir_dest *dest)
 	/* The only uses of this definition must be phi's in the
 	 * successor or in the current block
 	 */
-	nir_foreach_use(&dest->ssa, use) {
+	nir_foreach_use(use, &dest->ssa) {
 		nir_instr *dest_instr = use->parent_instr;
 		if (dest_instr->block == block)
 			continue;
diff --git a/src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c b/src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c
index e7df80d..86fcdd4 100644
--- a/src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c
+++ b/src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c
@@ -44,7 +44,7 @@ are_all_uses_fadd(nir_ssa_def *def)
    if (!list_empty(&def->if_uses))
       return false;
 
-   nir_foreach_use(def, use_src) {
+   nir_foreach_use(use_src, def) {
       nir_instr *use_instr = use_src->parent_instr;
 
       if (use_instr->type != nir_instr_type_alu)
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list