]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* Routines for liveness in SSA trees. |
85ec4feb | 2 | Copyright (C) 2003-2018 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Andrew MacLeod <amacleod@redhat.com> |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9dcd6f09 | 9 | the Free Software Foundation; either version 3, or (at your option) |
6de9cd9a DN |
10 | any later version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a DN |
20 | |
21 | ||
22 | #ifndef _TREE_SSA_LIVE_H | |
23 | #define _TREE_SSA_LIVE_H 1 | |
24 | ||
59587b18 | 25 | #include "partition.h" |
7290d709 | 26 | |
b8698a0f | 27 | /* Used to create the variable mapping when we go out of SSA form. |
7290d709 AM |
28 | |
29 | Mapping from an ssa_name to a partition number is maintained, as well as | |
5f564b8f | 30 | partition number back to ssa_name. |
7290d709 AM |
31 | |
32 | This data structure also supports "views", which work on a subset of all | |
b8698a0f | 33 | partitions. This allows the coalescer to decide what partitions are |
7290d709 AM |
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 | |
2e226e66 | 36 | change. (ie, it is truly a view since it doesn't change anything) |
7290d709 AM |
37 | |
38 | The final component of the data structure is the basevar map. This provides | |
9f5ed61a | 39 | a list of all the different base variables which occur in a partition view, |
7290d709 AM |
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 | ||
6de9cd9a DN |
45 | typedef struct _var_map |
46 | { | |
7290d709 | 47 | /* The partition manager of all variables. */ |
6de9cd9a DN |
48 | partition var_partition; |
49 | ||
7290d709 AM |
50 | /* Vector for managing partitions views. */ |
51 | int *partition_to_view; | |
52 | int *view_to_partition; | |
6de9cd9a | 53 | |
7290d709 | 54 | /* Current number of partitions in var_map based on the current view. */ |
6de9cd9a DN |
55 | unsigned int num_partitions; |
56 | ||
7290d709 | 57 | /* Original full partition size. */ |
6de9cd9a | 58 | unsigned int partition_size; |
7290d709 AM |
59 | |
60 | /* Number of base variables in the base var list. */ | |
61 | int num_basevars; | |
62 | ||
63 | /* Map of partitions numbers to base variable table indexes. */ | |
64 | int *partition_to_base_index; | |
e3bfa377 BC |
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. */ | |
68 | bitmap bmp_bbs; | |
69 | ||
70 | /* Vector of basic block in the region. */ | |
71 | vec<basic_block> vec_bbs; | |
72 | ||
73 | /* True if this map is for out-of-ssa, otherwise for live range | |
74 | computation. When for out-of-ssa, it also means the var map is computed | |
75 | for whole current function. */ | |
76 | bool outofssa_p; | |
6de9cd9a DN |
77 | } *var_map; |
78 | ||
6de9cd9a | 79 | |
7290d709 AM |
80 | /* Value used to represent no partition number. */ |
81 | #define NO_PARTITION -1 | |
6de9cd9a | 82 | |
e3bfa377 | 83 | extern var_map init_var_map (int, struct loop* = NULL); |
6de9cd9a | 84 | extern void delete_var_map (var_map); |
6de9cd9a | 85 | extern int var_union (var_map, tree, tree); |
1f9ceff1 AO |
86 | extern void partition_view_normal (var_map); |
87 | extern void partition_view_bitmap (var_map, bitmap); | |
1a817418 ML |
88 | extern void dump_scope_blocks (FILE *, dump_flags_t); |
89 | extern void debug_scope_block (tree, dump_flags_t); | |
90 | extern void debug_scope_blocks (dump_flags_t); | |
c1bf2a39 AM |
91 | extern void remove_unused_locals (void); |
92 | extern void dump_var_map (FILE *, var_map); | |
93 | extern void debug (_var_map &ref); | |
94 | extern void debug (_var_map *ptr); | |
6de9cd9a | 95 | |
6de9cd9a | 96 | |
e3bfa377 BC |
97 | /* Return TRUE if region of the MAP contains basic block BB. */ |
98 | ||
99 | inline bool | |
100 | region_contains_p (var_map map, basic_block bb) | |
101 | { | |
102 | /* It's possible that the function is called with ENTRY_BLOCK/EXIT_BLOCK. */ | |
103 | if (map->outofssa_p) | |
104 | return (bb->index != ENTRY_BLOCK && bb->index != EXIT_BLOCK); | |
105 | ||
106 | return bitmap_bit_p (map->bmp_bbs, bb->index); | |
107 | } | |
108 | ||
109 | ||
7290d709 | 110 | /* Return number of partitions in MAP. */ |
6de9cd9a | 111 | |
3cd8c58a | 112 | static inline unsigned |
6de9cd9a DN |
113 | num_var_partitions (var_map map) |
114 | { | |
115 | return map->num_partitions; | |
116 | } | |
117 | ||
118 | ||
b8698a0f | 119 | /* Given partition index I from MAP, return the variable which represents that |
6de9cd9a | 120 | partition. */ |
b8698a0f | 121 | |
6de9cd9a DN |
122 | static inline tree |
123 | partition_to_var (var_map map, int i) | |
124 | { | |
4e3825db | 125 | tree name; |
7290d709 AM |
126 | if (map->view_to_partition) |
127 | i = map->view_to_partition[i]; | |
6de9cd9a | 128 | i = partition_find (map->var_partition, i); |
4e3825db MM |
129 | name = ssa_name (i); |
130 | return name; | |
6de9cd9a DN |
131 | } |
132 | ||
133 | ||
b8698a0f | 134 | /* Given ssa_name VERSION, if it has a partition in MAP, return the var it |
6de9cd9a DN |
135 | is associated with. Otherwise return NULL. */ |
136 | ||
b8698a0f | 137 | static inline tree |
7290d709 | 138 | version_to_var (var_map map, int version) |
6de9cd9a DN |
139 | { |
140 | int part; | |
141 | part = partition_find (map->var_partition, version); | |
7290d709 AM |
142 | if (map->partition_to_view) |
143 | part = map->partition_to_view[part]; | |
6de9cd9a DN |
144 | if (part == NO_PARTITION) |
145 | return NULL_TREE; | |
b8698a0f | 146 | |
6de9cd9a DN |
147 | return partition_to_var (map, part); |
148 | } | |
6de9cd9a | 149 | |
b8698a0f L |
150 | |
151 | /* Given VAR, return the partition number in MAP which contains it. | |
89dbed81 | 152 | NO_PARTITION is returned if it's not in any partition. */ |
6de9cd9a DN |
153 | |
154 | static inline int | |
155 | var_to_partition (var_map map, tree var) | |
156 | { | |
6de9cd9a DN |
157 | int part; |
158 | ||
4e3825db MM |
159 | part = partition_find (map->var_partition, SSA_NAME_VERSION (var)); |
160 | if (map->partition_to_view) | |
161 | part = map->partition_to_view[part]; | |
6de9cd9a DN |
162 | return part; |
163 | } | |
164 | ||
165 | ||
166 | /* Given VAR, return the variable which represents the entire partition | |
167 | it is a member of in MAP. NULL is returned if it is not in a partition. */ | |
168 | ||
169 | static inline tree | |
170 | var_to_partition_to_var (var_map map, tree var) | |
171 | { | |
172 | int part; | |
173 | ||
174 | part = var_to_partition (map, var); | |
175 | if (part == NO_PARTITION) | |
176 | return NULL_TREE; | |
177 | return partition_to_var (map, part); | |
178 | } | |
179 | ||
180 | ||
7290d709 AM |
181 | /* Return the index into the basevar table for PARTITION's base in MAP. */ |
182 | ||
183 | static inline int | |
184 | basevar_index (var_map map, int partition) | |
185 | { | |
06795261 JH |
186 | gcc_checking_assert (partition >= 0 |
187 | && partition <= (int) num_var_partitions (map)); | |
7290d709 AM |
188 | return map->partition_to_base_index[partition]; |
189 | } | |
190 | ||
191 | ||
192 | /* Return the number of different base variables in MAP. */ | |
193 | ||
194 | static inline int | |
195 | num_basevars (var_map map) | |
196 | { | |
197 | return map->num_basevars; | |
198 | } | |
199 | ||
200 | ||
b8698a0f | 201 | /* ---------------- live on entry/exit info ------------------------------ |
6de9cd9a DN |
202 | |
203 | This structure is used to represent live range information on SSA based | |
204 | trees. A partition map must be provided, and based on the active partitions, | |
205 | live-on-entry information and live-on-exit information can be calculated. | |
b8698a0f | 206 | As well, partitions are marked as to whether they are global (live |
6de9cd9a DN |
207 | outside the basic block they are defined in). |
208 | ||
b8698a0f L |
209 | The live-on-entry information is per block. It provide a bitmap for |
210 | each block which has a bit set for each partition that is live on entry to | |
32ace6e2 | 211 | that block. |
6de9cd9a | 212 | |
32ace6e2 | 213 | The live-on-exit information is per block. It provides a bitmap for each |
6de9cd9a DN |
214 | block indicating which partitions are live on exit from the block. |
215 | ||
b8698a0f | 216 | For the purposes of this implementation, we treat the elements of a PHI |
6de9cd9a DN |
217 | as follows: |
218 | ||
219 | Uses in a PHI are considered LIVE-ON-EXIT to the block from which they | |
220 | originate. They are *NOT* considered live on entry to the block | |
221 | containing the PHI node. | |
222 | ||
223 | The Def of a PHI node is *not* considered live on entry to the block. | |
224 | It is considered to be "define early" in the block. Picture it as each | |
b8698a0f | 225 | block having a stmt (or block-preheader) before the first real stmt in |
6de9cd9a | 226 | the block which defines all the variables that are defined by PHIs. |
b8698a0f | 227 | |
6de9cd9a DN |
228 | ----------------------------------------------------------------------- */ |
229 | ||
230 | ||
231 | typedef struct tree_live_info_d | |
232 | { | |
233 | /* Var map this relates to. */ | |
234 | var_map map; | |
235 | ||
236 | /* Bitmap indicating which partitions are global. */ | |
237 | bitmap global; | |
238 | ||
3f9b14ff SB |
239 | /* Bitmaps of live on entry blocks for partition elements. */ |
240 | bitmap_head *livein; | |
241 | ||
242 | /* Bitmaps of what variables are live on exit for a basic blocks. */ | |
243 | bitmap_head *liveout; | |
6de9cd9a DN |
244 | |
245 | /* Number of basic blocks when live on exit calculated. */ | |
246 | int num_blocks; | |
247 | ||
32ace6e2 AM |
248 | /* Vector used when creating live ranges as a visited stack. */ |
249 | int *work_stack; | |
250 | ||
251 | /* Top of workstack. */ | |
252 | int *stack_top; | |
87d0d6c4 RB |
253 | |
254 | /* Obstacks to allocate the bitmaps on. */ | |
255 | bitmap_obstack livein_obstack; | |
256 | bitmap_obstack liveout_obstack; | |
6de9cd9a DN |
257 | } *tree_live_info_p; |
258 | ||
259 | ||
6de9cd9a DN |
260 | #define LIVEDUMP_ENTRY 0x01 |
261 | #define LIVEDUMP_EXIT 0x02 | |
262 | #define LIVEDUMP_ALL (LIVEDUMP_ENTRY | LIVEDUMP_EXIT) | |
c1bf2a39 | 263 | extern void delete_tree_live_info (tree_live_info_p); |
87d0d6c4 | 264 | extern tree_live_info_p calculate_live_ranges (var_map, bool); |
7b3b6ae4 LC |
265 | extern void debug (tree_live_info_d &ref); |
266 | extern void debug (tree_live_info_d *ptr); | |
c1bf2a39 | 267 | extern void dump_live_info (FILE *, tree_live_info_p, int); |
6de9cd9a | 268 | |
6de9cd9a DN |
269 | |
270 | /* Return TRUE if P is marked as a global in LIVE. */ | |
271 | ||
272 | static inline int | |
273 | partition_is_global (tree_live_info_p live, int p) | |
274 | { | |
06795261 | 275 | gcc_checking_assert (live->global); |
6de9cd9a DN |
276 | return bitmap_bit_p (live->global, p); |
277 | } | |
278 | ||
279 | ||
b8698a0f | 280 | /* Return the bitmap from LIVE representing the live on entry blocks for |
6de9cd9a DN |
281 | partition P. */ |
282 | ||
283 | static inline bitmap | |
32ace6e2 | 284 | live_on_entry (tree_live_info_p live, basic_block bb) |
6de9cd9a | 285 | { |
06795261 | 286 | gcc_checking_assert (live->livein |
fefa31b5 DM |
287 | && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun) |
288 | && bb != EXIT_BLOCK_PTR_FOR_FN (cfun)); | |
32ace6e2 | 289 | |
3f9b14ff | 290 | return &live->livein[bb->index]; |
6de9cd9a DN |
291 | } |
292 | ||
293 | ||
294 | /* Return the bitmap from LIVE representing the live on exit partitions from | |
295 | block BB. */ | |
296 | ||
297 | static inline bitmap | |
298 | live_on_exit (tree_live_info_p live, basic_block bb) | |
299 | { | |
06795261 | 300 | gcc_checking_assert (live->liveout |
fefa31b5 DM |
301 | && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun) |
302 | && bb != EXIT_BLOCK_PTR_FOR_FN (cfun)); | |
6de9cd9a | 303 | |
3f9b14ff | 304 | return &live->liveout[bb->index]; |
6de9cd9a DN |
305 | } |
306 | ||
307 | ||
308 | /* Return the partition map which the information in LIVE utilizes. */ | |
309 | ||
b8698a0f | 310 | static inline var_map |
6de9cd9a DN |
311 | live_var_map (tree_live_info_p live) |
312 | { | |
313 | return live->map; | |
314 | } | |
315 | ||
316 | ||
6de9cd9a DN |
317 | /* Mark partition P as live on entry to basic block BB in LIVE. */ |
318 | ||
b8698a0f | 319 | static inline void |
6de9cd9a DN |
320 | make_live_on_entry (tree_live_info_p live, basic_block bb , int p) |
321 | { | |
3f9b14ff | 322 | bitmap_set_bit (&live->livein[bb->index], p); |
6de9cd9a DN |
323 | bitmap_set_bit (live->global, p); |
324 | } | |
325 | ||
6de9cd9a | 326 | #endif /* _TREE_SSA_LIVE_H */ |