<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 28, 2016 at 12:10 AM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 04/27/2016 07:39 PM, Jason Ekstrand wrote:<br>
> On Wed, Apr 27, 2016 at 12:54 AM, Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a><br>
</span><div><div class="h5">> <mailto:<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>>> wrote:<br>
><br>
> On 04/27/2016 05:41 AM, Jason Ekstrand wrote:<br>
> > This matches the "foreach x in container" pattern found in many other<br>
> > programming languages. Generated by the following regular expression:<br>
> ><br>
> ><br>
> s/nir_foreach_phi_src(\([^,]*\),\s*\([^,]*\))/nir_foreach_phi_src(\2, \1)/<br>
> ><br>
> > and a similar expression for nir_foreach_phi_src_safe.<br>
> > ---<br>
> > src/compiler/nir/nir.c | 2 +-<br>
> > src/compiler/nir/nir.h | 8<br>
> ++++----<br>
> > src/compiler/nir/nir_control_flow.c | 4 ++--<br>
> > src/compiler/nir/nir_from_ssa.c | 4 ++--<br>
> > src/compiler/nir/nir_instr_set.c | 6 +++---<br>
> > src/compiler/nir/nir_liveness.c | 2 +-<br>
> > src/compiler/nir/nir_lower_phis_to_scalar.c | 4 ++--<br>
> > src/compiler/nir/nir_opt_dead_cf.c | 2 +-<br>
> > src/compiler/nir/nir_opt_gcm.c | 2 +-<br>
> > src/compiler/nir/nir_opt_peephole_select.c | 2 +-<br>
> > src/compiler/nir/nir_opt_remove_phis.c | 2 +-<br>
> > src/compiler/nir/nir_print.c | 2 +-<br>
> > src/compiler/nir/nir_to_ssa.c | 2 +-<br>
> > src/compiler/nir/nir_validate.c | 2 +-<br>
> > src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c | 2 +-<br>
> > 15 files changed, 23 insertions(+), 23 deletions(-)<br>
> ><br>
> > diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c<br>
> > index 6c1b129..4c283ef 100644<br>
> > --- a/src/compiler/nir/nir.c<br>
> > +++ b/src/compiler/nir/nir.c<br>
> > @@ -1162,7 +1162,7 @@ visit_load_const_src(nir_load_const_instr<br>
> *instr, nir_foreach_src_cb cb,<br>
> > static bool<br>
> > visit_phi_src(nir_phi_instr *instr, nir_foreach_src_cb cb, void<br>
> *state)<br>
> > {<br>
> > - nir_foreach_phi_src(instr, src) {<br>
> > + nir_foreach_phi_src(src, instr) {<br>
> > if (!visit_src(&src->src, cb, state))<br>
> > return false;<br>
> > }<br>
> > diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
> > index 113073f..ee6abdd 100644<br>
> > --- a/src/compiler/nir/nir.h<br>
> > +++ b/src/compiler/nir/nir.h<br>
> > @@ -1304,10 +1304,10 @@ typedef struct {<br>
> > nir_src src;<br>
> > } nir_phi_src;<br>
> ><br>
> > -#define nir_foreach_phi_src(phi, entry) \<br>
> > - foreach_list_typed(nir_phi_src, entry, node, &(phi)->srcs)<br>
> > -#define nir_foreach_phi_src_safe(phi, entry) \<br>
> > - foreach_list_typed_safe(nir_phi_src, entry, node, &(phi)->srcs)<br>
><br>
> Should the macro be renamed nir_foreach_src_phi? That way the words in<br>
> the name match the order of the parameters. That also makes the name<br>
> (almost) short for "for each source in phi". Maybe<br>
> nir_foreach_src_in_phi? I think Matt previously nixed having "in" in<br>
> these macro names, so I don't want to reopen a previously closed can of<br>
> worms.<br>
><br>
><br>
> That's a good question and I'm glad you asked it. Short version: I<br>
> don't know. I'll give it some thought.<br>
><br>
> Slightly longer version: The current naming scheme for the foreach<br>
> macros is that nir_foreach_foo iterates over things of type nir_foo so<br>
> nir_foreach_variable is for nir_variable, nir_foreach_block is for<br>
> nir_block, and nir_foreach_phi_src is for nir_phi_src. The fact that<br>
> it's called nir_foreach_phi_src and walks over every source in a phi is<br>
> kind of an accident.<br>
<br>
</div></div>Ah. I didn't realize it was iterating a phi_src. I was just looking at<br>
the names of the parameters. Maybe changing the parameter names to<br>
(phi_src, phi) would make it more obvious to newbs.</blockquote><div><br></div><div>Consider it done.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> *shrug* Now that<br>
you've explained it, the macro name is fine with me as is.<br>
<div class="HOEnZb"><div class="h5"><br>
> On the other hand, you're absolutely write that it does look a lot like<br>
> "foreach src in phi" which would also be perfectly sensible. To be<br>
> honest, I've never thought about it that way; I've always read it as<br>
> "foreach phi_src" so this is a thought that has never occured to me.<br>
><br>
> I'll give it a bit more thought. I think I still have a very slight<br>
> leaning towards keeping it named the way it is but I'll think about it a<br>
> bit more. I could also be easily swayed by someone with a strong<br>
> opinion. ;-)<br>
><br>
><br>
> > +#define nir_foreach_phi_src(src, phi) \<br>
> > + foreach_list_typed(nir_phi_src, src, node, &(phi)->srcs)<br>
> > +#define nir_foreach_phi_src_safe(src, phi) \<br>
> > + foreach_list_typed_safe(nir_phi_src, src, node, &(phi)->srcs)<br>
> ><br>
> > typedef struct {<br>
> > nir_instr instr;<br>
> > diff --git a/src/compiler/nir/nir_control_flow.c<br>
> b/src/compiler/nir/nir_control_flow.c<br>
> > index 64d9a86..a485e71 100644<br>
> > --- a/src/compiler/nir/nir_control_flow.c<br>
> > +++ b/src/compiler/nir/nir_control_flow.c<br>
> > @@ -261,7 +261,7 @@ rewrite_phi_preds(nir_block *block, nir_block<br>
> *old_pred, nir_block *new_pred)<br>
> > break;<br>
> ><br>
> > nir_phi_instr *phi = nir_instr_as_phi(instr);<br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > if (src->pred == old_pred) {<br>
> > src->pred = new_pred;<br>
> > break;<br>
> > @@ -542,7 +542,7 @@ remove_phi_src(nir_block *block, nir_block *pred)<br>
> > break;<br>
> ><br>
> > nir_phi_instr *phi = nir_instr_as_phi(instr);<br>
> > - nir_foreach_phi_src_safe(phi, src) {<br>
> > + nir_foreach_phi_src_safe(src, phi) {<br>
> > if (src->pred == pred) {<br>
> > list_del(&src->src.use_link);<br>
> > exec_node_remove(&src->node);<br>
> > diff --git a/src/compiler/nir/nir_from_ssa.c<br>
> b/src/compiler/nir/nir_from_ssa.c<br>
> > index 947ebe1..d333752 100644<br>
> > --- a/src/compiler/nir/nir_from_ssa.c<br>
> > +++ b/src/compiler/nir/nir_from_ssa.c<br>
> > @@ -331,7 +331,7 @@ isolate_phi_nodes_block(nir_block *block, void<br>
> *dead_ctx)<br>
> ><br>
> > nir_phi_instr *phi = nir_instr_as_phi(instr);<br>
> > assert(phi->dest.is_ssa);<br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > nir_parallel_copy_instr *pcopy =<br>
> > get_parallel_copy_at_end_of_block(src->pred);<br>
> > assert(pcopy);<br>
> > @@ -380,7 +380,7 @@ coalesce_phi_nodes_block(nir_block *block,<br>
> struct from_ssa_state *state)<br>
> > assert(phi->dest.is_ssa);<br>
> > merge_node *dest_node = get_merge_node(&phi->dest.ssa, state);<br>
> ><br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > assert(src->src.is_ssa);<br>
> > merge_node *src_node = get_merge_node(src->src.ssa, state);<br>
> > if (src_node->set != dest_node->set)<br>
> > diff --git a/src/compiler/nir/nir_instr_set.c<br>
> b/src/compiler/nir/nir_instr_set.c<br>
> > index c616143..fe312a0 100644<br>
> > --- a/src/compiler/nir/nir_instr_set.c<br>
> > +++ b/src/compiler/nir/nir_instr_set.c<br>
> > @@ -106,7 +106,7 @@ hash_phi(uint32_t hash, const nir_phi_instr<br>
> *instr)<br>
> > unsigned num_preds = instr->instr.block->predecessors->entries;<br>
> > NIR_VLA(nir_phi_src *, srcs, num_preds);<br>
> > unsigned i = 0;<br>
> > - nir_foreach_phi_src(instr, src) {<br>
> > + nir_foreach_phi_src(src, instr) {<br>
> > srcs[i++] = src;<br>
> > }<br>
> ><br>
> > @@ -343,8 +343,8 @@ nir_instrs_equal(const nir_instr *instr1,<br>
> const nir_instr *instr2)<br>
> > if (phi1->instr.block != phi2->instr.block)<br>
> > return false;<br>
> ><br>
> > - nir_foreach_phi_src(phi1, src1) {<br>
> > - nir_foreach_phi_src(phi2, src2) {<br>
> > + nir_foreach_phi_src(src1, phi1) {<br>
> > + nir_foreach_phi_src(src2, phi2) {<br>
> > if (src1->pred == src2->pred) {<br>
> > if (!nir_srcs_equal(src1->src, src2->src))<br>
> > return false;<br>
> > diff --git a/src/compiler/nir/nir_liveness.c<br>
> b/src/compiler/nir/nir_liveness.c<br>
> > index 69c6fd9..1fcb01d 100644<br>
> > --- a/src/compiler/nir/nir_liveness.c<br>
> > +++ b/src/compiler/nir/nir_liveness.c<br>
> > @@ -138,7 +138,7 @@ propagate_across_edge(nir_block *pred,<br>
> nir_block *succ,<br>
> > break;<br>
> > nir_phi_instr *phi = nir_instr_as_phi(instr);<br>
> ><br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > if (src->pred == pred) {<br>
> > set_src_live(&src->src, live);<br>
> > break;<br>
> > diff --git a/src/compiler/nir/nir_lower_phis_to_scalar.c<br>
> b/src/compiler/nir/nir_lower_phis_to_scalar.c<br>
> > index a1a679b..0e27e6d 100644<br>
> > --- a/src/compiler/nir/nir_lower_phis_to_scalar.c<br>
> > +++ b/src/compiler/nir/nir_lower_phis_to_scalar.c<br>
> > @@ -146,7 +146,7 @@ should_lower_phi(nir_phi_instr *phi, struct<br>
> lower_phis_to_scalar_state *state)<br>
> ><br>
> > bool scalarizable = true;<br>
> ><br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > scalarizable = is_phi_src_scalarizable(src, state);<br>
> > if (!scalarizable)<br>
> > break;<br>
> > @@ -214,7 +214,7 @@ lower_phis_to_scalar_block(nir_block *block,<br>
> ><br>
> > vec->src[i].src = nir_src_for_ssa(&new_phi->dest.ssa);<br>
> ><br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > /* We need to insert a mov to grab the i'th component<br>
> of src */<br>
> > nir_alu_instr *mov = nir_alu_instr_create(state->mem_ctx,<br>
> > nir_op_imov);<br>
> > diff --git a/src/compiler/nir/nir_opt_dead_cf.c<br>
> b/src/compiler/nir/nir_opt_dead_cf.c<br>
> > index ca73e50..4b62e55 100644<br>
> > --- a/src/compiler/nir/nir_opt_dead_cf.c<br>
> > +++ b/src/compiler/nir/nir_opt_dead_cf.c<br>
> > @@ -97,7 +97,7 @@ opt_constant_if(nir_if *if_stmt, bool condition)<br>
> ><br>
> > nir_phi_instr *phi = nir_instr_as_phi(instr);<br>
> > nir_ssa_def *def = NULL;<br>
> > - nir_foreach_phi_src(phi, phi_src) {<br>
> > + nir_foreach_phi_src(phi_src, phi) {<br>
> > if (phi_src->pred != last_block)<br>
> > continue;<br>
> ><br>
> > diff --git a/src/compiler/nir/nir_opt_gcm.c<br>
> b/src/compiler/nir/nir_opt_gcm.c<br>
> > index d79235d..a87a006 100644<br>
> > --- a/src/compiler/nir/nir_opt_gcm.c<br>
> > +++ b/src/compiler/nir/nir_opt_gcm.c<br>
> > @@ -292,7 +292,7 @@ gcm_schedule_late_def(nir_ssa_def *def, void<br>
> *void_state)<br>
> > if (use_instr->type == nir_instr_type_phi) {<br>
> > nir_phi_instr *phi = nir_instr_as_phi(use_instr);<br>
> ><br>
> > - nir_foreach_phi_src(phi, phi_src) {<br>
> > + nir_foreach_phi_src(phi_src, phi) {<br>
> > if (phi_src->src.ssa == def)<br>
> > lca = nir_dominance_lca(lca, phi_src->pred);<br>
> > }<br>
> > diff --git a/src/compiler/nir/nir_opt_peephole_select.c<br>
> b/src/compiler/nir/nir_opt_peephole_select.c<br>
> > index b31cc35..4d2b74d 100644<br>
> > --- a/src/compiler/nir/nir_opt_peephole_select.c<br>
> > +++ b/src/compiler/nir/nir_opt_peephole_select.c<br>
> > @@ -194,7 +194,7 @@ nir_opt_peephole_select_block(nir_block<br>
> *block, void *mem_ctx)<br>
> > memset(sel->src[0].swizzle, 0, sizeof sel->src[0].swizzle);<br>
> ><br>
> > assert(exec_list_length(&phi->srcs) == 2);<br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > assert(src->pred == then_block || src->pred == else_block);<br>
> > assert(src->src.is_ssa);<br>
> ><br>
> > diff --git a/src/compiler/nir/nir_opt_remove_phis.c<br>
> b/src/compiler/nir/nir_opt_remove_phis.c<br>
> > index 5234c0f..5d015c2 100644<br>
> > --- a/src/compiler/nir/nir_opt_remove_phis.c<br>
> > +++ b/src/compiler/nir/nir_opt_remove_phis.c<br>
> > @@ -56,7 +56,7 @@ remove_phis_block(nir_block *block)<br>
> > nir_ssa_def *def = NULL;<br>
> > bool srcs_same = true;<br>
> ><br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > assert(src->src.is_ssa);<br>
> ><br>
> > /* For phi nodes at the beginning of loops, we may<br>
> encounter some<br>
> > diff --git a/src/compiler/nir/nir_print.c<br>
> b/src/compiler/nir/nir_print.c<br>
> > index 76effa9..e504d88 100644<br>
> > --- a/src/compiler/nir/nir_print.c<br>
> > +++ b/src/compiler/nir/nir_print.c<br>
> > @@ -793,7 +793,7 @@ print_phi_instr(nir_phi_instr *instr,<br>
> print_state *state)<br>
> > FILE *fp = state->fp;<br>
> > print_dest(&instr->dest, state);<br>
> > fprintf(fp, " = phi ");<br>
> > - nir_foreach_phi_src(instr, src) {<br>
> > + nir_foreach_phi_src(src, instr) {<br>
> > if (&src->node != exec_list_get_head(&instr->srcs))<br>
> > fprintf(fp, ", ");<br>
> ><br>
> > diff --git a/src/compiler/nir/nir_to_ssa.c<br>
> b/src/compiler/nir/nir_to_ssa.c<br>
> > index 7668491..7dc283d 100644<br>
> > --- a/src/compiler/nir/nir_to_ssa.c<br>
> > +++ b/src/compiler/nir/nir_to_ssa.c<br>
> > @@ -389,7 +389,7 @@ rewrite_phi_sources(nir_block *block,<br>
> nir_block *pred, rewrite_state *state)<br>
> ><br>
> > state->parent_instr = instr;<br>
> ><br>
> > - nir_foreach_phi_src(phi_instr, src) {<br>
> > + nir_foreach_phi_src(src, phi_instr) {<br>
> > if (src->pred == pred) {<br>
> > rewrite_use(&src->src, state);<br>
> > break;<br>
> > diff --git a/src/compiler/nir/nir_validate.c<br>
> b/src/compiler/nir/nir_validate.c<br>
> > index 10a7832..e928c41 100644<br>
> > --- a/src/compiler/nir/nir_validate.c<br>
> > +++ b/src/compiler/nir/nir_validate.c<br>
> > @@ -588,7 +588,7 @@ validate_phi_src(nir_phi_instr *instr,<br>
> nir_block *pred, validate_state *state)<br>
> > assert(instr->dest.is_ssa);<br>
> ><br>
> > exec_list_validate(&instr->srcs);<br>
> > - nir_foreach_phi_src(instr, src) {<br>
> > + nir_foreach_phi_src(src, instr) {<br>
> > if (src->pred == pred) {<br>
> > assert(src->src.is_ssa);<br>
> > assert(src->src.ssa->num_components ==<br>
> > diff --git<br>
> a/src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c<br>
> b/src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c<br>
> > index 09c93da..8bd70e2 100644<br>
> > --- a/src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c<br>
> > +++ b/src/gallium/drivers/freedreno/ir3/ir3_nir_lower_if_else.c<br>
> > @@ -273,7 +273,7 @@ lower_if_else_block(nir_block *block,<br>
> nir_builder *b, void *mem_ctx)<br>
> > memset(sel->src[0].swizzle, 0, sizeof<br>
> sel->src[0].swizzle);<br>
> ><br>
> > assert(exec_list_length(&phi->srcs) == 2);<br>
> > - nir_foreach_phi_src(phi, src) {<br>
> > + nir_foreach_phi_src(src, phi) {<br>
> > assert(src->pred == then_block || src->pred<br>
> == else_block);<br>
> > assert(src->src.is_ssa);<br>
> ><br>
> ><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>