pan/bi: Use safe helpers to remove srcs/dests

Changing I->nr_srcs or I->nr_dests directly is generally unsafe, but the special
case of removing sources/destinations at the end is safe. Add and use helpers to
wrap this operation simplifying the remaining code audit before we can
dynamically allocate sources/destinations.

At this point in the series, nothing modifies I->nr_dests after allocation
except these helpers, so destinations should be safe to make dynamic. There's a
bit more work needed for sources.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17794>
This commit is contained in:
Alyssa Rosenzweig 2022-07-22 11:46:51 -04:00 committed by Marge Bot
parent 9c45ce309d
commit 50995dcb90
4 changed files with 32 additions and 11 deletions

View file

@ -744,8 +744,7 @@ bi_lower_texc_dual(bi_context *ctx)
if (I->op == BI_OPCODE_TEXC_DUAL) {
/* In hardware, TEXC has 1 destination */
I->op = BI_OPCODE_TEXC;
I->dest[1] = bi_null();
I->nr_dests = 1;
bi_drop_dests(I, 1);
}
}
}

View file

@ -328,13 +328,10 @@ bi_lower_cubeface(bi_context *ctx,
pinstr->op = BI_OPCODE_CUBEFACE2;
pinstr->dest[0] = pinstr->dest[1];
pinstr->dest[1] = bi_null();
pinstr->nr_dests = 1;
bi_drop_dests(pinstr, 1);
pinstr->src[0] = cubeface1->dest[0];
pinstr->src[1] = bi_null();
pinstr->src[2] = bi_null();
pinstr->nr_srcs = 1;
bi_drop_srcs(pinstr, 1);
return cubeface1;
}
@ -397,8 +394,7 @@ bi_lower_seg_add(bi_context *ctx,
pinstr->op = BI_OPCODE_SEG_ADD;
pinstr->src[0] = pinstr->src[1];
pinstr->src[1] = bi_null();
pinstr->nr_srcs = 1;
bi_drop_srcs(pinstr, 1);
assert(pinstr->dest[0].type == BI_INDEX_REGISTER);
pinstr->dest[0].value += 1;

View file

@ -547,6 +547,33 @@ bi_is_staging_src(const bi_instr *I, unsigned s)
return (s == 0 || s == 4) && bi_opcode_props[I->op].sr_read;
}
/*
* Safe helpers to remove destinations/sources at the end of the
* destination/source array when changing opcodes. Unlike adding
* sources/destinations, this does not require reallocation.
*/
static inline void
bi_drop_dests(bi_instr *I, unsigned new_count)
{
assert(new_count < I->nr_dests);
for (unsigned i = new_count; i < I->nr_dests; ++i)
I->dest[i] = bi_null();
I->nr_dests = new_count;
}
static inline void
bi_drop_srcs(bi_instr *I, unsigned new_count)
{
assert(new_count < I->nr_srcs);
for (unsigned i = new_count; i < I->nr_srcs; ++i)
I->src[i] = bi_null();
I->nr_srcs = new_count;
}
/* Represents the assignment of slots for a given bi_tuple */
typedef struct {

View file

@ -105,8 +105,7 @@ va_fuse_add_imm(bi_instr *I)
}
I->src[0] = I->src[1 - s];
I->src[1] = bi_null();
I->nr_srcs = 1;
bi_drop_srcs(I, 1);
}
void