From eca516ebdb8cf993a30f9f7acf36071b10f674df Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 6 Jan 2021 12:22:36 -0500 Subject: [PATCH] pan/bi: Add bi_foreach_instr_in_clause iterators These are convenient for post-sched passes, in particular register allocation. They work by noting the underlying linked list of instructions in the block must be preserved by scheduling. It isn't necessary iterate the clause structure directly, it can simply be used to bound a iteration within the block by recalling clauses are strictly contained in a single block. I don't think I'm enough of a C ninja to write fancy iterator macros yet. sometimes those can get pretty mind-bendy Signed-off-by: Alyssa Rosenzweig Reviewed-by: Boris Brezillon Part-of: --- src/panfrost/bifrost/compiler.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 3a2940ed0c2..bea25bc9083 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -807,6 +807,21 @@ bi_last_instr_in_clause(bi_clause *clause) return bundle.add ?: bundle.fma; } +/* Implemented by expanding bi_foreach_instr_in_block_from(_rev) with the start + * (end) of the clause and adding a condition for the clause boundary */ + +#define bi_foreach_instr_in_clause(block, clause, pos) \ + for (bi_instr *pos = LIST_ENTRY(bi_instr, bi_first_instr_in_clause(clause), link); \ + (&pos->link != &(block)->base.instructions) \ + && (pos != bi_next_op(bi_last_instr_in_clause(clause))); \ + pos = LIST_ENTRY(bi_instr, pos->link.next, link)) + +#define bi_foreach_instr_in_clause_rev(block, clause, pos) \ + for (bi_instr *pos = LIST_ENTRY(bi_instr, bi_last_instr_in_clause(clause), link); \ + (&pos->link != &(block)->base.instructions) \ + && pos != bi_prev_op(bi_first_instr_in_clause(clause)); \ + pos = LIST_ENTRY(bi_instr, pos->link.prev, link)) + static inline bi_cursor bi_before_clause(bi_clause *clause) {