[Mesa-dev] [PATCH v2 08/14] nir: add an optimization for removing dead control flow

Matt Turner mattst88 at gmail.com
Thu May 21 09:58:57 PDT 2015


On Thu, May 21, 2015 at 9:41 AM, Connor Abbott <cwabbott0 at gmail.com> wrote:
> I'm not so sure about where to put the helper currently in nir.c... on
> the one hand, it's pretty specific to this pass, but on the other hand
> it needs to do some very fiddly low-level things to the control flow
> which is why it needs access to a static function in nir.c
> (stitch_blocks()) that I'd rather not expose publically.
>
> v2: use nir_cf_node_remove_after() instead of our own broken thing.
> Signed-off-by: Connor Abbott <cwabbott0 at gmail.com>
> ---
>  src/glsl/nir/nir.c             |  26 ++++++++
>  src/glsl/nir/nir.h             |   7 +++
>  src/glsl/nir/nir_opt_dead_cf.c | 138 +++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 171 insertions(+)
>  create mode 100644 src/glsl/nir/nir_opt_dead_cf.c
>
> diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
> index 0223fcd..79c4a4a 100644
> --- a/src/glsl/nir/nir.c
> +++ b/src/glsl/nir/nir.c
> @@ -1426,6 +1426,32 @@ nir_cf_node_remove_after(nir_cf_node *node)
>  }
>
>
> +/* Takes a control flow list 'cf_list,' presumed to be a child of the control
> + * flow node 'node,' pastes cf_list after node, and then deletes node.
> + */
> +

Extra newline.

> +void
> +nir_cf_list_move_after_node(nir_cf_node *node, struct exec_list *cf_list)
> +{
> +   nir_cf_node *after = nir_cf_node_next(node);
> +   assert(after->type == nir_cf_node_block);
> +   nir_block *after_block = nir_cf_node_as_block(after);
> +
> +   foreach_list_typed(nir_cf_node, child, node, cf_list) {
> +      child->parent = node->parent;
> +   }
> +
> +   nir_cf_node *last = exec_node_data(nir_cf_node, exec_list_get_tail(cf_list),
> +                                      node);
> +   assert(last->type == nir_cf_node_block);
> +   nir_block *last_block = nir_cf_node_as_block(last);
> +
> +   exec_node_insert_list_before(&after->node, cf_list);
> +   stitch_blocks(last_block, after_block);
> +
> +   nir_cf_node_remove(node);
> +}
> +
>  static bool
>  add_use_cb(nir_src *src, void *state)
>  {
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
> index d6702b4..38bd9c4 100644
> --- a/src/glsl/nir/nir.h
> +++ b/src/glsl/nir/nir.h
> @@ -1524,6 +1524,11 @@ void nir_cf_node_remove(nir_cf_node *node);
>  /** removes everything after the given control flow node */
>  void nir_cf_node_remove_after(nir_cf_node *node);
>
> +/** Takes a control flow list 'cf_list,' presumed to be a child of the control
> + *  flow node 'node,' pastes cf_list after node, and then deletes node.
> + */

I don't think I'd put the comment in both places (I'd leave it with
the function definition). Otherwise it'll just inevitably get out of
sync.


More information about the mesa-dev mailing list