From 3bf3c45ae8b7de7ec6c99664b5561a38614ce5aa Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 28 Jul 2022 11:07:46 -0400 Subject: [PATCH] pan/bi: Add and use bi_num_successors helper Makes a few patterns easier to read. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bir.c | 17 +++-------------- src/panfrost/bifrost/compiler.h | 16 +++++++++++++++- src/panfrost/bifrost/valhall/va_merge_flow.c | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/panfrost/bifrost/bir.c b/src/panfrost/bifrost/bir.c index 8958756c235..92076f9c667 100644 --- a/src/panfrost/bifrost/bir.c +++ b/src/panfrost/bifrost/bir.c @@ -230,21 +230,10 @@ 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; } /* diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index b8a462c6c4d..1502560bd18 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -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; } diff --git a/src/panfrost/bifrost/valhall/va_merge_flow.c b/src/panfrost/bifrost/valhall/va_merge_flow.c index 42475c24164..64f3c38c9ae 100644 --- a/src/panfrost/bifrost/valhall/va_merge_flow.c +++ b/src/panfrost/bifrost/valhall/va_merge_flow.c @@ -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; }