From: Jason Ekstrand Date: Tue, 21 Apr 2015 19:12:26 +0000 (-0700) Subject: nir: Use nir_instr_rewrite_src in copy propagation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ecc2cfc8b60191c1df340467e086cd15b52b9fb7;p=mesa.git nir: Use nir_instr_rewrite_src in copy propagation We were rolling our own rewrite_src variant in copy-propagation. Let's stop doing that and use the ones in core NIR. Reviewed-by: Connor Abbott --- diff --git a/src/glsl/nir/nir_opt_copy_propagate.c b/src/glsl/nir/nir_opt_copy_propagate.c index ee78e5aa09d..71367d001bb 100644 --- a/src/glsl/nir/nir_opt_copy_propagate.c +++ b/src/glsl/nir/nir_opt_copy_propagate.c @@ -93,62 +93,6 @@ is_swizzleless_move(nir_alu_instr *instr) } } -typedef struct { - nir_ssa_def *def; - bool found; -} search_def_state; - -static bool -search_def(nir_src *src, void *_state) -{ - search_def_state *state = (search_def_state *) _state; - - if (src->is_ssa && src->ssa == state->def) - state->found = true; - - return true; -} - -static void -rewrite_src_instr(nir_src *src, nir_ssa_def *new_def, nir_instr *parent_instr) -{ - nir_ssa_def *old_def = src->ssa; - - src->ssa = new_def; - - /* - * The instruction could still use the old definition in one of its other - * sources, so only remove the instruction from the uses if there are no - * more uses left. - */ - - search_def_state search_state; - search_state.def = old_def; - search_state.found = false; - nir_foreach_src(parent_instr, search_def, &search_state); - if (!search_state.found) { - struct set_entry *entry = _mesa_set_search(old_def->uses, parent_instr); - assert(entry); - _mesa_set_remove(old_def->uses, entry); - } - - _mesa_set_add(new_def->uses, parent_instr); -} - -static void -rewrite_src_if(nir_if *if_stmt, nir_ssa_def *new_def) -{ - nir_ssa_def *old_def = if_stmt->condition.ssa; - - if_stmt->condition.ssa = new_def; - - struct set_entry *entry = _mesa_set_search(old_def->if_uses, if_stmt); - assert(entry); - _mesa_set_remove(old_def->if_uses, entry); - - _mesa_set_add(new_def->if_uses, if_stmt); -} - static bool copy_prop_src(nir_src *src, nir_instr *parent_instr, nir_if *parent_if) { @@ -178,10 +122,14 @@ copy_prop_src(nir_src *src, nir_instr *parent_instr, nir_if *parent_if) return false; } - if (parent_instr) - rewrite_src_instr(src, alu_instr->src[0].src.ssa, parent_instr); - else - rewrite_src_if(parent_if, alu_instr->src[0].src.ssa); + if (parent_instr) { + nir_instr_rewrite_src(parent_instr, src, + nir_src_for_ssa(alu_instr->src[0].src.ssa)); + } else { + assert(src == &parent_if->condition); + nir_if_rewrite_condition(parent_if, + nir_src_for_ssa(alu_instr->src[0].src.ssa)); + } return true; } @@ -234,7 +182,8 @@ copy_prop_alu_src(nir_alu_instr *parent_alu_instr, unsigned index) for (unsigned i = 0; i < 4; i++) src->swizzle[i] = new_swizzle[i]; - rewrite_src_instr(&src->src, def, &parent_alu_instr->instr); + nir_instr_rewrite_src(&parent_alu_instr->instr, &src->src, + nir_src_for_ssa(def)); return true; }