From: Connor Abbott Date: Fri, 8 Apr 2016 20:10:16 +0000 (-0400) Subject: nir/lower_indirect_derefs: fixup for new foreach_block() X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b89f0bb58c4eec72918656460bb6e14b0b178590;p=mesa.git nir/lower_indirect_derefs: fixup for new foreach_block() v2 (Jason Ekstrand): Use nir_foreach_block_safe Reviewed-by: Jason Ekstrand --- diff --git a/src/compiler/nir/nir_lower_indirect_derefs.c b/src/compiler/nir/nir_lower_indirect_derefs.c index 2484c49ec34..9045adc1c6f 100644 --- a/src/compiler/nir/nir_lower_indirect_derefs.c +++ b/src/compiler/nir/nir_lower_indirect_derefs.c @@ -159,16 +159,11 @@ deref_has_indirect(nir_deref_var *deref) return false; } -struct lower_indirect_state { - nir_builder builder; - nir_variable_mode modes; - bool progress; -}; - static bool -lower_indirect_block(nir_block *block, void *void_state) +lower_indirect_block(nir_block *block, nir_builder *b, + nir_variable_mode modes) { - struct lower_indirect_state *state = void_state; + bool progress = false; nir_foreach_instr_safe(block, instr) { if (instr->type != nir_instr_type_intrinsic) @@ -183,43 +178,43 @@ lower_indirect_block(nir_block *block, void *void_state) continue; /* Only lower variables whose mode is in the mask */ - if (!(state->modes & intrin->variables[0]->var->data.mode)) + if (!(modes & intrin->variables[0]->var->data.mode)) continue; - state->builder.cursor = nir_before_instr(&intrin->instr); + b->cursor = nir_before_instr(&intrin->instr); if (intrin->intrinsic == nir_intrinsic_load_var) { nir_ssa_def *result; - emit_load_store(&state->builder, intrin, intrin->variables[0], + emit_load_store(b, intrin, intrin->variables[0], &intrin->variables[0]->deref, &result, NULL); nir_ssa_def_rewrite_uses(&intrin->dest.ssa, nir_src_for_ssa(result)); } else { assert(intrin->src[0].is_ssa); - emit_load_store(&state->builder, intrin, intrin->variables[0], + emit_load_store(b, intrin, intrin->variables[0], &intrin->variables[0]->deref, NULL, intrin->src[0].ssa); } nir_instr_remove(&intrin->instr); - state->progress = true; + progress = true; } - return true; + return progress; } static bool lower_indirects_impl(nir_function_impl *impl, nir_variable_mode modes) { - struct lower_indirect_state state; - - state.progress = false; - state.modes = modes; - nir_builder_init(&state.builder, impl); + nir_builder builder; + nir_builder_init(&builder, impl); + bool progress = false; - nir_foreach_block_call(impl, lower_indirect_block, &state); + nir_foreach_block_safe(block, impl) { + progress |= lower_indirect_block(block, &builder, modes); + } - if (state.progress) + if (progress) nir_metadata_preserve(impl, nir_metadata_none); - return state.progress; + return progress; } /** Lowers indirect variable loads/stores to direct loads/stores.