panfrost: add LDST_ADDRESS property to atomic ops
[mesa.git] / src / panfrost / midgard / midgard_liveness.c
1 /*
2 * Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 */
23
24 #include "compiler.h"
25
26 void
27 mir_liveness_ins_update(uint16_t *live, midgard_instruction *ins, unsigned max)
28 {
29 /* live_in[s] = GEN[s] + (live_out[s] - KILL[s]) */
30
31 pan_liveness_kill(live, ins->dest, max, mir_bytemask(ins));
32
33 mir_foreach_src(ins, src) {
34 unsigned node = ins->src[src];
35 unsigned bytemask = mir_bytemask_of_read_components(ins, node);
36
37 pan_liveness_gen(live, node, max, bytemask);
38 }
39 }
40
41 static void
42 mir_liveness_ins_update_wrap(uint16_t *live, void *ins, unsigned max)
43 {
44 mir_liveness_ins_update(live, (midgard_instruction *) ins, max);
45 }
46
47 void
48 mir_compute_liveness(compiler_context *ctx)
49 {
50 /* If we already have fresh liveness, nothing to do */
51 if (ctx->metadata & MIDGARD_METADATA_LIVENESS)
52 return;
53
54 mir_compute_temp_count(ctx);
55 pan_compute_liveness(&ctx->blocks, ctx->temp_count, mir_liveness_ins_update_wrap);
56
57 /* Liveness is now valid */
58 ctx->metadata |= MIDGARD_METADATA_LIVENESS;
59 }
60
61 /* Once liveness data is no longer valid, call this */
62
63 void
64 mir_invalidate_liveness(compiler_context *ctx)
65 {
66 /* If we didn't already compute liveness, there's nothing to do */
67 if (!(ctx->metadata & MIDGARD_METADATA_LIVENESS))
68 return;
69
70 pan_free_liveness(&ctx->blocks);
71
72 /* It's now invalid regardless */
73 ctx->metadata &= ~MIDGARD_METADATA_LIVENESS;
74 }
75
76 bool
77 mir_is_live_after(compiler_context *ctx, midgard_block *block, midgard_instruction *start, int src)
78 {
79 mir_compute_liveness(ctx);
80
81 /* Check whether we're live in the successors */
82
83 if (pan_liveness_get(block->base.live_out, src, ctx->temp_count))
84 return true;
85
86 /* Check the rest of the block for liveness */
87
88 mir_foreach_instr_in_block_from(block, ins, mir_next_op(start)) {
89 if (mir_has_arg(ins, src))
90 return true;
91 }
92
93 return false;
94 }