]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* Generic routines for manipulating SSA_NAME expressions |
d1e082c2 | 2 | Copyright (C) 2003-2013 Free Software Foundation, Inc. |
7072a650 | 3 | |
6de9cd9a | 4 | This file is part of GCC. |
b8698a0f | 5 | |
6de9cd9a DN |
6 | GCC is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
9dcd6f09 | 8 | the Free Software Foundation; either version 3, or (at your option) |
6de9cd9a | 9 | any later version. |
b8698a0f | 10 | |
6de9cd9a DN |
11 | GCC is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
b8698a0f | 15 | |
6de9cd9a | 16 | You should have received a copy of the GNU General Public License |
9dcd6f09 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
0e61db61 | 19 | |
6de9cd9a DN |
20 | #include "config.h" |
21 | #include "system.h" | |
22 | #include "coretypes.h" | |
23 | #include "tm.h" | |
24 | #include "tree.h" | |
d8a2d370 | 25 | #include "stor-layout.h" |
2fb9a547 AM |
26 | #include "basic-block.h" |
27 | #include "tree-ssa-alias.h" | |
28 | #include "internal-fn.h" | |
29 | #include "gimple-expr.h" | |
30 | #include "is-a.h" | |
442b4905 AM |
31 | #include "gimple.h" |
32 | #include "gimple-ssa.h" | |
33 | #include "tree-phinodes.h" | |
34 | #include "ssa-iterators.h" | |
d8a2d370 | 35 | #include "stringpool.h" |
442b4905 AM |
36 | #include "tree-ssanames.h" |
37 | #include "tree-into-ssa.h" | |
7a300452 | 38 | #include "tree-ssa.h" |
7faade0f | 39 | #include "tree-pass.h" |
6de9cd9a DN |
40 | |
41 | /* Rewriting a function into SSA form can create a huge number of SSA_NAMEs, | |
42 | many of which may be thrown away shortly after their creation if jumps | |
b8698a0f | 43 | were threaded through PHI nodes. |
6de9cd9a DN |
44 | |
45 | While our garbage collection mechanisms will handle this situation, it | |
46 | is extremely wasteful to create nodes and throw them away, especially | |
47 | when the nodes can be reused. | |
48 | ||
49 | For PR 8361, we can significantly reduce the number of nodes allocated | |
50 | and thus the total amount of memory allocated by managing SSA_NAMEs a | |
51 | little. This additionally helps reduce the amount of work done by the | |
52 | garbage collector. Similar results have been seen on a wider variety | |
53 | of tests (such as the compiler itself). | |
54 | ||
55 | Right now we maintain our free list on a per-function basis. It may | |
56 | or may not make sense to maintain the free list for the duration of | |
b8698a0f | 57 | a compilation unit. |
6de9cd9a DN |
58 | |
59 | External code should rely solely upon HIGHEST_SSA_VERSION and the | |
60 | externally defined functions. External code should not know about | |
61 | the details of the free list management. | |
62 | ||
63 | External code should also not assume the version number on nodes is | |
64 | monotonically increasing. We reuse the version number when we | |
65 | reuse an SSA_NAME expression. This helps keep arrays and bitmaps | |
cd030c07 | 66 | more compact. */ |
6de9cd9a | 67 | |
6de9cd9a DN |
68 | |
69 | /* Version numbers with special meanings. We start allocating new version | |
70 | numbers after the special ones. */ | |
71 | #define UNUSED_NAME_VERSION 0 | |
72 | ||
6de9cd9a DN |
73 | unsigned int ssa_name_nodes_reused; |
74 | unsigned int ssa_name_nodes_created; | |
6de9cd9a | 75 | |
b12ebd96 AM |
76 | #define FREE_SSANAMES(fun) (fun)->gimple_df->free_ssanames |
77 | ||
78 | ||
5db9ba0c DN |
79 | /* Initialize management of SSA_NAMEs to default SIZE. If SIZE is |
80 | zero use default. */ | |
6de9cd9a DN |
81 | |
82 | void | |
5db9ba0c | 83 | init_ssanames (struct function *fn, int size) |
6de9cd9a | 84 | { |
5db9ba0c DN |
85 | if (size < 50) |
86 | size = 50; | |
87 | ||
9771b263 | 88 | vec_alloc (SSANAMES (fn), size); |
95a3742c DN |
89 | |
90 | /* Version 0 is special, so reserve the first slot in the table. Though | |
91 | currently unused, we may use version 0 in alias analysis as part of | |
92 | the heuristics used to group aliases when the alias sets are too | |
d2fce91b KH |
93 | large. |
94 | ||
9771b263 | 95 | We use vec::quick_push here because we know that SSA_NAMES has at |
078885f2 | 96 | least 50 elements reserved in it. */ |
9771b263 | 97 | SSANAMES (fn)->quick_push (NULL_TREE); |
5db9ba0c | 98 | FREE_SSANAMES (fn) = NULL; |
5006671f | 99 | |
13714310 RG |
100 | fn->gimple_df->ssa_renaming_needed = 0; |
101 | fn->gimple_df->rename_vops = 0; | |
6de9cd9a DN |
102 | } |
103 | ||
104 | /* Finalize management of SSA_NAMEs. */ | |
105 | ||
106 | void | |
107 | fini_ssanames (void) | |
108 | { | |
9771b263 DN |
109 | vec_free (SSANAMES (cfun)); |
110 | vec_free (FREE_SSANAMES (cfun)); | |
6de9cd9a DN |
111 | } |
112 | ||
113 | /* Dump some simple statistics regarding the re-use of SSA_NAME nodes. */ | |
114 | ||
6de9cd9a DN |
115 | void |
116 | ssanames_print_statistics (void) | |
117 | { | |
118 | fprintf (stderr, "SSA_NAME nodes allocated: %u\n", ssa_name_nodes_created); | |
119 | fprintf (stderr, "SSA_NAME nodes reused: %u\n", ssa_name_nodes_reused); | |
120 | } | |
6de9cd9a | 121 | |
5db9ba0c DN |
122 | /* Return an SSA_NAME node for variable VAR defined in statement STMT |
123 | in function FN. STMT may be an empty statement for artificial | |
124 | references (e.g., default definitions created when a variable is | |
125 | used without a preceding definition). */ | |
6de9cd9a DN |
126 | |
127 | tree | |
726a989a | 128 | make_ssa_name_fn (struct function *fn, tree var, gimple stmt) |
6de9cd9a DN |
129 | { |
130 | tree t; | |
f47c96aa | 131 | use_operand_p imm; |
6de9cd9a | 132 | |
67386041 RG |
133 | gcc_assert (TREE_CODE (var) == VAR_DECL |
134 | || TREE_CODE (var) == PARM_DECL | |
70b5e7dc RG |
135 | || TREE_CODE (var) == RESULT_DECL |
136 | || (TYPE_P (var) && is_gimple_reg_type (var))); | |
6de9cd9a | 137 | |
6f2aec07 | 138 | /* If our free list has an element, then use it. */ |
9771b263 | 139 | if (!vec_safe_is_empty (FREE_SSANAMES (fn))) |
6de9cd9a | 140 | { |
9771b263 | 141 | t = FREE_SSANAMES (fn)->pop (); |
7aa6d18a SB |
142 | if (GATHER_STATISTICS) |
143 | ssa_name_nodes_reused++; | |
6de9cd9a | 144 | |
6f2aec07 JL |
145 | /* The node was cleared out when we put it on the free list, so |
146 | there is no need to do so again here. */ | |
147 | gcc_assert (ssa_name (SSA_NAME_VERSION (t)) == NULL); | |
9771b263 | 148 | (*SSANAMES (fn))[SSA_NAME_VERSION (t)] = t; |
6de9cd9a DN |
149 | } |
150 | else | |
151 | { | |
152 | t = make_node (SSA_NAME); | |
9771b263 DN |
153 | SSA_NAME_VERSION (t) = SSANAMES (fn)->length (); |
154 | vec_safe_push (SSANAMES (fn), t); | |
7aa6d18a SB |
155 | if (GATHER_STATISTICS) |
156 | ssa_name_nodes_created++; | |
6de9cd9a DN |
157 | } |
158 | ||
70b5e7dc RG |
159 | if (TYPE_P (var)) |
160 | { | |
161 | TREE_TYPE (t) = var; | |
162 | SET_SSA_NAME_VAR_OR_IDENTIFIER (t, NULL_TREE); | |
163 | } | |
164 | else | |
165 | { | |
166 | TREE_TYPE (t) = TREE_TYPE (var); | |
167 | SET_SSA_NAME_VAR_OR_IDENTIFIER (t, var); | |
168 | } | |
6de9cd9a | 169 | SSA_NAME_DEF_STMT (t) = stmt; |
a895a2b8 KV |
170 | if (POINTER_TYPE_P (TREE_TYPE (t))) |
171 | SSA_NAME_PTR_INFO (t) = NULL; | |
172 | else | |
173 | SSA_NAME_RANGE_INFO (t) = NULL; | |
174 | ||
53b4bf74 | 175 | SSA_NAME_IN_FREE_LIST (t) = 0; |
cfaab3a9 | 176 | SSA_NAME_IS_DEFAULT_DEF (t) = 0; |
f430bae8 AM |
177 | imm = &(SSA_NAME_IMM_USE_NODE (t)); |
178 | imm->use = NULL; | |
179 | imm->prev = imm; | |
180 | imm->next = imm; | |
726a989a | 181 | imm->loc.ssa_name = t; |
6de9cd9a DN |
182 | |
183 | return t; | |
184 | } | |
185 | ||
a895a2b8 KV |
186 | /* Store range information MIN, and MAX to tree ssa_name NAME. */ |
187 | ||
188 | void | |
189 | set_range_info (tree name, double_int min, double_int max) | |
190 | { | |
191 | gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); | |
192 | range_info_def *ri = SSA_NAME_RANGE_INFO (name); | |
193 | ||
194 | /* Allocate if not available. */ | |
195 | if (ri == NULL) | |
196 | { | |
197 | ri = ggc_alloc_cleared_range_info_def (); | |
198 | SSA_NAME_RANGE_INFO (name) = ri; | |
c853f62a | 199 | ri->nonzero_bits = double_int::mask (TYPE_PRECISION (TREE_TYPE (name))); |
a895a2b8 KV |
200 | } |
201 | ||
202 | /* Set the values. */ | |
203 | ri->min = min; | |
204 | ri->max = max; | |
c853f62a JJ |
205 | |
206 | /* If it is a range, try to improve nonzero_bits from the min/max. */ | |
207 | if (min.cmp (max, TYPE_UNSIGNED (TREE_TYPE (name))) != 1) | |
208 | { | |
209 | int prec = TYPE_PRECISION (TREE_TYPE (name)); | |
210 | double_int xorv; | |
211 | ||
212 | min = min.zext (prec); | |
213 | max = max.zext (prec); | |
214 | xorv = min ^ max; | |
215 | if (xorv.high) | |
216 | xorv = double_int::mask (2 * HOST_BITS_PER_WIDE_INT | |
217 | - clz_hwi (xorv.high)); | |
218 | else if (xorv.low) | |
219 | xorv = double_int::mask (HOST_BITS_PER_WIDE_INT | |
220 | - clz_hwi (xorv.low)); | |
221 | ri->nonzero_bits = ri->nonzero_bits & (min | xorv); | |
222 | } | |
a895a2b8 KV |
223 | } |
224 | ||
225 | ||
226 | /* Gets range information MIN, MAX and returns enum value_range_type | |
227 | corresponding to tree ssa_name NAME. enum value_range_type returned | |
228 | is used to determine if MIN and MAX are valid values. */ | |
229 | ||
230 | enum value_range_type | |
eae76e53 | 231 | get_range_info (const_tree name, double_int *min, double_int *max) |
a895a2b8 KV |
232 | { |
233 | enum value_range_type range_type; | |
234 | gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); | |
235 | gcc_assert (min && max); | |
236 | range_info_def *ri = SSA_NAME_RANGE_INFO (name); | |
237 | ||
238 | /* Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs | |
239 | with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision. */ | |
240 | if (!ri || (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (name))) | |
0498471b | 241 | > 2 * HOST_BITS_PER_WIDE_INT)) |
a895a2b8 KV |
242 | return VR_VARYING; |
243 | ||
244 | /* If min > max, it is VR_ANTI_RANGE. */ | |
245 | if (ri->min.cmp (ri->max, TYPE_UNSIGNED (TREE_TYPE (name))) == 1) | |
246 | { | |
247 | /* VR_ANTI_RANGE ~[min, max] is encoded as [max + 1, min - 1]. */ | |
248 | range_type = VR_ANTI_RANGE; | |
249 | *min = ri->max + double_int_one; | |
250 | *max = ri->min - double_int_one; | |
251 | } | |
252 | else | |
253 | { | |
254 | /* Otherwise (when min <= max), it is VR_RANGE. */ | |
255 | range_type = VR_RANGE; | |
256 | *min = ri->min; | |
257 | *max = ri->max; | |
258 | } | |
259 | return range_type; | |
260 | } | |
95a3742c | 261 | |
c853f62a JJ |
262 | /* Change non-zero bits bitmask of NAME. */ |
263 | ||
264 | void | |
265 | set_nonzero_bits (tree name, double_int mask) | |
266 | { | |
267 | gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); | |
268 | if (SSA_NAME_RANGE_INFO (name) == NULL) | |
269 | set_range_info (name, | |
270 | tree_to_double_int (TYPE_MIN_VALUE (TREE_TYPE (name))), | |
271 | tree_to_double_int (TYPE_MAX_VALUE (TREE_TYPE (name)))); | |
272 | range_info_def *ri = SSA_NAME_RANGE_INFO (name); | |
273 | ri->nonzero_bits | |
274 | = mask & double_int::mask (TYPE_PRECISION (TREE_TYPE (name))); | |
275 | } | |
276 | ||
277 | /* Return a double_int with potentially non-zero bits in SSA_NAME | |
278 | NAME, or double_int_minus_one if unknown. */ | |
279 | ||
280 | double_int | |
eae76e53 | 281 | get_nonzero_bits (const_tree name) |
c853f62a JJ |
282 | { |
283 | if (POINTER_TYPE_P (TREE_TYPE (name))) | |
284 | { | |
285 | struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name); | |
286 | if (pi && pi->align) | |
287 | { | |
288 | double_int al = double_int::from_uhwi (pi->align - 1); | |
289 | return ((double_int::mask (TYPE_PRECISION (TREE_TYPE (name))) & ~al) | |
290 | | double_int::from_uhwi (pi->misalign)); | |
291 | } | |
292 | return double_int_minus_one; | |
293 | } | |
294 | ||
295 | range_info_def *ri = SSA_NAME_RANGE_INFO (name); | |
296 | if (!ri || (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (name))) | |
297 | > 2 * HOST_BITS_PER_WIDE_INT)) | |
298 | return double_int_minus_one; | |
299 | ||
300 | return ri->nonzero_bits; | |
301 | } | |
302 | ||
6de9cd9a | 303 | /* We no longer need the SSA_NAME expression VAR, release it so that |
b8698a0f | 304 | it may be reused. |
6de9cd9a DN |
305 | |
306 | Note it is assumed that no calls to make_ssa_name will be made | |
307 | until all uses of the ssa name are released and that the only | |
308 | use of the SSA_NAME expression is to check its SSA_NAME_VAR. All | |
309 | other fields must be assumed clobbered. */ | |
310 | ||
311 | void | |
312 | release_ssa_name (tree var) | |
313 | { | |
8b11a64c ZD |
314 | if (!var) |
315 | return; | |
316 | ||
53b4bf74 DN |
317 | /* Never release the default definition for a symbol. It's a |
318 | special SSA name that should always exist once it's created. */ | |
cfaab3a9 | 319 | if (SSA_NAME_IS_DEFAULT_DEF (var)) |
53b4bf74 DN |
320 | return; |
321 | ||
84d65814 DN |
322 | /* If VAR has been registered for SSA updating, don't remove it. |
323 | After update_ssa has run, the name will be released. */ | |
324 | if (name_registered_for_update_p (var)) | |
325 | { | |
326 | release_ssa_name_after_update_ssa (var); | |
327 | return; | |
328 | } | |
b0382c67 | 329 | |
6de9cd9a DN |
330 | /* release_ssa_name can be called multiple times on a single SSA_NAME. |
331 | However, it should only end up on our free list one time. We | |
332 | keep a status bit in the SSA_NAME node itself to indicate it has | |
b8698a0f | 333 | been put on the free list. |
6de9cd9a DN |
334 | |
335 | Note that once on the freelist you can not reference the SSA_NAME's | |
336 | defining statement. */ | |
337 | if (! SSA_NAME_IN_FREE_LIST (var)) | |
338 | { | |
6f2aec07 JL |
339 | tree saved_ssa_name_var = SSA_NAME_VAR (var); |
340 | int saved_ssa_name_version = SSA_NAME_VERSION (var); | |
f47c96aa | 341 | use_operand_p imm = &(SSA_NAME_IMM_USE_NODE (var)); |
f430bae8 | 342 | |
b5b8b0ac | 343 | if (MAY_HAVE_DEBUG_STMTS) |
0ca5af51 | 344 | insert_debug_temp_for_var_def (NULL, var); |
b5b8b0ac | 345 | |
f430bae8 AM |
346 | #ifdef ENABLE_CHECKING |
347 | verify_imm_links (stderr, var); | |
348 | #endif | |
349 | while (imm->next != imm) | |
0e61db61 | 350 | delink_imm_use (imm->next); |
6f2aec07 | 351 | |
9771b263 | 352 | (*SSANAMES (cfun))[SSA_NAME_VERSION (var)] = NULL_TREE; |
6f2aec07 JL |
353 | memset (var, 0, tree_size (var)); |
354 | ||
f430bae8 AM |
355 | imm->prev = imm; |
356 | imm->next = imm; | |
726a989a RB |
357 | imm->loc.ssa_name = var; |
358 | ||
6f2aec07 JL |
359 | /* First put back the right tree node so that the tree checking |
360 | macros do not complain. */ | |
361 | TREE_SET_CODE (var, SSA_NAME); | |
362 | ||
363 | /* Restore the version number. */ | |
364 | SSA_NAME_VERSION (var) = saved_ssa_name_version; | |
365 | ||
366 | /* Hopefully this can go away once we have the new incremental | |
367 | SSA updating code installed. */ | |
70b5e7dc | 368 | SET_SSA_NAME_VAR_OR_IDENTIFIER (var, saved_ssa_name_var); |
6f2aec07 JL |
369 | |
370 | /* Note this SSA_NAME is now in the first list. */ | |
6de9cd9a | 371 | SSA_NAME_IN_FREE_LIST (var) = 1; |
6f2aec07 | 372 | |
4b1a4694 | 373 | /* And finally put it on the free list. */ |
9771b263 | 374 | vec_safe_push (FREE_SSANAMES (cfun), var); |
6de9cd9a DN |
375 | } |
376 | } | |
377 | ||
644ffefd MJ |
378 | /* If the alignment of the pointer described by PI is known, return true and |
379 | store the alignment and the deviation from it into *ALIGNP and *MISALIGNP | |
380 | respectively. Otherwise return false. */ | |
381 | ||
382 | bool | |
383 | get_ptr_info_alignment (struct ptr_info_def *pi, unsigned int *alignp, | |
384 | unsigned int *misalignp) | |
385 | { | |
386 | if (pi->align) | |
387 | { | |
388 | *alignp = pi->align; | |
389 | *misalignp = pi->misalign; | |
390 | return true; | |
391 | } | |
392 | else | |
393 | return false; | |
394 | } | |
395 | ||
396 | /* State that the pointer described by PI has unknown alignment. */ | |
397 | ||
398 | void | |
399 | mark_ptr_info_alignment_unknown (struct ptr_info_def *pi) | |
400 | { | |
401 | pi->align = 0; | |
402 | pi->misalign = 0; | |
403 | } | |
404 | ||
405 | /* Store the the power-of-two byte alignment and the deviation from that | |
406 | alignment of pointer described by PI to ALIOGN and MISALIGN | |
407 | respectively. */ | |
408 | ||
409 | void | |
410 | set_ptr_info_alignment (struct ptr_info_def *pi, unsigned int align, | |
411 | unsigned int misalign) | |
412 | { | |
413 | gcc_checking_assert (align != 0); | |
414 | gcc_assert ((align & (align - 1)) == 0); | |
415 | gcc_assert ((misalign & ~(align - 1)) == 0); | |
416 | ||
417 | pi->align = align; | |
418 | pi->misalign = misalign; | |
419 | } | |
420 | ||
073a8998 | 421 | /* If pointer described by PI has known alignment, increase its known |
644ffefd MJ |
422 | misalignment by INCREMENT modulo its current alignment. */ |
423 | ||
424 | void | |
425 | adjust_ptr_info_misalignment (struct ptr_info_def *pi, | |
426 | unsigned int increment) | |
427 | { | |
428 | if (pi->align != 0) | |
429 | { | |
430 | pi->misalign += increment; | |
431 | pi->misalign &= (pi->align - 1); | |
432 | } | |
433 | } | |
d7621d3c | 434 | |
1be38ccb RG |
435 | /* Return the alias information associated with pointer T. It creates a |
436 | new instance if none existed. */ | |
437 | ||
438 | struct ptr_info_def * | |
439 | get_ptr_info (tree t) | |
d7621d3c | 440 | { |
1be38ccb | 441 | struct ptr_info_def *pi; |
8bb46326 | 442 | |
1be38ccb | 443 | gcc_assert (POINTER_TYPE_P (TREE_TYPE (t))); |
8bb46326 | 444 | |
1be38ccb RG |
445 | pi = SSA_NAME_PTR_INFO (t); |
446 | if (pi == NULL) | |
447 | { | |
448 | pi = ggc_alloc_cleared_ptr_info_def (); | |
449 | pt_solution_reset (&pi->pt); | |
644ffefd | 450 | mark_ptr_info_alignment_unknown (pi); |
1be38ccb RG |
451 | SSA_NAME_PTR_INFO (t) = pi; |
452 | } | |
8bb46326 | 453 | |
1be38ccb RG |
454 | return pi; |
455 | } | |
8bb46326 | 456 | |
070ecdfd RG |
457 | |
458 | /* Creates a new SSA name using the template NAME tobe defined by | |
459 | statement STMT in function FN. */ | |
460 | ||
461 | tree | |
462 | copy_ssa_name_fn (struct function *fn, tree name, gimple stmt) | |
463 | { | |
70b5e7dc RG |
464 | tree new_name; |
465 | ||
466 | if (SSA_NAME_VAR (name)) | |
467 | new_name = make_ssa_name_fn (fn, SSA_NAME_VAR (name), stmt); | |
468 | else | |
469 | { | |
470 | new_name = make_ssa_name_fn (fn, TREE_TYPE (name), stmt); | |
471 | SET_SSA_NAME_VAR_OR_IDENTIFIER (new_name, SSA_NAME_IDENTIFIER (name)); | |
472 | } | |
473 | ||
474 | return new_name; | |
070ecdfd RG |
475 | } |
476 | ||
477 | ||
8bb46326 | 478 | /* Creates a duplicate of the ptr_info_def at PTR_INFO for use by |
84d65814 | 479 | the SSA name NAME. */ |
8bb46326 DN |
480 | |
481 | void | |
482 | duplicate_ssa_name_ptr_info (tree name, struct ptr_info_def *ptr_info) | |
483 | { | |
d7621d3c ZD |
484 | struct ptr_info_def *new_ptr_info; |
485 | ||
8bb46326 DN |
486 | gcc_assert (POINTER_TYPE_P (TREE_TYPE (name))); |
487 | gcc_assert (!SSA_NAME_PTR_INFO (name)); | |
488 | ||
489 | if (!ptr_info) | |
490 | return; | |
d7621d3c | 491 | |
a9429e29 | 492 | new_ptr_info = ggc_alloc_ptr_info_def (); |
8bb46326 | 493 | *new_ptr_info = *ptr_info; |
d7621d3c | 494 | |
8bb46326 | 495 | SSA_NAME_PTR_INFO (name) = new_ptr_info; |
d7621d3c ZD |
496 | } |
497 | ||
a895a2b8 KV |
498 | /* Creates a duplicate of the range_info_def at RANGE_INFO for use by |
499 | the SSA name NAME. */ | |
500 | void | |
501 | duplicate_ssa_name_range_info (tree name, struct range_info_def *range_info) | |
502 | { | |
503 | struct range_info_def *new_range_info; | |
504 | ||
505 | gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); | |
506 | gcc_assert (!SSA_NAME_RANGE_INFO (name)); | |
507 | ||
508 | if (!range_info) | |
509 | return; | |
510 | ||
511 | new_range_info = ggc_alloc_range_info_def (); | |
512 | *new_range_info = *range_info; | |
513 | ||
514 | SSA_NAME_RANGE_INFO (name) = new_range_info; | |
515 | } | |
516 | ||
517 | ||
53b4bf74 | 518 | |
070ecdfd RG |
519 | /* Creates a duplicate of a ssa name NAME tobe defined by statement STMT |
520 | in function FN. */ | |
1be38ccb RG |
521 | |
522 | tree | |
070ecdfd | 523 | duplicate_ssa_name_fn (struct function *fn, tree name, gimple stmt) |
1be38ccb | 524 | { |
070ecdfd | 525 | tree new_name = copy_ssa_name_fn (fn, name, stmt); |
a895a2b8 KV |
526 | if (POINTER_TYPE_P (TREE_TYPE (name))) |
527 | { | |
528 | struct ptr_info_def *old_ptr_info = SSA_NAME_PTR_INFO (name); | |
529 | ||
530 | if (old_ptr_info) | |
0498471b | 531 | duplicate_ssa_name_ptr_info (new_name, old_ptr_info); |
a895a2b8 KV |
532 | } |
533 | else | |
534 | { | |
535 | struct range_info_def *old_range_info = SSA_NAME_RANGE_INFO (name); | |
1be38ccb | 536 | |
a895a2b8 | 537 | if (old_range_info) |
0498471b | 538 | duplicate_ssa_name_range_info (new_name, old_range_info); |
a895a2b8 | 539 | } |
1be38ccb RG |
540 | |
541 | return new_name; | |
542 | } | |
543 | ||
544 | ||
53b4bf74 DN |
545 | /* Release all the SSA_NAMEs created by STMT. */ |
546 | ||
547 | void | |
726a989a | 548 | release_defs (gimple stmt) |
53b4bf74 | 549 | { |
4c124b4c AM |
550 | tree def; |
551 | ssa_op_iter iter; | |
53b4bf74 | 552 | |
1ff54bfb KH |
553 | /* Make sure that we are in SSA. Otherwise, operand cache may point |
554 | to garbage. */ | |
5cd4ec7f | 555 | gcc_assert (gimple_in_ssa_p (cfun)); |
1ff54bfb | 556 | |
4c124b4c | 557 | FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS) |
80d8221e JH |
558 | if (TREE_CODE (def) == SSA_NAME) |
559 | release_ssa_name (def); | |
53b4bf74 DN |
560 | } |
561 | ||
bbc630f5 DN |
562 | |
563 | /* Replace the symbol associated with SSA_NAME with SYM. */ | |
564 | ||
565 | void | |
566 | replace_ssa_name_symbol (tree ssa_name, tree sym) | |
567 | { | |
70b5e7dc | 568 | SET_SSA_NAME_VAR_OR_IDENTIFIER (ssa_name, sym); |
bbc630f5 DN |
569 | TREE_TYPE (ssa_name) = TREE_TYPE (sym); |
570 | } | |
7faade0f | 571 | |
14f60a5a RG |
572 | /* Return SSA names that are unused to GGC memory and compact the SSA |
573 | version namespace. This is used to keep footprint of compiler during | |
574 | interprocedural optimization. */ | |
7faade0f JH |
575 | static unsigned int |
576 | release_dead_ssa_names (void) | |
577 | { | |
14f60a5a | 578 | unsigned i, j; |
9771b263 | 579 | int n = vec_safe_length (FREE_SSANAMES (cfun)); |
14f60a5a | 580 | |
7faade0f | 581 | /* Now release the freelist. */ |
9771b263 | 582 | vec_free (FREE_SSANAMES (cfun)); |
03b1d134 | 583 | |
14f60a5a RG |
584 | /* And compact the SSA number space. We make sure to not change the |
585 | relative order of SSA versions. */ | |
9771b263 | 586 | for (i = 1, j = 1; i < cfun->gimple_df->ssa_names->length (); ++i) |
14f60a5a RG |
587 | { |
588 | tree name = ssa_name (i); | |
589 | if (name) | |
590 | { | |
591 | if (i != j) | |
592 | { | |
593 | SSA_NAME_VERSION (name) = j; | |
9771b263 | 594 | (*cfun->gimple_df->ssa_names)[j] = name; |
14f60a5a RG |
595 | } |
596 | j++; | |
597 | } | |
598 | } | |
9771b263 | 599 | cfun->gimple_df->ssa_names->truncate (j); |
14f60a5a | 600 | |
736fe2d5 | 601 | statistics_counter_event (cfun, "SSA names released", n); |
14f60a5a | 602 | statistics_counter_event (cfun, "SSA name holes removed", i - j); |
7faade0f | 603 | if (dump_file) |
14f60a5a RG |
604 | fprintf (dump_file, "Released %i names, %.2f%%, removed %i holes\n", |
605 | n, n * 100.0 / num_ssa_names, i - j); | |
7faade0f JH |
606 | return 0; |
607 | } | |
608 | ||
27a4cd48 DM |
609 | namespace { |
610 | ||
611 | const pass_data pass_data_release_ssa_names = | |
7faade0f | 612 | { |
27a4cd48 DM |
613 | GIMPLE_PASS, /* type */ |
614 | "release_ssa", /* name */ | |
615 | OPTGROUP_NONE, /* optinfo_flags */ | |
616 | false, /* has_gate */ | |
617 | true, /* has_execute */ | |
618 | TV_TREE_SSA_OTHER, /* tv_id */ | |
619 | PROP_ssa, /* properties_required */ | |
620 | 0, /* properties_provided */ | |
621 | 0, /* properties_destroyed */ | |
622 | TODO_remove_unused_locals, /* todo_flags_start */ | |
623 | 0, /* todo_flags_finish */ | |
7faade0f | 624 | }; |
27a4cd48 DM |
625 | |
626 | class pass_release_ssa_names : public gimple_opt_pass | |
627 | { | |
628 | public: | |
c3284718 RS |
629 | pass_release_ssa_names (gcc::context *ctxt) |
630 | : gimple_opt_pass (pass_data_release_ssa_names, ctxt) | |
27a4cd48 DM |
631 | {} |
632 | ||
633 | /* opt_pass methods: */ | |
634 | unsigned int execute () { return release_dead_ssa_names (); } | |
635 | ||
636 | }; // class pass_release_ssa_names | |
637 | ||
638 | } // anon namespace | |
639 | ||
640 | gimple_opt_pass * | |
641 | make_pass_release_ssa_names (gcc::context *ctxt) | |
642 | { | |
643 | return new pass_release_ssa_names (ctxt); | |
644 | } |