From dc85065944af2c1f089c59155630561263b6b2e0 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 1 Mar 2021 21:22:06 -0600 Subject: [PATCH] nir: Add an options parameter to deref_instr_has_complex_use Reviewed-by: Kristian H. Kristensen Reviewed-by: Jason Ekstrand (1.5 years later) Part-of: --- src/compiler/nir/nir.h | 9 ++++++++- src/compiler/nir/nir_deref.c | 14 ++++++++++++-- .../nir/nir_lower_const_arrays_to_uniforms.c | 2 +- src/compiler/nir/nir_lower_vars_to_ssa.c | 2 +- src/compiler/nir/nir_opt_large_constants.c | 2 +- src/compiler/nir/nir_split_vars.c | 4 ++-- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index a64513d47d6..08ffa825b5b 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1686,7 +1686,14 @@ nir_deref_instr_get_variable(const nir_deref_instr *instr) bool nir_deref_instr_has_indirect(nir_deref_instr *instr); bool nir_deref_instr_is_known_out_of_bounds(nir_deref_instr *instr); -bool nir_deref_instr_has_complex_use(nir_deref_instr *instr); + +typedef enum { + nir_deref_instr_has_complex_use_allow_memcpy_src = (1 << 0), + nir_deref_instr_has_complex_use_allow_memcpy_dst = (1 << 1), +} nir_deref_instr_has_complex_use_options; + +bool nir_deref_instr_has_complex_use(nir_deref_instr *instr, + nir_deref_instr_has_complex_use_options opts); bool nir_deref_instr_remove_if_unused(nir_deref_instr *instr); diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index f9d599c02d5..9e46d0ab5d5 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -154,7 +154,8 @@ nir_deref_instr_is_known_out_of_bounds(nir_deref_instr *instr) } bool -nir_deref_instr_has_complex_use(nir_deref_instr *deref) +nir_deref_instr_has_complex_use(nir_deref_instr *deref, + nir_deref_instr_has_complex_use_options opts) { nir_foreach_use(use_src, &deref->dest.ssa) { nir_instr *use_instr = use_src->parent_instr; @@ -184,7 +185,7 @@ nir_deref_instr_has_complex_use(nir_deref_instr *deref) use_deref->deref_type != nir_deref_type_array) return true; - if (nir_deref_instr_has_complex_use(use_deref)) + if (nir_deref_instr_has_complex_use(use_deref, opts)) return true; continue; @@ -214,6 +215,15 @@ nir_deref_instr_has_complex_use(nir_deref_instr *deref) continue; return true; + case nir_intrinsic_memcpy_deref: + if (use_src == &use_intrin->src[0] && + (opts & nir_deref_instr_has_complex_use_allow_memcpy_dst)) + continue; + if (use_src == &use_intrin->src[1] && + (opts & nir_deref_instr_has_complex_use_allow_memcpy_src)) + continue; + return true; + default: return true; } diff --git a/src/compiler/nir/nir_lower_const_arrays_to_uniforms.c b/src/compiler/nir/nir_lower_const_arrays_to_uniforms.c index d7efdf6a4a5..72dc706ded5 100644 --- a/src/compiler/nir/nir_lower_const_arrays_to_uniforms.c +++ b/src/compiler/nir/nir_lower_const_arrays_to_uniforms.c @@ -273,7 +273,7 @@ nir_lower_const_arrays_to_uniforms(nir_shader *shader, nir_deref_instr *deref = nir_instr_as_deref(instr); if (deref->deref_type == nir_deref_type_var && deref->var->data.mode == nir_var_function_temp && - nir_deref_instr_has_complex_use(deref)) + nir_deref_instr_has_complex_use(deref, 0)) var_infos[deref->var->index].is_constant = false; continue; } diff --git a/src/compiler/nir/nir_lower_vars_to_ssa.c b/src/compiler/nir/nir_lower_vars_to_ssa.c index 292366a590f..e69a9280562 100644 --- a/src/compiler/nir/nir_lower_vars_to_ssa.c +++ b/src/compiler/nir/nir_lower_vars_to_ssa.c @@ -460,7 +460,7 @@ register_variable_uses(nir_function_impl *impl, nir_deref_instr *deref = nir_instr_as_deref(instr); if (deref->deref_type == nir_deref_type_var && - nir_deref_instr_has_complex_use(deref)) + nir_deref_instr_has_complex_use(deref, 0)) register_complex_use(deref, state); break; diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c index 1e032f199c2..08002b28002 100644 --- a/src/compiler/nir/nir_opt_large_constants.c +++ b/src/compiler/nir/nir_opt_large_constants.c @@ -206,7 +206,7 @@ nir_opt_large_constants(nir_shader *shader, nir_deref_instr *deref = nir_instr_as_deref(instr); if (deref->deref_type == nir_deref_type_var && deref->var->data.mode == nir_var_function_temp && - nir_deref_instr_has_complex_use(deref)) + nir_deref_instr_has_complex_use(deref, 0)) var_infos[deref->var->index].is_constant = false; continue; } diff --git a/src/compiler/nir/nir_split_vars.c b/src/compiler/nir/nir_split_vars.c index ca1a5d21d1b..d7894c3db44 100644 --- a/src/compiler/nir/nir_split_vars.c +++ b/src/compiler/nir/nir_split_vars.c @@ -49,7 +49,7 @@ get_complex_used_vars(nir_shader *shader, void *mem_ctx) * nir_deref_instr_has_complex_use is recursive. */ if (deref->deref_type == nir_deref_type_var && - nir_deref_instr_has_complex_use(deref)) + nir_deref_instr_has_complex_use(deref, 0)) _mesa_set_add(complex_vars, deref->var); } } @@ -1044,7 +1044,7 @@ mark_deref_if_complex(nir_deref_instr *deref, if (!(deref->var->data.mode & modes)) return; - if (!nir_deref_instr_has_complex_use(deref)) + if (!nir_deref_instr_has_complex_use(deref, 0)) return; struct vec_var_usage *usage =