[Mesa-dev] [PATCH 06/10] nir: Make nir_[cf_node/instr]_[prev/next] return null if at the end

Connor Abbott cwabbott0 at gmail.com
Thu Feb 5 15:40:56 PST 2015


This should go before the previous patch, or else that patch won't
work as intended, and also it confused me a little by using a behavior
(the returning NULL) before introducing it.

On Thu, Feb 5, 2015 at 5:29 PM, Jason Ekstrand <jason at jlekstrand.net> wrote:
> ---
>  src/glsl/nir/nir.h | 28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
> index 4cb2e92..32c991a 100644
> --- a/src/glsl/nir/nir.h
> +++ b/src/glsl/nir/nir.h
> @@ -416,15 +416,23 @@ typedef struct {
>  } nir_instr;
>
>  static inline nir_instr *
> -nir_instr_next(const nir_instr *instr)
> +nir_instr_next(nir_instr *instr)
>  {
> -   return exec_node_data(nir_instr, (instr)->node.next, node);
> +   struct exec_node *next = exec_node_get_next(&instr->node);
> +   if (exec_node_is_tail_sentinel(next))
> +      return NULL;
> +   else
> +      return exec_node_data(nir_instr, next, node);
>  }
>
>  static inline nir_instr *
> -nir_instr_prev(const nir_instr *instr)
> +nir_instr_prev(nir_instr *instr)
>  {
> -   return exec_node_data(nir_instr, (instr)->node.prev, node);
> +   struct exec_node *prev = exec_node_get_prev(&instr->node);
> +   if (exec_node_is_head_sentinel(prev))
> +      return NULL;
> +   else
> +      return exec_node_data(nir_instr, prev, node);
>  }
>
>  typedef struct {
> @@ -1264,13 +1272,21 @@ typedef struct {
>  static inline nir_cf_node *
>  nir_cf_node_next(nir_cf_node *node)
>  {
> -   return exec_node_data(nir_cf_node, exec_node_get_next(&node->node), node);
> +   struct exec_node *next = exec_node_get_next(&node->node);
> +   if (exec_node_is_tail_sentinel(next))
> +      return NULL;
> +   else
> +      return exec_node_data(nir_cf_node, next, node);
>  }
>
>  static inline nir_cf_node *
>  nir_cf_node_prev(nir_cf_node *node)
>  {
> -   return exec_node_data(nir_cf_node, exec_node_get_prev(&node->node), node);
> +   struct exec_node *prev = exec_node_get_prev(&node->node);
> +   if (exec_node_is_head_sentinel(prev))
> +      return NULL;
> +   else
> +      return exec_node_data(nir_cf_node, prev, node);
>  }
>
>  static inline bool
> --
> 2.2.2
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list