<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 6, 2015 at 5:38 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"><div class="HOEnZb"><div class="h5">On Fri, Feb 6, 2015 at 5:12 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> This is mostly thanks to Connor.  The idea is to do a depth-first search<br>
> that computes pre and post indices for all the blocks.  We can then figure<br>
> out if one block dominates another in constant time by two simple<br>
> comparison operations.<br>
> ---<br>
>  src/glsl/nir/nir.h           |  9 +++++++++<br>
>  src/glsl/nir/nir_dominance.c | 27 +++++++++++++++++++++++++++<br>
>  2 files changed, 36 insertions(+)<br>
><br>
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h<br>
> index 886dcd2..5d84343 100644<br>
> --- a/src/glsl/nir/nir.h<br>
> +++ b/src/glsl/nir/nir.h<br>
> @@ -1135,6 +1135,14 @@ typedef struct nir_block {<br>
>     /* Set of nir_block's on the dominance frontier of this block */<br>
>     struct set *dom_frontier;<br>
><br>
> +   /*<br>
> +    * These two indices have the property that dom_{pre,post}_index for each<br>
> +    * child of this block in the dominance tree will always be between<br>
> +    * dom_pre_index and dom_post_index for this block, which makes testing if<br>
> +    * a given block is dominated by another block an O(1) operation.<br>
> +    */<br>
> +   unsigned dom_pre_index, dom_post_index;<br>
> +<br>
>     /* live in and out for this block; used for liveness analysis */<br>
>     BITSET_WORD *live_in;<br>
>     BITSET_WORD *live_out;<br>
> @@ -1501,6 +1509,7 @@ void nir_calc_dominance_impl(nir_function_impl *impl);<br>
>  void nir_calc_dominance(nir_shader *shader);<br>
><br>
>  nir_block *nir_dominance_lca(nir_block *b1, nir_block *b2);<br>
> +bool nir_block_dominates(nir_block *parent, nir_block *child);<br>
><br>
>  void nir_dump_dom_tree_impl(nir_function_impl *impl, FILE *fp);<br>
>  void nir_dump_dom_tree(nir_shader *shader, FILE *fp);<br>
> diff --git a/src/glsl/nir/nir_dominance.c b/src/glsl/nir/nir_dominance.c<br>
> index 1022692..76508f5 100644<br>
> --- a/src/glsl/nir/nir_dominance.c<br>
> +++ b/src/glsl/nir/nir_dominance.c<br>
> @@ -177,6 +177,17 @@ calc_dom_children(nir_function_impl* impl)<br>
>     nir_foreach_block(impl, block_add_child, NULL);<br>
>  }<br>
><br>
> +static void<br>
> +calc_dfs_indicies(nir_block *block, unsigned *index)<br>
> +{<br>
> +   block->dom_pre_index = (*index)++;<br>
> +<br>
> +   for (unsigned i = 0; i < block->num_dom_children; i++)<br>
> +      calc_dfs_indicies(block->dom_children[i], index);<br>
> +<br>
> +   block->dom_post_index = (*index)++;<br>
> +}<br>
> +<br>
>  void<br>
>  nir_calc_dominance_impl(nir_function_impl *impl)<br>
>  {<br>
> @@ -201,6 +212,9 @@ nir_calc_dominance_impl(nir_function_impl *impl)<br>
>     impl->start_block->imm_dom = NULL;<br>
><br>
>     calc_dom_children(impl);<br>
> +<br>
> +   unsigned dfs_index = 0;<br>
> +   calc_dfs_indicies(impl->start_block, &dfs_index);<br>
>  }<br>
><br>
>  void<br>
> @@ -224,6 +238,19 @@ nir_dominance_lca(nir_block *b1, nir_block *b2)<br>
>     return intersect(b1, b2);<br>
>  }<br>
><br>
> +bool<br>
> +nir_block_dominates(nir_block *parent, nir_block *child)<br>
> +{<br>
> +   assert(nir_cf_node_get_function(&parent->cf_node) ==<br>
> +          nir_cf_node_get_function(&child->cf_node));<br>
> +<br>
> +   assert(nir_cf_node_get_function(&parent->cf_node)->valid_metadata &<br>
> +          nir_metadata_dominance);<br>
> +<br>
> +   return child->dom_pre_index >= parent->dom_pre_index &&<br>
> +          child->dom_pre_index <= parent->dom_post_index;<br>
<br>
</div></div>It doesn't matter too much, but I think doing child->dom_post_index <=<br>
parent->dom_post_index will make it less likely for people to think<br>
it's a bug (I did at first). Other than that,<br></blockquote><div><br></div><div>I copied and pasted it from you. :-P  Sure, I'll fix it up.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Reviewed-by: Connor Abbott <<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>><br>
<span class=""><br>
> +}<br>
> +<br>
>  static bool<br>
>  dump_block_dom(nir_block *block, void *state)<br>
>  {<br>
> --<br>
> 2.2.2<br>
><br>
</span>> _______________________________________________<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>