diff --git a/src/.clang-format b/src/.clang-format index 27c0dae5970..f55d7db76e9 100644 --- a/src/.clang-format +++ b/src/.clang-format @@ -196,6 +196,7 @@ ForEachMacros: - agx_foreach_block_from_rev - agx_foreach_block_rev - agx_foreach_dest + - agx_foreach_dest_rev - agx_foreach_instr_global - agx_foreach_instr_global_rev - agx_foreach_instr_global_safe @@ -208,10 +209,14 @@ ForEachMacros: - agx_foreach_instr_in_block_safe_rev - agx_foreach_non_phi_in_block_rev - agx_foreach_phi_in_block + - agx_foreach_phi_in_block_safe - agx_foreach_predecessor - agx_foreach_src + - agx_foreach_src_rev - agx_foreach_ssa_dest + - agx_foreach_ssa_dest_rev - agx_foreach_ssa_src + - agx_foreach_ssa_src_rev - agx_foreach_successor # radv diff --git a/src/asahi/compiler/agx_compiler.h b/src/asahi/compiler/agx_compiler.h index 5483c67e0ed..4ec39735e7b 100644 --- a/src/asahi/compiler/agx_compiler.h +++ b/src/asahi/compiler/agx_compiler.h @@ -639,16 +639,30 @@ agx_start_block(agx_context *ctx) #define agx_foreach_src(ins, v) for (unsigned v = 0; v < ins->nr_srcs; ++v) +#define agx_foreach_src_rev(ins, v) \ + for (signed v = ins->nr_srcs - 1; v >= 0; --v) + #define agx_foreach_dest(ins, v) for (unsigned v = 0; v < ins->nr_dests; ++v) +#define agx_foreach_dest_rev(ins, v) \ + for (signed v = ins->nr_dests - 1; v >= 0; --v) + #define agx_foreach_ssa_src(ins, v) \ agx_foreach_src(ins, v) \ if (ins->src[v].type == AGX_INDEX_NORMAL) +#define agx_foreach_ssa_src_rev(ins, v) \ + agx_foreach_src_rev(ins, v) \ + if (ins->src[v].type == AGX_INDEX_NORMAL) + #define agx_foreach_ssa_dest(ins, v) \ agx_foreach_dest(ins, v) \ if (ins->dest[v].type == AGX_INDEX_NORMAL) +#define agx_foreach_ssa_dest_rev(ins, v) \ + agx_foreach_dest_rev(ins, v) \ + if (ins->dest[v].type == AGX_INDEX_NORMAL) + /* Phis only come at the start (after else instructions) so we stop as soon as * we hit a non-phi */ @@ -660,6 +674,14 @@ agx_start_block(agx_context *ctx) break; \ else +#define agx_foreach_phi_in_block_safe(block, v) \ + agx_foreach_instr_in_block_safe(block, v) \ + if (v->op == AGX_OPCODE_ELSE_ICMP || v->op == AGX_OPCODE_ELSE_FCMP) \ + continue; \ + else if (v->op != AGX_OPCODE_PHI) \ + break; \ + else + /* * Find the index of a predecessor, used as the implicit order of phi sources. */