[Mesa-dev] [PATCH 1/2] nir: add rewrite_phi_predecessor_blocks() helper
Thomas Helland
thomashelland90 at gmail.com
Tue Nov 27 06:38:31 UTC 2018
This patch is:
Reviewed-by: Thomas Helland <thomashelland90 at gmail.com>
Den tir. 27. nov. 2018 kl. 06:32 skrev Timothy Arceri <tarceri at itsqueeze.com>:
>
> This will also be used by the if merge pass in the following commit.
> ---
> src/compiler/nir/nir_opt_if.c | 45 ++++++++++++++++++++++-------------
> 1 file changed, 28 insertions(+), 17 deletions(-)
>
> diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c
> index 8a971c43f2..62566eb403 100644
> --- a/src/compiler/nir/nir_opt_if.c
> +++ b/src/compiler/nir/nir_opt_if.c
> @@ -237,6 +237,32 @@ is_block_empty(nir_block *block)
> exec_list_is_empty(&block->instr_list);
> }
>
> +static void
> +rewrite_phi_predecessor_blocks(nir_if *nif,
> + nir_block *old_then_block,
> + nir_block *old_else_block,
> + nir_block *new_then_block,
> + nir_block *new_else_block)
> +{
> + nir_block *after_if_block =
> + nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node));
> +
> + nir_foreach_instr(instr, after_if_block) {
> + if (instr->type != nir_instr_type_phi)
> + continue;
> +
> + nir_phi_instr *phi = nir_instr_as_phi(instr);
> +
> + foreach_list_typed(nir_phi_src, src, node, &phi->srcs) {
> + if (src->pred == old_then_block) {
> + src->pred = new_then_block;
> + } else if (src->pred == old_else_block) {
> + src->pred = new_else_block;
> + }
> + }
> + }
> +}
> +
> /**
> * This optimization turns:
> *
> @@ -284,23 +310,8 @@ opt_if_simplification(nir_builder *b, nir_if *nif)
> /* Walk all the phis in the block immediately following the if statement and
> * swap the blocks.
> */
> - nir_block *after_if_block =
> - nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node));
> -
> - nir_foreach_instr(instr, after_if_block) {
> - if (instr->type != nir_instr_type_phi)
> - continue;
> -
> - nir_phi_instr *phi = nir_instr_as_phi(instr);
> -
> - foreach_list_typed(nir_phi_src, src, node, &phi->srcs) {
> - if (src->pred == else_block) {
> - src->pred = then_block;
> - } else if (src->pred == then_block) {
> - src->pred = else_block;
> - }
> - }
> - }
> + rewrite_phi_predecessor_blocks(nif, then_block, else_block, else_block,
> + then_block);
>
> /* Finally, move the else block to the then block. */
> nir_cf_list tmp;
> --
> 2.19.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list