mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 05:18:08 +02:00
nir/repair_ssa: Refactor some use handling
We can mostly unify the instr-use and if-use handling, which is a lot more concise. Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22343>
This commit is contained in:
parent
dcb59a7672
commit
9a35079074
1 changed files with 19 additions and 37 deletions
|
|
@ -57,7 +57,9 @@ prep_build_phi(struct repair_ssa_state *state)
|
|||
static nir_block *
|
||||
get_src_block(nir_src *src)
|
||||
{
|
||||
if (src->parent_instr->type == nir_instr_type_phi) {
|
||||
if (src->is_if) {
|
||||
return nir_cf_node_as_block(nir_cf_node_prev(&src->parent_if->cf_node));
|
||||
} else if (src->parent_instr->type == nir_instr_type_phi) {
|
||||
return exec_node_data(nir_phi_src, src, src)->pred;
|
||||
} else {
|
||||
return src->parent_instr->block;
|
||||
|
|
@ -71,20 +73,12 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
|
|||
|
||||
bool is_valid = true;
|
||||
nir_foreach_use_including_if(src, def) {
|
||||
if (src->is_if) {
|
||||
nir_block *block_before_if =
|
||||
nir_cf_node_as_block(nir_cf_node_prev(&src->parent_if->cf_node));
|
||||
if (nir_block_is_unreachable(block_before_if) ||
|
||||
!nir_block_dominates(def->parent_instr->block, block_before_if)) {
|
||||
is_valid = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (nir_block_is_unreachable(get_src_block(src)) ||
|
||||
!nir_block_dominates(def->parent_instr->block, get_src_block(src))) {
|
||||
is_valid = false;
|
||||
break;
|
||||
}
|
||||
nir_block *src_block = get_src_block(src);
|
||||
|
||||
if (nir_block_is_unreachable(src_block) ||
|
||||
!nir_block_dominates(def->parent_instr->block, src_block)) {
|
||||
is_valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,31 +96,15 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
|
|||
nir_phi_builder_value_set_block_def(val, def->parent_instr->block, def);
|
||||
|
||||
nir_foreach_use_including_if_safe(src, def) {
|
||||
if (src->is_if) {
|
||||
nir_block *block_before_if =
|
||||
nir_cf_node_as_block(nir_cf_node_prev(&src->parent_if->cf_node));
|
||||
if (block_before_if == def->parent_instr->block) {
|
||||
assert(nir_phi_builder_value_get_block_def(val, block_before_if) == def);
|
||||
continue;
|
||||
}
|
||||
nir_block *block = get_src_block(src);
|
||||
|
||||
nir_ssa_def *block_def =
|
||||
nir_phi_builder_value_get_block_def(val, block_before_if);
|
||||
if (block_def == def)
|
||||
continue;
|
||||
|
||||
nir_if_rewrite_condition(src->parent_if, nir_src_for_ssa(block_def));
|
||||
continue;
|
||||
}
|
||||
|
||||
nir_block *src_block = get_src_block(src);
|
||||
if (src_block == def->parent_instr->block) {
|
||||
assert(nir_phi_builder_value_get_block_def(val, src_block) == def);
|
||||
if (block == def->parent_instr->block) {
|
||||
assert(nir_phi_builder_value_get_block_def(val, block) == def);
|
||||
continue;
|
||||
}
|
||||
|
||||
nir_ssa_def *block_def =
|
||||
nir_phi_builder_value_get_block_def(val, src_block);
|
||||
nir_phi_builder_value_get_block_def(val, block);
|
||||
if (block_def == def)
|
||||
continue;
|
||||
|
||||
|
|
@ -134,7 +112,8 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
|
|||
* isn't a cast, we need to wrap it in a cast so we don't loose any
|
||||
* deref information.
|
||||
*/
|
||||
if (def->parent_instr->type == nir_instr_type_deref &&
|
||||
if (!src->is_if &&
|
||||
def->parent_instr->type == nir_instr_type_deref &&
|
||||
src->parent_instr->type == nir_instr_type_deref &&
|
||||
nir_instr_as_deref(src->parent_instr)->deref_type != nir_deref_type_cast) {
|
||||
nir_deref_instr *cast =
|
||||
|
|
@ -154,7 +133,10 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
|
|||
block_def = &cast->dest.ssa;
|
||||
}
|
||||
|
||||
nir_instr_rewrite_src(src->parent_instr, src, nir_src_for_ssa(block_def));
|
||||
if (src->is_if)
|
||||
nir_if_rewrite_condition(src->parent_if, nir_src_for_ssa(block_def));
|
||||
else
|
||||
nir_instr_rewrite_src(src->parent_instr, src, nir_src_for_ssa(block_def));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue