Mesa (main): pan/bi: Use a dynarray for predecessors
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue May 3 18:20:09 UTC 2022
Module: Mesa
Branch: main
Commit: 80f8e9da162ba50206c94b7915548f96cdd1ad51
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=80f8e9da162ba50206c94b7915548f96cdd1ad51
Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date: Tue Apr 19 18:58:27 2022 -0400
pan/bi: Use a dynarray for predecessors
This is deterministic, unlike a set. Note we need the extra dereferencing to
keep the macro safe, simple, and standards compliant:
1. Nesting two for-loops would cause break/continue to fail.
2. Declaring variables outside the loop would pollute the namespace.
3. Declaring an anonymous struct is not conformant and doesn't compile in clang.
Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16279>
---
src/panfrost/bifrost/bi_helper_invocations.c | 6 +++---
src/panfrost/bifrost/bi_liveness.c | 2 +-
src/panfrost/bifrost/bi_opt_dce.c | 2 +-
src/panfrost/bifrost/bi_print.c | 4 ++--
src/panfrost/bifrost/bi_scoreboard.c | 4 ++--
src/panfrost/bifrost/bi_test.h | 5 +----
src/panfrost/bifrost/bifrost_compile.c | 6 ++----
src/panfrost/bifrost/bir.c | 3 +--
src/panfrost/bifrost/compiler.h | 20 +++++++++-----------
9 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/src/panfrost/bifrost/bi_helper_invocations.c b/src/panfrost/bifrost/bi_helper_invocations.c
index fb2f1ccda2f..c4e8dcd7a9d 100644
--- a/src/panfrost/bifrost/bi_helper_invocations.c
+++ b/src/panfrost/bifrost/bi_helper_invocations.c
@@ -143,8 +143,8 @@ bi_propagate_pass_flag(bi_block *block)
block->pass_flags = 1;
bi_foreach_predecessor(block, pred) {
- if (pred->pass_flags == 0)
- bi_propagate_pass_flag(pred);
+ if ((*pred)->pass_flags == 0)
+ bi_propagate_pass_flag(*pred);
}
}
@@ -243,7 +243,7 @@ bi_analyze_helper_requirements(bi_context *ctx)
if (bi_helper_block_update(deps, blk)) {
bi_foreach_predecessor(blk, pred)
- bi_worklist_push_head(&worklist, pred);
+ bi_worklist_push_head(&worklist, *pred);
}
}
diff --git a/src/panfrost/bifrost/bi_liveness.c b/src/panfrost/bifrost/bi_liveness.c
index 069ceff88b3..6c8070337d5 100644
--- a/src/panfrost/bifrost/bi_liveness.c
+++ b/src/panfrost/bifrost/bi_liveness.c
@@ -121,7 +121,7 @@ bi_compute_liveness(bi_context *ctx)
*/
if (liveness_block_update(blk, temp_count)) {
bi_foreach_predecessor(blk, pred)
- bi_worklist_push_head(&worklist, pred);
+ bi_worklist_push_head(&worklist, *pred);
}
}
diff --git a/src/panfrost/bifrost/bi_opt_dce.c b/src/panfrost/bifrost/bi_opt_dce.c
index abb2600342b..38f2537a74f 100644
--- a/src/panfrost/bifrost/bi_opt_dce.c
+++ b/src/panfrost/bifrost/bi_opt_dce.c
@@ -133,7 +133,7 @@ bi_postra_liveness(bi_context *ctx)
*/
if (bi_postra_liveness_block(blk)) {
bi_foreach_predecessor(blk, pred)
- bi_worklist_push_head(&worklist, pred);
+ bi_worklist_push_head(&worklist, *pred);
}
}
diff --git a/src/panfrost/bifrost/bi_print.c b/src/panfrost/bifrost/bi_print.c
index 85f71f5e588..8aa0293dfe1 100644
--- a/src/panfrost/bifrost/bi_print.c
+++ b/src/panfrost/bifrost/bi_print.c
@@ -177,11 +177,11 @@ bi_print_block(bi_block *block, FILE *fp)
fprintf(fp, "block%u ", succ->index);
}
- if (block->predecessors->entries) {
+ if (bi_num_predecessors(block)) {
fprintf(fp, " from");
bi_foreach_predecessor(block, pred)
- fprintf(fp, " block%u", pred->index);
+ fprintf(fp, " block%u", (*pred)->index);
}
if (block->scheduled) {
diff --git a/src/panfrost/bifrost/bi_scoreboard.c b/src/panfrost/bifrost/bi_scoreboard.c
index d9a42ab0c9f..f54e413e8da 100644
--- a/src/panfrost/bifrost/bi_scoreboard.c
+++ b/src/panfrost/bifrost/bi_scoreboard.c
@@ -252,8 +252,8 @@ scoreboard_block_update(bi_block *blk)
/* pending_in[s] = sum { p in pred[s] } ( pending_out[p] ) */
bi_foreach_predecessor(blk, pred) {
for (unsigned i = 0; i < BI_NUM_SLOTS; ++i) {
- blk->scoreboard_in.read[i] |= pred->scoreboard_out.read[i];
- blk->scoreboard_in.write[i] |= pred->scoreboard_out.write[i];
+ blk->scoreboard_in.read[i] |= (*pred)->scoreboard_out.read[i];
+ blk->scoreboard_in.write[i] |= (*pred)->scoreboard_out.write[i];
}
}
diff --git a/src/panfrost/bifrost/bi_test.h b/src/panfrost/bifrost/bi_test.h
index 9a745fef6f2..e39aa006a6b 100644
--- a/src/panfrost/bifrost/bi_test.h
+++ b/src/panfrost/bifrost/bi_test.h
@@ -41,10 +41,7 @@ bit_builder(void *memctx)
bi_block *blk = rzalloc(ctx, bi_block);
- blk->predecessors = _mesa_set_create(blk,
- _mesa_hash_pointer,
- _mesa_key_pointer_equal);
-
+ util_dynarray_init(&blk->predecessors, blk);
list_addtail(&blk->link, &ctx->blocks);
list_inithead(&blk->instructions);
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c
index c653530e939..5464e581024 100644
--- a/src/panfrost/bifrost/bifrost_compile.c
+++ b/src/panfrost/bifrost/bifrost_compile.c
@@ -88,7 +88,7 @@ bi_block_add_successor(bi_block *block, bi_block *successor)
}
block->successors[i] = successor;
- _mesa_set_add(successor->predecessors, block);
+ util_dynarray_append(&successor->predecessors, bi_block *, block);
return;
}
@@ -3539,9 +3539,7 @@ create_empty_block(bi_context *ctx)
{
bi_block *blk = rzalloc(ctx, bi_block);
- blk->predecessors = _mesa_set_create(blk,
- _mesa_hash_pointer,
- _mesa_key_pointer_equal);
+ util_dynarray_init(&blk->predecessors, blk);
return blk;
}
diff --git a/src/panfrost/bifrost/bir.c b/src/panfrost/bifrost/bir.c
index d7ac4b283c0..d7106a23aae 100644
--- a/src/panfrost/bifrost/bir.c
+++ b/src/panfrost/bifrost/bir.c
@@ -222,8 +222,7 @@ bi_reconverge_branches(bi_block *block)
/* Must have at least one successor */
struct bi_block *succ = block->successors[0];
- assert(succ->predecessors);
/* Reconverge if the successor has multiple predecessors */
- return (succ->predecessors->entries > 1);
+ return bi_num_predecessors(succ) > 1;
}
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index c3cf7868959..40d39a14e28 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -663,7 +663,7 @@ typedef struct bi_block {
/* Control flow graph */
struct bi_block *successors[2];
- struct set *predecessors;
+ struct util_dynarray predecessors;
bool unconditional_jumps;
/* Per 32-bit word live masks for the block indexed by node */
@@ -684,11 +684,17 @@ typedef struct bi_block {
uint8_t pass_flags;
} bi_block;
+static inline unsigned
+bi_num_predecessors(bi_block *block)
+{
+ return util_dynarray_num_elements(&block->predecessors, bi_block *);
+}
+
static inline bi_block *
bi_start_block(struct list_head *blocks)
{
bi_block *first = list_first_entry(blocks, bi_block, link);
- assert(first->predecessors->entries == 0);
+ assert(bi_num_predecessors(first) == 0);
return first;
}
@@ -969,16 +975,8 @@ bi_node_to_index(unsigned node, unsigned node_count)
v != NULL && _v < &blk->successors[2]; \
_v++, v = *_v) \
-/* Based on set_foreach, expanded with automatic type casts */
-
#define bi_foreach_predecessor(blk, v) \
- struct set_entry *_entry_##v; \
- bi_block *v; \
- for (_entry_##v = _mesa_set_next_entry(blk->predecessors, NULL), \
- v = (bi_block *) (_entry_##v ? _entry_##v->key : NULL); \
- _entry_##v != NULL; \
- _entry_##v = _mesa_set_next_entry(blk->predecessors, _entry_##v), \
- v = (bi_block *) (_entry_##v ? _entry_##v->key : NULL))
+ util_dynarray_foreach(&(blk)->predecessors, bi_block *, v)
#define bi_foreach_src(ins, v) \
for (unsigned v = 0; v < ARRAY_SIZE(ins->src); ++v)
More information about the mesa-commit
mailing list