pan/bi: Add and use bi_num_successors helper
authorAlyssa Rosenzweig <alyssa@collabora.com>
Thu, 28 Jul 2022 15:07:46 +0000 (11:07 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Sep 2022 16:03:24 +0000 (16:03 +0000)
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>

src/panfrost/bifrost/bir.c
src/panfrost/bifrost/compiler.h
src/panfrost/bifrost/valhall/va_merge_flow.c

index 8958756..92076f9 100644 (file)
@@ -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]);
-                return true;
-        }
-
-        /* Multiple successors? We're branching */
-        if (block->successors[1])
+        if (bi_num_successors(block) == 1)
+                return bi_num_predecessors(block->successors[0]) > 1;
+        else
                 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;
 }
 
 /*
index b8a462c..1502560 100644 (file)
@@ -731,6 +731,20 @@ typedef struct bi_block {
 } 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)
 {
         return util_dynarray_num_elements(&block->predecessors, bi_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;
 }
 
index 42475c2..64f3c38 100644 (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;
          }