}
void
-nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src)
-{
- nir_shader *shader = ralloc_parent(if_stmt);
- nir_src *src = &if_stmt->condition;
- assert(!src_is_valid(src) || (src->is_if && src->parent_if == if_stmt));
-
- src_remove_all_uses(src);
- src_copy(src, &new_src, shader->gctx);
- src_add_all_uses(src, NULL, if_stmt);
-}
-
-void
nir_def_init(nir_instr *instr, nir_def *def,
unsigned num_components,
unsigned bit_size)
if (new_def->parent_instr->block != instr->block)
preserved = nir_metadata_none;
- nir_src new_src = nir_src_for_ssa(new_def);
- list_for_each_entry_safe(nir_src, use_src, &old_uses, use_link) {
- if (use_src->is_if)
- nir_if_rewrite_condition(use_src->parent_if, new_src);
- else
- nir_instr_rewrite_src(use_src->parent_instr, use_src, new_src);
- }
+ list_for_each_entry_safe(nir_src, use_src, &old_uses, use_link)
+ nir_src_rewrite(use_src, new_def);
if (nir_def_is_unused(old_def)) {
iter = nir_instr_free_and_dce(instr);
void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src);
-void nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src);
-
void nir_def_init(nir_instr *instr, nir_def *def,
unsigned num_components, unsigned bit_size);
static inline void
get_phi_builder_def_for_src(&following_if->condition,
&pbv_arr, block);
if (new_def != NULL)
- nir_if_rewrite_condition(following_if, nir_src_for_ssa(new_def));
+ nir_src_rewrite(&following_if->condition, new_def);
}
/* Handle phi sources that source from this block. We have to do this
nir_def *new_condition =
nir_inot(b, &alu_instr->def);
- nir_if_rewrite_condition(nif, nir_src_for_ssa(new_condition));
+ nir_src_rewrite(&nif->condition, new_condition);
/* Grab pointers to the last then/else blocks for fixing up the phis. */
nir_block *then_block = nir_if_last_then_block(nif);
}
nir_def *nalu = clone_alu_and_replace_src_defs(b, alu, def);
-
- /* Rewrite use to use new alu instruction */
- nir_src new_src = nir_src_for_ssa(nalu);
-
- if (alu_use->is_if)
- nir_if_rewrite_condition(alu_use->parent_if, new_src);
- else
- nir_instr_rewrite_src(alu_use->parent_instr, alu_use, new_src);
+ nir_src_rewrite(alu_use, nalu);
return true;
}
bool bool_value;
if (evaluate_if_condition(nif, b->cursor, &bool_value)) {
/* Rewrite use to use const */
- nir_src imm_src = nir_src_for_ssa(nir_imm_bool(b, bool_value));
- if (use_src->is_if)
- nir_if_rewrite_condition(use_src->parent_if, imm_src);
- else
- nir_instr_rewrite_src(use_src->parent_instr, use_src, imm_src);
-
+ nir_src_rewrite(use_src, nir_imm_bool(b, bool_value));
progress = true;
}
struct nir_builder b = nir_builder_at(nir_before_cf_node(&if_stmt->cf_node));
nir_def *cond = nir_iand(&b, if_stmt->condition.ssa,
parent_if->condition.ssa);
- nir_if_rewrite_condition(if_stmt, nir_src_for_ssa(cond));
+ nir_src_rewrite(&if_stmt->condition, cond);
/* move the whole inner if before the parent if */
nir_cf_list tmp;
nir_instr_insert_after_block(prev_block, &clone->instr);
- nir_if_rewrite_condition(if_stmt,
- nir_src_for_ssa(&clone->def));
+ nir_src_rewrite(&if_stmt->condition, &clone->def);
progress = true;
} else {
nir_instr *const use_instr = use->parent_instr;
}
if (src->is_if)
- nir_if_rewrite_condition(src->parent_if, nir_src_for_ssa(block_def));
+ nir_src_rewrite(&src->parent_if->condition, block_def);
else
nir_instr_rewrite_src(src->parent_instr, src, nir_src_for_ssa(block_def));
}
nir_foreach_use_including_if_safe(use, def) {
if (use->is_if) {
if (!is_if_use_inside_loop(use, state->loop))
- nir_if_rewrite_condition(use->parent_if, nir_src_for_ssa(dest));
+ nir_src_rewrite(&use->parent_if->condition, dest);
continue;
}
dupl = last_dupl;
}
- nir_if_rewrite_condition(use_src->parent_if, nir_src_for_ssa(&dupl->def));
+ nir_src_rewrite(&use_src->parent_if->condition, &dupl->def);
last_parent_instr = use_src->parent_instr;
last_dupl = dupl;
}
dupl = last_dupl;
}
- nir_if_rewrite_condition(use_src->parent_if, nir_src_for_ssa(&dupl->def));
+ nir_src_rewrite(&use_src->parent_if->condition, &dupl->def);
last_parent_instr = use_src->parent_instr;
last_dupl = dupl;
}
}
nir_foreach_if_use_safe(src, &intrin->def) {
b->cursor = nir_before_src(src);
- nir_if_rewrite_condition(src->parent_if,
- nir_src_for_ssa(clone_intrinsic(b, intrin)));
+ nir_src_rewrite(&src->parent_if->condition, clone_intrinsic(b, intrin));
}
nir_instr_remove(&intrin->instr);