[Mesa-dev] [PATCH] nir: remove remaining global register support

Jason Ekstrand jason at jlekstrand.net
Mon Aug 1 14:08:54 UTC 2016


On Aug 1, 2016 12:37 AM, "Timothy Arceri" <timothy.arceri at collabora.com>
wrote:
>
> These don't seem to have been used since d1d12efb36074.

I'm a bit torn...  On the one hand, I do think we will probably want to
bring them back at some point in the future.  On the other hand, dead code
is broken code...

> ---
>  src/compiler/Makefile.sources               |   1 -
>  src/compiler/nir/nir.c                      |  23 -------
>  src/compiler/nir/nir.h                      |  14 ----
>  src/compiler/nir/nir_clone.c                |   6 +-
>  src/compiler/nir/nir_opt_global_to_local.c  | 102
----------------------------
>  src/compiler/nir/nir_print.c                |  10 +--
>  src/compiler/nir/nir_sweep.c                |   1 -
>  src/compiler/nir/nir_validate.c             |  39 +++--------
>  src/gallium/drivers/freedreno/ir3/ir3_nir.c |   1 -
>  src/gallium/drivers/vc4/vc4_program.c       |   2 -
>  10 files changed, 10 insertions(+), 189 deletions(-)
>  delete mode 100644 src/compiler/nir/nir_opt_global_to_local.c
>
> diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
> index 0ff9b23..e23c52a 100644
> --- a/src/compiler/Makefile.sources
> +++ b/src/compiler/Makefile.sources
> @@ -224,7 +224,6 @@ NIR_FILES = \
>         nir/nir_opt_dce.c \
>         nir/nir_opt_dead_cf.c \
>         nir/nir_opt_gcm.c \
> -       nir/nir_opt_global_to_local.c \
>         nir/nir_opt_peephole_select.c \
>         nir/nir_opt_remove_phis.c \
>         nir/nir_opt_undef.c \
> diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
> index 6bebb73..c0cc0cd 100644
> --- a/src/compiler/nir/nir.c
> +++ b/src/compiler/nir/nir.c
> @@ -45,10 +45,8 @@ nir_shader_create(void *mem_ctx,
>     memset(&shader->info, 0, sizeof(shader->info));
>
>     exec_list_make_empty(&shader->functions);
> -   exec_list_make_empty(&shader->registers);
>     exec_list_make_empty(&shader->globals);
>     exec_list_make_empty(&shader->system_values);
> -   shader->reg_alloc = 0;
>
>     shader->num_inputs = 0;
>     shader->num_outputs = 0;
> @@ -81,21 +79,10 @@ reg_create(void *mem_ctx, struct exec_list *list)
>  }
>
>  nir_register *
> -nir_global_reg_create(nir_shader *shader)
> -{
> -   nir_register *reg = reg_create(shader, &shader->registers);
> -   reg->index = shader->reg_alloc++;
> -   reg->is_global = true;
> -
> -   return reg;
> -}
> -
> -nir_register *
>  nir_local_reg_create(nir_function_impl *impl)
>  {
>     nir_register *reg = reg_create(ralloc_parent(impl), &impl->registers);
>     reg->index = impl->reg_alloc++;
> -   reg->is_global = false;
>
>     return reg;
>  }
> @@ -1061,16 +1048,6 @@ nir_index_local_regs(nir_function_impl *impl)
>     impl->reg_alloc = index;
>  }
>
> -void
> -nir_index_global_regs(nir_shader *shader)
> -{
> -   unsigned index = 0;
> -   foreach_list_typed(nir_register, reg, node, &shader->registers) {
> -      reg->index = index++;
> -   }
> -   shader->reg_alloc = index;
> -}
> -
>  static bool
>  visit_alu_dest(nir_alu_instr *instr, nir_foreach_dest_cb cb, void *state)
>  {
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index 65ecd33..f354f78 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -363,9 +363,6 @@ typedef struct nir_register {
>     /** only for debug purposes, can be NULL */
>     const char *name;
>
> -   /** whether this register is local (per-function) or global
(per-shader) */
> -   bool is_global;
> -
>     /**
>      * If this flag is set to true, then accessing channels >=
num_components
>      * is well-defined, and simply spills over to the next array element.
This
> @@ -1877,12 +1874,6 @@ typedef struct nir_shader {
>
>     struct exec_list functions; /** < list of nir_function */
>
> -   /** list of global register in the shader */
> -   struct exec_list registers;
> -
> -   /** next available global register index */
> -   unsigned reg_alloc;
> -
>     /**
>      * the highest index a load_input_*, load_uniform_*, etc. intrinsic
can
>      * access plus one
> @@ -1912,8 +1903,6 @@ nir_shader *nir_shader_create(void *mem_ctx,
>                                const nir_shader_compiler_options
*options);
>
>  /** creates a register, including assigning it an index and adding it to
the list */
> -nir_register *nir_global_reg_create(nir_shader *shader);
> -
>  nir_register *nir_local_reg_create(nir_function_impl *impl);
>
>  void nir_reg_remove(nir_register *reg);
> @@ -2275,7 +2264,6 @@ nir_if *nir_block_get_following_if(nir_block
*block);
>  nir_loop *nir_block_get_following_loop(nir_block *block);
>
>  void nir_index_local_regs(nir_function_impl *impl);
> -void nir_index_global_regs(nir_shader *shader);
>  void nir_index_ssa_defs(nir_function_impl *impl);
>  unsigned nir_index_instrs(nir_function_impl *impl);
>
> @@ -2559,8 +2547,6 @@ bool nir_opt_algebraic(nir_shader *shader);
>  bool nir_opt_algebraic_late(nir_shader *shader);
>  bool nir_opt_constant_folding(nir_shader *shader);
>
> -bool nir_opt_global_to_local(nir_shader *shader);
> -
>  bool nir_copy_prop(nir_shader *shader);
>
>  bool nir_opt_cse(nir_shader *shader);
> diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c
> index 0e397b0..1a874e7 100644
> --- a/src/compiler/nir/nir_clone.c
> +++ b/src/compiler/nir/nir_clone.c
> @@ -100,7 +100,7 @@ remap_global(clone_state *state, const void *ptr)
>  static nir_register *
>  remap_reg(clone_state *state, const nir_register *reg)
>  {
> -   return _lookup_ptr(state, reg, reg->is_global);
> +   return _lookup_ptr(state, reg, false);
>  }
>
>  static nir_variable *
> @@ -183,7 +183,6 @@ clone_register(clone_state *state, const nir_register
*reg)
>     nreg->num_array_elems = reg->num_array_elems;
>     nreg->index = reg->index;
>     nreg->name = ralloc_strdup(nreg, reg->name);
> -   nreg->is_global = reg->is_global;
>     nreg->is_packed = reg->is_packed;
>
>     /* reconstructing uses/defs/if_uses handled by nir_instr_insert() */
> @@ -707,9 +706,6 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
>        nfxn->impl->function = nfxn;
>     }
>
> -   clone_reg_list(&state, &ns->registers, &s->registers);
> -   ns->reg_alloc = s->reg_alloc;
> -
>     ns->info = s->info;
>     ns->info.name = ralloc_strdup(ns, ns->info.name);
>     if (ns->info.label)
> diff --git a/src/compiler/nir/nir_opt_global_to_local.c
b/src/compiler/nir/nir_opt_global_to_local.c
> deleted file mode 100644
> index 64d689e..0000000
> --- a/src/compiler/nir/nir_opt_global_to_local.c
> +++ /dev/null
> @@ -1,102 +0,0 @@
> -/*
> - * Copyright © 2014 Intel Corporation
> - *
> - * 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"
> -
> -static bool
> -global_to_local(nir_register *reg)
> -{
> -   nir_function_impl *impl = NULL;
> -
> -   assert(reg->is_global);
> -
> -   nir_foreach_def(def_dest, reg) {
> -      nir_instr *instr = def_dest->reg.parent_instr;
> -      nir_function_impl *instr_impl =
> -         nir_cf_node_get_function(&instr->block->cf_node);
> -      if (impl != NULL) {
> -         if (impl != instr_impl)
> -            return false;
> -      } else {
> -         impl = instr_impl;
> -      }
> -   }
> -
> -   nir_foreach_use(use_src, reg) {
> -      nir_instr *instr = use_src->parent_instr;
> -      nir_function_impl *instr_impl =
> -         nir_cf_node_get_function(&instr->block->cf_node);
> -      if (impl != NULL) {
> -         if (impl != instr_impl)
> -            return false;
> -      } else {
> -         impl = instr_impl;
> -      }
> -   }
> -
> -   nir_foreach_if_use(use_src, reg) {
> -      nir_if *if_stmt = use_src->parent_if;
> -      nir_function_impl *if_impl =
nir_cf_node_get_function(&if_stmt->cf_node);
> -      if (impl != NULL) {
> -         if (impl != if_impl)
> -            return false;
> -      } else {
> -         impl = if_impl;
> -      }
> -   }
> -
> -   if (impl == NULL) {
> -      /* this instruction is never used/defined, delete it */
> -      nir_reg_remove(reg);
> -      return true;
> -   }
> -
> -   /*
> -    * if we've gotten to this point, the register is always used/defined
in
> -    * the same implementation so we can move it to be local to that
> -    * implementation.
> -    */
> -
> -   exec_node_remove(&reg->node);
> -   exec_list_push_tail(&impl->registers, &reg->node);
> -   reg->index = impl->reg_alloc++;
> -   reg->is_global = false;
> -   return true;
> -}
> -
> -bool
> -nir_opt_global_to_local(nir_shader *shader)
> -{
> -   bool progress = false;
> -
> -   foreach_list_typed_safe(nir_register, reg, node, &shader->registers) {
> -      if (global_to_local(reg))
> -         progress = true;
> -   }
> -
> -   return progress;
> -}
> diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
> index 3beb70a..74449b6 100644
> --- a/src/compiler/nir/nir_print.c
> +++ b/src/compiler/nir/nir_print.c
> @@ -82,11 +82,7 @@ print_register(nir_register *reg, print_state *state)
>  {
>     FILE *fp = state->fp;
>     if (reg->name != NULL)
> -      fprintf(fp, "/* %s */ ", reg->name);
> -   if (reg->is_global)
> -      fprintf(fp, "gr%u", reg->index);
> -   else
> -      fprintf(fp, "r%u", reg->index);
> +      fprintf(fp, "/* %s */ r%u", reg->name, reg->index);
>  }
>
>  static const char *sizes[] = { "error", "vec1", "vec2", "vec3", "vec4" };
> @@ -1172,10 +1168,6 @@ nir_print_shader_annotated(nir_shader *shader,
FILE *fp,
>        print_var_decl(var, &state);
>     }
>
> -   foreach_list_typed(nir_register, reg, node, &shader->registers) {
> -      print_register_decl(reg, &state);
> -   }
> -
>     foreach_list_typed(nir_function, func, node, &shader->functions) {
>        print_function(func, &state);
>     }
> diff --git a/src/compiler/nir/nir_sweep.c b/src/compiler/nir/nir_sweep.c
> index 0f1debc..276c1ca 100644
> --- a/src/compiler/nir/nir_sweep.c
> +++ b/src/compiler/nir/nir_sweep.c
> @@ -164,7 +164,6 @@ nir_sweep(nir_shader *nir)
>     steal_list(nir, nir_variable, &nir->shared);
>     steal_list(nir, nir_variable, &nir->globals);
>     steal_list(nir, nir_variable, &nir->system_values);
> -   steal_list(nir, nir_register, &nir->registers);
>
>     /* Recurse into functions, stealing their contents back. */
>     foreach_list_typed(nir_function, func, node, &nir->functions) {
> diff --git a/src/compiler/nir/nir_validate.c
b/src/compiler/nir/nir_validate.c
> index 63e85cf..8d9b706 100644
> --- a/src/compiler/nir/nir_validate.c
> +++ b/src/compiler/nir/nir_validate.c
> @@ -146,10 +146,8 @@ validate_reg_src(nir_src *src, validate_state *state)
>        _mesa_set_add(reg_state->if_uses, src);
>     }
>
> -   if (!src->reg.reg->is_global) {
> -      validate_assert(state, reg_state->where_defined == state->impl &&
> -             "using a register declared in a different function");
> -   }
> +   validate_assert(state, reg_state->where_defined == state->impl &&
> +          "using a register declared in a different function");
>
>     validate_assert(state, (src->reg.reg->num_array_elems == 0 ||
>            src->reg.base_offset < src->reg.reg->num_array_elems) &&
> @@ -262,10 +260,8 @@ validate_reg_dest(nir_reg_dest *dest, validate_state
*state)
>     reg_validate_state *reg_state = (reg_validate_state *) entry2->data;
>     _mesa_set_add(reg_state->defs, dest);
>
> -   if (!dest->reg->is_global) {
> -      validate_assert(state, reg_state->where_defined == state->impl &&
> -             "writing to a register declared in a different function");
> -   }
> +   validate_assert(state, reg_state->where_defined == state->impl &&
> +          "writing to a register declared in a different function");
>
>     validate_assert(state, (dest->reg->num_array_elems == 0 ||
>            dest->base_offset < dest->reg->num_array_elems) &&
> @@ -849,14 +845,9 @@ validate_cf_node(nir_cf_node *node, validate_state
*state)
>  }
>
>  static void
> -prevalidate_reg_decl(nir_register *reg, bool is_global, validate_state
*state)
> +prevalidate_reg_decl(nir_register *reg, validate_state *state)
>  {
> -   validate_assert(state, reg->is_global == is_global);
> -
> -   if (is_global)
> -      validate_assert(state, reg->index < state->shader->reg_alloc);
> -   else
> -      validate_assert(state, reg->index < state->impl->reg_alloc);
> +   validate_assert(state, reg->index < state->impl->reg_alloc);
>     validate_assert(state, !BITSET_TEST(state->regs_found, reg->index));
>     BITSET_SET(state->regs_found, reg->index);
>
> @@ -872,7 +863,7 @@ prevalidate_reg_decl(nir_register *reg, bool
is_global, validate_state *state)
>     reg_state->defs = _mesa_set_create(reg_state, _mesa_hash_pointer,
>                                        _mesa_key_pointer_equal);
>
> -   reg_state->where_defined = is_global ? NULL : state->impl;
> +   reg_state->where_defined = state->impl;
>
>     _mesa_hash_table_insert(state->regs, reg, reg_state);
>  }
> @@ -1038,7 +1029,7 @@ validate_function_impl(nir_function_impl *impl,
validate_state *state)
>                                  sizeof(BITSET_WORD));
>     exec_list_validate(&impl->registers);
>     foreach_list_typed(nir_register, reg, node, &impl->registers) {
> -      prevalidate_reg_decl(reg, false, state);
> +      prevalidate_reg_decl(reg, state);
>     }
>
>     state->ssa_defs_found = realloc(state->ssa_defs_found,
> @@ -1165,25 +1156,11 @@ nir_validate_shader(nir_shader *shader)
>       validate_var_decl(var, true, &state);
>     }
>
> -   state.regs_found = realloc(state.regs_found,
> -                              BITSET_WORDS(shader->reg_alloc) *
> -                              sizeof(BITSET_WORD));
> -   memset(state.regs_found, 0, BITSET_WORDS(shader->reg_alloc) *
> -                               sizeof(BITSET_WORD));
> -   exec_list_validate(&shader->registers);
> -   foreach_list_typed(nir_register, reg, node, &shader->registers) {
> -      prevalidate_reg_decl(reg, true, &state);
> -   }
> -
>     exec_list_validate(&shader->functions);
>     foreach_list_typed(nir_function, func, node, &shader->functions) {
>        validate_function(func, &state);
>     }
>
> -   foreach_list_typed(nir_register, reg, node, &shader->registers) {
> -      postvalidate_reg_decl(reg, &state);
> -   }
> -
>     if (_mesa_hash_table_num_entries(state.errors) > 0)
>        dump_errors(&state);
>
> diff --git a/src/gallium/drivers/freedreno/ir3/ir3_nir.c
b/src/gallium/drivers/freedreno/ir3/ir3_nir.c
> index 023da3b..33c5512 100644
> --- a/src/gallium/drivers/freedreno/ir3/ir3_nir.c
> +++ b/src/gallium/drivers/freedreno/ir3/ir3_nir.c
> @@ -141,7 +141,6 @@ ir3_optimize_nir(struct ir3_shader *shader,
nir_shader *s,
>                 debug_printf("----------------------\n");
>         }
>
> -       OPT_V(s, nir_opt_global_to_local);
>         OPT_V(s, nir_convert_to_ssa);
>
>         if (key) {
> diff --git a/src/gallium/drivers/vc4/vc4_program.c
b/src/gallium/drivers/vc4/vc4_program.c
> index 9057b86..950345f 100644
> --- a/src/gallium/drivers/vc4/vc4_program.c
> +++ b/src/gallium/drivers/vc4/vc4_program.c
> @@ -1940,7 +1940,6 @@ nir_to_qir(struct vc4_compile *c)
>          ntq_setup_inputs(c);
>          ntq_setup_outputs(c);
>          ntq_setup_uniforms(c);
> -        ntq_setup_registers(c, &c->s->registers);

Did you really mean to delete this?

>
>          /* Find the main function and emit the body. */
>          nir_foreach_function(function, c->s) {
> @@ -2009,7 +2008,6 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage
stage,
>          }
>
>          c->s = nir_shader_clone(c, key->shader_state->base.ir.nir);
> -        NIR_PASS_V(c->s, nir_opt_global_to_local);
>          NIR_PASS_V(c->s, nir_convert_to_ssa);
>
>          if (stage == QSTAGE_FRAG)
> --
> 2.7.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160801/b12e75aa/attachment-0001.html>


More information about the mesa-dev mailing list