pan/bi: Add and use bi_num_successors helper

Makes a few patterns easier to read.

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-28 11:07:46 -04:00
committed by Marge Bot
parent 875a34160a
commit 3bf3c45ae8
3 changed files with 19 additions and 16 deletions

View File

@@ -230,23 +230,12 @@ bi_side_effects(const bi_instr *I)
bool
bi_reconverge_branches(bi_block *block)
{
/* Last block of a program */
if (!block->successors[0]) {
assert(!block->successors[1]);
if (bi_num_successors(block) == 1)
return bi_num_predecessors(block->successors[0]) > 1;
else
return true;
}
/* Multiple successors? We're branching */
if (block->successors[1])
return true;
/* Must have at least one successor */
struct bi_block *succ = block->successors[0];
/* Reconverge if the successor has multiple predecessors */
return bi_num_predecessors(succ) > 1;
}
/*
* When MUX.i32 or MUX.v2i16 is used to multiplex entire sources, they can be
* replaced by CSEL as follows:

View File

@@ -730,6 +730,20 @@ typedef struct bi_block {
uint8_t pass_flags;
} bi_block;
static inline unsigned
bi_num_successors(bi_block *block)
{
STATIC_ASSERT(ARRAY_SIZE(block->successors) == 2);
assert(block->successors[0] || !block->successors[1]);
if (block->successors[1])
return 2;
else if (block->successors[0])
return 1;
else
return 0;
}
static inline unsigned
bi_num_predecessors(bi_block *block)
{
@@ -748,7 +762,7 @@ static inline bi_block *
bi_exit_block(struct list_head *blocks)
{
bi_block *last = list_last_entry(blocks, bi_block, link);
assert(!last->successors[0] && !last->successors[1]);
assert(bi_num_successors(last) == 0);
return last;
}

View File

@@ -195,7 +195,7 @@ merge_discard(bi_block *block)
/* If there's nowhere to merge and this is the end of the shader, just
* remove the discard.
*/
if (!block->successors[0] && !block->successors[1]) {
if (bi_num_successors(block) == 0) {
bi_remove_instruction(I);
continue;
}