pan/bi: Lift bi_predecessor_index helper
authorAlyssa Rosenzweig <alyssa@collabora.com>
Mon, 9 May 2022 21:10:18 +0000 (17:10 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Sep 2022 16:03:23 +0000 (16:03 +0000)
From AGX for handling phi node.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17794>

src/panfrost/bifrost/compiler.h

index 344aab4..bb8f582 100644 (file)
@@ -1060,6 +1060,23 @@ bi_node_to_index(unsigned node, unsigned node_count)
         bi_foreach_instr_in_tuple(tuple, ins) \
                 bi_foreach_src(ins, s)
 
+/*
+ * Find the index of a predecessor, used as the implicit order of phi sources.
+ */
+static inline unsigned
+bi_predecessor_index(bi_block *succ, bi_block *pred)
+{
+        unsigned index = 0;
+
+        bi_foreach_predecessor(succ, x) {
+                if (*x == pred) return index;
+
+                index++;
+        }
+
+        unreachable("Invalid predecessor");
+}
+
 static inline bi_instr *
 bi_prev_op(bi_instr *ins)
 {