diff options
author | Jason Ekstrand <[email protected]> | 2016-12-24 09:42:34 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2016-12-30 12:38:04 -0800 |
commit | 134a5ad31c8d39219f241f7a7cad246a6864c74b (patch) | |
tree | f31ba3874da61a7d6a75fd13c9dc89f42339a873 /src/compiler/nir | |
parent | 832dddcf91f168ab057cb5c7f6914b24ae6b864c (diff) |
nir: Make nir_copy_deref follow the "clone" pattern
We rename it to nir_deref_clone, re-order the sources to match the other
clone functions, and expose nir_deref_var_clone. This past part, in
particular, lets us get rid of quite a few lines since we no longer have
to call nir_copy_deref and wrap it in deref_as_var.
Reviewed-by: Jordan Justen <[email protected]>
Diffstat (limited to 'src/compiler/nir')
-rw-r--r-- | src/compiler/nir/nir.c | 25 | ||||
-rw-r--r-- | src/compiler/nir/nir.h | 4 | ||||
-rw-r--r-- | src/compiler/nir/nir_builder.h | 6 | ||||
-rw-r--r-- | src/compiler/nir/nir_inline_functions.c | 2 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_indirect_derefs.c | 6 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_tex.c | 18 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_var_copies.c | 4 | ||||
-rw-r--r-- | src/compiler/nir/nir_split_var_copies.c | 17 |
8 files changed, 37 insertions, 45 deletions
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 885616e99c3..1f6837a88dd 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -624,18 +624,21 @@ nir_deref_struct_create(void *mem_ctx, unsigned field_index) return deref; } -static nir_deref_var * -copy_deref_var(void *mem_ctx, nir_deref_var *deref) +nir_deref_var * +nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx) { + if (deref == NULL) + return NULL; + nir_deref_var *ret = nir_deref_var_create(mem_ctx, deref->var); ret->deref.type = deref->deref.type; if (deref->deref.child) - ret->deref.child = nir_copy_deref(ret, deref->deref.child); + ret->deref.child = nir_deref_clone(deref->deref.child, ret); return ret; } static nir_deref_array * -copy_deref_array(void *mem_ctx, nir_deref_array *deref) +deref_array_clone(const nir_deref_array *deref, void *mem_ctx) { nir_deref_array *ret = nir_deref_array_create(mem_ctx); ret->base_offset = deref->base_offset; @@ -645,33 +648,33 @@ copy_deref_array(void *mem_ctx, nir_deref_array *deref) } ret->deref.type = deref->deref.type; if (deref->deref.child) - ret->deref.child = nir_copy_deref(ret, deref->deref.child); + ret->deref.child = nir_deref_clone(deref->deref.child, ret); return ret; } static nir_deref_struct * -copy_deref_struct(void *mem_ctx, nir_deref_struct *deref) +deref_struct_clone(const nir_deref_struct *deref, void *mem_ctx) { nir_deref_struct *ret = nir_deref_struct_create(mem_ctx, deref->index); ret->deref.type = deref->deref.type; if (deref->deref.child) - ret->deref.child = nir_copy_deref(ret, deref->deref.child); + ret->deref.child = nir_deref_clone(deref->deref.child, ret); return ret; } nir_deref * -nir_copy_deref(void *mem_ctx, nir_deref *deref) +nir_deref_clone(const nir_deref *deref, void *mem_ctx) { if (deref == NULL) return NULL; switch (deref->deref_type) { case nir_deref_type_var: - return ©_deref_var(mem_ctx, nir_deref_as_var(deref))->deref; + return &nir_deref_var_clone(nir_deref_as_var(deref), mem_ctx)->deref; case nir_deref_type_array: - return ©_deref_array(mem_ctx, nir_deref_as_array(deref))->deref; + return &deref_array_clone(nir_deref_as_array(deref), mem_ctx)->deref; case nir_deref_type_struct: - return ©_deref_struct(mem_ctx, nir_deref_as_struct(deref))->deref; + return &deref_struct_clone(nir_deref_as_struct(deref), mem_ctx)->deref; default: unreachable("Invalid dereference type"); } diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 71983be0344..b96b0b1f0c6 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1932,8 +1932,6 @@ nir_deref_var *nir_deref_var_create(void *mem_ctx, nir_variable *var); nir_deref_array *nir_deref_array_create(void *mem_ctx); nir_deref_struct *nir_deref_struct_create(void *mem_ctx, unsigned field_index); -nir_deref *nir_copy_deref(void *mem_ctx, nir_deref *deref); - typedef bool (*nir_deref_foreach_leaf_cb)(nir_deref_var *deref, void *state); bool nir_deref_foreach_leaf(nir_deref_var *deref, nir_deref_foreach_leaf_cb cb, void *state); @@ -2241,6 +2239,8 @@ nir_shader *nir_shader_clone(void *mem_ctx, const nir_shader *s); nir_function_impl *nir_function_impl_clone(const nir_function_impl *fi); nir_constant *nir_constant_clone(const nir_constant *c, nir_variable *var); nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader); +nir_deref *nir_deref_clone(const nir_deref *deref, void *mem_ctx); +nir_deref_var *nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx); #ifdef DEBUG void nir_validate_shader(nir_shader *shader); diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 0ee7d1a6f39..2ea9af1e63d 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -437,7 +437,7 @@ nir_store_deref_var(nir_builder *build, nir_deref_var *deref, nir_intrinsic_instr_create(build->shader, nir_intrinsic_store_var); store->num_components = num_components; store->const_index[0] = writemask & ((1 << num_components) - 1); - store->variables[0] = nir_deref_as_var(nir_copy_deref(store, &deref->deref)); + store->variables[0] = nir_deref_var_clone(deref, store); store->src[0] = nir_src_for_ssa(value); nir_builder_instr_insert(build, &store->instr); } @@ -450,8 +450,8 @@ nir_copy_deref_var(nir_builder *build, nir_deref_var *dest, nir_deref_var *src) nir_intrinsic_instr *copy = nir_intrinsic_instr_create(build->shader, nir_intrinsic_copy_var); - copy->variables[0] = nir_deref_as_var(nir_copy_deref(copy, &dest->deref)); - copy->variables[1] = nir_deref_as_var(nir_copy_deref(copy, &src->deref)); + copy->variables[0] = nir_deref_var_clone(dest, copy); + copy->variables[1] = nir_deref_var_clone(src, copy); nir_builder_instr_insert(build, ©->instr); } diff --git a/src/compiler/nir/nir_inline_functions.c b/src/compiler/nir/nir_inline_functions.c index c36748d6cf5..b91e7bc86da 100644 --- a/src/compiler/nir/nir_inline_functions.c +++ b/src/compiler/nir/nir_inline_functions.c @@ -49,7 +49,7 @@ convert_deref_to_param_deref(nir_instr *instr, nir_deref_var **deref, /* Now we make a new deref by concatenating the deref in the call's * parameter with the deref we were given. */ - nir_deref_var *new_deref = nir_deref_as_var(nir_copy_deref(instr, &call_deref->deref)); + nir_deref_var *new_deref = nir_deref_var_clone(call_deref, instr); nir_deref *new_tail = nir_deref_tail(&new_deref->deref); new_tail->child = (*deref)->deref.child; ralloc_steal(new_tail, new_tail->child); diff --git a/src/compiler/nir/nir_lower_indirect_derefs.c b/src/compiler/nir/nir_lower_indirect_derefs.c index 5c97dc8e5fe..09cc9a310b1 100644 --- a/src/compiler/nir/nir_lower_indirect_derefs.c +++ b/src/compiler/nir/nir_lower_indirect_derefs.c @@ -122,8 +122,7 @@ emit_load_store(nir_builder *b, nir_intrinsic_instr *orig_instr, nir_intrinsic_instr *load = nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_var); load->num_components = orig_instr->num_components; - load->variables[0] = - nir_deref_as_var(nir_copy_deref(load, &deref->deref)); + load->variables[0] = nir_deref_var_clone(deref, load); unsigned bit_size = orig_instr->dest.ssa.bit_size; nir_ssa_dest_init(&load->instr, &load->dest, load->num_components, bit_size, NULL); @@ -135,8 +134,7 @@ emit_load_store(nir_builder *b, nir_intrinsic_instr *orig_instr, nir_intrinsic_instr_create(b->shader, nir_intrinsic_store_var); store->num_components = orig_instr->num_components; nir_intrinsic_set_write_mask(store, nir_intrinsic_write_mask(orig_instr)); - store->variables[0] = - nir_deref_as_var(nir_copy_deref(store, &deref->deref)); + store->variables[0] = nir_deref_var_clone(deref, store); store->src[0] = nir_src_for_ssa(src); nir_builder_instr_insert(b, &store->instr); } diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 3e3ac8c2558..66e231762f8 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -163,11 +163,9 @@ get_texture_size(nir_builder *b, nir_tex_instr *tex) txs->is_shadow = tex->is_shadow; txs->is_new_style_shadow = tex->is_new_style_shadow; txs->texture_index = tex->texture_index; - txs->texture = (nir_deref_var *) - nir_copy_deref(txs, &tex->texture->deref); + txs->texture = nir_deref_var_clone(tex->texture, txs); txs->sampler_index = tex->sampler_index; - txs->sampler = (nir_deref_var *) - nir_copy_deref(txs, &tex->sampler->deref); + txs->sampler = nir_deref_var_clone(tex->sampler, txs); txs->dest_type = nir_type_int; /* only single src, the lod: */ @@ -221,11 +219,9 @@ sample_plane(nir_builder *b, nir_tex_instr *tex, int plane) plane_tex->coord_components = 2; plane_tex->texture_index = tex->texture_index; - plane_tex->texture = (nir_deref_var *) - nir_copy_deref(plane_tex, &tex->texture->deref); + plane_tex->texture = nir_deref_var_clone(tex->texture, plane_tex); plane_tex->sampler_index = tex->sampler_index; - plane_tex->sampler = (nir_deref_var *) - nir_copy_deref(plane_tex, &tex->sampler->deref); + plane_tex->sampler = nir_deref_var_clone(tex->sampler, plane_tex); nir_ssa_dest_init(&plane_tex->instr, &plane_tex->dest, 4, 32, NULL); @@ -325,10 +321,8 @@ replace_gradient_with_lod(nir_builder *b, nir_ssa_def *lod, nir_tex_instr *tex) txl->is_shadow = tex->is_shadow; txl->is_new_style_shadow = tex->is_new_style_shadow; txl->sampler_index = tex->sampler_index; - txl->texture = (nir_deref_var *) - nir_copy_deref(txl, &tex->texture->deref); - txl->sampler = (nir_deref_var *) - nir_copy_deref(txl, &tex->sampler->deref); + txl->texture = nir_deref_var_clone(tex->texture, txl); + txl->sampler = nir_deref_var_clone(tex->sampler, txl); txl->coord_components = tex->coord_components; nir_ssa_dest_init(&txl->instr, &txl->dest, 4, 32, NULL); diff --git a/src/compiler/nir/nir_lower_var_copies.c b/src/compiler/nir/nir_lower_var_copies.c index b7e9989808b..b12d953820f 100644 --- a/src/compiler/nir/nir_lower_var_copies.c +++ b/src/compiler/nir/nir_lower_var_copies.c @@ -121,7 +121,7 @@ emit_copy_load_store(nir_intrinsic_instr *copy_instr, nir_intrinsic_instr *load = nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_load_var); load->num_components = num_components; - load->variables[0] = nir_deref_as_var(nir_copy_deref(load, &src_head->deref)); + load->variables[0] = nir_deref_var_clone(src_head, load); nir_ssa_dest_init(&load->instr, &load->dest, num_components, bit_size, NULL); @@ -131,7 +131,7 @@ emit_copy_load_store(nir_intrinsic_instr *copy_instr, nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_store_var); store->num_components = num_components; nir_intrinsic_set_write_mask(store, (1 << num_components) - 1); - store->variables[0] = nir_deref_as_var(nir_copy_deref(store, &dest_head->deref)); + store->variables[0] = nir_deref_var_clone(dest_head, store); store->src[0].is_ssa = true; store->src[0].ssa = &load->dest.ssa; diff --git a/src/compiler/nir/nir_split_var_copies.c b/src/compiler/nir/nir_split_var_copies.c index 63a7611b914..cfebb0bb948 100644 --- a/src/compiler/nir/nir_split_var_copies.c +++ b/src/compiler/nir/nir_split_var_copies.c @@ -82,7 +82,7 @@ struct split_var_copies_state { */ static void split_var_copy_instr(nir_intrinsic_instr *old_copy, - nir_deref *dest_head, nir_deref *src_head, + nir_deref_var *dest_head, nir_deref_var *src_head, nir_deref *dest_tail, nir_deref *src_tail, struct split_var_copies_state *state) { @@ -182,11 +182,8 @@ split_var_copy_instr(nir_intrinsic_instr *old_copy, * belongs to the copy instruction and b) the deref chains may * have some of the same links due to the way we constructed them */ - nir_deref *src = nir_copy_deref(new_copy, src_head); - nir_deref *dest = nir_copy_deref(new_copy, dest_head); - - new_copy->variables[0] = nir_deref_as_var(dest); - new_copy->variables[1] = nir_deref_as_var(src); + new_copy->variables[0] = nir_deref_var_clone(dest_head, new_copy); + new_copy->variables[1] = nir_deref_var_clone(src_head, new_copy); /* Emit the copy instruction after the old instruction. We'll * remove the old one later. @@ -216,10 +213,10 @@ split_var_copies_block(nir_block *block, struct split_var_copies_state *state) if (intrinsic->intrinsic != nir_intrinsic_copy_var) continue; - nir_deref *dest_head = &intrinsic->variables[0]->deref; - nir_deref *src_head = &intrinsic->variables[1]->deref; - nir_deref *dest_tail = nir_deref_tail(dest_head); - nir_deref *src_tail = nir_deref_tail(src_head); + nir_deref_var *dest_head = intrinsic->variables[0]; + nir_deref_var *src_head = intrinsic->variables[1]; + nir_deref *dest_tail = nir_deref_tail(&dest_head->deref); + nir_deref *src_tail = nir_deref_tail(&src_head->deref); switch (glsl_get_base_type(src_tail->type)) { case GLSL_TYPE_ARRAY: |