From 3be0be7d545334107977e850ce9ab51b0110a222 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 20 Jul 2020 16:49:46 -0500 Subject: [PATCH] nir: Split nir_index_vars into two functions We also very slightly change the semantics. It no longer is one index per list for global variables and is a single index over-all. Reviewed-by: Gert Wollny Part-of: --- src/compiler/nir/nir.c | 35 +++++++++++-------- src/compiler/nir/nir.h | 3 +- src/compiler/nir/nir_opt_large_constants.c | 3 +- .../nir/nir_opt_load_store_vectorize.c | 4 +-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 3d0fd42b316..a9fe16f4069 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -1821,36 +1821,43 @@ nir_index_instrs(nir_function_impl *impl) } static void -index_var_list(struct exec_list *list) +index_var_list(struct exec_list *list, unsigned *count) { - unsigned next_index = 0; nir_foreach_variable(var, list) - var->index = next_index++; + var->index = (*count)++; } -void -nir_index_vars(nir_shader *shader, nir_function_impl *impl, nir_variable_mode modes) +unsigned +nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes) { - if ((modes & nir_var_function_temp) && impl) - index_var_list(&impl->locals); - + unsigned count = 0; if (modes & nir_var_shader_temp) - index_var_list(&shader->globals); + index_var_list(&shader->globals, &count); if (modes & nir_var_shader_in) - index_var_list(&shader->inputs); + index_var_list(&shader->inputs, &count); if (modes & nir_var_shader_out) - index_var_list(&shader->outputs); + index_var_list(&shader->outputs, &count); if (modes & (nir_var_uniform | nir_var_mem_ubo | nir_var_mem_ssbo)) - index_var_list(&shader->uniforms); + index_var_list(&shader->uniforms, &count); if (modes & nir_var_mem_shared) - index_var_list(&shader->shared); + index_var_list(&shader->shared, &count); if (modes & nir_var_system_value) - index_var_list(&shader->system_values); + index_var_list(&shader->system_values, &count); + + return count; +} + +unsigned +nir_function_impl_index_vars(nir_function_impl *impl) +{ + unsigned count = 0; + index_var_list(&impl->locals, &count); + return count; } static nir_instr * diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index dca19596632..f131e0b3f24 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3737,7 +3737,8 @@ unsigned nir_index_instrs(nir_function_impl *impl); void nir_index_blocks(nir_function_impl *impl); -void nir_index_vars(nir_shader *shader, nir_function_impl *impl, nir_variable_mode modes); +unsigned nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes); +unsigned nir_function_impl_index_vars(nir_function_impl *impl); void nir_print_shader(nir_shader *shader, FILE *fp); void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table *errors); diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c index 2575407ca0b..25c40292033 100644 --- a/src/compiler/nir/nir_opt_large_constants.c +++ b/src/compiler/nir/nir_opt_large_constants.c @@ -176,8 +176,7 @@ nir_opt_large_constants(nir_shader *shader, /* This pass can only be run once */ assert(shader->constant_data == NULL && shader->constant_data_size == 0); - unsigned num_locals = exec_list_length(&impl->locals); - nir_index_vars(shader, impl, nir_var_function_temp); + unsigned num_locals = nir_function_impl_index_vars(impl); if (num_locals == 0) { nir_shader_preserve_all_metadata(shader); diff --git a/src/compiler/nir/nir_opt_load_store_vectorize.c b/src/compiler/nir/nir_opt_load_store_vectorize.c index 7777a63c5ae..f9b6774aa4e 100644 --- a/src/compiler/nir/nir_opt_load_store_vectorize.c +++ b/src/compiler/nir/nir_opt_load_store_vectorize.c @@ -1359,12 +1359,12 @@ nir_opt_load_store_vectorize(nir_shader *shader, nir_variable_mode modes, ctx->callback = callback; ctx->robust_modes = robust_modes; - nir_index_vars(shader, NULL, modes); + nir_shader_index_vars(shader, modes); nir_foreach_function(function, shader) { if (function->impl) { if (modes & nir_var_function_temp) - nir_index_vars(shader, function->impl, nir_var_function_temp); + nir_function_impl_index_vars(function->impl); nir_foreach_block(block, function->impl) progress |= process_block(function->impl, ctx, block); -- 2.30.2