From 56e1c606f89134e7033e25ca65a23478e13365b8 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 11 Mar 2020 14:54:49 -0400 Subject: [PATCH] pan/bi: Add liveness analysis pass Now that all the guts are shared with Midgard, it's just a matter of wiring it in. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_liveness.c | 88 ++++++++++++++++++++++++++++++ src/panfrost/bifrost/compiler.h | 10 ++++ src/panfrost/bifrost/meson.build | 1 + 3 files changed, 99 insertions(+) create mode 100644 src/panfrost/bifrost/bi_liveness.c diff --git a/src/panfrost/bifrost/bi_liveness.c b/src/panfrost/bifrost/bi_liveness.c new file mode 100644 index 00000000000..335562ca3e9 --- /dev/null +++ b/src/panfrost/bifrost/bi_liveness.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2020 Collabora, Ltd. + * Copyright (C) 2018-2019 Alyssa Rosenzweig + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "compiler.h" + +void +bi_liveness_ins_update(uint16_t *live, bi_instruction *ins, unsigned max) +{ + /* live_in[s] = GEN[s] + (live_out[s] - KILL[s]) */ + + pan_liveness_kill(live, ins->dest, max, ins->writemask); + + bi_foreach_src(ins, src) { + unsigned node = ins->src[src]; + unsigned bytemask = bi_bytemask_of_read_components(ins, node); + + pan_liveness_gen(live, node, max, bytemask); + } +} + +static void +bi_liveness_ins_update_wrap(uint16_t *live, void *ins, unsigned max) +{ + bi_liveness_ins_update(live, (bi_instruction *) ins, max); +} + +void +bi_compute_liveness(bi_context *ctx) +{ + if (ctx->has_liveness) + return; + + pan_compute_liveness(&ctx->blocks, bi_max_temp(ctx), bi_liveness_ins_update_wrap); + + ctx->has_liveness = true; +} + +/* Once liveness data is no longer valid, call this */ + +void +bi_invalidate_liveness(bi_context *ctx) +{ + if (ctx->has_liveness) + pan_free_liveness(&ctx->blocks); + + ctx->has_liveness = false; +} + +bool +bi_is_live_after(bi_context *ctx, bi_block *block, bi_instruction *start, int src) +{ + bi_compute_liveness(ctx); + + /* Check whether we're live in the successors */ + + if (pan_liveness_get(block->base.live_out, src, bi_max_temp(ctx))) + return true; + + /* Check the rest of the block for liveness */ + + bi_foreach_instr_in_block_from(block, ins, bi_next_op(start)) { + if (bi_has_arg(ins, src)) + return true; + } + + return false; +} diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 9c64a910f6f..cc00c7f69ef 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -334,6 +334,9 @@ typedef struct { /* For creating temporaries */ unsigned temp_alloc; + /* Analysis results */ + bool has_liveness; + /* Stats for shader-db */ unsigned instruction_count; unsigned loop_count; @@ -500,4 +503,11 @@ uint16_t bi_bytemask_of_read_components(bi_instruction *ins, unsigned node); void bi_schedule(bi_context *ctx); +/* Liveness */ + +void bi_compute_liveness(bi_context *ctx); +void bi_liveness_ins_update(uint16_t *live, bi_instruction *ins, unsigned max); +void bi_invalidate_liveness(bi_context *ctx); +bool bi_is_live_after(bi_context *ctx, bi_block *block, bi_instruction *start, int src); + #endif diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build index 7b374cc4d10..1033318508e 100644 --- a/src/panfrost/bifrost/meson.build +++ b/src/panfrost/bifrost/meson.build @@ -21,6 +21,7 @@ libpanfrost_bifrost_files = files( 'disassemble.c', + 'bi_liveness.c', 'bi_print.c', 'bi_schedule.c', 'bi_tables.c', -- 2.30.2