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: 0ffcb19b9d
("ir3: Rewrite register allocation")
Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12923>
This commit is contained in:
parent
344683c932
commit
24326f25b9
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue