<div dir="ltr"><div><div><div><div>Status update:<br><br></div>I've rebased on master, applied my own review comments and couple of bugs and pushed it here:<br><br><a href="https://cgit.freedesktop.org/~jekstrand/mesa/log/?h=wip/nir-foreach-block-v3" target="_blank">https://cgit.freedesktop.org/~jekstrand/mesa/log/?h=wip/nir-foreach-block-v3</a><br><br></div><div>Changes over what Connor sent:<br></div><div> 1) Minor cosmetic changes to the iteration helper functions<br></div><div> 2) Fixed a bug in the nir_cf_node_cf_tree_last where it would grab the first node in a loop instead of the last<br></div><div> 3) Reversed the parameters to nir_foreach_block to use the x in Y convention common to Java and other languages.<br></div><div> 4) Fixed a bug in inline_functions where it needed to use foreach_block_safe but wasn't<br></div><div> 5) Added patches to update the three passes in the Vulkan driver to use the new functions<br></div><div><br></div>I kicked it off to the CI system and it passes the Vulkan CTS 100%.  I'm still waiting back for the GL CTS/dEQP/piglit results but I expect them to be green as well.<br><br></div>I haven't had a chance to go through all of the little refactor patches.  I'm going to try and do that today.  That said, I think it would be good to get one more set of eyes on so if one other person would be willing to at least skim it that would make me feel more comfortable.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 12, 2016 at 9:34 PM, Connor Abbott <span dir="ltr"><<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is a series based on an idea I had a while ago. It gets one<br>
instance of an awful callback-based interface for iterating over things.<br>
The other instance, nir_foreach_source(), would be harder to fix since<br>
iterating over the sources actually needs state (in order to handle<br>
indirect sources). Now, instead of doing:<br>
<br>
struct my_small_state {<br>
   nir_builder b;<br>
   bool progress;<br>
};<br>
<br>
...<br>
<br>
bool my_trivial_function(nir_block *b, void *void_state)<br>
{<br>
   struct my_small_state *state = void_state;<br>
   ...<br>
}<br>
<br>
...<br>
<br>
struct my_small_state state;<br>
nir_builder_init(&state.b, impl);<br>
state.progress = false;<br>
<br>
nir_foreach_block(impl, my_trivial_function, &state);<br>
<br>
you can just do:<br>
<br>
bool progress = false;<br>
nir_builder b;<br>
nir_builder_init(&b, impl);<br>
<br>
nir_foreach_block(impl, block) {<br>
   ...<br>
}<br>
<br>
It's a lot of churn, but it results in a much nicer API, as you can see<br>
from the diffstat: almost 200 lines of code are deleted, despite the<br>
impl of the new nir_foreach_block() taking more code. I took the liberty<br>
of refactoring the code I touched to take advantage of the newer API, in<br>
order to see just how much nicer we can make things. When the callback<br>
function was just a simple walk across instructions, I inlined it, and<br>
most of the time the little state structures passed around became<br>
unnecessary given that we're now free to pass whatever parameters we<br>
want. Someone might want to bikeshed some of my choices, though.<br>
<br>
Right now, it's split into a number of patches to help<br>
reviewability/rebasability, but obviously the entire thing needs to be<br>
squashed before pushing. The patches aren't in any particular order,<br>
since none of them are really related to each other, and the order will<br>
be lost when squashing anyways. Nobody should hold off pushing other<br>
things until this is done, but I'd like to get it in as soon as possible<br>
to avoid rebase hell.<br>
<br>
Piglit tested on i965, but only compile tested on vc4 and freedreno.<br>
<br>
Finally, the series is also available at:<br>
<br>
git://<a href="http://people.freedesktop.org/~cwabbott0/mesa" rel="noreferrer" target="_blank">people.freedesktop.org/~cwabbott0/mesa</a> nir-foreach-block-rewrite<br>
<br>
Connor Abbott (47):<br>
  nir: rewrite nir_foreach_block and friends<br>
  nir/dominance: update to new foreach_block<br>
  nir/from_ssa: fixup for new foreach_block()<br>
  nir/inline_functions: fixup for new foreach_block()<br>
  nir/liveness: adapt to new foreach_block()<br>
  nir/lower_alu_to_scalar: fixup for new foreach_block()<br>
  nir/lower_clip: fixup for new foreach_block()<br>
  nir/nir: fixup for new foreach_block()<br>
  nir/lower_gs_intrinsics: fixup for new foreach_block()<br>
  nir/lower_locals_to_regs: fixup for new foreach_block<br>
  nir/lower_load_const: fixup for new foreach_block()<br>
  nir/lower_atomics: fixup for new foreach_block(<br>
  nir/nir_lower_global_vars: fixup for new foreach_block()<br>
  nir/lower_indirect_derefs: fixup for new foreach_block()<br>
  nir/lower_phis_to_scalar: fixup for new foreach_block()<br>
  nir/lower_system_values: fixup for new foreach_block()<br>
  nir/lower_io: adapt to new foreach_block()<br>
  nir/lower_to_source_mods: fixup for new foreeach_block()<br>
  nir/lower_outputs_to_temporaries: fixup for new foreach_block()<br>
  nir/lower_tex: fixup for new foreach_block()<br>
  nir/lower_idiv: fixup for new foreach_block()<br>
  nir/lower_vec_to_movs: fixup for new foreach_block()<br>
  nir/lower_vars_to_ssa: fixup for new foreach_block()<br>
  nir/move_vec_src_uses_to_dest: fixup for new foreach_block()<br>
  nir/lower_two_sided_color: fixup for new foreach_block()<br>
  nir/lower_var_copies: fixup for new foreach_block()<br>
  nir/normalize_cubemap_coords: fixup for new foreach_block()<br>
  nir/lower_samplers: fixup for new foreach_block()<br>
  nir/opt_constant_folding: fixup for new foreach_block()<br>
  nir/opt_gcm: fixup for new foreach_block()<br>
  nir/opt_dce: fixup for new foreach_block()<br>
  nir/opt_dead_cf: fixup for new foreach_block()<br>
  nir/opt_undef: fixup for new foreach_block()<br>
  nir/opt_remove_phis: fixup for new foreach_block()<br>
  nir/opt_cp: use nir_block_get_following_if()<br>
  nir/opt_cp: fixup for new foreach_block()<br>
  nir/phi_builder: fixup for new foreach_block()<br>
  nir/opt_peephole_select: fixup for new foreach_block()<br>
  nir/repair_ssa: fixup for new foreach_block()<br>
  nir/split_var_copies: fixup for new foreach_block()<br>
  nir/remove_dead_variables: fixup for new foreach_block()<br>
  nir/nir_worklist: fixup for new foreach_block()<br>
  nir/validate: fixup for new foreach_block()<br>
  nir/algebraic: fixup for new foreach_block()<br>
  i965/nir: fixup for new foreach_block()<br>
  ir3: fixup for new nir_foreach_block()<br>
  vc4: fixup for new nir_foreach_block()<br>
<br>
 src/compiler/nir/nir.c                             | 228 +++++++++++----------<br>
 src/compiler/nir/nir.h                             |  57 +++++-<br>
 src/compiler/nir/nir_algebraic.py                  |  34 ++-<br>
 src/compiler/nir/nir_dominance.c                   | 160 ++++++---------<br>
 src/compiler/nir/nir_from_ssa.c                    |  57 +++---<br>
 src/compiler/nir/nir_inline_functions.c            |  53 +++--<br>
 src/compiler/nir/nir_liveness.c                    |  24 +--<br>
 src/compiler/nir/nir_lower_alu_to_scalar.c         |  18 +-<br>
 src/compiler/nir/nir_lower_atomics.c               |  36 +---<br>
 src/compiler/nir/nir_lower_clip.c                  |  50 ++---<br>
 src/compiler/nir/nir_lower_global_vars_to_local.c  |  38 ++--<br>
 src/compiler/nir/nir_lower_gs_intrinsics.c         |   8 +-<br>
 src/compiler/nir/nir_lower_idiv.c                  |  21 +-<br>
 src/compiler/nir/nir_lower_indirect_derefs.c       |  39 ++--<br>
 src/compiler/nir/nir_lower_io.c                    |   9 +-<br>
 src/compiler/nir/nir_lower_load_const_to_scalar.c  |  18 +-<br>
 src/compiler/nir/nir_lower_locals_to_regs.c        |   9 +-<br>
 .../nir/nir_lower_outputs_to_temporaries.c         |  28 ++-<br>
 src/compiler/nir/nir_lower_phis_to_scalar.c        |   9 +-<br>
 src/compiler/nir/nir_lower_samplers.c              |  40 +---<br>
 src/compiler/nir/nir_lower_system_values.c         |  27 +--<br>
 src/compiler/nir/nir_lower_tex.c                   |  58 +++---<br>
 src/compiler/nir/nir_lower_to_source_mods.c        |  15 +-<br>
 src/compiler/nir/nir_lower_two_sided_color.c       |   8 +-<br>
 src/compiler/nir/nir_lower_var_copies.c            |  34 ++-<br>
 src/compiler/nir/nir_lower_vars_to_ssa.c           |  14 +-<br>
 src/compiler/nir/nir_lower_vec_to_movs.c           |  24 +--<br>
 src/compiler/nir/nir_move_vec_src_uses_to_dest.c   |   7 +-<br>
 src/compiler/nir/nir_normalize_cubemap_coords.c    |  26 +--<br>
 src/compiler/nir/nir_opt_constant_folding.c        |  29 ++-<br>
 src/compiler/nir/nir_opt_copy_propagate.c          |  32 +--<br>
 src/compiler/nir/nir_opt_dce.c                     |  33 ++-<br>
 src/compiler/nir/nir_opt_dead_cf.c                 |  43 ++--<br>
 src/compiler/nir/nir_opt_gcm.c                     |   9 +-<br>
 src/compiler/nir/nir_opt_peephole_select.c         |  37 ++--<br>
 src/compiler/nir/nir_opt_remove_phis.c             |  12 +-<br>
 src/compiler/nir/nir_opt_undef.c                   |  23 +--<br>
 src/compiler/nir/nir_phi_builder.c                 |  12 +-<br>
 src/compiler/nir/nir_remove_dead_variables.c       |  48 ++---<br>
 src/compiler/nir/nir_repair_ssa.c                  |  16 +-<br>
 src/compiler/nir/nir_split_var_copies.c            |   8 +-<br>
 src/compiler/nir/nir_validate.c                    |  14 +-<br>
 src/compiler/nir/nir_worklist.c                    |  12 +-<br>
 .../drivers/freedreno/ir3/ir3_nir_lower_if_else.c  |  51 ++---<br>
 src/gallium/drivers/vc4/vc4_nir_lower_blend.c      |   9 +-<br>
 src/gallium/drivers/vc4/vc4_nir_lower_io.c         |  20 +-<br>
 src/gallium/drivers/vc4/vc4_nir_lower_txf_ms.c     |  24 +--<br>
 src/gallium/drivers/vc4/vc4_program.c              |  15 +-<br>
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp           |   7 +-<br>
 src/mesa/drivers/dri/i965/brw_nir.c                |  90 ++++----<br>
 .../dri/i965/brw_nir_analyze_boolean_resolves.c    |   6 +-<br>
 .../dri/i965/brw_nir_attribute_workarounds.c       |   7 +-<br>
 .../drivers/dri/i965/brw_nir_opt_peephole_ffma.c   |  29 ++-<br>
 src/mesa/drivers/dri/i965/brw_vec4_nir.cpp         |   8 +-<br>
 54 files changed, 776 insertions(+), 967 deletions(-)<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.5.0<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>