aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_lower_locals_to_regs.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2016-07-15 17:17:40 -0700
committerJason Ekstrand <[email protected]>2016-12-05 15:40:09 -0800
commit50e0b0bee3fb97089cf9913af7a0c980dfce6dce (patch)
tree943f3e970522698601dfc8871797d06cc50c8551 /src/compiler/nir/nir_lower_locals_to_regs.c
parent2f19c19b5de66c4966fc5f5926efe5d435e505db (diff)
nir: Delete most of the constant_initializer support
Constant initializers have been a constant (ha!) pain for quite some time. While they're useful from a language perspective, people writing passes or backends really don't want deal with them most of the time. This commit removes most of the constant initializer support from NIR. It is expected that you call nir_lower_constant_initializers VERY EARLY to ensure that they're gone before you do anything interesting. Reviewed-by: Iago Toral Quiroga <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_lower_locals_to_regs.c')
-rw-r--r--src/compiler/nir/nir_lower_locals_to_regs.c91
1 files changed, 2 insertions, 89 deletions
diff --git a/src/compiler/nir/nir_lower_locals_to_regs.c b/src/compiler/nir/nir_lower_locals_to_regs.c
index cddd9fa9b53..25a62b3624a 100644
--- a/src/compiler/nir/nir_lower_locals_to_regs.c
+++ b/src/compiler/nir/nir_lower_locals_to_regs.c
@@ -101,6 +101,8 @@ get_reg_for_deref(nir_deref_var *deref, struct locals_to_regs_state *state)
{
uint32_t hash = hash_deref(deref);
+ assert(deref->var->constant_initializer == NULL);
+
struct hash_entry *entry =
_mesa_hash_table_search_pre_hashed(state->regs_table, hash, deref);
if (entry)
@@ -269,80 +271,6 @@ lower_locals_to_regs_block(nir_block *block,
return true;
}
-static nir_block *
-compute_reg_usedef_lca(nir_register *reg)
-{
- nir_block *lca = NULL;
-
- list_for_each_entry(nir_dest, def_dest, &reg->defs, reg.def_link)
- lca = nir_dominance_lca(lca, def_dest->reg.parent_instr->block);
-
- list_for_each_entry(nir_src, use_src, &reg->uses, use_link)
- lca = nir_dominance_lca(lca, use_src->parent_instr->block);
-
- list_for_each_entry(nir_src, use_src, &reg->if_uses, use_link) {
- nir_cf_node *prev_node = nir_cf_node_prev(&use_src->parent_if->cf_node);
- lca = nir_dominance_lca(lca, nir_cf_node_as_block(prev_node));
- }
-
- return lca;
-}
-
-static void
-insert_constant_initializer(nir_deref_var *deref_head, nir_deref *deref_tail,
- nir_block *block,
- struct locals_to_regs_state *state)
-{
- if (deref_tail->child) {
- switch (deref_tail->child->deref_type) {
- case nir_deref_type_array: {
- unsigned array_elems = glsl_get_length(deref_tail->type);
-
- nir_deref_array arr_deref;
- arr_deref.deref = *deref_tail->child;
- arr_deref.deref_array_type = nir_deref_array_type_direct;
-
- nir_deref *old_child = deref_tail->child;
- deref_tail->child = &arr_deref.deref;
- for (unsigned i = 0; i < array_elems; i++) {
- arr_deref.base_offset = i;
- insert_constant_initializer(deref_head, &arr_deref.deref,
- block, state);
- }
- deref_tail->child = old_child;
- return;
- }
-
- case nir_deref_type_struct:
- insert_constant_initializer(deref_head, deref_tail->child,
- block, state);
- return;
-
- default:
- unreachable("Invalid deref child type");
- }
- }
-
- assert(deref_tail->child == NULL);
-
- nir_load_const_instr *load =
- nir_deref_get_const_initializer_load(state->shader, deref_head);
- nir_instr_insert_before_block(block, &load->instr);
-
- nir_src reg_src = get_deref_reg_src(deref_head, &load->instr, state);
-
- nir_alu_instr *mov = nir_alu_instr_create(state->shader, nir_op_imov);
- mov->src[0].src = nir_src_for_ssa(&load->def);
- mov->dest.write_mask = (1 << load->def.num_components) - 1;
- mov->dest.dest.is_ssa = false;
- mov->dest.dest.reg.reg = reg_src.reg.reg;
- mov->dest.dest.reg.base_offset = reg_src.reg.base_offset;
- mov->dest.dest.reg.indirect = reg_src.reg.indirect;
-
- nir_instr_insert_after(&load->instr, &mov->instr);
- state->progress = true;
-}
-
static bool
nir_lower_locals_to_regs_impl(nir_function_impl *impl)
{
@@ -360,21 +288,6 @@ nir_lower_locals_to_regs_impl(nir_function_impl *impl)
lower_locals_to_regs_block(block, &state);
}
- nir_array_foreach(&state.derefs_array, nir_deref_var *, deref_ptr) {
- nir_deref_var *deref = *deref_ptr;
- struct hash_entry *deref_entry =
- _mesa_hash_table_search(state.regs_table, deref);
- assert(deref_entry && deref_entry->key == deref);
- nir_register *reg = (nir_register *)deref_entry->data;
-
- if (deref->var->constant_initializer == NULL)
- continue;
-
- nir_block *usedef_lca = compute_reg_usedef_lca(reg);
-
- insert_constant_initializer(deref, &deref->deref, usedef_lca, &state);
- }
-
nir_metadata_preserve(impl, nir_metadata_block_index |
nir_metadata_dominance);