]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-ssanames.c
rm a bunch of _stat allocation functions
[thirdparty/gcc.git] / gcc / tree-ssanames.c
CommitLineData
4ee9c684 1/* Generic routines for manipulating SSA_NAME expressions
3aea1f79 2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
0b1615c1 3
4ee9c684 4This file is part of GCC.
48e1416a 5
4ee9c684 6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8c4c00c1 8the Free Software Foundation; either version 3, or (at your option)
4ee9c684 9any later version.
48e1416a 10
4ee9c684 11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
48e1416a 15
4ee9c684 16You should have received a copy of the GNU General Public License
8c4c00c1 17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
1fa3a8f6 19
4ee9c684 20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
23#include "tm.h"
24#include "tree.h"
9ed99284 25#include "stor-layout.h"
bc61cadb 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"
073c1fd5 31#include "gimple.h"
32#include "gimple-ssa.h"
33#include "tree-phinodes.h"
34#include "ssa-iterators.h"
9ed99284 35#include "stringpool.h"
073c1fd5 36#include "tree-ssanames.h"
37#include "tree-into-ssa.h"
69ee5dbb 38#include "tree-ssa.h"
49290934 39#include "tree-pass.h"
4ee9c684 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
48e1416a 43 were threaded through PHI nodes.
4ee9c684 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
48e1416a 57 a compilation unit.
4ee9c684 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
5cc13354 66 more compact. */
4ee9c684 67
4ee9c684 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
4ee9c684 73unsigned int ssa_name_nodes_reused;
74unsigned int ssa_name_nodes_created;
4ee9c684 75
9e2e2283 76#define FREE_SSANAMES(fun) (fun)->gimple_df->free_ssanames
77
78
bcaa2770 79/* Initialize management of SSA_NAMEs to default SIZE. If SIZE is
80 zero use default. */
4ee9c684 81
82void
bcaa2770 83init_ssanames (struct function *fn, int size)
4ee9c684 84{
bcaa2770 85 if (size < 50)
86 size = 50;
87
f1f41a6c 88 vec_alloc (SSANAMES (fn), size);
c211d998 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
8b292c7f 93 large.
94
f1f41a6c 95 We use vec::quick_push here because we know that SSA_NAMES has at
b62e1ab2 96 least 50 elements reserved in it. */
f1f41a6c 97 SSANAMES (fn)->quick_push (NULL_TREE);
bcaa2770 98 FREE_SSANAMES (fn) = NULL;
dd277d48 99
e70e8b13 100 fn->gimple_df->ssa_renaming_needed = 0;
101 fn->gimple_df->rename_vops = 0;
4ee9c684 102}
103
104/* Finalize management of SSA_NAMEs. */
105
106void
107fini_ssanames (void)
108{
f1f41a6c 109 vec_free (SSANAMES (cfun));
110 vec_free (FREE_SSANAMES (cfun));
4ee9c684 111}
112
113/* Dump some simple statistics regarding the re-use of SSA_NAME nodes. */
114
4ee9c684 115void
116ssanames_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}
4ee9c684 121
bcaa2770 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). */
4ee9c684 126
127tree
75a70cf9 128make_ssa_name_fn (struct function *fn, tree var, gimple stmt)
4ee9c684 129{
130 tree t;
b66731e8 131 use_operand_p imm;
4ee9c684 132
2f4ec87c 133 gcc_assert (TREE_CODE (var) == VAR_DECL
134 || TREE_CODE (var) == PARM_DECL
ec11736b 135 || TREE_CODE (var) == RESULT_DECL
136 || (TYPE_P (var) && is_gimple_reg_type (var)));
4ee9c684 137
fa0f49c6 138 /* If our free list has an element, then use it. */
f1f41a6c 139 if (!vec_safe_is_empty (FREE_SSANAMES (fn)))
4ee9c684 140 {
f1f41a6c 141 t = FREE_SSANAMES (fn)->pop ();
ecd52ea9 142 if (GATHER_STATISTICS)
143 ssa_name_nodes_reused++;
4ee9c684 144
fa0f49c6 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. */
98107def 147 gcc_assert ((*SSANAMES (fn))[SSA_NAME_VERSION (t)] == NULL);
f1f41a6c 148 (*SSANAMES (fn))[SSA_NAME_VERSION (t)] = t;
4ee9c684 149 }
150 else
151 {
152 t = make_node (SSA_NAME);
f1f41a6c 153 SSA_NAME_VERSION (t) = SSANAMES (fn)->length ();
154 vec_safe_push (SSANAMES (fn), t);
ecd52ea9 155 if (GATHER_STATISTICS)
156 ssa_name_nodes_created++;
4ee9c684 157 }
158
ec11736b 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 }
4ee9c684 169 SSA_NAME_DEF_STMT (t) = stmt;
3c59e4a7 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
81d08033 175 SSA_NAME_IN_FREE_LIST (t) = 0;
de6ed584 176 SSA_NAME_IS_DEFAULT_DEF (t) = 0;
22aa74c4 177 imm = &(SSA_NAME_IMM_USE_NODE (t));
178 imm->use = NULL;
179 imm->prev = imm;
180 imm->next = imm;
75a70cf9 181 imm->loc.ssa_name = t;
4ee9c684 182
183 return t;
184}
185
0c20fe49 186/* Store range information RANGE_TYPE, MIN, and MAX to tree ssa_name NAME. */
3c59e4a7 187
188void
0c20fe49 189set_range_info (tree name, enum value_range_type range_type,
9c1be15e 190 const wide_int_ref &min, const wide_int_ref &max)
3c59e4a7 191{
192 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
0c20fe49 193 gcc_assert (range_type == VR_RANGE || range_type == VR_ANTI_RANGE);
3c59e4a7 194 range_info_def *ri = SSA_NAME_RANGE_INFO (name);
9c1be15e 195 unsigned int precision = TYPE_PRECISION (TREE_TYPE (name));
3c59e4a7 196
197 /* Allocate if not available. */
198 if (ri == NULL)
199 {
9c1be15e 200 size_t size = (sizeof (range_info_def)
201 + trailing_wide_ints <3>::extra_size (precision));
202 ri = ggc_alloc_range_info_def (size);
203 ri->ints.set_precision (precision);
3c59e4a7 204 SSA_NAME_RANGE_INFO (name) = ri;
9c1be15e 205 ri->set_nonzero_bits (wi::shwi (-1, precision));
3c59e4a7 206 }
207
0c20fe49 208 /* Record the range type. */
209 if (SSA_NAME_RANGE_TYPE (name) != range_type)
210 SSA_NAME_ANTI_RANGE_P (name) = (range_type == VR_ANTI_RANGE);
211
3c59e4a7 212 /* Set the values. */
9c1be15e 213 ri->set_min (min);
214 ri->set_max (max);
fc08b993 215
216 /* If it is a range, try to improve nonzero_bits from the min/max. */
0c20fe49 217 if (range_type == VR_RANGE)
fc08b993 218 {
9c1be15e 219 wide_int xorv = ri->get_min () ^ ri->get_max ();
aeb682a2 220 if (xorv != 0)
9c1be15e 221 xorv = wi::mask (precision - wi::clz (xorv), false, precision);
222 ri->set_nonzero_bits (ri->get_nonzero_bits () & (ri->get_min () | xorv));
fc08b993 223 }
3c59e4a7 224}
225
226
227/* Gets range information MIN, MAX and returns enum value_range_type
228 corresponding to tree ssa_name NAME. enum value_range_type returned
229 is used to determine if MIN and MAX are valid values. */
230
231enum value_range_type
9c1be15e 232get_range_info (const_tree name, wide_int *min, wide_int *max)
3c59e4a7 233{
3c59e4a7 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)))
0cf78115 241 > 2 * HOST_BITS_PER_WIDE_INT))
3c59e4a7 242 return VR_VARYING;
243
9c1be15e 244 *min = ri->get_min ();
245 *max = ri->get_max ();
0c20fe49 246 return SSA_NAME_RANGE_TYPE (name);
3c59e4a7 247}
c211d998 248
fc08b993 249/* Change non-zero bits bitmask of NAME. */
250
251void
9c1be15e 252set_nonzero_bits (tree name, const wide_int_ref &mask)
fc08b993 253{
254 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
255 if (SSA_NAME_RANGE_INFO (name) == NULL)
0c20fe49 256 set_range_info (name, VR_RANGE,
9c1be15e 257 TYPE_MIN_VALUE (TREE_TYPE (name)),
258 TYPE_MAX_VALUE (TREE_TYPE (name)));
fc08b993 259 range_info_def *ri = SSA_NAME_RANGE_INFO (name);
9c1be15e 260 ri->set_nonzero_bits (mask);
fc08b993 261}
262
aeb682a2 263/* Return a widest_int with potentially non-zero bits in SSA_NAME
264 NAME, or -1 if unknown. */
fc08b993 265
9c1be15e 266wide_int
c8a2b4ff 267get_nonzero_bits (const_tree name)
fc08b993 268{
9c1be15e 269 unsigned int precision = TYPE_PRECISION (TREE_TYPE (name));
fc08b993 270 if (POINTER_TYPE_P (TREE_TYPE (name)))
271 {
272 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name);
273 if (pi && pi->align)
6e5e0d6b 274 return wi::shwi (-(HOST_WIDE_INT) pi->align
275 | (HOST_WIDE_INT) pi->misalign, precision);
9c1be15e 276 return wi::shwi (-1, precision);
fc08b993 277 }
278
279 range_info_def *ri = SSA_NAME_RANGE_INFO (name);
9c1be15e 280 if (!ri)
281 return wi::shwi (-1, precision);
fc08b993 282
9c1be15e 283 return ri->get_nonzero_bits ();
fc08b993 284}
285
4ee9c684 286/* We no longer need the SSA_NAME expression VAR, release it so that
48e1416a 287 it may be reused.
4ee9c684 288
289 Note it is assumed that no calls to make_ssa_name will be made
290 until all uses of the ssa name are released and that the only
291 use of the SSA_NAME expression is to check its SSA_NAME_VAR. All
292 other fields must be assumed clobbered. */
293
294void
861b4e39 295release_ssa_name_fn (struct function *fn, tree var)
4ee9c684 296{
dec41e98 297 if (!var)
298 return;
299
81d08033 300 /* Never release the default definition for a symbol. It's a
301 special SSA name that should always exist once it's created. */
de6ed584 302 if (SSA_NAME_IS_DEFAULT_DEF (var))
81d08033 303 return;
304
095dcfa3 305 /* If VAR has been registered for SSA updating, don't remove it.
306 After update_ssa has run, the name will be released. */
307 if (name_registered_for_update_p (var))
308 {
309 release_ssa_name_after_update_ssa (var);
310 return;
311 }
deb78f9e 312
4ee9c684 313 /* release_ssa_name can be called multiple times on a single SSA_NAME.
314 However, it should only end up on our free list one time. We
315 keep a status bit in the SSA_NAME node itself to indicate it has
48e1416a 316 been put on the free list.
4ee9c684 317
318 Note that once on the freelist you can not reference the SSA_NAME's
319 defining statement. */
320 if (! SSA_NAME_IN_FREE_LIST (var))
321 {
fa0f49c6 322 tree saved_ssa_name_var = SSA_NAME_VAR (var);
323 int saved_ssa_name_version = SSA_NAME_VERSION (var);
b66731e8 324 use_operand_p imm = &(SSA_NAME_IMM_USE_NODE (var));
22aa74c4 325
9845d120 326 if (MAY_HAVE_DEBUG_STMTS)
688ff29b 327 insert_debug_temp_for_var_def (NULL, var);
9845d120 328
22aa74c4 329#ifdef ENABLE_CHECKING
330 verify_imm_links (stderr, var);
331#endif
332 while (imm->next != imm)
1fa3a8f6 333 delink_imm_use (imm->next);
fa0f49c6 334
861b4e39 335 (*SSANAMES (fn))[SSA_NAME_VERSION (var)] = NULL_TREE;
fa0f49c6 336 memset (var, 0, tree_size (var));
337
22aa74c4 338 imm->prev = imm;
339 imm->next = imm;
75a70cf9 340 imm->loc.ssa_name = var;
341
fa0f49c6 342 /* First put back the right tree node so that the tree checking
343 macros do not complain. */
344 TREE_SET_CODE (var, SSA_NAME);
345
346 /* Restore the version number. */
347 SSA_NAME_VERSION (var) = saved_ssa_name_version;
348
349 /* Hopefully this can go away once we have the new incremental
350 SSA updating code installed. */
ec11736b 351 SET_SSA_NAME_VAR_OR_IDENTIFIER (var, saved_ssa_name_var);
fa0f49c6 352
353 /* Note this SSA_NAME is now in the first list. */
4ee9c684 354 SSA_NAME_IN_FREE_LIST (var) = 1;
fa0f49c6 355
acb5ba8c 356 /* And finally put it on the free list. */
861b4e39 357 vec_safe_push (FREE_SSANAMES (fn), var);
4ee9c684 358 }
359}
360
ceea063b 361/* If the alignment of the pointer described by PI is known, return true and
362 store the alignment and the deviation from it into *ALIGNP and *MISALIGNP
363 respectively. Otherwise return false. */
364
365bool
366get_ptr_info_alignment (struct ptr_info_def *pi, unsigned int *alignp,
367 unsigned int *misalignp)
368{
369 if (pi->align)
370 {
371 *alignp = pi->align;
372 *misalignp = pi->misalign;
373 return true;
374 }
375 else
376 return false;
377}
378
379/* State that the pointer described by PI has unknown alignment. */
380
381void
382mark_ptr_info_alignment_unknown (struct ptr_info_def *pi)
383{
384 pi->align = 0;
385 pi->misalign = 0;
386}
387
388/* Store the the power-of-two byte alignment and the deviation from that
389 alignment of pointer described by PI to ALIOGN and MISALIGN
390 respectively. */
391
392void
393set_ptr_info_alignment (struct ptr_info_def *pi, unsigned int align,
394 unsigned int misalign)
395{
396 gcc_checking_assert (align != 0);
397 gcc_assert ((align & (align - 1)) == 0);
398 gcc_assert ((misalign & ~(align - 1)) == 0);
399
400 pi->align = align;
401 pi->misalign = misalign;
402}
403
9d75589a 404/* If pointer described by PI has known alignment, increase its known
ceea063b 405 misalignment by INCREMENT modulo its current alignment. */
406
407void
408adjust_ptr_info_misalignment (struct ptr_info_def *pi,
409 unsigned int increment)
410{
411 if (pi->align != 0)
412 {
413 pi->misalign += increment;
414 pi->misalign &= (pi->align - 1);
415 }
416}
3aaaf63f 417
153c3b50 418/* Return the alias information associated with pointer T. It creates a
419 new instance if none existed. */
420
421struct ptr_info_def *
422get_ptr_info (tree t)
3aaaf63f 423{
153c3b50 424 struct ptr_info_def *pi;
abb91f0b 425
153c3b50 426 gcc_assert (POINTER_TYPE_P (TREE_TYPE (t)));
abb91f0b 427
153c3b50 428 pi = SSA_NAME_PTR_INFO (t);
429 if (pi == NULL)
430 {
431 pi = ggc_alloc_cleared_ptr_info_def ();
432 pt_solution_reset (&pi->pt);
ceea063b 433 mark_ptr_info_alignment_unknown (pi);
153c3b50 434 SSA_NAME_PTR_INFO (t) = pi;
435 }
abb91f0b 436
153c3b50 437 return pi;
438}
abb91f0b 439
874117c8 440
441/* Creates a new SSA name using the template NAME tobe defined by
442 statement STMT in function FN. */
443
444tree
445copy_ssa_name_fn (struct function *fn, tree name, gimple stmt)
446{
ec11736b 447 tree new_name;
448
449 if (SSA_NAME_VAR (name))
450 new_name = make_ssa_name_fn (fn, SSA_NAME_VAR (name), stmt);
451 else
452 {
453 new_name = make_ssa_name_fn (fn, TREE_TYPE (name), stmt);
454 SET_SSA_NAME_VAR_OR_IDENTIFIER (new_name, SSA_NAME_IDENTIFIER (name));
455 }
456
457 return new_name;
874117c8 458}
459
460
abb91f0b 461/* Creates a duplicate of the ptr_info_def at PTR_INFO for use by
095dcfa3 462 the SSA name NAME. */
abb91f0b 463
464void
465duplicate_ssa_name_ptr_info (tree name, struct ptr_info_def *ptr_info)
466{
3aaaf63f 467 struct ptr_info_def *new_ptr_info;
468
abb91f0b 469 gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
470 gcc_assert (!SSA_NAME_PTR_INFO (name));
471
472 if (!ptr_info)
473 return;
3aaaf63f 474
ba72912a 475 new_ptr_info = ggc_alloc_ptr_info_def ();
abb91f0b 476 *new_ptr_info = *ptr_info;
3aaaf63f 477
abb91f0b 478 SSA_NAME_PTR_INFO (name) = new_ptr_info;
3aaaf63f 479}
480
0c20fe49 481/* Creates a duplicate of the range_info_def at RANGE_INFO of type
482 RANGE_TYPE for use by the SSA name NAME. */
3c59e4a7 483void
0c20fe49 484duplicate_ssa_name_range_info (tree name, enum value_range_type range_type,
485 struct range_info_def *range_info)
3c59e4a7 486{
487 struct range_info_def *new_range_info;
488
489 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
490 gcc_assert (!SSA_NAME_RANGE_INFO (name));
0c20fe49 491 gcc_assert (!SSA_NAME_ANTI_RANGE_P (name));
3c59e4a7 492
493 if (!range_info)
494 return;
495
9c1be15e 496 unsigned int precision = TYPE_PRECISION (TREE_TYPE (name));
497 size_t size = (sizeof (range_info_def)
498 + trailing_wide_ints <3>::extra_size (precision));
499 new_range_info = ggc_alloc_range_info_def (size);
500 memcpy (new_range_info, range_info, size);
3c59e4a7 501
0c20fe49 502 gcc_assert (range_type == VR_RANGE || range_type == VR_ANTI_RANGE);
503 SSA_NAME_ANTI_RANGE_P (name) = (range_type == VR_ANTI_RANGE);
3c59e4a7 504 SSA_NAME_RANGE_INFO (name) = new_range_info;
505}
506
507
81d08033 508
874117c8 509/* Creates a duplicate of a ssa name NAME tobe defined by statement STMT
510 in function FN. */
153c3b50 511
512tree
874117c8 513duplicate_ssa_name_fn (struct function *fn, tree name, gimple stmt)
153c3b50 514{
874117c8 515 tree new_name = copy_ssa_name_fn (fn, name, stmt);
3c59e4a7 516 if (POINTER_TYPE_P (TREE_TYPE (name)))
517 {
518 struct ptr_info_def *old_ptr_info = SSA_NAME_PTR_INFO (name);
519
520 if (old_ptr_info)
0cf78115 521 duplicate_ssa_name_ptr_info (new_name, old_ptr_info);
3c59e4a7 522 }
523 else
524 {
525 struct range_info_def *old_range_info = SSA_NAME_RANGE_INFO (name);
153c3b50 526
3c59e4a7 527 if (old_range_info)
0c20fe49 528 duplicate_ssa_name_range_info (new_name, SSA_NAME_RANGE_TYPE (name),
529 old_range_info);
3c59e4a7 530 }
153c3b50 531
532 return new_name;
533}
534
535
81d08033 536/* Release all the SSA_NAMEs created by STMT. */
537
538void
75a70cf9 539release_defs (gimple stmt)
81d08033 540{
43daa21e 541 tree def;
542 ssa_op_iter iter;
81d08033 543
d7eb56de 544 /* Make sure that we are in SSA. Otherwise, operand cache may point
545 to garbage. */
2d04fd8d 546 gcc_assert (gimple_in_ssa_p (cfun));
d7eb56de 547
43daa21e 548 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS)
ac6db781 549 if (TREE_CODE (def) == SSA_NAME)
550 release_ssa_name (def);
81d08033 551}
552
cbbefea4 553
554/* Replace the symbol associated with SSA_NAME with SYM. */
555
556void
557replace_ssa_name_symbol (tree ssa_name, tree sym)
558{
ec11736b 559 SET_SSA_NAME_VAR_OR_IDENTIFIER (ssa_name, sym);
cbbefea4 560 TREE_TYPE (ssa_name) = TREE_TYPE (sym);
561}
49290934 562
f901fae2 563/* Return SSA names that are unused to GGC memory and compact the SSA
564 version namespace. This is used to keep footprint of compiler during
565 interprocedural optimization. */
49290934 566
cbe8bda8 567namespace {
568
569const pass_data pass_data_release_ssa_names =
49290934 570{
cbe8bda8 571 GIMPLE_PASS, /* type */
572 "release_ssa", /* name */
573 OPTGROUP_NONE, /* optinfo_flags */
cbe8bda8 574 true, /* has_execute */
575 TV_TREE_SSA_OTHER, /* tv_id */
576 PROP_ssa, /* properties_required */
577 0, /* properties_provided */
578 0, /* properties_destroyed */
579 TODO_remove_unused_locals, /* todo_flags_start */
580 0, /* todo_flags_finish */
49290934 581};
cbe8bda8 582
583class pass_release_ssa_names : public gimple_opt_pass
584{
585public:
9af5ce0c 586 pass_release_ssa_names (gcc::context *ctxt)
587 : gimple_opt_pass (pass_data_release_ssa_names, ctxt)
cbe8bda8 588 {}
589
590 /* opt_pass methods: */
65b0537f 591 virtual unsigned int execute (function *);
cbe8bda8 592
593}; // class pass_release_ssa_names
594
65b0537f 595unsigned int
596pass_release_ssa_names::execute (function *fun)
597{
598 unsigned i, j;
599 int n = vec_safe_length (FREE_SSANAMES (fun));
600
601 /* Now release the freelist. */
602 vec_free (FREE_SSANAMES (fun));
603
604 /* And compact the SSA number space. We make sure to not change the
605 relative order of SSA versions. */
606 for (i = 1, j = 1; i < fun->gimple_df->ssa_names->length (); ++i)
607 {
608 tree name = ssa_name (i);
609 if (name)
610 {
611 if (i != j)
612 {
613 SSA_NAME_VERSION (name) = j;
614 (*fun->gimple_df->ssa_names)[j] = name;
615 }
616 j++;
617 }
618 }
619 fun->gimple_df->ssa_names->truncate (j);
620
621 statistics_counter_event (fun, "SSA names released", n);
622 statistics_counter_event (fun, "SSA name holes removed", i - j);
623 if (dump_file)
624 fprintf (dump_file, "Released %i names, %.2f%%, removed %i holes\n",
625 n, n * 100.0 / num_ssa_names, i - j);
626 return 0;
627}
628
cbe8bda8 629} // anon namespace
630
631gimple_opt_pass *
632make_pass_release_ssa_names (gcc::context *ctxt)
633{
634 return new pass_release_ssa_names (ctxt);
635}