]>
Commit | Line | Data |
---|---|---|
4ee9c684 | 1 | /* Routines for liveness in SSA trees. |
f1717362 | 2 | Copyright (C) 2003-2016 Free Software Foundation, Inc. |
4ee9c684 | 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 | |
8c4c00c1 | 9 | the Free Software Foundation; either version 3, or (at your option) |
4ee9c684 | 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 | |
8c4c00c1 | 18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
4ee9c684 | 20 | |
21 | ||
22 | #ifndef _TREE_SSA_LIVE_H | |
23 | #define _TREE_SSA_LIVE_H 1 | |
24 | ||
bcf3c70d | 25 | #include "partition.h" |
2d043327 | 26 | |
48e1416a | 27 | /* Used to create the variable mapping when we go out of SSA form. |
2d043327 | 28 | |
29 | Mapping from an ssa_name to a partition number is maintained, as well as | |
4ae5778c | 30 | partition number back to ssa_name. |
2d043327 | 31 | |
32 | This data structure also supports "views", which work on a subset of all | |
48e1416a | 33 | partitions. This allows the coalescer to decide what partitions are |
2d043327 | 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 | |
7920eed5 | 36 | change. (ie, it is truly a view since it doesn't change anything) |
2d043327 | 37 | |
38 | The final component of the data structure is the basevar map. This provides | |
f2b32076 | 39 | a list of all the different base variables which occur in a partition view, |
2d043327 | 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 | ||
4ee9c684 | 45 | typedef struct _var_map |
46 | { | |
2d043327 | 47 | /* The partition manager of all variables. */ |
4ee9c684 | 48 | partition var_partition; |
49 | ||
2d043327 | 50 | /* Vector for managing partitions views. */ |
51 | int *partition_to_view; | |
52 | int *view_to_partition; | |
4ee9c684 | 53 | |
2d043327 | 54 | /* Current number of partitions in var_map based on the current view. */ |
4ee9c684 | 55 | unsigned int num_partitions; |
56 | ||
2d043327 | 57 | /* Original full partition size. */ |
4ee9c684 | 58 | unsigned int partition_size; |
2d043327 | 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; | |
4ee9c684 | 65 | } *var_map; |
66 | ||
4ee9c684 | 67 | |
2d043327 | 68 | /* Value used to represent no partition number. */ |
69 | #define NO_PARTITION -1 | |
4ee9c684 | 70 | |
4ee9c684 | 71 | extern var_map init_var_map (int); |
72 | extern void delete_var_map (var_map); | |
4ee9c684 | 73 | extern int var_union (var_map, tree, tree); |
94f92c36 | 74 | extern void partition_view_normal (var_map); |
75 | extern void partition_view_bitmap (var_map, bitmap); | |
64641360 | 76 | extern void dump_scope_blocks (FILE *, int); |
77 | extern void debug_scope_block (tree, int); | |
78 | extern void debug_scope_blocks (int); | |
79 | extern void remove_unused_locals (void); | |
80 | extern void dump_var_map (FILE *, var_map); | |
81 | extern void debug (_var_map &ref); | |
82 | extern void debug (_var_map *ptr); | |
8c0963c4 | 83 | extern void register_ssa_partition_check (tree ssa_var); |
4ee9c684 | 84 | |
4ee9c684 | 85 | |
2d043327 | 86 | /* Return number of partitions in MAP. */ |
4ee9c684 | 87 | |
4f917ffe | 88 | static inline unsigned |
4ee9c684 | 89 | num_var_partitions (var_map map) |
90 | { | |
91 | return map->num_partitions; | |
92 | } | |
93 | ||
94 | ||
48e1416a | 95 | /* Given partition index I from MAP, return the variable which represents that |
4ee9c684 | 96 | partition. */ |
48e1416a | 97 | |
4ee9c684 | 98 | static inline tree |
99 | partition_to_var (var_map map, int i) | |
100 | { | |
a8dd994c | 101 | tree name; |
2d043327 | 102 | if (map->view_to_partition) |
103 | i = map->view_to_partition[i]; | |
4ee9c684 | 104 | i = partition_find (map->var_partition, i); |
a8dd994c | 105 | name = ssa_name (i); |
106 | return name; | |
4ee9c684 | 107 | } |
108 | ||
109 | ||
48e1416a | 110 | /* Given ssa_name VERSION, if it has a partition in MAP, return the var it |
4ee9c684 | 111 | is associated with. Otherwise return NULL. */ |
112 | ||
48e1416a | 113 | static inline tree |
2d043327 | 114 | version_to_var (var_map map, int version) |
4ee9c684 | 115 | { |
116 | int part; | |
117 | part = partition_find (map->var_partition, version); | |
2d043327 | 118 | if (map->partition_to_view) |
119 | part = map->partition_to_view[part]; | |
4ee9c684 | 120 | if (part == NO_PARTITION) |
121 | return NULL_TREE; | |
48e1416a | 122 | |
4ee9c684 | 123 | return partition_to_var (map, part); |
124 | } | |
4ee9c684 | 125 | |
48e1416a | 126 | |
127 | /* Given VAR, return the partition number in MAP which contains it. | |
5c9dae64 | 128 | NO_PARTITION is returned if it's not in any partition. */ |
4ee9c684 | 129 | |
130 | static inline int | |
131 | var_to_partition (var_map map, tree var) | |
132 | { | |
4ee9c684 | 133 | int part; |
134 | ||
a8dd994c | 135 | part = partition_find (map->var_partition, SSA_NAME_VERSION (var)); |
136 | if (map->partition_to_view) | |
137 | part = map->partition_to_view[part]; | |
4ee9c684 | 138 | return part; |
139 | } | |
140 | ||
141 | ||
142 | /* Given VAR, return the variable which represents the entire partition | |
143 | it is a member of in MAP. NULL is returned if it is not in a partition. */ | |
144 | ||
145 | static inline tree | |
146 | var_to_partition_to_var (var_map map, tree var) | |
147 | { | |
148 | int part; | |
149 | ||
150 | part = var_to_partition (map, var); | |
151 | if (part == NO_PARTITION) | |
152 | return NULL_TREE; | |
153 | return partition_to_var (map, part); | |
154 | } | |
155 | ||
156 | ||
2d043327 | 157 | /* Return the index into the basevar table for PARTITION's base in MAP. */ |
158 | ||
159 | static inline int | |
160 | basevar_index (var_map map, int partition) | |
161 | { | |
e95895ef | 162 | gcc_checking_assert (partition >= 0 |
163 | && partition <= (int) num_var_partitions (map)); | |
2d043327 | 164 | return map->partition_to_base_index[partition]; |
165 | } | |
166 | ||
167 | ||
168 | /* Return the number of different base variables in MAP. */ | |
169 | ||
170 | static inline int | |
171 | num_basevars (var_map map) | |
172 | { | |
173 | return map->num_basevars; | |
174 | } | |
175 | ||
176 | ||
177 | ||
48e1416a | 178 | /* This routine registers a partition for SSA_VAR with MAP. Any unregistered |
179 | partitions may be filtered out by a view later. */ | |
4ee9c684 | 180 | |
181 | static inline void | |
382ecba7 | 182 | register_ssa_partition (var_map map ATTRIBUTE_UNUSED, tree ssa_var) |
4ee9c684 | 183 | { |
382ecba7 | 184 | if (flag_checking) |
185 | register_ssa_partition_check (ssa_var); | |
4ee9c684 | 186 | } |
187 | ||
188 | ||
48e1416a | 189 | /* ---------------- live on entry/exit info ------------------------------ |
4ee9c684 | 190 | |
191 | This structure is used to represent live range information on SSA based | |
192 | trees. A partition map must be provided, and based on the active partitions, | |
193 | live-on-entry information and live-on-exit information can be calculated. | |
48e1416a | 194 | As well, partitions are marked as to whether they are global (live |
4ee9c684 | 195 | outside the basic block they are defined in). |
196 | ||
48e1416a | 197 | The live-on-entry information is per block. It provide a bitmap for |
198 | each block which has a bit set for each partition that is live on entry to | |
30928c44 | 199 | that block. |
4ee9c684 | 200 | |
30928c44 | 201 | The live-on-exit information is per block. It provides a bitmap for each |
4ee9c684 | 202 | block indicating which partitions are live on exit from the block. |
203 | ||
48e1416a | 204 | For the purposes of this implementation, we treat the elements of a PHI |
4ee9c684 | 205 | as follows: |
206 | ||
207 | Uses in a PHI are considered LIVE-ON-EXIT to the block from which they | |
208 | originate. They are *NOT* considered live on entry to the block | |
209 | containing the PHI node. | |
210 | ||
211 | The Def of a PHI node is *not* considered live on entry to the block. | |
212 | It is considered to be "define early" in the block. Picture it as each | |
48e1416a | 213 | block having a stmt (or block-preheader) before the first real stmt in |
4ee9c684 | 214 | the block which defines all the variables that are defined by PHIs. |
48e1416a | 215 | |
4ee9c684 | 216 | ----------------------------------------------------------------------- */ |
217 | ||
218 | ||
219 | typedef struct tree_live_info_d | |
220 | { | |
221 | /* Var map this relates to. */ | |
222 | var_map map; | |
223 | ||
224 | /* Bitmap indicating which partitions are global. */ | |
225 | bitmap global; | |
226 | ||
4fb07d00 | 227 | /* Bitmaps of live on entry blocks for partition elements. */ |
228 | bitmap_head *livein; | |
229 | ||
230 | /* Bitmaps of what variables are live on exit for a basic blocks. */ | |
231 | bitmap_head *liveout; | |
4ee9c684 | 232 | |
233 | /* Number of basic blocks when live on exit calculated. */ | |
234 | int num_blocks; | |
235 | ||
30928c44 | 236 | /* Vector used when creating live ranges as a visited stack. */ |
237 | int *work_stack; | |
238 | ||
239 | /* Top of workstack. */ | |
240 | int *stack_top; | |
78775228 | 241 | |
242 | /* Obstacks to allocate the bitmaps on. */ | |
243 | bitmap_obstack livein_obstack; | |
244 | bitmap_obstack liveout_obstack; | |
4ee9c684 | 245 | } *tree_live_info_p; |
246 | ||
247 | ||
4ee9c684 | 248 | #define LIVEDUMP_ENTRY 0x01 |
249 | #define LIVEDUMP_EXIT 0x02 | |
250 | #define LIVEDUMP_ALL (LIVEDUMP_ENTRY | LIVEDUMP_EXIT) | |
64641360 | 251 | extern void delete_tree_live_info (tree_live_info_p); |
78775228 | 252 | extern tree_live_info_p calculate_live_ranges (var_map, bool); |
c7d89805 | 253 | extern void debug (tree_live_info_d &ref); |
254 | extern void debug (tree_live_info_d *ptr); | |
64641360 | 255 | extern void dump_live_info (FILE *, tree_live_info_p, int); |
4ee9c684 | 256 | |
4ee9c684 | 257 | |
258 | /* Return TRUE if P is marked as a global in LIVE. */ | |
259 | ||
260 | static inline int | |
261 | partition_is_global (tree_live_info_p live, int p) | |
262 | { | |
e95895ef | 263 | gcc_checking_assert (live->global); |
4ee9c684 | 264 | return bitmap_bit_p (live->global, p); |
265 | } | |
266 | ||
267 | ||
48e1416a | 268 | /* Return the bitmap from LIVE representing the live on entry blocks for |
4ee9c684 | 269 | partition P. */ |
270 | ||
271 | static inline bitmap | |
30928c44 | 272 | live_on_entry (tree_live_info_p live, basic_block bb) |
4ee9c684 | 273 | { |
e95895ef | 274 | gcc_checking_assert (live->livein |
34154e27 | 275 | && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun) |
276 | && bb != EXIT_BLOCK_PTR_FOR_FN (cfun)); | |
30928c44 | 277 | |
4fb07d00 | 278 | return &live->livein[bb->index]; |
4ee9c684 | 279 | } |
280 | ||
281 | ||
282 | /* Return the bitmap from LIVE representing the live on exit partitions from | |
283 | block BB. */ | |
284 | ||
285 | static inline bitmap | |
286 | live_on_exit (tree_live_info_p live, basic_block bb) | |
287 | { | |
e95895ef | 288 | gcc_checking_assert (live->liveout |
34154e27 | 289 | && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun) |
290 | && bb != EXIT_BLOCK_PTR_FOR_FN (cfun)); | |
4ee9c684 | 291 | |
4fb07d00 | 292 | return &live->liveout[bb->index]; |
4ee9c684 | 293 | } |
294 | ||
295 | ||
296 | /* Return the partition map which the information in LIVE utilizes. */ | |
297 | ||
48e1416a | 298 | static inline var_map |
4ee9c684 | 299 | live_var_map (tree_live_info_p live) |
300 | { | |
301 | return live->map; | |
302 | } | |
303 | ||
304 | ||
305 | /* Merge the live on entry information in LIVE for partitions P1 and P2. Place | |
0bed3869 | 306 | the result into P1. Clear P2. */ |
4ee9c684 | 307 | |
48e1416a | 308 | static inline void |
4ee9c684 | 309 | live_merge_and_clear (tree_live_info_p live, int p1, int p2) |
310 | { | |
4fb07d00 | 311 | gcc_checking_assert (&live->livein[p1] && &live->livein[p2]); |
312 | bitmap_ior_into (&live->livein[p1], &live->livein[p2]); | |
53c5d9d4 | 313 | bitmap_clear (&live->livein[p2]); |
4ee9c684 | 314 | } |
315 | ||
316 | ||
317 | /* Mark partition P as live on entry to basic block BB in LIVE. */ | |
318 | ||
48e1416a | 319 | static inline void |
4ee9c684 | 320 | make_live_on_entry (tree_live_info_p live, basic_block bb , int p) |
321 | { | |
4fb07d00 | 322 | bitmap_set_bit (&live->livein[bb->index], p); |
4ee9c684 | 323 | bitmap_set_bit (live->global, p); |
324 | } | |
325 | ||
4ee9c684 | 326 | #endif /* _TREE_SSA_LIVE_H */ |