Module: Mesa Branch: main Commit: 24326f25b918d9f4ee0e4eb48108bffcf3cc2268 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=24326f25b918d9f4ee0e4eb48108bffcf3cc2268
Author: Rob Clark <[email protected]> Date: Sat Sep 18 09:32:21 2021 -0700 freedreno/ir3: Cleanup liveness lifetime I'm going to want to use this in other passes, so lets let the allocation hang off the pass's context. Also, while we're at it, fix the error path leak in ir3_ra(). Fixes: 0ffcb19b9d9 ("ir3: Rewrite register allocation") Signed-off-by: Rob Clark <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12923> --- src/freedreno/ir3/ir3_liveness.c | 10 +++++----- src/freedreno/ir3/ir3_ra.c | 22 +++++++++++++--------- src/freedreno/ir3/ir3_ra.h | 2 +- src/freedreno/ir3/ir3_spill.c | 5 +++-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/freedreno/ir3/ir3_liveness.c b/src/freedreno/ir3/ir3_liveness.c index 4cdf5fb3c94..c343728800e 100644 --- a/src/freedreno/ir3/ir3_liveness.c +++ b/src/freedreno/ir3/ir3_liveness.c @@ -115,9 +115,9 @@ compute_block_liveness(struct ir3_liveness *live, struct ir3_block *block, } struct ir3_liveness * -ir3_calc_liveness(struct ir3_shader_variant *v) +ir3_calc_liveness(void *mem_ctx, struct ir3 *ir) { - struct ir3_liveness *live = rzalloc(NULL, struct ir3_liveness); + struct ir3_liveness *live = rzalloc(mem_ctx, struct ir3_liveness); /* Reserve name 0 to mean "doesn't have a name yet" to make the debug * output nicer. @@ -126,7 +126,7 @@ ir3_calc_liveness(struct ir3_shader_variant *v) /* Build definition <-> name mapping */ unsigned block_count = 0; - foreach_block (block, &v->ir->block_list) { + foreach_block (block, &ir->block_list) { block->index = block_count++; foreach_instr (instr, &block->instr_list) { ra_foreach_dst (dst, instr) { @@ -143,7 +143,7 @@ ir3_calc_liveness(struct ir3_shader_variant *v) live->live_in = ralloc_array(live, BITSET_WORD *, block_count); live->live_out = ralloc_array(live, BITSET_WORD *, block_count); unsigned i = 0; - foreach_block (block, &v->ir->block_list) { + foreach_block (block, &ir->block_list) { block->index = i++; live->live_in[block->index] = rzalloc_array(live, BITSET_WORD, bitset_words); @@ -154,7 +154,7 @@ ir3_calc_liveness(struct ir3_shader_variant *v) bool progress = true; while (progress) { progress = false; - foreach_block_rev (block, &v->ir->block_list) { + foreach_block_rev (block, &ir->block_list) { progress |= compute_block_liveness(live, block, tmp_live, bitset_words); } diff --git a/src/freedreno/ir3/ir3_ra.c b/src/freedreno/ir3/ir3_ra.c index c2dbe43723a..f03ceef4b24 100644 --- a/src/freedreno/ir3/ir3_ra.c +++ b/src/freedreno/ir3/ir3_ra.c @@ -2143,7 +2143,13 @@ ir3_ra(struct ir3_shader_variant *v) ir3_create_parallel_copies(v->ir); - struct ir3_liveness *live = ir3_calc_liveness(v); + struct ra_ctx *ctx = rzalloc(NULL, struct ra_ctx); + + ctx->merged_regs = v->mergedregs; + ctx->compiler = v->shader->compiler; + ctx->stage = v->type; + + struct ir3_liveness *live = ir3_calc_liveness(ctx, v->ir); ir3_debug_print(v->ir, "AFTER: create_parallel_copies"); @@ -2169,7 +2175,7 @@ ir3_ra(struct ir3_shader_variant *v) if (max_pressure.shared > limit_pressure.shared) { /* TODO shared reg -> normal reg spilling */ d("shared max pressure exceeded!"); - return 1; + goto fail; } bool spilled = false; @@ -2177,7 +2183,7 @@ ir3_ra(struct ir3_shader_variant *v) max_pressure.half > limit_pressure.half) { if (!v->shader->compiler->has_pvtmem) { d("max pressure exceeded!"); - return 1; + goto fail; } d("max pressure exceeded, spilling!"); IR3_PASS(v->ir, ir3_spill, v, &live, &limit_pressure); @@ -2187,11 +2193,6 @@ ir3_ra(struct ir3_shader_variant *v) spilled = true; } - struct ra_ctx *ctx = rzalloc(NULL, struct ra_ctx); - - ctx->merged_regs = v->mergedregs; - ctx->compiler = v->shader->compiler; - ctx->stage = v->type; ctx->live = live; ctx->intervals = rzalloc_array(ctx, struct ra_interval, live->definitions_count); @@ -2250,6 +2251,9 @@ ir3_ra(struct ir3_shader_variant *v) ir3_debug_print(v->ir, "AFTER: ir3_lower_copies"); ralloc_free(ctx); - ralloc_free(live); + return 0; +fail: + ralloc_free(ctx); + return -1; } diff --git a/src/freedreno/ir3/ir3_ra.h b/src/freedreno/ir3/ir3_ra.h index 4a7c9d7752a..259341eaac9 100644 --- a/src/freedreno/ir3/ir3_ra.h +++ b/src/freedreno/ir3/ir3_ra.h @@ -143,7 +143,7 @@ struct ir3_liveness { DECLARE_ARRAY(BITSET_WORD *, live_in); }; -struct ir3_liveness *ir3_calc_liveness(struct ir3_shader_variant *v); +struct ir3_liveness *ir3_calc_liveness(void *mem_ctx, struct ir3 *ir); bool ir3_def_live_after(struct ir3_liveness *live, struct ir3_register *def, struct ir3_instruction *instr); diff --git a/src/freedreno/ir3/ir3_spill.c b/src/freedreno/ir3/ir3_spill.c index 0b9c56a7680..38627f4db02 100644 --- a/src/freedreno/ir3/ir3_spill.c +++ b/src/freedreno/ir3/ir3_spill.c @@ -1962,7 +1962,8 @@ ir3_spill(struct ir3 *ir, struct ir3_shader_variant *v, struct ir3_liveness **live, const struct ir3_pressure *limit_pressure) { - struct ra_spill_ctx *ctx = rzalloc(NULL, struct ra_spill_ctx); + void *mem_ctx = ralloc_parent(*live); + struct ra_spill_ctx *ctx = rzalloc(mem_ctx, struct ra_spill_ctx); spill_ctx_init(ctx, v, *live); ctx->spilling = true; @@ -1994,7 +1995,7 @@ ir3_spill(struct ir3 *ir, struct ir3_shader_variant *v, * so recalculate it. We'll need it for recalculating the merge sets. */ ralloc_free(ctx->live); - *live = ir3_calc_liveness(v); + *live = ir3_calc_liveness(mem_ctx, ir); fixup_merge_sets(*live, ir);
