2 * Copyright (C) 2020 Collabora Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * 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 THE
23 * Authors (Collabora):
24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
28 #include "panfrost/util/lcra.h"
29 #include "util/u_memory.h"
32 bi_compute_interference(bi_context
*ctx
, struct lcra_state
*l
)
34 bi_compute_liveness(ctx
);
36 bi_foreach_block(ctx
, _blk
) {
37 bi_block
*blk
= (bi_block
*) _blk
;
38 uint16_t *live
= mem_dup(_blk
->live_out
, l
->node_count
* sizeof(uint16_t));
40 bi_foreach_instr_in_block_rev(blk
, ins
) {
41 /* Mark all registers live after the instruction as
42 * interfering with the destination */
44 if (ins
->dest
&& (ins
->dest
< l
->node_count
)) {
45 for (unsigned i
= 1; i
< l
->node_count
; ++i
) {
47 lcra_add_node_interference(l
, ins
->dest
, ins
->writemask
, i
, live
[i
]);
52 bi_liveness_ins_update(live
, ins
, l
->node_count
);
60 BI_REG_CLASS_WORK
= 0,
63 static struct lcra_state
*
64 bi_allocate_registers(bi_context
*ctx
, bool *success
)
66 unsigned node_count
= bi_max_temp(ctx
);
68 struct lcra_state
*l
=
69 lcra_alloc_equations(node_count
, 1, 8, 16, 1);
71 l
->class_start
[BI_REG_CLASS_WORK
] = 0;
72 l
->class_size
[BI_REG_CLASS_WORK
] = 64 * 4; /* R0 - R63, all 32-bit */
74 bi_foreach_instr_global(ctx
, ins
) {
75 unsigned dest
= ins
->dest
;
77 if (!dest
|| (dest
>= node_count
))
80 l
->class[dest
] = BI_REG_CLASS_WORK
;
81 lcra_set_alignment(l
, dest
, 2); /* 2^2 = 4 */
82 lcra_restrict_range(l
, dest
, 4);
85 bi_compute_interference(ctx
, l
);
87 *success
= lcra_solve(l
);
93 bi_register_allocate(bi_context
*ctx
)
95 struct lcra_state
*l
= NULL
;
104 bi_invalidate_liveness(ctx
);
105 l
= bi_allocate_registers(ctx
, &success
);