GCC Middle and Back End API Reference
tree-ssa-live.h
Go to the documentation of this file.
1/* Routines for liveness in SSA trees.
2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21
22#ifndef _TREE_SSA_LIVE_H
23#define _TREE_SSA_LIVE_H 1
24
25#include "partition.h"
26
27/* Used to create the variable mapping when we go out of SSA form.
28
29 Mapping from an ssa_name to a partition number is maintained, as well as
30 partition number back to ssa_name.
31
32 This data structure also supports "views", which work on a subset of all
33 partitions. This allows the coalescer to decide what partitions are
34 interesting to it, and only work with those partitions. Whenever the view
35 is changed, the partition numbers change, but none of the partition groupings
36 change. (ie, it is truly a view since it doesn't change anything)
37
38 The final component of the data structure is the basevar map. This provides
39 a list of all the different base variables which occur in a partition view,
40 and a unique index for each one. Routines are provided to quickly produce
41 the base variable of a partition.
42
43 Note that members of a partition MUST all have the same base variable. */
44
45typedef struct _var_map
46{
47 /* The partition manager of all variables. */
49
50 /* Vector for managing partitions views. */
53
54 /* Current number of partitions in var_map based on the current view. */
55 unsigned int num_partitions;
56
57 /* Original full partition size. */
58 unsigned int partition_size;
59
60 /* Number of base variables in the base var list. */
62
63 /* Map of partitions numbers to base variable table indexes. */
65
66 /* Bitmap of basic block. It describes the region within which the analysis
67 is done. Using pointer avoids allocating memory in out-of-ssa case. */
69
70 /* Vector of basic block in the region. */
72
73 /* If non-NULL, only coalesce SSA_NAMEs from this bitmap, and try harder
74 for those (for bitint lowering pass). */
76
77 /* True if this map is for out-of-ssa, otherwise for live range
78 computation. When for out-of-ssa, it also means the var map is computed
79 for whole current function. */
82
83
84/* Value used to represent no partition number. */
85#define NO_PARTITION -1
86
87extern var_map init_var_map (int, class loop * = NULL, bitmap = NULL);
88extern void delete_var_map (var_map);
89extern int var_union (var_map, tree, tree);
90extern void partition_view_normal (var_map);
92extern void dump_scope_blocks (FILE *, dump_flags_t);
95extern void remove_unused_locals (void);
96extern void dump_var_map (FILE *, var_map);
97extern void debug (_var_map &ref);
98extern void debug (_var_map *ptr);
99
100
101/* Return TRUE if region of the MAP contains basic block BB. */
102
103inline bool
105{
106 /* It's possible that the function is called with ENTRY_BLOCK/EXIT_BLOCK. */
107 if (map->outofssa_p || map->bitint)
108 return (bb->index != ENTRY_BLOCK && bb->index != EXIT_BLOCK);
109
110 return bitmap_bit_p (map->bmp_bbs, bb->index);
111}
112
113
114/* Return number of partitions in MAP. */
115
116inline unsigned
118{
119 return map->num_partitions;
120}
121
122
123/* Given partition index I from MAP, return the variable which represents that
124 partition. */
125
126inline tree
128{
129 tree name;
130 if (map->view_to_partition)
131 i = map->view_to_partition[i];
132 i = partition_find (map->var_partition, i);
133 name = ssa_name (i);
134 return name;
135}
136
137
138/* Given ssa_name VERSION, if it has a partition in MAP, return the var it
139 is associated with. Otherwise return NULL. */
140
141inline tree
143{
144 int part;
145 part = partition_find (map->var_partition, version);
146 if (map->partition_to_view)
147 part = map->partition_to_view[part];
148 if (part == NO_PARTITION)
149 return NULL_TREE;
150
151 return partition_to_var (map, part);
152}
153
154
155/* Given VAR, return the partition number in MAP which contains it.
156 NO_PARTITION is returned if it's not in any partition. */
157
158inline int
160{
161 int part;
162
163 part = partition_find (map->var_partition, SSA_NAME_VERSION (var));
164 if (map->partition_to_view)
165 part = map->partition_to_view[part];
166 return part;
167}
168
169
170/* Given VAR, return the variable which represents the entire partition
171 it is a member of in MAP. NULL is returned if it is not in a partition. */
172
173inline tree
175{
176 int part;
177
178 part = var_to_partition (map, var);
179 if (part == NO_PARTITION)
180 return NULL_TREE;
181 return partition_to_var (map, part);
182}
183
184
185/* Return the index into the basevar table for PARTITION's base in MAP. */
186
187inline int
189{
191 && partition <= (int) num_var_partitions (map));
192 return map->partition_to_base_index[partition];
193}
194
195
196/* Return the number of different base variables in MAP. */
197
198inline int
200{
201 return map->num_basevars;
202}
203
204
205/* ---------------- live on entry/exit info ------------------------------
206
207 This structure is used to represent live range information on SSA based
208 trees. A partition map must be provided, and based on the active partitions,
209 live-on-entry information and live-on-exit information can be calculated.
210 As well, partitions are marked as to whether they are global (live
211 outside the basic block they are defined in).
212
213 The live-on-entry information is per block. It provide a bitmap for
214 each block which has a bit set for each partition that is live on entry to
215 that block.
216
217 The live-on-exit information is per block. It provides a bitmap for each
218 block indicating which partitions are live on exit from the block.
219
220 For the purposes of this implementation, we treat the elements of a PHI
221 as follows:
222
223 Uses in a PHI are considered LIVE-ON-EXIT to the block from which they
224 originate. They are *NOT* considered live on entry to the block
225 containing the PHI node.
226
227 The Def of a PHI node is *not* considered live on entry to the block.
228 It is considered to be "define early" in the block. Picture it as each
229 block having a stmt (or block-preheader) before the first real stmt in
230 the block which defines all the variables that are defined by PHIs.
231
232 ----------------------------------------------------------------------- */
233
234
235typedef struct tree_live_info_d
236{
237 /* Var map this relates to. */
239
240 /* Bitmaps of live on entry blocks for partition elements. */
242
243 /* Bitmaps of what variables are live on exit for a basic blocks. */
245
246 /* Number of basic blocks when live on exit calculated. */
248
249 /* Vector used when creating live ranges as a visited stack. */
251
252 /* Top of workstack. */
254
255 /* Obstacks to allocate the bitmaps on. */
259
260
261#define LIVEDUMP_ENTRY 0x01
262#define LIVEDUMP_EXIT 0x02
263#define LIVEDUMP_ALL (LIVEDUMP_ENTRY | LIVEDUMP_EXIT)
266extern void debug (tree_live_info_d &ref);
267extern void debug (tree_live_info_d *ptr);
268extern void dump_live_info (FILE *, tree_live_info_p, int);
269
270typedef hash_map<int_hash <unsigned int, -1U>, unsigned int> live_vars_map;
273 gimple *);
274extern void destroy_live_vars (vec<bitmap_head> &);
275
276
277/* Return the bitmap from LIVE representing the live on entry blocks for
278 partition P. */
279
280inline bitmap
282{
285 && bb != EXIT_BLOCK_PTR_FOR_FN (cfun));
286
287 return &live->livein[bb->index];
288}
289
290
291/* Return the bitmap from LIVE representing the live on exit partitions from
292 block BB. */
293
294inline bitmap
296{
299 && bb != EXIT_BLOCK_PTR_FOR_FN (cfun));
300
301 return &live->liveout[bb->index];
302}
303
304
305/* Return the partition map which the information in LIVE utilizes. */
306
307inline var_map
309{
310 return live->map;
311}
312
313
314/* Mark partition P as live on entry to basic block BB in LIVE. */
315
316inline void
318{
319 bitmap_set_bit (&live->livein[bb->index], p);
320}
321
322
323/* On-demand virtual operand global live analysis. There is at most
324 a single virtual operand live at a time, the following computes and
325 caches the virtual operand live at the exit of a basic block
326 supporting related live-in and live-on-edge queries. It requires
327 up-to-date marked backedges. */
328
330{
331public:
334 {
335 if (liveout)
336 free (liveout);
337 }
338
341 tree get_live_on_edge (edge e) { return get_live_out (e->src); }
342
343private:
344 void init ();
345
347};
348
349
350#endif /* _TREE_SSA_LIVE_H */
#define ENTRY_BLOCK_PTR_FOR_FN(FN)
Definition basic-block.h:194
#define EXIT_BLOCK
Definition basic-block.h:262
#define EXIT_BLOCK_PTR_FOR_FN(FN)
Definition basic-block.h:195
#define ENTRY_BLOCK
Definition basic-block.h:261
Definition bitmap.h:328
Definition hash-map.h:40
Definition cfgloop.h:120
Definition tree-ssa-live.h:330
~virtual_operand_live()
Definition tree-ssa-live.h:333
tree get_live_in(basic_block bb)
Definition tree-ssa-live.cc:1682
tree get_live_out(basic_block bb)
Definition tree-ssa-live.cc:1722
void init()
Definition tree-ssa-live.cc:1673
tree * liveout
Definition tree-ssa-live.h:346
tree get_live_on_edge(edge e)
Definition tree-ssa-live.h:341
virtual_operand_live()
Definition tree-ssa-live.h:332
bool debug
Definition collect-utils.cc:34
class edge_def * edge
Definition coretypes.h:352
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
static struct string2counter_map map[debug_counter_number_of_counters]
Definition dbgcnt.cc:39
enum dump_flag dump_flags_t
Definition dumpfile.h:209
#define cfun
Definition function.h:478
#define bitmap_bit_p(bitstring, bitno)
Definition genautomata.cc:3429
#define bitmap_set_bit(bitstring, bitno)
Definition genautomata.cc:3419
free(str)
i
Definition poly-int.h:776
Definition tree-ssa-live.h:46
bool outofssa_p
Definition tree-ssa-live.h:80
vec< basic_block > vec_bbs
Definition tree-ssa-live.h:71
bitmap bmp_bbs
Definition tree-ssa-live.h:68
unsigned int num_partitions
Definition tree-ssa-live.h:55
bitmap bitint
Definition tree-ssa-live.h:75
unsigned int partition_size
Definition tree-ssa-live.h:58
int num_basevars
Definition tree-ssa-live.h:61
partition var_partition
Definition tree-ssa-live.h:48
int * partition_to_base_index
Definition tree-ssa-live.h:64
int * partition_to_view
Definition tree-ssa-live.h:51
int * view_to_partition
Definition tree-ssa-live.h:52
Definition basic-block.h:117
int index
Definition basic-block.h:147
Definition bitmap.h:294
Definition function.h:249
Definition gimple.h:221
Definition hash-traits.h:122
Definition tree-loop-distribution.cc:257
Definition tree-ssa-live.h:236
int * stack_top
Definition tree-ssa-live.h:253
int * work_stack
Definition tree-ssa-live.h:250
bitmap_head * liveout
Definition tree-ssa-live.h:244
bitmap_obstack livein_obstack
Definition tree-ssa-live.h:256
var_map map
Definition tree-ssa-live.h:238
bitmap_head * livein
Definition tree-ssa-live.h:241
int num_blocks
Definition tree-ssa-live.h:247
bitmap_obstack liveout_obstack
Definition tree-ssa-live.h:257
Definition vec.h:450
#define NULL
Definition system.h:50
#define gcc_checking_assert(EXPR)
Definition system.h:821
void partition_view_normal(var_map)
Definition tree-ssa-live.cc:277
void delete_var_map(var_map)
Definition tree-ssa-live.cc:128
void remove_unused_locals(void)
Definition tree-ssa-live.cc:780
void partition_view_bitmap(var_map, bitmap)
Definition tree-ssa-live.cc:293
int num_basevars(var_map map)
Definition tree-ssa-live.h:199
void debug_scope_block(tree, dump_flags_t)
Definition tree-ssa-live.cc:752
#define NO_PARTITION
Definition tree-ssa-live.h:85
void debug_scope_blocks(dump_flags_t)
Definition tree-ssa-live.cc:772
struct tree_live_info_d * tree_live_info_p
tree var_to_partition_to_var(var_map map, tree var)
Definition tree-ssa-live.h:174
hash_map< int_hash< unsigned int, -1U >, unsigned int > live_vars_map
Definition tree-ssa-live.h:270
void dump_var_map(FILE *, var_map)
Definition tree-ssa-live.cc:1434
bitmap live_vars_at_stmt(vec< bitmap_head > &, live_vars_map *, gimple *)
Definition tree-ssa-live.cc:1409
void delete_tree_live_info(tree_live_info_p)
Definition tree-ssa-live.cc:1047
void dump_live_info(FILE *, tree_live_info_p, int)
Definition tree-ssa-live.cc:1498
int basevar_index(var_map map, int partition)
Definition tree-ssa-live.h:188
bitmap live_on_exit(tree_live_info_p live, basic_block bb)
Definition tree-ssa-live.h:295
tree_live_info_p calculate_live_ranges(var_map, bool)
Definition tree-ssa-live.cc:1258
struct _var_map * var_map
int var_to_partition(var_map map, tree var)
Definition tree-ssa-live.h:159
var_map live_var_map(tree_live_info_p live)
Definition tree-ssa-live.h:308
bool region_contains_p(var_map map, basic_block bb)
Definition tree-ssa-live.h:104
void dump_scope_blocks(FILE *, dump_flags_t)
Definition tree-ssa-live.cc:762
bitmap live_on_entry(tree_live_info_p live, basic_block bb)
Definition tree-ssa-live.h:281
vec< bitmap_head > compute_live_vars(struct function *, live_vars_map *)
Definition tree-ssa-live.cc:1360
tree version_to_var(var_map map, int version)
Definition tree-ssa-live.h:142
void destroy_live_vars(vec< bitmap_head > &)
Definition tree-ssa-live.cc:1422
void make_live_on_entry(tree_live_info_p live, basic_block bb, int p)
Definition tree-ssa-live.h:317
int var_union(var_map, tree, tree)
Definition tree-ssa-live.cc:146
tree partition_to_var(var_map map, int i)
Definition tree-ssa-live.h:127
var_map init_var_map(int, class loop *=NULL, bitmap=NULL)
Definition tree-ssa-live.cc:84
unsigned num_var_partitions(var_map map)
Definition tree-ssa-live.h:117
#define ssa_name(i)
Definition tree-ssanames.h:53
#define SSA_NAME_VERSION(NODE)
Definition tree.h:2144
#define NULL_TREE
Definition tree.h:317