<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 24, 2017 at 6:05 AM, Samuel Iglesias Gonsálvez <span dir="ltr"><<a href="mailto:siglesias@igalia.com" target="_blank">siglesias@igalia.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"><br>
<br>
On 24/02/17 02:14, Jason Ekstrand wrote:<br>
> Each of the pop functions (and push_else) take a control flow parameter as<br>
> their second argument.  If NULL, it assumes that the builder is in a block<br>
> that's a direct child of the control-flow node you want to pop off the<br>
> virtual stack.  This is what 90% of consumers will want.  The SPIR-V pass,<br>
> however, is a bit more "creative" about how it walks the CFG and it needs<br>
> to be able to pop multiple levels at a time, hence the argument.<br>
> ---<br>
>  src/compiler/nir/nir_builder.h | 95 ++++++++++++++++++++++++++++++<wbr>++++++++++++<br>
>  1 file changed, 95 insertions(+)<br>
><br>
> diff --git a/src/compiler/nir/nir_<wbr>builder.h b/src/compiler/nir/nir_<wbr>builder.h<br>
> index 194d327..2eaa025 100644<br>
> --- a/src/compiler/nir/nir_<wbr>builder.h<br>
> +++ b/src/compiler/nir/nir_<wbr>builder.h<br>
> @@ -81,6 +81,101 @@ nir_builder_cf_insert(nir_<wbr>builder *build, nir_cf_node *cf)<br>
>     nir_cf_node_insert(build-><wbr>cursor, cf);<br>
>  }<br>
><br>
> +static inline bool<br>
> +nir_builder_is_inside_cf(nir_<wbr>builder *build, nir_cf_node *cf_node)<br>
> +{<br>
> +   nir_block *block = nir_cursor_current_block(<wbr>build->cursor);<br>
> +   for (nir_cf_node *n = &block->cf_node; n; n = n->parent) {<br>
> +      if (n == cf_node)<br>
> +         return true;<br>
> +   }<br>
> +   return false;<br>
> +}<br>
> +<br>
> +static inline nir_if *<br>
> +nir_push_if(nir_builder *build, nir_ssa_def *condition)<br>
> +{<br>
> +   nir_if *nif = nir_if_create(build->shader);<br>
> +   nif->condition = nir_src_for_ssa(condition);<br>
> +   nir_builder_cf_insert(build, &nif->cf_node);<br>
> +   build->cursor = nir_before_cf_list(&nif->then_<wbr>list);<br>
<br>
</div></div>Is this fine? In the places you replace code with this function, there<br>
was nir_after_cf_list(&nif->then_<wbr>list), and same for the others.<br></blockquote><div><br></div><div>it should be.  The if statement is empty so then_list has exactly one block with zero instructions in it.  Inserting before or after the list should be equivalent.  That said, I'm happy to change it to after if that makes more sense to someone.<br></div></div></div></div>