<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 5, 2015 at 3:27 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">While we're cleaning this up, we should go a little farther - we<br>
should also see if anything is using the SSA result of any of these<br>
instructions, and if so make it point to an undef_instr instead to<br>
avoid dangling pointers. This doesn't come up yet but it will when we<br>
start cleaning up constant control flow.<br><div><div class="h5"></div></div></blockquote><div><br></div><div>I'm about to send a v2 and I'm leaving this out for now.  First, because that's a bit more invasive than I want to do/test right now and second, because I'm not convinced it's needed.  For control flow, what we really need to do is assert that there are no phi nodes.  As long as that and the dominance property both hold, we won't have any uses of deleted SSA values.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
On Thu, Feb 5, 2015 at 5:28 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> Previously, if you remved a CF node that still had instructions in it, none<br>
> of the use/def information from those instructions would get cleaned up.<br>
> Also, we weren't removing if statements from the if_uses of the<br>
> corresponding register or SSA def.  This commit fixes both of these<br>
> problems<br>
> ---<br>
>  src/glsl/nir/nir.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
>  1 file changed, 54 insertions(+)<br>
><br>
> diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c<br>
> index 9a88bd3..8ea7bb5 100644<br>
> --- a/src/glsl/nir/nir.c<br>
> +++ b/src/glsl/nir/nir.c<br>
> @@ -1148,6 +1148,58 @@ stitch_blocks(nir_block *before, nir_block *after)<br>
>     exec_node_remove(&after->cf_node.node);<br>
>  }<br>
><br>
> +static void<br>
> +remove_defs_uses(nir_instr *instr);<br>
> +<br>
> +static void<br>
> +cleanup_cf_node(nir_cf_node *node)<br>
> +{<br>
> +   switch (node->type) {<br>
> +   case nir_cf_node_block: {<br>
> +      nir_block *block = nir_cf_node_as_block(node);<br>
> +      /* We need to walk the instructions and clean up defs/uses */<br>
> +      nir_foreach_instr(block, instr)<br>
> +         remove_defs_uses(instr);<br>
> +      break;<br>
> +   }<br>
> +<br>
> +   case nir_cf_node_if: {<br>
> +      nir_if *if_stmt = nir_cf_node_as_if(node);<br>
> +      foreach_list_typed(nir_cf_node, child, node, &if_stmt->then_list)<br>
> +         cleanup_cf_node(child);<br>
> +      foreach_list_typed(nir_cf_node, child, node, &if_stmt->else_list)<br>
> +         cleanup_cf_node(child);<br>
> +<br>
> +      struct set *if_uses;<br>
> +      if (if_stmt->condition.is_ssa) {<br>
> +         if_uses = if_stmt->condition.ssa->if_uses;<br>
> +      } else {<br>
> +         if_uses = if_stmt->condition.reg.reg->if_uses;<br>
> +      }<br>
> +<br>
> +      struct set_entry *entry = _mesa_set_search(if_uses, if_stmt);<br>
> +      assert(entry);<br>
> +      _mesa_set_remove(if_uses, entry);<br>
> +      break;<br>
> +   }<br>
> +<br>
> +   case nir_cf_node_loop: {<br>
> +      nir_loop *loop = nir_cf_node_as_loop(node);<br>
> +      foreach_list_typed(nir_cf_node, child, node, &loop->body)<br>
> +         cleanup_cf_node(child);<br>
> +      break;<br>
> +   }<br>
> +   case nir_cf_node_function: {<br>
> +      nir_function_impl *impl = nir_cf_node_as_function(node);<br>
> +      foreach_list_typed(nir_cf_node, child, node, &impl->body)<br>
> +         cleanup_cf_node(child);<br>
> +      break;<br>
> +   }<br>
> +   default:<br>
> +      unreachable("Invalid CF node type");<br>
> +   }<br>
> +}<br>
> +<br>
>  void<br>
>  nir_cf_node_remove(nir_cf_node *node)<br>
>  {<br>
> @@ -1175,6 +1227,8 @@ nir_cf_node_remove(nir_cf_node *node)<br>
>        exec_node_remove(&node->node);<br>
>        stitch_blocks(before_block, after_block);<br>
>     }<br>
> +<br>
> +   cleanup_cf_node(node);<br>
>  }<br>
><br>
>  static bool<br>
> --<br>
> 2.2.2<br>
><br>
</div></div>> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div>