[Mesa-dev] [PATCH 1/8] nir/builder: Add support for easily building control-flow

Jason Ekstrand jason at jlekstrand.net
Fri Feb 24 20:54:57 UTC 2017


On Fri, Feb 24, 2017 at 6:05 AM, Samuel Iglesias Gonsálvez <
siglesias at igalia.com> wrote:

>
>
> On 24/02/17 02:14, Jason Ekstrand wrote:
> > Each of the pop functions (and push_else) take a control flow parameter
> as
> > their second argument.  If NULL, it assumes that the builder is in a
> block
> > that's a direct child of the control-flow node you want to pop off the
> > virtual stack.  This is what 90% of consumers will want.  The SPIR-V
> pass,
> > however, is a bit more "creative" about how it walks the CFG and it needs
> > to be able to pop multiple levels at a time, hence the argument.
> > ---
> >  src/compiler/nir/nir_builder.h | 95 ++++++++++++++++++++++++++++++
> ++++++++++++
> >  1 file changed, 95 insertions(+)
> >
> > diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_
> builder.h
> > index 194d327..2eaa025 100644
> > --- a/src/compiler/nir/nir_builder.h
> > +++ b/src/compiler/nir/nir_builder.h
> > @@ -81,6 +81,101 @@ nir_builder_cf_insert(nir_builder *build,
> nir_cf_node *cf)
> >     nir_cf_node_insert(build->cursor, cf);
> >  }
> >
> > +static inline bool
> > +nir_builder_is_inside_cf(nir_builder *build, nir_cf_node *cf_node)
> > +{
> > +   nir_block *block = nir_cursor_current_block(build->cursor);
> > +   for (nir_cf_node *n = &block->cf_node; n; n = n->parent) {
> > +      if (n == cf_node)
> > +         return true;
> > +   }
> > +   return false;
> > +}
> > +
> > +static inline nir_if *
> > +nir_push_if(nir_builder *build, nir_ssa_def *condition)
> > +{
> > +   nir_if *nif = nir_if_create(build->shader);
> > +   nif->condition = nir_src_for_ssa(condition);
> > +   nir_builder_cf_insert(build, &nif->cf_node);
> > +   build->cursor = nir_before_cf_list(&nif->then_list);
>
> Is this fine? In the places you replace code with this function, there
> was nir_after_cf_list(&nif->then_list), and same for the others.
>

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170224/42e39c66/attachment.html>


More information about the mesa-dev mailing list