Debian Codegraph @

src/panfrost/compiler/midgard/mir_squeeze.c

raw
1 /*
2 * Copyright (C) 2019 Collabora, Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "compiler.h"
7
8 /* When we're 'squeezing down' the values in the IR, we maintain a hash
9 * as such */
10
11 static unsigned
12 find_or_allocate_temp(compiler_context *ctx, struct hash_table_u64 *map,
13 unsigned hash)
14 {
15 if (hash >= SSA_FIXED_MINIMUM)
16 return hash;
17
18 unsigned temp = (uintptr_t)_mesa_hash_table_u64_search(map, hash + 1);
19
20 if (temp)
21 return temp - 1;
22
23 /* If no temp is find, allocate one */
24 temp = ctx->temp_count++;
25 ctx->max_hash = MAX2(ctx->max_hash, hash);
26
27 _mesa_hash_table_u64_insert(map, hash + 1, (void *)((uintptr_t)temp + 1));
28
29 return temp;
30 }
31
32 /* Reassigns numbering to get rid of gaps in the indices and to prioritize
33 * smaller register classes */
34
35 void
36 mir_squeeze_index(compiler_context *ctx)
37 {
38 struct hash_table_u64 *map = _mesa_hash_table_u64_create(NULL);
39
40 /* Reset */
41 ctx->temp_count = 0;
42
43 /* We need to prioritize texture registers on older GPUs so we don't
44 * fail RA trying to assign to work registers r0/r1 when a work
45 * register is already there */
46
47 mir_foreach_instr_global(ctx, ins) {
48 if (ins->type == TAG_TEXTURE_4)
49 ins->dest = find_or_allocate_temp(ctx, map, ins->dest);
50 }
51
52 mir_foreach_instr_global(ctx, ins) {
53 if (ins->type != TAG_TEXTURE_4)
54 ins->dest = find_or_allocate_temp(ctx, map, ins->dest);
55
56 for (unsigned i = 0; i < ARRAY_SIZE(ins->src); ++i)
57 ins->src[i] = find_or_allocate_temp(ctx, map, ins->src[i]);
58 }
59
60 ctx->blend_input = find_or_allocate_temp(ctx, map, ctx->blend_input);
61 ctx->blend_src1 = find_or_allocate_temp(ctx, map, ctx->blend_src1);
62
63 _mesa_hash_table_u64_destroy(map);
64 }