Path: blob/21.2-virgl/src/asahi/compiler/agx_dce.c
4564 views
/*1* Copyright (C) 2021 Alyssa Rosenzweig <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#include "agx_compiler.h"2425/* SSA-based scalar dead code elimination */2627void28agx_dce(agx_context *ctx)29{30BITSET_WORD *seen = calloc(BITSET_WORDS(ctx->alloc), sizeof(BITSET_WORD));3132agx_foreach_instr_global_safe_rev(ctx, I) {33if (agx_opcodes_info[I->op].can_eliminate) {34bool needed = false;3536agx_foreach_dest(I, d) {37if (I->dest[d].type == AGX_INDEX_NORMAL)38needed |= BITSET_TEST(seen, I->dest[d].value);39else if (I->dest[d].type != AGX_INDEX_NULL)40needed = true;41}4243if (!needed) {44agx_remove_instruction(I);45continue;46}47}4849agx_foreach_src(I, s) {50if (I->src[s].type == AGX_INDEX_NORMAL)51BITSET_SET(seen, I->src[s].value);52}53}5455free(seen);56}575859