<div dir="ltr"><div>Pushed!<br><br></div>Tim, this is going to cause you a bit of rebase trouble on loop unrolling but it should actually make your code simpler.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 5, 2016 at 9:56 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><p dir="ltr">On Oct 5, 2016 21:42, "Connor Abbott" <<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>> wrote:<br>
><br>
> Thanks for doing this! This has always bugged me. For the series,</p>
</span><p dir="ltr">Yeah, nir_loop_last_cf_node and friends in particular have been bugging me for a loooong time.</p>
<p dir="ltr">> Reviewed-by: Connor Abbott <<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>></p>
<p dir="ltr">Thanks!</p><div class="HOEnZb"><div class="h5">
<p dir="ltr">> On Wed, Oct 5, 2016 at 11:37 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>> wrote:<br>
> > This makes calling nir_foo_as_bar a bit safer because we're no longer 100%<br>
> > trusting in the caller to ensure that it's safe.  The caller still needs to<br>
> > do the right thing but this ensures that we catch invalid casts with an<br>
> > assert rather than by reading garbage data.  The one downside is that we do<br>
> > use the casts a bit in nir_validate and it's not a validate_assert.<br>
> ><br>
> > Signed-off-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>><br>
> > ---<br>
> >  src/compiler/nir/nir.h        | 60 ++++++++++++++++++++++++++++--<wbr>-------------<br>
> >  src/compiler/nir/nir_search.h |  9 ++++---<br>
> >  2 files changed, 45 insertions(+), 24 deletions(-)<br>
> ><br>
> > diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
> > index 8d1afb9..a122f12 100644<br>
> > --- a/src/compiler/nir/nir.h<br>
> > +++ b/src/compiler/nir/nir.h<br>
> > @@ -59,11 +59,13 @@ struct gl_shader_program;<br>
> >   * Note that you have to be a bit careful as the generated cast function<br>
> >   * destroys constness.<br>
> >   */<br>
> > -#define NIR_DEFINE_CAST(name, in_type, out_type, field)  \<br>
> > -static inline out_type *                                 \<br>
> > -name(const in_type *parent)                              \<br>
> > -{                                                        \<br>
> > -   return exec_node_data(out_type, parent, field);       \<br>
> > +#define NIR_DEFINE_CAST(name, in_type, out_type, field, \<br>
> > +                        type_field, type_value)         \<br>
> > +static inline out_type *                                \<br>
> > +name(const in_type *parent)                             \<br>
> > +{                                                       \<br>
> > +   assert(parent && parent->type_field == type_value);  \<br>
> > +   return exec_node_data(out_type, parent, field);      \<br>
> >  }<br>
> ><br>
> >  struct nir_function;<br>
> > @@ -841,9 +843,12 @@ typedef struct {<br>
> >     unsigned index;<br>
> >  } nir_deref_struct;<br>
> ><br>
> > -NIR_DEFINE_CAST(nir_deref_as_<wbr>var, nir_deref, nir_deref_var, deref)<br>
> > -NIR_DEFINE_CAST(nir_deref_as_<wbr>array, nir_deref, nir_deref_array, deref)<br>
> > -NIR_DEFINE_CAST(nir_deref_as_<wbr>struct, nir_deref, nir_deref_struct, deref)<br>
> > +NIR_DEFINE_CAST(nir_deref_as_<wbr>var, nir_deref, nir_deref_var, deref,<br>
> > +                deref_type, nir_deref_type_var)<br>
> > +NIR_DEFINE_CAST(nir_deref_as_<wbr>array, nir_deref, nir_deref_array, deref,<br>
> > +                deref_type, nir_deref_type_array)<br>
> > +NIR_DEFINE_CAST(nir_deref_as_<wbr>struct, nir_deref, nir_deref_struct, deref,<br>
> > +                deref_type, nir_deref_type_struct)<br>
> ><br>
> >  /* Returns the last deref in the chain. */<br>
> >  static inline nir_deref *<br>
> > @@ -1409,16 +1414,25 @@ typedef struct {<br>
> >     struct exec_list entries;<br>
> >  } nir_parallel_copy_instr;<br>
> ><br>
> > -NIR_DEFINE_CAST(nir_instr_as_<wbr>alu, nir_instr, nir_alu_instr, instr)<br>
> > -NIR_DEFINE_CAST(nir_instr_as_<wbr>call, nir_instr, nir_call_instr, instr)<br>
> > -NIR_DEFINE_CAST(nir_instr_as_<wbr>jump, nir_instr, nir_jump_instr, instr)<br>
> > -NIR_DEFINE_CAST(nir_instr_as_<wbr>tex, nir_instr, nir_tex_instr, instr)<br>
> > -NIR_DEFINE_CAST(nir_instr_as_<wbr>intrinsic, nir_instr, nir_intrinsic_instr, instr)<br>
> > -NIR_DEFINE_CAST(nir_instr_as_<wbr>load_const, nir_instr, nir_load_const_instr, instr)<br>
> > -NIR_DEFINE_CAST(nir_instr_as_<wbr>ssa_undef, nir_instr, nir_ssa_undef_instr, instr)<br>
> > -NIR_DEFINE_CAST(nir_instr_as_<wbr>phi, nir_instr, nir_phi_instr, instr)<br>
> > +NIR_DEFINE_CAST(nir_instr_as_<wbr>alu, nir_instr, nir_alu_instr, instr,<br>
> > +                type, nir_instr_type_alu)<br>
> > +NIR_DEFINE_CAST(nir_instr_as_<wbr>call, nir_instr, nir_call_instr, instr,<br>
> > +                type, nir_instr_type_call)<br>
> > +NIR_DEFINE_CAST(nir_instr_as_<wbr>jump, nir_instr, nir_jump_instr, instr,<br>
> > +                type, nir_instr_type_jump)<br>
> > +NIR_DEFINE_CAST(nir_instr_as_<wbr>tex, nir_instr, nir_tex_instr, instr,<br>
> > +                type, nir_instr_type_tex)<br>
> > +NIR_DEFINE_CAST(nir_instr_as_<wbr>intrinsic, nir_instr, nir_intrinsic_instr, instr,<br>
> > +                type, nir_instr_type_intrinsic)<br>
> > +NIR_DEFINE_CAST(nir_instr_as_<wbr>load_const, nir_instr, nir_load_const_instr, instr,<br>
> > +                type, nir_instr_type_load_const)<br>
> > +NIR_DEFINE_CAST(nir_instr_as_<wbr>ssa_undef, nir_instr, nir_ssa_undef_instr, instr,<br>
> > +                type, nir_instr_type_ssa_undef)<br>
> > +NIR_DEFINE_CAST(nir_instr_as_<wbr>phi, nir_instr, nir_phi_instr, instr,<br>
> > +                type, nir_instr_type_phi)<br>
> >  NIR_DEFINE_CAST(nir_instr_as_<wbr>parallel_copy, nir_instr,<br>
> > -                nir_parallel_copy_instr, instr)<br>
> > +                nir_parallel_copy_instr, instr,<br>
> > +                type, nir_instr_type_parallel_copy)<br>
> ><br>
> >  /*<br>
> >   * Control flow<br>
> > @@ -1660,10 +1674,14 @@ nir_cf_node_is_last(const nir_cf_node *node)<br>
> >     return exec_node_is_tail_sentinel(<wbr>node->node.next);<br>
> >  }<br>
> ><br>
> > -NIR_DEFINE_CAST(nir_cf_node_<wbr>as_block, nir_cf_node, nir_block, cf_node)<br>
> > -NIR_DEFINE_CAST(nir_cf_node_<wbr>as_if, nir_cf_node, nir_if, cf_node)<br>
> > -NIR_DEFINE_CAST(nir_cf_node_<wbr>as_loop, nir_cf_node, nir_loop, cf_node)<br>
> > -NIR_DEFINE_CAST(nir_cf_node_<wbr>as_function, nir_cf_node, nir_function_impl, cf_node)<br>
> > +NIR_DEFINE_CAST(nir_cf_node_<wbr>as_block, nir_cf_node, nir_block, cf_node,<br>
> > +                type, nir_cf_node_block)<br>
> > +NIR_DEFINE_CAST(nir_cf_node_<wbr>as_if, nir_cf_node, nir_if, cf_node,<br>
> > +                type, nir_cf_node_if)<br>
> > +NIR_DEFINE_CAST(nir_cf_node_<wbr>as_loop, nir_cf_node, nir_loop, cf_node,<br>
> > +                type, nir_cf_node_loop)<br>
> > +NIR_DEFINE_CAST(nir_cf_node_<wbr>as_function, nir_cf_node,<br>
> > +                nir_function_impl, cf_node, type, nir_cf_node_function)<br>
> ><br>
> >  typedef enum {<br>
> >     nir_parameter_in,<br>
> > diff --git a/src/compiler/nir/nir_search.<wbr>h b/src/compiler/nir/nir_search.<wbr>h<br>
> > index f55d797..dec19d5 100644<br>
> > --- a/src/compiler/nir/nir_search.<wbr>h<br>
> > +++ b/src/compiler/nir/nir_search.<wbr>h<br>
> > @@ -106,11 +106,14 @@ typedef struct {<br>
> >  } nir_search_expression;<br>
> ><br>
> >  NIR_DEFINE_CAST(nir_search_<wbr>value_as_variable, nir_search_value,<br>
> > -                nir_search_variable, value)<br>
> > +                nir_search_variable, value,<br>
> > +                type, nir_search_value_variable)<br>
> >  NIR_DEFINE_CAST(nir_search_<wbr>value_as_constant, nir_search_value,<br>
> > -                nir_search_constant, value)<br>
> > +                nir_search_constant, value,<br>
> > +                type, nir_search_value_constant)<br>
> >  NIR_DEFINE_CAST(nir_search_<wbr>value_as_expression, nir_search_value,<br>
> > -                nir_search_expression, value)<br>
> > +                nir_search_expression, value,<br>
> > +                type, nir_search_value_expression)<br>
> ><br>
> >  nir_alu_instr *<br>
> >  nir_replace_instr(nir_alu_<wbr>instr *instr, const nir_search_expression *search,<br>
> > --<br>
> > 2.5.0.400.gff86faf<br>
> ><br>
> > ______________________________<wbr>_________________<br>
> > mesa-dev mailing list<br>
> > <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
> > <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br></p>
</div></div></blockquote></div><br></div>