• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 Collabora, Ltd.
3  * Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
4  *
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:
11  *
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
14  * Software.
15  *
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
22  * SOFTWARE.
23  */
24 
25 #include "compiler.h"
26 
27 void
bi_liveness_ins_update(uint16_t * live,bi_instruction * ins,unsigned max)28 bi_liveness_ins_update(uint16_t *live, bi_instruction *ins, unsigned max)
29 {
30         /* live_in[s] = GEN[s] + (live_out[s] - KILL[s]) */
31 
32         pan_liveness_kill(live, ins->dest, max, bi_writemask(ins));
33 
34         bi_foreach_src(ins, src) {
35                 unsigned node = ins->src[src];
36                 unsigned bytemask = bi_bytemask_of_read_components(ins, node);
37 
38                 pan_liveness_gen(live, node, max, bytemask);
39         }
40 }
41 
42 static void
bi_liveness_ins_update_wrap(uint16_t * live,void * ins,unsigned max)43 bi_liveness_ins_update_wrap(uint16_t *live, void *ins, unsigned max)
44 {
45         bi_liveness_ins_update(live, (bi_instruction *) ins, max);
46 }
47 
48 void
bi_compute_liveness(bi_context * ctx)49 bi_compute_liveness(bi_context *ctx)
50 {
51         if (ctx->has_liveness)
52                 return;
53 
54         pan_compute_liveness(&ctx->blocks, bi_max_temp(ctx), bi_liveness_ins_update_wrap);
55 
56         ctx->has_liveness = true;
57 }
58 
59 /* Once liveness data is no longer valid, call this */
60 
61 void
bi_invalidate_liveness(bi_context * ctx)62 bi_invalidate_liveness(bi_context *ctx)
63 {
64         if (ctx->has_liveness)
65                 pan_free_liveness(&ctx->blocks);
66 
67         ctx->has_liveness = false;
68 }
69 
70 bool
bi_is_live_after(bi_context * ctx,bi_block * block,bi_instruction * start,int src)71 bi_is_live_after(bi_context *ctx, bi_block *block, bi_instruction *start, int src)
72 {
73         bi_compute_liveness(ctx);
74 
75         /* Check whether we're live in the successors */
76 
77         if (pan_liveness_get(block->base.live_out, src, bi_max_temp(ctx)))
78                 return true;
79 
80         /* Check the rest of the block for liveness */
81 
82         bi_foreach_instr_in_block_from(block, ins, bi_next_op(start)) {
83                 if (bi_has_arg(ins, src))
84                         return true;
85         }
86 
87         return false;
88 }
89