2 * Copyright (C) 2020 Collabora, Ltd.
3 * Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 bi_liveness_ins_update(uint16_t *live
, bi_instruction
*ins
, unsigned max
)
30 /* live_in[s] = GEN[s] + (live_out[s] - KILL[s]) */
32 pan_liveness_kill(live
, ins
->dest
, max
, bi_writemask(ins
));
34 bi_foreach_src(ins
, src
) {
35 unsigned node
= ins
->src
[src
];
36 unsigned bytemask
= bi_bytemask_of_read_components(ins
, node
);
38 pan_liveness_gen(live
, node
, max
, bytemask
);
43 bi_liveness_ins_update_wrap(uint16_t *live
, void *ins
, unsigned max
)
45 bi_liveness_ins_update(live
, (bi_instruction
*) ins
, max
);
49 bi_compute_liveness(bi_context
*ctx
)
51 if (ctx
->has_liveness
)
54 pan_compute_liveness(&ctx
->blocks
, bi_max_temp(ctx
), bi_liveness_ins_update_wrap
);
56 ctx
->has_liveness
= true;
59 /* Once liveness data is no longer valid, call this */
62 bi_invalidate_liveness(bi_context
*ctx
)
64 if (ctx
->has_liveness
)
65 pan_free_liveness(&ctx
->blocks
);
67 ctx
->has_liveness
= false;
71 bi_is_live_after(bi_context
*ctx
, bi_block
*block
, bi_instruction
*start
, int src
)
73 bi_compute_liveness(ctx
);
75 /* Check whether we're live in the successors */
77 if (pan_liveness_get(block
->base
.live_out
, src
, bi_max_temp(ctx
)))
80 /* Check the rest of the block for liveness */
82 bi_foreach_instr_in_block_from(block
, ins
, bi_next_op(start
)) {
83 if (bi_has_arg(ins
, src
))