Lines Matching refs:deref
44 nir_deref_instr *deref, void *mem_ctx)
46 assert(deref != NULL);
59 for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {
82 for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {
103 * Recursively removes unused deref instructions
111 /* If anyone is using this deref, leave it alone */
157 nir_deref_instr_has_complex_use(nir_deref_instr *deref)
159 nir_foreach_use(use_src, &deref->dest.ssa) {
166 /* A var deref has no sources */
169 /* If a deref shows up in an array index or something like that, it's
175 /* Anything that isn't a basic struct or array deref is considered to
228 nir_foreach_if_use(use, &deref->dest.ssa)
243 nir_deref_instr_array_stride(nir_deref_instr *deref)
245 switch (deref->deref_type) {
248 const struct glsl_type *arr_type = nir_deref_instr_parent(deref)->type;
259 return nir_deref_instr_array_stride(nir_deref_instr_parent(deref));
261 return deref->cast.ptr_stride;
294 nir_deref_instr_get_const_offset(nir_deref_instr *deref,
298 nir_deref_path_init(&path, deref, NULL);
318 unreachable("Unsupported deref type");
328 nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
332 nir_deref_path_init(&path, deref, NULL);
334 nir_ssa_def *offset = nir_imm_intN_t(b, 0, deref->dest.ssa.bit_size);
357 unreachable("Unsupported deref type");
410 nir_deref_instr *deref = nir_instr_as_deref(instr);
411 if (deref->deref_type == nir_deref_type_cast)
415 if (deref->deref_type == nir_deref_type_var) {
416 parent_modes = deref->var->data.mode;
418 assert(deref->parent.is_ssa);
420 nir_instr_as_deref(deref->parent.ssa->parent_instr);
424 deref->modes = parent_modes;
507 /* If we can chase the deref all the way back to the variable and
518 * just assume nit_opt_deref will combine them and compare the deref
544 /* We're at either the tail or the divergence point between the two deref
545 * paths. Look to see if either contains cast or a ptr_as_array deref. If
551 * case where we have exactly one ptr_as_array deref in the chain after the
615 unreachable("Invalid deref type");
656 nir_deref_path *nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref)
658 if (!deref->_path) {
659 deref->_path = ralloc(mem_ctx, nir_deref_path);
660 nir_deref_path_init(deref->_path, deref->instr, mem_ctx);
662 return deref->_path;
684 rematerialize_deref_in_block(nir_deref_instr *deref,
687 if (deref->instr.block == state->block)
688 return deref;
694 struct hash_entry *cached = _mesa_hash_table_search(state->cache, deref);
700 nir_deref_instr_create(b->shader, deref->deref_type);
701 new_deref->modes = deref->modes;
702 new_deref->type = deref->type;
704 if (deref->deref_type == nir_deref_type_var) {
705 new_deref->var = deref->var;
707 nir_deref_instr *parent = nir_src_as_deref(deref->parent);
712 nir_src_copy(&new_deref->parent, &deref->parent);
716 switch (deref->deref_type) {
723 new_deref->cast.ptr_stride = deref->cast.ptr_stride;
728 assert(!nir_src_as_deref(deref->arr.index));
729 nir_src_copy(&new_deref->arr.index, &deref->arr.index);
733 new_deref->strct.index = deref->strct.index;
737 unreachable("Invalid deref instruction type");
741 deref->dest.ssa.num_components,
742 deref->dest.ssa.bit_size,
754 nir_deref_instr *deref = nir_src_as_deref(*src);
755 if (!deref)
758 nir_deref_instr *block_deref = rematerialize_deref_in_block(deref, state);
759 if (block_deref != deref) {
762 nir_deref_instr_remove_if_unused(deref);
771 * This pass re-materializes deref instructions in every block in which it is
772 * used. After this pass has been run, every use of a deref will be of a
773 * deref in the same block as the use. Also, all unused derefs will be
796 /* If a deref is used in a phi, we can't rematerialize it, as the new
902 * somehow disagrees with the smaller alignment further up the deref chain.
910 /* If we've gotten here, we have a parent deref with an align_mul at least
912 * information on this deref. There are two cases to consider here:
914 * 1. We can chase the deref all the way back to the variable. In this
917 * calculations, our knowledge from the deref walk is better than the
923 * get here is if something further up the deref chain has a cast with
926 * provided us with two conflicting alignments in the deref chain,
930 * away the alignment information on this deref. However, to be "nice" to
973 * If we know from something higher up the deref chain that the deref has a
979 opt_restrict_deref_modes(nir_deref_instr *deref)
981 if (deref->deref_type == nir_deref_type_var) {
982 assert(deref->modes == deref->var->data.mode);
986 nir_deref_instr *parent = nir_src_as_deref(deref->parent);
987 if (parent == NULL || parent->modes == deref->modes)
990 assert(parent->modes & deref->modes);
991 deref->modes &= parent->modes;
1027 /* Recursively crawl the deref tree and clean up types */
1088 /* If this deref still contains useful alignment information, we don't want
1121 opt_deref_ptr_as_array(nir_builder *b, nir_deref_instr *deref)
1123 assert(deref->deref_type == nir_deref_type_ptr_as_array);
1125 nir_deref_instr *parent = nir_deref_instr_parent(deref);
1127 if (nir_src_is_const(deref->arr.index) &&
1128 nir_src_as_int(deref->arr.index) == 0) {
1129 /* If it's a ptr_as_array deref with an index of 0, it does nothing
1133 * The source of a ptr_as_array deref always has a deref_type of
1143 nir_ssa_def_rewrite_uses(&deref->dest.ssa,
1145 nir_instr_remove(&deref->instr);
1155 assert(deref->arr.index.is_ssa);
1158 deref->arr.index.ssa);
1160 deref->deref_type = parent->deref_type;
1161 nir_instr_rewrite_src(&deref->instr, &deref->parent, parent->parent);
1162 nir_instr_rewrite_src(&deref->instr, &deref->arr.index,
1179 /* It has to be a cast of another deref */
1230 nir_deref_instr *deref = nir_src_as_deref(load->src[0]);
1238 if (is_vector_bitcast_deref(deref, read_mask, false)) {
1242 nir_deref_instr *parent = nir_src_as_deref(deref->parent);
1271 nir_deref_instr *deref = nir_src_as_deref(store->src[0]);
1278 if (is_vector_bitcast_deref(deref, write_mask, true)) {
1284 nir_deref_instr *parent = nir_src_as_deref(deref->parent);
1314 nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
1315 if (deref == NULL)
1320 if (nir_deref_mode_must_be(deref, modes))
1323 if (!nir_deref_mode_may_be(deref, modes))
1348 nir_deref_instr *deref = nir_instr_as_deref(instr);
1350 if (opt_restrict_deref_modes(deref))
1353 switch (deref->deref_type) {
1355 if (opt_deref_ptr_as_array(&b, deref))
1360 if (opt_deref_cast(&b, deref))