nir: Switch the arguments to nir_foreach_phi_src
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 27 Apr 2016 03:16:21 +0000 (20:16 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 28 Apr 2016 22:54:48 +0000 (15:54 -0700)
This matches the "foreach x in container" pattern found in many other
programming languages.  Generated by the following regular expression:

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

and a similar expression for nir_foreach_phi_src_safe.

Reviewed-by: Eduardo Lima Mitev <elima@igalia.com>
15 files changed:
src/compiler/nir/nir.c
src/compiler/nir/nir.h
src/compiler/nir/nir_control_flow.c
src/compiler/nir/nir_from_ssa.c
src/compiler/nir/nir_instr_set.c
src/compiler/nir/nir_liveness.c
src/compiler/nir/nir_lower_phis_to_scalar.c
src/compiler/nir/nir_opt_dead_cf.c
src/compiler/nir/nir_opt_gcm.c
src/compiler/nir/nir_opt_peephole_select.c
src/compiler/nir/nir_opt_remove_phis.c
src/compiler/nir/nir_print.c
src/compiler/nir/nir_to_ssa.c
src/compiler/nir/nir_validate.c
src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c

index 37a15cf5bc5bdbbb175fc0739c40a95fbf640c0b..238f5257602ff23b2f8b392abe7cfc84ef6b94d4 100644 (file)
@@ -1162,7 +1162,7 @@ visit_load_const_src(nir_load_const_instr *instr, nir_foreach_src_cb cb,
 static bool
 visit_phi_src(nir_phi_instr *instr, nir_foreach_src_cb cb, void *state)
 {
-   nir_foreach_phi_src(instr, src) {
+   nir_foreach_phi_src(src, instr) {
       if (!visit_src(&src->src, cb, state))
          return false;
    }
index 604eb4e11fef2345b4ad8963beae624b91e106c5..e2585c65bfb228449fd89862d0d3e8ac82ceba44 100644 (file)
@@ -1304,10 +1304,10 @@ typedef struct {
    nir_src src;
 } nir_phi_src;
 
-#define nir_foreach_phi_src(phi, entry) \
-   foreach_list_typed(nir_phi_src, entry, node, &(phi)->srcs)
-#define nir_foreach_phi_src_safe(phi, entry) \
-   foreach_list_typed_safe(nir_phi_src, entry, node, &(phi)->srcs)
+#define nir_foreach_phi_src(phi_src, phi) \
+   foreach_list_typed(nir_phi_src, phi_src, node, &(phi)->srcs)
+#define nir_foreach_phi_src_safe(phi_src, phi) \
+   foreach_list_typed_safe(nir_phi_src, phi_src, node, &(phi)->srcs)
 
 typedef struct {
    nir_instr instr;
index 64d9a86cde79c30988c1ae988bedd25914f309aa..a485e713fa4b37250acca9037a5f2e463b839525 100644 (file)
@@ -261,7 +261,7 @@ rewrite_phi_preds(nir_block *block, nir_block *old_pred, nir_block *new_pred)
          break;
 
       nir_phi_instr *phi = nir_instr_as_phi(instr);
-      nir_foreach_phi_src(phi, src) {
+      nir_foreach_phi_src(src, phi) {
          if (src->pred == old_pred) {
             src->pred = new_pred;
             break;
@@ -542,7 +542,7 @@ remove_phi_src(nir_block *block, nir_block *pred)
          break;
 
       nir_phi_instr *phi = nir_instr_as_phi(instr);
-      nir_foreach_phi_src_safe(phi, src) {
+      nir_foreach_phi_src_safe(src, phi) {
          if (src->pred == pred) {
             list_del(&src->src.use_link);
             exec_node_remove(&src->node);
index 947ebe1ccb74060ca8fc2a0030b431f510f289ce..d333752b3715f3e9fb4602ecebddd9725f8bb2b8 100644 (file)
@@ -331,7 +331,7 @@ isolate_phi_nodes_block(nir_block *block, void *dead_ctx)
 
       nir_phi_instr *phi = nir_instr_as_phi(instr);
       assert(phi->dest.is_ssa);
-      nir_foreach_phi_src(phi, src) {
+      nir_foreach_phi_src(src, phi) {
          nir_parallel_copy_instr *pcopy =
             get_parallel_copy_at_end_of_block(src->pred);
          assert(pcopy);
@@ -380,7 +380,7 @@ coalesce_phi_nodes_block(nir_block *block, struct from_ssa_state *state)
       assert(phi->dest.is_ssa);
       merge_node *dest_node = get_merge_node(&phi->dest.ssa, state);
 
-      nir_foreach_phi_src(phi, src) {
+      nir_foreach_phi_src(src, phi) {
          assert(src->src.is_ssa);
          merge_node *src_node = get_merge_node(src->src.ssa, state);
          if (src_node->set != dest_node->set)
index c616143351611c508978a2b1883d49d22414a4cf..fe312a048bdb8b6a8d061158d0e77fb6bb0a2e7e 100644 (file)
@@ -106,7 +106,7 @@ hash_phi(uint32_t hash, const nir_phi_instr *instr)
    unsigned num_preds = instr->instr.block->predecessors->entries;
    NIR_VLA(nir_phi_src *, srcs, num_preds);
    unsigned i = 0;
-   nir_foreach_phi_src(instr, src) {
+   nir_foreach_phi_src(src, instr) {
       srcs[i++] = src;
    }
 
@@ -343,8 +343,8 @@ nir_instrs_equal(const nir_instr *instr1, const nir_instr *instr2)
       if (phi1->instr.block != phi2->instr.block)
          return false;
 
-      nir_foreach_phi_src(phi1, src1) {
-         nir_foreach_phi_src(phi2, src2) {
+      nir_foreach_phi_src(src1, phi1) {
+         nir_foreach_phi_src(src2, phi2) {
             if (src1->pred == src2->pred) {
                if (!nir_srcs_equal(src1->src, src2->src))
                   return false;
index 69c6fd93b5857663291c4a21259bd81b167eb760..1fcb01d5ef63abb6c03c6ee7916f7a8cba6cf683 100644 (file)
@@ -138,7 +138,7 @@ propagate_across_edge(nir_block *pred, nir_block *succ,
          break;
       nir_phi_instr *phi = nir_instr_as_phi(instr);
 
-      nir_foreach_phi_src(phi, src) {
+      nir_foreach_phi_src(src, phi) {
          if (src->pred == pred) {
             set_src_live(&src->src, live);
             break;
index a1a679bfcc2f07f74de2d5cad01312f73914a286..0e27e6dd7f4b0a96e7faeb62fac8900799b77858 100644 (file)
@@ -146,7 +146,7 @@ should_lower_phi(nir_phi_instr *phi, struct lower_phis_to_scalar_state *state)
 
    bool scalarizable = true;
 
-   nir_foreach_phi_src(phi, src) {
+   nir_foreach_phi_src(src, phi) {
       scalarizable = is_phi_src_scalarizable(src, state);
       if (!scalarizable)
          break;
@@ -214,7 +214,7 @@ lower_phis_to_scalar_block(nir_block *block,
 
          vec->src[i].src = nir_src_for_ssa(&new_phi->dest.ssa);
 
-         nir_foreach_phi_src(phi, src) {
+         nir_foreach_phi_src(src, phi) {
             /* We need to insert a mov to grab the i'th component of src */
             nir_alu_instr *mov = nir_alu_instr_create(state->mem_ctx,
                                                       nir_op_imov);
index ca73e50061b8fc9b477a58e9502613e5a7499eeb..4b62e55d030b7aa5ad13e7788b9c690c17947548 100644 (file)
@@ -97,7 +97,7 @@ opt_constant_if(nir_if *if_stmt, bool condition)
 
       nir_phi_instr *phi = nir_instr_as_phi(instr);
       nir_ssa_def *def = NULL;
-      nir_foreach_phi_src(phi, phi_src) {
+      nir_foreach_phi_src(phi_src, phi) {
          if (phi_src->pred != last_block)
             continue;
 
index d79235d171970f448e4d05d5f4408b34bebe2374..a87a0067230da12aee5bf1f7703eabe291104f99 100644 (file)
@@ -292,7 +292,7 @@ gcm_schedule_late_def(nir_ssa_def *def, void *void_state)
       if (use_instr->type == nir_instr_type_phi) {
          nir_phi_instr *phi = nir_instr_as_phi(use_instr);
 
-         nir_foreach_phi_src(phi, phi_src) {
+         nir_foreach_phi_src(phi_src, phi) {
             if (phi_src->src.ssa == def)
                lca = nir_dominance_lca(lca, phi_src->pred);
          }
index b31cc35ba71f04303525ba7c2ff11e9df6abdcb3..4d2b74dc7ffa5c219c42a629d19af38059721056 100644 (file)
@@ -194,7 +194,7 @@ nir_opt_peephole_select_block(nir_block *block, void *mem_ctx)
       memset(sel->src[0].swizzle, 0, sizeof sel->src[0].swizzle);
 
       assert(exec_list_length(&phi->srcs) == 2);
-      nir_foreach_phi_src(phi, src) {
+      nir_foreach_phi_src(src, phi) {
          assert(src->pred == then_block || src->pred == else_block);
          assert(src->src.is_ssa);
 
index 5234c0f667ad9154be5451e561c3bb6e7a1b2176..5d015c243de1040d159a91e40c54e8e3860f3da3 100644 (file)
@@ -56,7 +56,7 @@ remove_phis_block(nir_block *block)
       nir_ssa_def *def = NULL;
       bool srcs_same = true;
 
-      nir_foreach_phi_src(phi, src) {
+      nir_foreach_phi_src(src, phi) {
          assert(src->src.is_ssa);
 
          /* For phi nodes at the beginning of loops, we may encounter some
index 76effa99e8c56ffa0339d77fb5b88f5e5c48741a..e504d88484ee92c3ad06c39304f69a028aaeede5 100644 (file)
@@ -793,7 +793,7 @@ print_phi_instr(nir_phi_instr *instr, print_state *state)
    FILE *fp = state->fp;
    print_dest(&instr->dest, state);
    fprintf(fp, " = phi ");
-   nir_foreach_phi_src(instr, src) {
+   nir_foreach_phi_src(src, instr) {
       if (&src->node != exec_list_get_head(&instr->srcs))
          fprintf(fp, ", ");
 
index 766849192ffe0b6374c5c4159c88404febfa0e2b..7dc283d045b3d23985848bfa2fae6ef99e93d7d2 100644 (file)
@@ -389,7 +389,7 @@ rewrite_phi_sources(nir_block *block, nir_block *pred, rewrite_state *state)
 
       state->parent_instr = instr;
 
-      nir_foreach_phi_src(phi_instr, src) {
+      nir_foreach_phi_src(src, phi_instr) {
          if (src->pred == pred) {
             rewrite_use(&src->src, state);
             break;
index 10a78323550969e84e86501785c2fa03111a0efd..e928c41607be4fdd7ce8daeb9b776b423d03fea8 100644 (file)
@@ -588,7 +588,7 @@ validate_phi_src(nir_phi_instr *instr, nir_block *pred, validate_state *state)
    assert(instr->dest.is_ssa);
 
    exec_list_validate(&instr->srcs);
-   nir_foreach_phi_src(instr, src) {
+   nir_foreach_phi_src(src, instr) {
       if (src->pred == pred) {
          assert(src->src.is_ssa);
          assert(src->src.ssa->num_components ==
index 395b59b667ceb7eb579a000cfa7b695443c29785..f8a1a57d0facf6c80af8ab195a67df9531f7e73c 100644 (file)
@@ -281,7 +281,7 @@ lower_if_else_block(nir_block *block, void *void_state)
                memset(sel->src[0].swizzle, 0, sizeof sel->src[0].swizzle);
 
                assert(exec_list_length(&phi->srcs) == 2);
-               nir_foreach_phi_src(phi, src) {
+               nir_foreach_phi_src(src, phi) {
                        assert(src->pred == then_block || src->pred == else_block);
                        assert(src->src.is_ssa);