Path: blob/21.2-virgl/src/panfrost/midgard/midgard_liveness.c
4564 views
/*1* Copyright (C) 2018-2019 Alyssa Rosenzweig <[email protected]>2* Copyright (C) 2019-2020 Collabora, Ltd.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#include "compiler.h"2526void27mir_liveness_ins_update(uint16_t *live, midgard_instruction *ins, unsigned max)28{29/* live_in[s] = GEN[s] + (live_out[s] - KILL[s]) */3031pan_liveness_kill(live, ins->dest, max, mir_bytemask(ins));3233mir_foreach_src(ins, src) {34unsigned node = ins->src[src];35unsigned bytemask = mir_bytemask_of_read_components(ins, node);3637pan_liveness_gen(live, node, max, bytemask);38}39}4041static void42mir_liveness_ins_update_wrap(uint16_t *live, void *ins, unsigned max)43{44mir_liveness_ins_update(live, (midgard_instruction *) ins, max);45}4647void48mir_compute_liveness(compiler_context *ctx)49{50/* If we already have fresh liveness, nothing to do */51if (ctx->metadata & MIDGARD_METADATA_LIVENESS)52return;5354mir_compute_temp_count(ctx);55pan_compute_liveness(&ctx->blocks, ctx->temp_count, mir_liveness_ins_update_wrap);5657/* Liveness is now valid */58ctx->metadata |= MIDGARD_METADATA_LIVENESS;59}6061/* Once liveness data is no longer valid, call this */6263void64mir_invalidate_liveness(compiler_context *ctx)65{66/* If we didn't already compute liveness, there's nothing to do */67if (!(ctx->metadata & MIDGARD_METADATA_LIVENESS))68return;6970pan_free_liveness(&ctx->blocks);7172/* It's now invalid regardless */73ctx->metadata &= ~MIDGARD_METADATA_LIVENESS;74}7576bool77mir_is_live_after(compiler_context *ctx, midgard_block *block, midgard_instruction *start, int src)78{79mir_compute_liveness(ctx);8081/* Check whether we're live in the successors */8283if (pan_liveness_get(block->base.live_out, src, ctx->temp_count))84return true;8586/* Check the rest of the block for liveness */8788mir_foreach_instr_in_block_from(block, ins, mir_next_op(start)) {89if (mir_has_arg(ins, src))90return true;91}9293return false;94}959697