From be8a73f40d0ac6850d483d2bd30d9220c5dd74a2 Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Mon, 18 Sep 2023 18:32:07 +0200 Subject: [PATCH] nir/deref: Layer rematerialization helpers nir_rematerialize_derefs_in_use_blocks_impl can be implemented on top of nir_rematerialize_deref_in_use_blocks. Reviewed-by: Rhys Perry Part-of: --- src/compiler/nir/nir_deref.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 5dfb06e..902e7a2 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -863,25 +863,13 @@ nir_rematerialize_deref_in_use_blocks(nir_deref_instr *instr) bool nir_rematerialize_derefs_in_use_blocks_impl(nir_function_impl *impl) { - struct rematerialize_deref_state state = { 0 }; - state.builder = nir_builder_create(impl); - + bool progress = false; nir_foreach_block_unstructured(block, impl) { - state.block = block; - nir_foreach_instr_safe(instr, block) { - if (instr->type == nir_instr_type_deref && - nir_deref_instr_remove_if_unused(nir_instr_as_deref(instr))) - continue; - - /* If a deref is used in a phi, we can't rematerialize it, as the new - * derefs would appear before the phi, which is not valid. - */ - if (instr->type == nir_instr_type_phi) - continue; - - state.builder.cursor = nir_before_instr(instr); - nir_foreach_src(instr, rematerialize_deref_src, &state); + if (instr->type == nir_instr_type_deref) { + nir_deref_instr *deref = nir_instr_as_deref(instr); + progress |= nir_rematerialize_deref_in_use_blocks(deref); + } } #ifndef NDEBUG @@ -891,7 +879,7 @@ nir_rematerialize_derefs_in_use_blocks_impl(nir_function_impl *impl) #endif } - return state.progress; + return progress; } static void -- 2.7.4