Path: blob/21.2-virgl/src/panfrost/midgard/mir_squeeze.c
4564 views
/*1* Copyright (C) 2019 Collabora, Ltd.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*22* Authors (Collabora):23* Alyssa Rosenzweig <[email protected]>24*/2526#include "compiler.h"2728/* When we're 'squeezing down' the values in the IR, we maintain a hash29* as such */3031static unsigned32find_or_allocate_temp(compiler_context *ctx, struct hash_table_u64 *map,33unsigned hash)34{35if (hash >= SSA_FIXED_MINIMUM)36return hash;3738unsigned temp = (uintptr_t) _mesa_hash_table_u64_search(39map, hash + 1);4041if (temp)42return temp - 1;4344/* If no temp is find, allocate one */45temp = ctx->temp_count++;46ctx->max_hash = MAX2(ctx->max_hash, hash);4748_mesa_hash_table_u64_insert(map,49hash + 1, (void *) ((uintptr_t) temp + 1));5051return temp;52}5354/* Reassigns numbering to get rid of gaps in the indices and to prioritize55* smaller register classes */5657void58mir_squeeze_index(compiler_context *ctx)59{60struct hash_table_u64 *map = _mesa_hash_table_u64_create(NULL);6162/* Reset */63ctx->temp_count = 0;6465/* We need to prioritize texture registers on older GPUs so we don't66* fail RA trying to assign to work registers r0/r1 when a work67* register is already there */6869mir_foreach_instr_global(ctx, ins) {70if (ins->type == TAG_TEXTURE_4)71ins->dest = find_or_allocate_temp(ctx, map, ins->dest);72}7374mir_foreach_instr_global(ctx, ins) {75if (ins->type != TAG_TEXTURE_4)76ins->dest = find_or_allocate_temp(ctx, map, ins->dest);7778for (unsigned i = 0; i < ARRAY_SIZE(ins->src); ++i)79ins->src[i] = find_or_allocate_temp(ctx, map, ins->src[i]);80}8182ctx->blend_input = find_or_allocate_temp(ctx, map, ctx->blend_input);83ctx->blend_src1 = find_or_allocate_temp(ctx, map, ctx->blend_src1);8485_mesa_hash_table_u64_destroy(map);86}878889