[Mesa-dev] [PATCH v2 08/14] nir: add an optimization for removing dead control flow
Pohjolainen, Topi
topi.pohjolainen at intel.com
Mon May 25 01:29:08 PDT 2015
On Thu, May 21, 2015 at 12:41:03PM -0400, Connor Abbott 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.
> + */
> +
> +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.
> + */
> +void nir_cf_list_move_after_node(nir_cf_node *node, struct exec_list *cf_list);
> +
> /** requests that the given pieces of metadata be generated */
> void nir_metadata_require(nir_function_impl *impl, nir_metadata required);
> /** dirties all but the preserved metadata */
> @@ -1698,6 +1703,8 @@ bool nir_opt_cse(nir_shader *shader);
> bool nir_opt_dce_impl(nir_function_impl *impl);
> bool nir_opt_dce(nir_shader *shader);
>
> +bool nir_opt_dead_cf(nir_shader *shader);
> +
> void nir_opt_gcm(nir_shader *shader);
>
> bool nir_opt_peephole_select(nir_shader *shader);
> diff --git a/src/glsl/nir/nir_opt_dead_cf.c b/src/glsl/nir/nir_opt_dead_cf.c
> new file mode 100644
> index 0000000..e0d4859
> --- /dev/null
> +++ b/src/glsl/nir/nir_opt_dead_cf.c
> @@ -0,0 +1,138 @@
> +/*
> + * Copyright © 2014 Connor Abbott
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + * Authors:
> + * Connor Abbott (cwabbott0 at gmail.com)
> + *
> + */
> +
> +#include "nir.h"
> +
> +/*
> + * This file implements an optimization that deletes statically unreachable
> + * code. In NIR, one way this can happen if if an if statement has a constant
I guess you meant "...happen is if an..."?
More information about the mesa-dev
mailing list