2 * Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
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
27 mir_liveness_ins_update(uint16_t *live
, midgard_instruction
*ins
, unsigned max
)
29 /* live_in[s] = GEN[s] + (live_out[s] - KILL[s]) */
31 pan_liveness_kill(live
, ins
->dest
, max
, mir_bytemask(ins
));
33 mir_foreach_src(ins
, src
) {
34 unsigned node
= ins
->src
[src
];
35 unsigned bytemask
= mir_bytemask_of_read_components(ins
, node
);
37 pan_liveness_gen(live
, node
, max
, bytemask
);
42 mir_liveness_ins_update_wrap(uint16_t *live
, void *ins
, unsigned max
)
44 mir_liveness_ins_update(live
, (midgard_instruction
*) ins
, max
);
48 mir_compute_liveness(compiler_context
*ctx
)
50 /* If we already have fresh liveness, nothing to do */
51 if (ctx
->metadata
& MIDGARD_METADATA_LIVENESS
)
54 mir_compute_temp_count(ctx
);
55 pan_compute_liveness(&ctx
->blocks
, ctx
->temp_count
, mir_liveness_ins_update_wrap
);
57 /* Liveness is now valid */
58 ctx
->metadata
|= MIDGARD_METADATA_LIVENESS
;
61 /* Once liveness data is no longer valid, call this */
64 mir_invalidate_liveness(compiler_context
*ctx
)
66 /* If we didn't already compute liveness, there's nothing to do */
67 if (!(ctx
->metadata
& MIDGARD_METADATA_LIVENESS
))
70 pan_free_liveness(&ctx
->blocks
);
72 /* It's now invalid regardless */
73 ctx
->metadata
&= ~MIDGARD_METADATA_LIVENESS
;
77 mir_is_live_after(compiler_context
*ctx
, midgard_block
*block
, midgard_instruction
*start
, int src
)
79 mir_compute_liveness(ctx
);
81 /* Check whether we're live in the successors */
83 if (pan_liveness_get(block
->base
.live_out
, src
, ctx
->temp_count
))
86 /* Check the rest of the block for liveness */
88 mir_foreach_instr_in_block_from(block
, ins
, mir_next_op(start
)) {
89 if (mir_has_arg(ins
, src
))