]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/tree-into-ssa.c
tree-ssa-pre.c (alloc_expression_id): Fix use of VEC_reserve.
[thirdparty/gcc.git] / gcc / tree-into-ssa.c
1 /* Rewrite a program in Normal form into SSA.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@redhat.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "flags.h"
28 #include "tm_p.h"
29 #include "langhooks.h"
30 #include "basic-block.h"
31 #include "function.h"
32 #include "gimple-pretty-print.h"
33 #include "bitmap.h"
34 #include "tree-flow.h"
35 #include "gimple.h"
36 #include "tree-inline.h"
37 #include "hashtab.h"
38 #include "tree-pass.h"
39 #include "cfgloop.h"
40 #include "domwalk.h"
41 #include "params.h"
42 #include "vecprim.h"
43
44
45 /* This file builds the SSA form for a function as described in:
46 R. Cytron, J. Ferrante, B. Rosen, M. Wegman, and K. Zadeck. Efficiently
47 Computing Static Single Assignment Form and the Control Dependence
48 Graph. ACM Transactions on Programming Languages and Systems,
49 13(4):451-490, October 1991. */
50
51 /* Structure to map a variable VAR to the set of blocks that contain
52 definitions for VAR. */
53 struct def_blocks_d
54 {
55 /* Blocks that contain definitions of VAR. Bit I will be set if the
56 Ith block contains a definition of VAR. */
57 bitmap def_blocks;
58
59 /* Blocks that contain a PHI node for VAR. */
60 bitmap phi_blocks;
61
62 /* Blocks where VAR is live-on-entry. Similar semantics as
63 DEF_BLOCKS. */
64 bitmap livein_blocks;
65 };
66
67 typedef struct def_blocks_d *def_blocks_p;
68
69
70 /* Stack of trees used to restore the global currdefs to its original
71 state after completing rewriting of a block and its dominator
72 children. Its elements have the following properties:
73
74 - An SSA_NAME (N) indicates that the current definition of the
75 underlying variable should be set to the given SSA_NAME. If the
76 symbol associated with the SSA_NAME is not a GIMPLE register, the
77 next slot in the stack must be a _DECL node (SYM). In this case,
78 the name N in the previous slot is the current reaching
79 definition for SYM.
80
81 - A _DECL node indicates that the underlying variable has no
82 current definition.
83
84 - A NULL node at the top entry is used to mark the last slot
85 associated with the current block. */
86 static VEC(tree,heap) *block_defs_stack;
87
88
89 /* Set of existing SSA names being replaced by update_ssa. */
90 static sbitmap old_ssa_names;
91
92 /* Set of new SSA names being added by update_ssa. Note that both
93 NEW_SSA_NAMES and OLD_SSA_NAMES are dense bitmaps because most of
94 the operations done on them are presence tests. */
95 static sbitmap new_ssa_names;
96
97 sbitmap interesting_blocks;
98
99 /* Set of SSA names that have been marked to be released after they
100 were registered in the replacement table. They will be finally
101 released after we finish updating the SSA web. */
102 static bitmap names_to_release;
103
104 /* VEC of VECs of PHIs to rewrite in a basic block. Element I corresponds
105 the to basic block with index I. Allocated once per compilation, *not*
106 released between different functions. */
107 static VEC(gimple_vec, heap) *phis_to_rewrite;
108
109 /* The bitmap of non-NULL elements of PHIS_TO_REWRITE. */
110 static bitmap blocks_with_phis_to_rewrite;
111
112 /* Growth factor for NEW_SSA_NAMES and OLD_SSA_NAMES. These sets need
113 to grow as the callers to register_new_name_mapping will typically
114 create new names on the fly. FIXME. Currently set to 1/3 to avoid
115 frequent reallocations but still need to find a reasonable growth
116 strategy. */
117 #define NAME_SETS_GROWTH_FACTOR (MAX (3, num_ssa_names / 3))
118
119
120 /* The function the SSA updating data structures have been initialized for.
121 NULL if they need to be initialized by register_new_name_mapping. */
122 static struct function *update_ssa_initialized_fn = NULL;
123
124 /* Global data to attach to the main dominator walk structure. */
125 struct mark_def_sites_global_data
126 {
127 /* This bitmap contains the variables which are set before they
128 are used in a basic block. */
129 bitmap kills;
130 };
131
132 /* Information stored for both SSA names and decls. */
133 struct common_info_d
134 {
135 /* This field indicates whether or not the variable may need PHI nodes.
136 See the enum's definition for more detailed information about the
137 states. */
138 ENUM_BITFIELD (need_phi_state) need_phi_state : 2;
139
140 /* The current reaching definition replacing this var. */
141 tree current_def;
142
143 /* Definitions for this var. */
144 struct def_blocks_d def_blocks;
145 };
146
147 /* The information associated with decls and SSA names. */
148 typedef struct common_info_d *common_info_p;
149
150 /* Information stored for decls. */
151 struct var_info_d
152 {
153 /* The variable. */
154 tree var;
155
156 /* Information stored for both SSA names and decls. */
157 struct common_info_d info;
158 };
159
160 /* The information associated with decls. */
161 typedef struct var_info_d *var_info_p;
162
163 DEF_VEC_P(var_info_p);
164 DEF_VEC_ALLOC_P(var_info_p,heap);
165
166 /* Each entry in VAR_INFOS contains an element of type STRUCT
167 VAR_INFO_D. */
168 static htab_t var_infos;
169
170
171 /* Information stored for SSA names. */
172 struct ssa_name_info
173 {
174 /* Age of this record (so that info_for_ssa_name table can be cleared
175 quickly); if AGE < CURRENT_INFO_FOR_SSA_NAME_AGE, then the fields
176 are assumed to be null. */
177 unsigned age;
178
179 /* Replacement mappings, allocated from update_ssa_obstack. */
180 bitmap repl_set;
181
182 /* Information stored for both SSA names and decls. */
183 struct common_info_d info;
184 };
185
186 /* The information associated with names. */
187 typedef struct ssa_name_info *ssa_name_info_p;
188 DEF_VEC_P (ssa_name_info_p);
189 DEF_VEC_ALLOC_P (ssa_name_info_p, heap);
190
191 static VEC(ssa_name_info_p, heap) *info_for_ssa_name;
192 static unsigned current_info_for_ssa_name_age;
193
194 static bitmap_obstack update_ssa_obstack;
195
196 /* The set of blocks affected by update_ssa. */
197 static bitmap blocks_to_update;
198
199 /* The main entry point to the SSA renamer (rewrite_blocks) may be
200 called several times to do different, but related, tasks.
201 Initially, we need it to rename the whole program into SSA form.
202 At other times, we may need it to only rename into SSA newly
203 exposed symbols. Finally, we can also call it to incrementally fix
204 an already built SSA web. */
205 enum rewrite_mode {
206 /* Convert the whole function into SSA form. */
207 REWRITE_ALL,
208
209 /* Incrementally update the SSA web by replacing existing SSA
210 names with new ones. See update_ssa for details. */
211 REWRITE_UPDATE
212 };
213
214
215
216
217 /* Prototypes for debugging functions. */
218 extern void dump_tree_ssa (FILE *);
219 extern void debug_tree_ssa (void);
220 extern void debug_def_blocks (void);
221 extern void dump_tree_ssa_stats (FILE *);
222 extern void debug_tree_ssa_stats (void);
223 extern void dump_update_ssa (FILE *);
224 extern void debug_update_ssa (void);
225 extern void dump_names_replaced_by (FILE *, tree);
226 extern void debug_names_replaced_by (tree);
227 extern void dump_var_infos (FILE *);
228 extern void debug_var_infos (void);
229 extern void dump_defs_stack (FILE *, int);
230 extern void debug_defs_stack (int);
231 extern void dump_currdefs (FILE *);
232 extern void debug_currdefs (void);
233
234
235 /* The set of symbols we ought to re-write into SSA form in update_ssa. */
236 static bitmap symbols_to_rename_set;
237 static VEC(tree,heap) *symbols_to_rename;
238
239 /* Mark SYM for renaming. */
240
241 static void
242 mark_for_renaming (tree sym)
243 {
244 if (!symbols_to_rename_set)
245 symbols_to_rename_set = BITMAP_ALLOC (NULL);
246 if (bitmap_set_bit (symbols_to_rename_set, DECL_UID (sym)))
247 VEC_safe_push (tree, heap, symbols_to_rename, sym);
248 }
249
250 /* Return true if SYM is marked for renaming. */
251
252 static bool
253 marked_for_renaming (tree sym)
254 {
255 if (!symbols_to_rename_set || sym == NULL_TREE)
256 return false;
257 return bitmap_bit_p (symbols_to_rename_set, DECL_UID (sym));
258 }
259
260
261 /* Return true if STMT needs to be rewritten. When renaming a subset
262 of the variables, not all statements will be processed. This is
263 decided in mark_def_sites. */
264
265 static inline bool
266 rewrite_uses_p (gimple stmt)
267 {
268 return gimple_visited_p (stmt);
269 }
270
271
272 /* Set the rewrite marker on STMT to the value given by REWRITE_P. */
273
274 static inline void
275 set_rewrite_uses (gimple stmt, bool rewrite_p)
276 {
277 gimple_set_visited (stmt, rewrite_p);
278 }
279
280
281 /* Return true if the DEFs created by statement STMT should be
282 registered when marking new definition sites. This is slightly
283 different than rewrite_uses_p: it's used by update_ssa to
284 distinguish statements that need to have both uses and defs
285 processed from those that only need to have their defs processed.
286 Statements that define new SSA names only need to have their defs
287 registered, but they don't need to have their uses renamed. */
288
289 static inline bool
290 register_defs_p (gimple stmt)
291 {
292 return gimple_plf (stmt, GF_PLF_1) != 0;
293 }
294
295
296 /* If REGISTER_DEFS_P is true, mark STMT to have its DEFs registered. */
297
298 static inline void
299 set_register_defs (gimple stmt, bool register_defs_p)
300 {
301 gimple_set_plf (stmt, GF_PLF_1, register_defs_p);
302 }
303
304
305 /* Get the information associated with NAME. */
306
307 static inline ssa_name_info_p
308 get_ssa_name_ann (tree name)
309 {
310 unsigned ver = SSA_NAME_VERSION (name);
311 unsigned len = VEC_length (ssa_name_info_p, info_for_ssa_name);
312 struct ssa_name_info *info;
313
314 if (ver >= len)
315 {
316 unsigned old_len = VEC_length (ssa_name_info_p, info_for_ssa_name);
317 unsigned new_len = num_ssa_names;
318
319 VEC_reserve (ssa_name_info_p, heap, info_for_ssa_name,
320 new_len - old_len);
321 while (len++ < new_len)
322 {
323 struct ssa_name_info *info = XCNEW (struct ssa_name_info);
324 info->age = current_info_for_ssa_name_age;
325 VEC_quick_push (ssa_name_info_p, info_for_ssa_name, info);
326 }
327 }
328
329 info = VEC_index (ssa_name_info_p, info_for_ssa_name, ver);
330 if (info->age < current_info_for_ssa_name_age)
331 {
332 info->age = current_info_for_ssa_name_age;
333 info->repl_set = NULL;
334 info->info.need_phi_state = NEED_PHI_STATE_UNKNOWN;
335 info->info.current_def = NULL_TREE;
336 info->info.def_blocks.def_blocks = NULL;
337 info->info.def_blocks.phi_blocks = NULL;
338 info->info.def_blocks.livein_blocks = NULL;
339 }
340
341 return info;
342 }
343
344 /* Return and allocate the auxiliar information for DECL. */
345
346 static inline var_info_p
347 get_var_info (tree decl)
348 {
349 struct var_info_d vi;
350 void **slot;
351 vi.var = decl;
352 slot = htab_find_slot_with_hash (var_infos, &vi, DECL_UID (decl), INSERT);
353 if (*slot == NULL)
354 {
355 var_info_p v = XCNEW (struct var_info_d);
356 v->var = decl;
357 *slot = (void *)v;
358 return v;
359 }
360 return (var_info_p) *slot;
361 }
362
363
364 /* Clears info for SSA names. */
365
366 static void
367 clear_ssa_name_info (void)
368 {
369 current_info_for_ssa_name_age++;
370
371 /* If current_info_for_ssa_name_age wraps we use stale information.
372 Asser that this does not happen. */
373 gcc_assert (current_info_for_ssa_name_age != 0);
374 }
375
376
377 /* Get access to the auxiliar information stored per SSA name or decl. */
378
379 static inline common_info_p
380 get_common_info (tree var)
381 {
382 if (TREE_CODE (var) == SSA_NAME)
383 return &get_ssa_name_ann (var)->info;
384 else
385 return &get_var_info (var)->info;
386 }
387
388
389 /* Return the current definition for VAR. */
390
391 tree
392 get_current_def (tree var)
393 {
394 return get_common_info (var)->current_def;
395 }
396
397
398 /* Sets current definition of VAR to DEF. */
399
400 void
401 set_current_def (tree var, tree def)
402 {
403 get_common_info (var)->current_def = def;
404 }
405
406
407 /* Compute global livein information given the set of blocks where
408 an object is locally live at the start of the block (LIVEIN)
409 and the set of blocks where the object is defined (DEF_BLOCKS).
410
411 Note: This routine augments the existing local livein information
412 to include global livein (i.e., it modifies the underlying bitmap
413 for LIVEIN). */
414
415 void
416 compute_global_livein (bitmap livein, bitmap def_blocks)
417 {
418 unsigned i;
419 bitmap_iterator bi;
420 VEC (basic_block, heap) *worklist;
421
422 /* Normally the work list size is bounded by the number of basic
423 blocks in the largest loop. We don't know this number, but we
424 can be fairly sure that it will be relatively small. */
425 worklist = VEC_alloc (basic_block, heap, MAX (8, n_basic_blocks / 128));
426
427 EXECUTE_IF_SET_IN_BITMAP (livein, 0, i, bi)
428 VEC_safe_push (basic_block, heap, worklist, BASIC_BLOCK (i));
429
430 /* Iterate until the worklist is empty. */
431 while (! VEC_empty (basic_block, worklist))
432 {
433 edge e;
434 edge_iterator ei;
435
436 /* Pull a block off the worklist. */
437 basic_block bb = VEC_pop (basic_block, worklist);
438
439 /* Make sure we have at least enough room in the work list
440 for all predecessors of this block. */
441 VEC_reserve (basic_block, heap, worklist, EDGE_COUNT (bb->preds));
442
443 /* For each predecessor block. */
444 FOR_EACH_EDGE (e, ei, bb->preds)
445 {
446 basic_block pred = e->src;
447 int pred_index = pred->index;
448
449 /* None of this is necessary for the entry block. */
450 if (pred != ENTRY_BLOCK_PTR
451 && ! bitmap_bit_p (def_blocks, pred_index)
452 && bitmap_set_bit (livein, pred_index))
453 {
454 VEC_quick_push (basic_block, worklist, pred);
455 }
456 }
457 }
458
459 VEC_free (basic_block, heap, worklist);
460 }
461
462
463 /* Cleans up the REWRITE_THIS_STMT and REGISTER_DEFS_IN_THIS_STMT flags for
464 all statements in basic block BB. */
465
466 static void
467 initialize_flags_in_bb (basic_block bb)
468 {
469 gimple stmt;
470 gimple_stmt_iterator gsi;
471
472 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
473 {
474 gimple phi = gsi_stmt (gsi);
475 set_rewrite_uses (phi, false);
476 set_register_defs (phi, false);
477 }
478
479 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
480 {
481 stmt = gsi_stmt (gsi);
482
483 /* We are going to use the operand cache API, such as
484 SET_USE, SET_DEF, and FOR_EACH_IMM_USE_FAST. The operand
485 cache for each statement should be up-to-date. */
486 gcc_assert (!gimple_modified_p (stmt));
487 set_rewrite_uses (stmt, false);
488 set_register_defs (stmt, false);
489 }
490 }
491
492 /* Mark block BB as interesting for update_ssa. */
493
494 static void
495 mark_block_for_update (basic_block bb)
496 {
497 gcc_assert (blocks_to_update != NULL);
498 if (!bitmap_set_bit (blocks_to_update, bb->index))
499 return;
500 initialize_flags_in_bb (bb);
501 }
502
503 /* Return the set of blocks where variable VAR is defined and the blocks
504 where VAR is live on entry (livein). If no entry is found in
505 DEF_BLOCKS, a new one is created and returned. */
506
507 static inline struct def_blocks_d *
508 get_def_blocks_for (common_info_p info)
509 {
510 struct def_blocks_d *db_p = &info->def_blocks;
511 if (!db_p->def_blocks)
512 {
513 db_p->def_blocks = BITMAP_ALLOC (&update_ssa_obstack);
514 db_p->phi_blocks = BITMAP_ALLOC (&update_ssa_obstack);
515 db_p->livein_blocks = BITMAP_ALLOC (&update_ssa_obstack);
516 }
517
518 return db_p;
519 }
520
521
522 /* Mark block BB as the definition site for variable VAR. PHI_P is true if
523 VAR is defined by a PHI node. */
524
525 static void
526 set_def_block (tree var, basic_block bb, bool phi_p)
527 {
528 struct def_blocks_d *db_p;
529 common_info_p info;
530
531 info = get_common_info (var);
532 db_p = get_def_blocks_for (info);
533
534 /* Set the bit corresponding to the block where VAR is defined. */
535 bitmap_set_bit (db_p->def_blocks, bb->index);
536 if (phi_p)
537 bitmap_set_bit (db_p->phi_blocks, bb->index);
538
539 /* Keep track of whether or not we may need to insert PHI nodes.
540
541 If we are in the UNKNOWN state, then this is the first definition
542 of VAR. Additionally, we have not seen any uses of VAR yet, so
543 we do not need a PHI node for this variable at this time (i.e.,
544 transition to NEED_PHI_STATE_NO).
545
546 If we are in any other state, then we either have multiple definitions
547 of this variable occurring in different blocks or we saw a use of the
548 variable which was not dominated by the block containing the
549 definition(s). In this case we may need a PHI node, so enter
550 state NEED_PHI_STATE_MAYBE. */
551 if (info->need_phi_state == NEED_PHI_STATE_UNKNOWN)
552 info->need_phi_state = NEED_PHI_STATE_NO;
553 else
554 info->need_phi_state = NEED_PHI_STATE_MAYBE;
555 }
556
557
558 /* Mark block BB as having VAR live at the entry to BB. */
559
560 static void
561 set_livein_block (tree var, basic_block bb)
562 {
563 common_info_p info;
564 struct def_blocks_d *db_p;
565
566 info = get_common_info (var);
567 db_p = get_def_blocks_for (info);
568
569 /* Set the bit corresponding to the block where VAR is live in. */
570 bitmap_set_bit (db_p->livein_blocks, bb->index);
571
572 /* Keep track of whether or not we may need to insert PHI nodes.
573
574 If we reach here in NEED_PHI_STATE_NO, see if this use is dominated
575 by the single block containing the definition(s) of this variable. If
576 it is, then we remain in NEED_PHI_STATE_NO, otherwise we transition to
577 NEED_PHI_STATE_MAYBE. */
578 if (info->need_phi_state == NEED_PHI_STATE_NO)
579 {
580 int def_block_index = bitmap_first_set_bit (db_p->def_blocks);
581
582 if (def_block_index == -1
583 || ! dominated_by_p (CDI_DOMINATORS, bb,
584 BASIC_BLOCK (def_block_index)))
585 info->need_phi_state = NEED_PHI_STATE_MAYBE;
586 }
587 else
588 info->need_phi_state = NEED_PHI_STATE_MAYBE;
589 }
590
591
592 /* Return true if NAME is in OLD_SSA_NAMES. */
593
594 static inline bool
595 is_old_name (tree name)
596 {
597 unsigned ver = SSA_NAME_VERSION (name);
598 if (!new_ssa_names)
599 return false;
600 return (ver < SBITMAP_SIZE (new_ssa_names)
601 && TEST_BIT (old_ssa_names, ver));
602 }
603
604
605 /* Return true if NAME is in NEW_SSA_NAMES. */
606
607 static inline bool
608 is_new_name (tree name)
609 {
610 unsigned ver = SSA_NAME_VERSION (name);
611 if (!new_ssa_names)
612 return false;
613 return (ver < SBITMAP_SIZE (new_ssa_names)
614 && TEST_BIT (new_ssa_names, ver));
615 }
616
617
618 /* Return the names replaced by NEW_TREE (i.e., REPL_TBL[NEW_TREE].SET). */
619
620 static inline bitmap
621 names_replaced_by (tree new_tree)
622 {
623 return get_ssa_name_ann (new_tree)->repl_set;
624 }
625
626
627 /* Add OLD to REPL_TBL[NEW_TREE].SET. */
628
629 static inline void
630 add_to_repl_tbl (tree new_tree, tree old)
631 {
632 bitmap *set = &get_ssa_name_ann (new_tree)->repl_set;
633 if (!*set)
634 *set = BITMAP_ALLOC (&update_ssa_obstack);
635 bitmap_set_bit (*set, SSA_NAME_VERSION (old));
636 }
637
638
639 /* Add a new mapping NEW_TREE -> OLD REPL_TBL. Every entry N_i in REPL_TBL
640 represents the set of names O_1 ... O_j replaced by N_i. This is
641 used by update_ssa and its helpers to introduce new SSA names in an
642 already formed SSA web. */
643
644 static void
645 add_new_name_mapping (tree new_tree, tree old)
646 {
647 timevar_push (TV_TREE_SSA_INCREMENTAL);
648
649 /* OLD and NEW_TREE must be different SSA names for the same symbol. */
650 gcc_assert (new_tree != old && SSA_NAME_VAR (new_tree) == SSA_NAME_VAR (old));
651
652 /* We may need to grow NEW_SSA_NAMES and OLD_SSA_NAMES because our
653 caller may have created new names since the set was created. */
654 if (SBITMAP_SIZE (new_ssa_names) <= num_ssa_names - 1)
655 {
656 unsigned int new_sz = num_ssa_names + NAME_SETS_GROWTH_FACTOR;
657 new_ssa_names = sbitmap_resize (new_ssa_names, new_sz, 0);
658 old_ssa_names = sbitmap_resize (old_ssa_names, new_sz, 0);
659 }
660
661 /* Update the REPL_TBL table. */
662 add_to_repl_tbl (new_tree, old);
663
664 /* If OLD had already been registered as a new name, then all the
665 names that OLD replaces should also be replaced by NEW_TREE. */
666 if (is_new_name (old))
667 bitmap_ior_into (names_replaced_by (new_tree), names_replaced_by (old));
668
669 /* Register NEW_TREE and OLD in NEW_SSA_NAMES and OLD_SSA_NAMES,
670 respectively. */
671 SET_BIT (new_ssa_names, SSA_NAME_VERSION (new_tree));
672 SET_BIT (old_ssa_names, SSA_NAME_VERSION (old));
673
674 timevar_pop (TV_TREE_SSA_INCREMENTAL);
675 }
676
677
678 /* Call back for walk_dominator_tree used to collect definition sites
679 for every variable in the function. For every statement S in block
680 BB:
681
682 1- Variables defined by S in the DEFS of S are marked in the bitmap
683 KILLS.
684
685 2- If S uses a variable VAR and there is no preceding kill of VAR,
686 then it is marked in the LIVEIN_BLOCKS bitmap associated with VAR.
687
688 This information is used to determine which variables are live
689 across block boundaries to reduce the number of PHI nodes
690 we create. */
691
692 static void
693 mark_def_sites (basic_block bb, gimple stmt, bitmap kills)
694 {
695 tree def;
696 use_operand_p use_p;
697 ssa_op_iter iter;
698
699 /* Since this is the first time that we rewrite the program into SSA
700 form, force an operand scan on every statement. */
701 update_stmt (stmt);
702
703 gcc_assert (blocks_to_update == NULL);
704 set_register_defs (stmt, false);
705 set_rewrite_uses (stmt, false);
706
707 if (is_gimple_debug (stmt))
708 {
709 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
710 {
711 tree sym = USE_FROM_PTR (use_p);
712 gcc_assert (DECL_P (sym));
713 set_rewrite_uses (stmt, true);
714 }
715 if (rewrite_uses_p (stmt))
716 SET_BIT (interesting_blocks, bb->index);
717 return;
718 }
719
720 /* If a variable is used before being set, then the variable is live
721 across a block boundary, so mark it live-on-entry to BB. */
722 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
723 {
724 tree sym = USE_FROM_PTR (use_p);
725 gcc_assert (DECL_P (sym));
726 if (!bitmap_bit_p (kills, DECL_UID (sym)))
727 set_livein_block (sym, bb);
728 set_rewrite_uses (stmt, true);
729 }
730
731 /* Now process the defs. Mark BB as the definition block and add
732 each def to the set of killed symbols. */
733 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS)
734 {
735 gcc_assert (DECL_P (def));
736 set_def_block (def, bb, false);
737 bitmap_set_bit (kills, DECL_UID (def));
738 set_register_defs (stmt, true);
739 }
740
741 /* If we found the statement interesting then also mark the block BB
742 as interesting. */
743 if (rewrite_uses_p (stmt) || register_defs_p (stmt))
744 SET_BIT (interesting_blocks, bb->index);
745 }
746
747 /* Structure used by prune_unused_phi_nodes to record bounds of the intervals
748 in the dfs numbering of the dominance tree. */
749
750 struct dom_dfsnum
751 {
752 /* Basic block whose index this entry corresponds to. */
753 unsigned bb_index;
754
755 /* The dfs number of this node. */
756 unsigned dfs_num;
757 };
758
759 /* Compares two entries of type struct dom_dfsnum by dfs_num field. Callback
760 for qsort. */
761
762 static int
763 cmp_dfsnum (const void *a, const void *b)
764 {
765 const struct dom_dfsnum *const da = (const struct dom_dfsnum *) a;
766 const struct dom_dfsnum *const db = (const struct dom_dfsnum *) b;
767
768 return (int) da->dfs_num - (int) db->dfs_num;
769 }
770
771 /* Among the intervals starting at the N points specified in DEFS, find
772 the one that contains S, and return its bb_index. */
773
774 static unsigned
775 find_dfsnum_interval (struct dom_dfsnum *defs, unsigned n, unsigned s)
776 {
777 unsigned f = 0, t = n, m;
778
779 while (t > f + 1)
780 {
781 m = (f + t) / 2;
782 if (defs[m].dfs_num <= s)
783 f = m;
784 else
785 t = m;
786 }
787
788 return defs[f].bb_index;
789 }
790
791 /* Clean bits from PHIS for phi nodes whose value cannot be used in USES.
792 KILLS is a bitmap of blocks where the value is defined before any use. */
793
794 static void
795 prune_unused_phi_nodes (bitmap phis, bitmap kills, bitmap uses)
796 {
797 VEC(int, heap) *worklist;
798 bitmap_iterator bi;
799 unsigned i, b, p, u, top;
800 bitmap live_phis;
801 basic_block def_bb, use_bb;
802 edge e;
803 edge_iterator ei;
804 bitmap to_remove;
805 struct dom_dfsnum *defs;
806 unsigned n_defs, adef;
807
808 if (bitmap_empty_p (uses))
809 {
810 bitmap_clear (phis);
811 return;
812 }
813
814 /* The phi must dominate a use, or an argument of a live phi. Also, we
815 do not create any phi nodes in def blocks, unless they are also livein. */
816 to_remove = BITMAP_ALLOC (NULL);
817 bitmap_and_compl (to_remove, kills, uses);
818 bitmap_and_compl_into (phis, to_remove);
819 if (bitmap_empty_p (phis))
820 {
821 BITMAP_FREE (to_remove);
822 return;
823 }
824
825 /* We want to remove the unnecessary phi nodes, but we do not want to compute
826 liveness information, as that may be linear in the size of CFG, and if
827 there are lot of different variables to rewrite, this may lead to quadratic
828 behavior.
829
830 Instead, we basically emulate standard dce. We put all uses to worklist,
831 then for each of them find the nearest def that dominates them. If this
832 def is a phi node, we mark it live, and if it was not live before, we
833 add the predecessors of its basic block to the worklist.
834
835 To quickly locate the nearest def that dominates use, we use dfs numbering
836 of the dominance tree (that is already available in order to speed up
837 queries). For each def, we have the interval given by the dfs number on
838 entry to and on exit from the corresponding subtree in the dominance tree.
839 The nearest dominator for a given use is the smallest of these intervals
840 that contains entry and exit dfs numbers for the basic block with the use.
841 If we store the bounds for all the uses to an array and sort it, we can
842 locate the nearest dominating def in logarithmic time by binary search.*/
843 bitmap_ior (to_remove, kills, phis);
844 n_defs = bitmap_count_bits (to_remove);
845 defs = XNEWVEC (struct dom_dfsnum, 2 * n_defs + 1);
846 defs[0].bb_index = 1;
847 defs[0].dfs_num = 0;
848 adef = 1;
849 EXECUTE_IF_SET_IN_BITMAP (to_remove, 0, i, bi)
850 {
851 def_bb = BASIC_BLOCK (i);
852 defs[adef].bb_index = i;
853 defs[adef].dfs_num = bb_dom_dfs_in (CDI_DOMINATORS, def_bb);
854 defs[adef + 1].bb_index = i;
855 defs[adef + 1].dfs_num = bb_dom_dfs_out (CDI_DOMINATORS, def_bb);
856 adef += 2;
857 }
858 BITMAP_FREE (to_remove);
859 gcc_assert (adef == 2 * n_defs + 1);
860 qsort (defs, adef, sizeof (struct dom_dfsnum), cmp_dfsnum);
861 gcc_assert (defs[0].bb_index == 1);
862
863 /* Now each DEFS entry contains the number of the basic block to that the
864 dfs number corresponds. Change them to the number of basic block that
865 corresponds to the interval following the dfs number. Also, for the
866 dfs_out numbers, increase the dfs number by one (so that it corresponds
867 to the start of the following interval, not to the end of the current
868 one). We use WORKLIST as a stack. */
869 worklist = VEC_alloc (int, heap, n_defs + 1);
870 VEC_quick_push (int, worklist, 1);
871 top = 1;
872 n_defs = 1;
873 for (i = 1; i < adef; i++)
874 {
875 b = defs[i].bb_index;
876 if (b == top)
877 {
878 /* This is a closing element. Interval corresponding to the top
879 of the stack after removing it follows. */
880 VEC_pop (int, worklist);
881 top = VEC_index (int, worklist, VEC_length (int, worklist) - 1);
882 defs[n_defs].bb_index = top;
883 defs[n_defs].dfs_num = defs[i].dfs_num + 1;
884 }
885 else
886 {
887 /* Opening element. Nothing to do, just push it to the stack and move
888 it to the correct position. */
889 defs[n_defs].bb_index = defs[i].bb_index;
890 defs[n_defs].dfs_num = defs[i].dfs_num;
891 VEC_quick_push (int, worklist, b);
892 top = b;
893 }
894
895 /* If this interval starts at the same point as the previous one, cancel
896 the previous one. */
897 if (defs[n_defs].dfs_num == defs[n_defs - 1].dfs_num)
898 defs[n_defs - 1].bb_index = defs[n_defs].bb_index;
899 else
900 n_defs++;
901 }
902 VEC_pop (int, worklist);
903 gcc_assert (VEC_empty (int, worklist));
904
905 /* Now process the uses. */
906 live_phis = BITMAP_ALLOC (NULL);
907 EXECUTE_IF_SET_IN_BITMAP (uses, 0, i, bi)
908 {
909 VEC_safe_push (int, heap, worklist, i);
910 }
911
912 while (!VEC_empty (int, worklist))
913 {
914 b = VEC_pop (int, worklist);
915 if (b == ENTRY_BLOCK)
916 continue;
917
918 /* If there is a phi node in USE_BB, it is made live. Otherwise,
919 find the def that dominates the immediate dominator of USE_BB
920 (the kill in USE_BB does not dominate the use). */
921 if (bitmap_bit_p (phis, b))
922 p = b;
923 else
924 {
925 use_bb = get_immediate_dominator (CDI_DOMINATORS, BASIC_BLOCK (b));
926 p = find_dfsnum_interval (defs, n_defs,
927 bb_dom_dfs_in (CDI_DOMINATORS, use_bb));
928 if (!bitmap_bit_p (phis, p))
929 continue;
930 }
931
932 /* If the phi node is already live, there is nothing to do. */
933 if (!bitmap_set_bit (live_phis, p))
934 continue;
935
936 /* Add the new uses to the worklist. */
937 def_bb = BASIC_BLOCK (p);
938 FOR_EACH_EDGE (e, ei, def_bb->preds)
939 {
940 u = e->src->index;
941 if (bitmap_bit_p (uses, u))
942 continue;
943
944 /* In case there is a kill directly in the use block, do not record
945 the use (this is also necessary for correctness, as we assume that
946 uses dominated by a def directly in their block have been filtered
947 out before). */
948 if (bitmap_bit_p (kills, u))
949 continue;
950
951 bitmap_set_bit (uses, u);
952 VEC_safe_push (int, heap, worklist, u);
953 }
954 }
955
956 VEC_free (int, heap, worklist);
957 bitmap_copy (phis, live_phis);
958 BITMAP_FREE (live_phis);
959 free (defs);
960 }
961
962 /* Return the set of blocks where variable VAR is defined and the blocks
963 where VAR is live on entry (livein). Return NULL, if no entry is
964 found in DEF_BLOCKS. */
965
966 static inline struct def_blocks_d *
967 find_def_blocks_for (tree var)
968 {
969 def_blocks_p p = &get_common_info (var)->def_blocks;
970 if (!p->def_blocks)
971 return NULL;
972 return p;
973 }
974
975
976 /* Marks phi node PHI in basic block BB for rewrite. */
977
978 static void
979 mark_phi_for_rewrite (basic_block bb, gimple phi)
980 {
981 gimple_vec phis;
982 unsigned n, idx = bb->index;
983
984 if (rewrite_uses_p (phi))
985 return;
986
987 set_rewrite_uses (phi, true);
988
989 if (!blocks_with_phis_to_rewrite)
990 return;
991
992 bitmap_set_bit (blocks_with_phis_to_rewrite, idx);
993
994 n = (unsigned) last_basic_block + 1;
995 if (VEC_length (gimple_vec, phis_to_rewrite) < n)
996 VEC_safe_grow_cleared (gimple_vec, heap, phis_to_rewrite, n);
997
998 phis = VEC_index (gimple_vec, phis_to_rewrite, idx);
999 if (!phis)
1000 phis = VEC_alloc (gimple, heap, 10);
1001
1002 VEC_safe_push (gimple, heap, phis, phi);
1003 VEC_replace (gimple_vec, phis_to_rewrite, idx, phis);
1004 }
1005
1006 /* Insert PHI nodes for variable VAR using the iterated dominance
1007 frontier given in PHI_INSERTION_POINTS. If UPDATE_P is true, this
1008 function assumes that the caller is incrementally updating the
1009 existing SSA form, in which case VAR may be an SSA name instead of
1010 a symbol.
1011
1012 PHI_INSERTION_POINTS is updated to reflect nodes that already had a
1013 PHI node for VAR. On exit, only the nodes that received a PHI node
1014 for VAR will be present in PHI_INSERTION_POINTS. */
1015
1016 static void
1017 insert_phi_nodes_for (tree var, bitmap phi_insertion_points, bool update_p)
1018 {
1019 unsigned bb_index;
1020 edge e;
1021 gimple phi;
1022 basic_block bb;
1023 bitmap_iterator bi;
1024 struct def_blocks_d *def_map;
1025
1026 def_map = find_def_blocks_for (var);
1027 gcc_assert (def_map);
1028
1029 /* Remove the blocks where we already have PHI nodes for VAR. */
1030 bitmap_and_compl_into (phi_insertion_points, def_map->phi_blocks);
1031
1032 /* Remove obviously useless phi nodes. */
1033 prune_unused_phi_nodes (phi_insertion_points, def_map->def_blocks,
1034 def_map->livein_blocks);
1035
1036 /* And insert the PHI nodes. */
1037 EXECUTE_IF_SET_IN_BITMAP (phi_insertion_points, 0, bb_index, bi)
1038 {
1039 bb = BASIC_BLOCK (bb_index);
1040 if (update_p)
1041 mark_block_for_update (bb);
1042
1043 phi = NULL;
1044
1045 if (TREE_CODE (var) == SSA_NAME)
1046 {
1047 /* If we are rewriting SSA names, create the LHS of the PHI
1048 node by duplicating VAR. This is useful in the case of
1049 pointers, to also duplicate pointer attributes (alias
1050 information, in particular). */
1051 edge_iterator ei;
1052 tree new_lhs;
1053
1054 gcc_assert (update_p);
1055 new_lhs = duplicate_ssa_name (var, NULL);
1056 phi = create_phi_node (new_lhs, bb);
1057 add_new_name_mapping (new_lhs, var);
1058
1059 /* Add VAR to every argument slot of PHI. We need VAR in
1060 every argument so that rewrite_update_phi_arguments knows
1061 which name is this PHI node replacing. If VAR is a
1062 symbol marked for renaming, this is not necessary, the
1063 renamer will use the symbol on the LHS to get its
1064 reaching definition. */
1065 FOR_EACH_EDGE (e, ei, bb->preds)
1066 add_phi_arg (phi, var, e, UNKNOWN_LOCATION);
1067 }
1068 else
1069 {
1070 tree tracked_var;
1071
1072 gcc_assert (DECL_P (var));
1073 phi = create_phi_node (var, bb);
1074
1075 tracked_var = target_for_debug_bind (var);
1076 if (tracked_var)
1077 {
1078 gimple note = gimple_build_debug_bind (tracked_var,
1079 PHI_RESULT (phi),
1080 phi);
1081 gimple_stmt_iterator si = gsi_after_labels (bb);
1082 gsi_insert_before (&si, note, GSI_SAME_STMT);
1083 }
1084 }
1085
1086 /* Mark this PHI node as interesting for update_ssa. */
1087 set_register_defs (phi, true);
1088 mark_phi_for_rewrite (bb, phi);
1089 }
1090 }
1091
1092 /* Sort var_infos after DECL_UID of their var. */
1093
1094 static int
1095 insert_phi_nodes_compare_var_infos (const void *a, const void *b)
1096 {
1097 const struct var_info_d *defa = *(struct var_info_d * const *)a;
1098 const struct var_info_d *defb = *(struct var_info_d * const *)b;
1099 if (DECL_UID (defa->var) < DECL_UID (defb->var))
1100 return -1;
1101 else
1102 return 1;
1103 }
1104
1105 /* Insert PHI nodes at the dominance frontier of blocks with variable
1106 definitions. DFS contains the dominance frontier information for
1107 the flowgraph. */
1108
1109 static void
1110 insert_phi_nodes (bitmap_head *dfs)
1111 {
1112 htab_iterator hi;
1113 unsigned i;
1114 var_info_p info;
1115 VEC(var_info_p,heap) *vars;
1116
1117 timevar_push (TV_TREE_INSERT_PHI_NODES);
1118
1119 vars = VEC_alloc (var_info_p, heap, htab_elements (var_infos));
1120 FOR_EACH_HTAB_ELEMENT (var_infos, info, var_info_p, hi)
1121 if (info->info.need_phi_state != NEED_PHI_STATE_NO)
1122 VEC_quick_push (var_info_p, vars, info);
1123
1124 /* Do two stages to avoid code generation differences for UID
1125 differences but no UID ordering differences. */
1126 VEC_qsort (var_info_p, vars, insert_phi_nodes_compare_var_infos);
1127
1128 FOR_EACH_VEC_ELT (var_info_p, vars, i, info)
1129 {
1130 bitmap idf = compute_idf (info->info.def_blocks.def_blocks, dfs);
1131 insert_phi_nodes_for (info->var, idf, false);
1132 BITMAP_FREE (idf);
1133 }
1134
1135 VEC_free(var_info_p, heap, vars);
1136
1137 timevar_pop (TV_TREE_INSERT_PHI_NODES);
1138 }
1139
1140
1141 /* Push SYM's current reaching definition into BLOCK_DEFS_STACK and
1142 register DEF (an SSA_NAME) to be a new definition for SYM. */
1143
1144 static void
1145 register_new_def (tree def, tree sym)
1146 {
1147 common_info_p info = get_common_info (sym);
1148 tree currdef;
1149
1150 /* If this variable is set in a single basic block and all uses are
1151 dominated by the set(s) in that single basic block, then there is
1152 no reason to record anything for this variable in the block local
1153 definition stacks. Doing so just wastes time and memory.
1154
1155 This is the same test to prune the set of variables which may
1156 need PHI nodes. So we just use that information since it's already
1157 computed and available for us to use. */
1158 if (info->need_phi_state == NEED_PHI_STATE_NO)
1159 {
1160 info->current_def = def;
1161 return;
1162 }
1163
1164 currdef = info->current_def;
1165
1166 /* If SYM is not a GIMPLE register, then CURRDEF may be a name whose
1167 SSA_NAME_VAR is not necessarily SYM. In this case, also push SYM
1168 in the stack so that we know which symbol is being defined by
1169 this SSA name when we unwind the stack. */
1170 if (currdef && !is_gimple_reg (sym))
1171 VEC_safe_push (tree, heap, block_defs_stack, sym);
1172
1173 /* Push the current reaching definition into BLOCK_DEFS_STACK. This
1174 stack is later used by the dominator tree callbacks to restore
1175 the reaching definitions for all the variables defined in the
1176 block after a recursive visit to all its immediately dominated
1177 blocks. If there is no current reaching definition, then just
1178 record the underlying _DECL node. */
1179 VEC_safe_push (tree, heap, block_defs_stack, currdef ? currdef : sym);
1180
1181 /* Set the current reaching definition for SYM to be DEF. */
1182 info->current_def = def;
1183 }
1184
1185
1186 /* Perform a depth-first traversal of the dominator tree looking for
1187 variables to rename. BB is the block where to start searching.
1188 Renaming is a five step process:
1189
1190 1- Every definition made by PHI nodes at the start of the blocks is
1191 registered as the current definition for the corresponding variable.
1192
1193 2- Every statement in BB is rewritten. USE and VUSE operands are
1194 rewritten with their corresponding reaching definition. DEF and
1195 VDEF targets are registered as new definitions.
1196
1197 3- All the PHI nodes in successor blocks of BB are visited. The
1198 argument corresponding to BB is replaced with its current reaching
1199 definition.
1200
1201 4- Recursively rewrite every dominator child block of BB.
1202
1203 5- Restore (in reverse order) the current reaching definition for every
1204 new definition introduced in this block. This is done so that when
1205 we return from the recursive call, all the current reaching
1206 definitions are restored to the names that were valid in the
1207 dominator parent of BB. */
1208
1209 /* Return the current definition for variable VAR. If none is found,
1210 create a new SSA name to act as the zeroth definition for VAR. */
1211
1212 static tree
1213 get_reaching_def (tree var)
1214 {
1215 common_info_p info = get_common_info (var);
1216 tree currdef;
1217
1218 /* Lookup the current reaching definition for VAR. */
1219 currdef = info->current_def;
1220
1221 /* If there is no reaching definition for VAR, create and register a
1222 default definition for it (if needed). */
1223 if (currdef == NULL_TREE)
1224 {
1225 tree sym = DECL_P (var) ? var : SSA_NAME_VAR (var);
1226 currdef = get_or_create_ssa_default_def (cfun, sym);
1227 }
1228
1229 /* Return the current reaching definition for VAR, or the default
1230 definition, if we had to create one. */
1231 return currdef;
1232 }
1233
1234
1235 /* Helper function for rewrite_stmt. Rewrite uses in a debug stmt. */
1236
1237 static void
1238 rewrite_debug_stmt_uses (gimple stmt)
1239 {
1240 use_operand_p use_p;
1241 ssa_op_iter iter;
1242 bool update = false;
1243
1244 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
1245 {
1246 tree var = USE_FROM_PTR (use_p), def;
1247 common_info_p info = get_common_info (var);
1248 gcc_assert (DECL_P (var));
1249 def = info->current_def;
1250 if (!def)
1251 {
1252 if (TREE_CODE (var) == PARM_DECL && single_succ_p (ENTRY_BLOCK_PTR))
1253 {
1254 gimple_stmt_iterator gsi
1255 = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR));
1256 int lim;
1257 /* Search a few source bind stmts at the start of first bb to
1258 see if a DEBUG_EXPR_DECL can't be reused. */
1259 for (lim = 32;
1260 !gsi_end_p (gsi) && lim > 0;
1261 gsi_next (&gsi), lim--)
1262 {
1263 gimple gstmt = gsi_stmt (gsi);
1264 if (!gimple_debug_source_bind_p (gstmt))
1265 break;
1266 if (gimple_debug_source_bind_get_value (gstmt) == var)
1267 {
1268 def = gimple_debug_source_bind_get_var (gstmt);
1269 if (TREE_CODE (def) == DEBUG_EXPR_DECL)
1270 break;
1271 else
1272 def = NULL_TREE;
1273 }
1274 }
1275 /* If not, add a new source bind stmt. */
1276 if (def == NULL_TREE)
1277 {
1278 gimple def_temp;
1279 def = make_node (DEBUG_EXPR_DECL);
1280 def_temp = gimple_build_debug_source_bind (def, var, NULL);
1281 DECL_ARTIFICIAL (def) = 1;
1282 TREE_TYPE (def) = TREE_TYPE (var);
1283 DECL_MODE (def) = DECL_MODE (var);
1284 gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR));
1285 gsi_insert_before (&gsi, def_temp, GSI_SAME_STMT);
1286 }
1287 update = true;
1288 }
1289 }
1290 else
1291 {
1292 /* Check if info->current_def can be trusted. */
1293 basic_block bb = gimple_bb (stmt);
1294 basic_block def_bb
1295 = SSA_NAME_IS_DEFAULT_DEF (def)
1296 ? NULL : gimple_bb (SSA_NAME_DEF_STMT (def));
1297
1298 /* If definition is in current bb, it is fine. */
1299 if (bb == def_bb)
1300 ;
1301 /* If definition bb doesn't dominate the current bb,
1302 it can't be used. */
1303 else if (def_bb && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
1304 def = NULL;
1305 /* If there is just one definition and dominates the current
1306 bb, it is fine. */
1307 else if (info->need_phi_state == NEED_PHI_STATE_NO)
1308 ;
1309 else
1310 {
1311 struct def_blocks_d *db_p = get_def_blocks_for (info);
1312
1313 /* If there are some non-debug uses in the current bb,
1314 it is fine. */
1315 if (bitmap_bit_p (db_p->livein_blocks, bb->index))
1316 ;
1317 /* Otherwise give up for now. */
1318 else
1319 def = NULL;
1320 }
1321 }
1322 if (def == NULL)
1323 {
1324 gimple_debug_bind_reset_value (stmt);
1325 update_stmt (stmt);
1326 return;
1327 }
1328 SET_USE (use_p, def);
1329 }
1330 if (update)
1331 update_stmt (stmt);
1332 }
1333
1334 /* SSA Rewriting Step 2. Rewrite every variable used in each statement in
1335 the block with its immediate reaching definitions. Update the current
1336 definition of a variable when a new real or virtual definition is found. */
1337
1338 static void
1339 rewrite_stmt (gimple_stmt_iterator *si)
1340 {
1341 use_operand_p use_p;
1342 def_operand_p def_p;
1343 ssa_op_iter iter;
1344 gimple stmt = gsi_stmt (*si);
1345
1346 /* If mark_def_sites decided that we don't need to rewrite this
1347 statement, ignore it. */
1348 gcc_assert (blocks_to_update == NULL);
1349 if (!rewrite_uses_p (stmt) && !register_defs_p (stmt))
1350 return;
1351
1352 if (dump_file && (dump_flags & TDF_DETAILS))
1353 {
1354 fprintf (dump_file, "Renaming statement ");
1355 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
1356 fprintf (dump_file, "\n");
1357 }
1358
1359 /* Step 1. Rewrite USES in the statement. */
1360 if (rewrite_uses_p (stmt))
1361 {
1362 if (is_gimple_debug (stmt))
1363 rewrite_debug_stmt_uses (stmt);
1364 else
1365 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
1366 {
1367 tree var = USE_FROM_PTR (use_p);
1368 gcc_assert (DECL_P (var));
1369 SET_USE (use_p, get_reaching_def (var));
1370 }
1371 }
1372
1373 /* Step 2. Register the statement's DEF operands. */
1374 if (register_defs_p (stmt))
1375 FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, iter, SSA_OP_ALL_DEFS)
1376 {
1377 tree var = DEF_FROM_PTR (def_p);
1378 tree name;
1379 tree tracked_var;
1380
1381 gcc_assert (DECL_P (var));
1382
1383 if (gimple_clobber_p (stmt)
1384 && is_gimple_reg (var))
1385 {
1386 /* If we rewrite a DECL into SSA form then drop its
1387 clobber stmts and replace uses with a new default def. */
1388 gcc_assert (TREE_CODE (var) == VAR_DECL
1389 && !gimple_vdef (stmt));
1390 gsi_replace (si, gimple_build_nop (), true);
1391 register_new_def (get_or_create_ssa_default_def (cfun, var), var);
1392 break;
1393 }
1394
1395 name = make_ssa_name (var, stmt);
1396 SET_DEF (def_p, name);
1397 register_new_def (DEF_FROM_PTR (def_p), var);
1398
1399 tracked_var = target_for_debug_bind (var);
1400 if (tracked_var)
1401 {
1402 gimple note = gimple_build_debug_bind (tracked_var, name, stmt);
1403 gsi_insert_after (si, note, GSI_SAME_STMT);
1404 }
1405 }
1406 }
1407
1408
1409 /* SSA Rewriting Step 3. Visit all the successor blocks of BB looking for
1410 PHI nodes. For every PHI node found, add a new argument containing the
1411 current reaching definition for the variable and the edge through which
1412 that definition is reaching the PHI node. */
1413
1414 static void
1415 rewrite_add_phi_arguments (basic_block bb)
1416 {
1417 edge e;
1418 edge_iterator ei;
1419
1420 FOR_EACH_EDGE (e, ei, bb->succs)
1421 {
1422 gimple phi;
1423 gimple_stmt_iterator gsi;
1424
1425 for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi);
1426 gsi_next (&gsi))
1427 {
1428 tree currdef;
1429 gimple stmt;
1430
1431 phi = gsi_stmt (gsi);
1432 currdef = get_reaching_def (SSA_NAME_VAR (gimple_phi_result (phi)));
1433 stmt = SSA_NAME_DEF_STMT (currdef);
1434 add_phi_arg (phi, currdef, e, gimple_location (stmt));
1435 }
1436 }
1437 }
1438
1439 /* SSA Rewriting Step 1. Initialization, create a block local stack
1440 of reaching definitions for new SSA names produced in this block
1441 (BLOCK_DEFS). Register new definitions for every PHI node in the
1442 block. */
1443
1444 static void
1445 rewrite_enter_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
1446 basic_block bb)
1447 {
1448 gimple_stmt_iterator gsi;
1449
1450 if (dump_file && (dump_flags & TDF_DETAILS))
1451 fprintf (dump_file, "\n\nRenaming block #%d\n\n", bb->index);
1452
1453 /* Mark the unwind point for this block. */
1454 VEC_safe_push (tree, heap, block_defs_stack, NULL_TREE);
1455
1456 /* Step 1. Register new definitions for every PHI node in the block.
1457 Conceptually, all the PHI nodes are executed in parallel and each PHI
1458 node introduces a new version for the associated variable. */
1459 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1460 {
1461 tree result = gimple_phi_result (gsi_stmt (gsi));
1462 register_new_def (result, SSA_NAME_VAR (result));
1463 }
1464
1465 /* Step 2. Rewrite every variable used in each statement in the block
1466 with its immediate reaching definitions. Update the current definition
1467 of a variable when a new real or virtual definition is found. */
1468 if (TEST_BIT (interesting_blocks, bb->index))
1469 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1470 rewrite_stmt (&gsi);
1471
1472 /* Step 3. Visit all the successor blocks of BB looking for PHI nodes.
1473 For every PHI node found, add a new argument containing the current
1474 reaching definition for the variable and the edge through which that
1475 definition is reaching the PHI node. */
1476 rewrite_add_phi_arguments (bb);
1477 }
1478
1479
1480
1481 /* Called after visiting all the statements in basic block BB and all
1482 of its dominator children. Restore CURRDEFS to its original value. */
1483
1484 static void
1485 rewrite_leave_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
1486 basic_block bb ATTRIBUTE_UNUSED)
1487 {
1488 /* Restore CURRDEFS to its original state. */
1489 while (VEC_length (tree, block_defs_stack) > 0)
1490 {
1491 tree tmp = VEC_pop (tree, block_defs_stack);
1492 tree saved_def, var;
1493
1494 if (tmp == NULL_TREE)
1495 break;
1496
1497 if (TREE_CODE (tmp) == SSA_NAME)
1498 {
1499 /* If we recorded an SSA_NAME, then make the SSA_NAME the
1500 current definition of its underlying variable. Note that
1501 if the SSA_NAME is not for a GIMPLE register, the symbol
1502 being defined is stored in the next slot in the stack.
1503 This mechanism is needed because an SSA name for a
1504 non-register symbol may be the definition for more than
1505 one symbol (e.g., SFTs, aliased variables, etc). */
1506 saved_def = tmp;
1507 var = SSA_NAME_VAR (saved_def);
1508 if (!is_gimple_reg (var))
1509 var = VEC_pop (tree, block_defs_stack);
1510 }
1511 else
1512 {
1513 /* If we recorded anything else, it must have been a _DECL
1514 node and its current reaching definition must have been
1515 NULL. */
1516 saved_def = NULL;
1517 var = tmp;
1518 }
1519
1520 get_common_info (var)->current_def = saved_def;
1521 }
1522 }
1523
1524
1525 /* Dump bitmap SET (assumed to contain VAR_DECLs) to FILE. */
1526
1527 void
1528 dump_decl_set (FILE *file, bitmap set)
1529 {
1530 if (set)
1531 {
1532 bitmap_iterator bi;
1533 unsigned i;
1534
1535 fprintf (file, "{ ");
1536
1537 EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
1538 {
1539 fprintf (file, "D.%u", i);
1540 fprintf (file, " ");
1541 }
1542
1543 fprintf (file, "}");
1544 }
1545 else
1546 fprintf (file, "NIL");
1547 }
1548
1549
1550 /* Dump bitmap SET (assumed to contain VAR_DECLs) to FILE. */
1551
1552 DEBUG_FUNCTION void
1553 debug_decl_set (bitmap set)
1554 {
1555 dump_decl_set (stderr, set);
1556 fprintf (stderr, "\n");
1557 }
1558
1559
1560 /* Dump the renaming stack (block_defs_stack) to FILE. Traverse the
1561 stack up to a maximum of N levels. If N is -1, the whole stack is
1562 dumped. New levels are created when the dominator tree traversal
1563 used for renaming enters a new sub-tree. */
1564
1565 void
1566 dump_defs_stack (FILE *file, int n)
1567 {
1568 int i, j;
1569
1570 fprintf (file, "\n\nRenaming stack");
1571 if (n > 0)
1572 fprintf (file, " (up to %d levels)", n);
1573 fprintf (file, "\n\n");
1574
1575 i = 1;
1576 fprintf (file, "Level %d (current level)\n", i);
1577 for (j = (int) VEC_length (tree, block_defs_stack) - 1; j >= 0; j--)
1578 {
1579 tree name, var;
1580
1581 name = VEC_index (tree, block_defs_stack, j);
1582 if (name == NULL_TREE)
1583 {
1584 i++;
1585 if (n > 0 && i > n)
1586 break;
1587 fprintf (file, "\nLevel %d\n", i);
1588 continue;
1589 }
1590
1591 if (DECL_P (name))
1592 {
1593 var = name;
1594 name = NULL_TREE;
1595 }
1596 else
1597 {
1598 var = SSA_NAME_VAR (name);
1599 if (!is_gimple_reg (var))
1600 {
1601 j--;
1602 var = VEC_index (tree, block_defs_stack, j);
1603 }
1604 }
1605
1606 fprintf (file, " Previous CURRDEF (");
1607 print_generic_expr (file, var, 0);
1608 fprintf (file, ") = ");
1609 if (name)
1610 print_generic_expr (file, name, 0);
1611 else
1612 fprintf (file, "<NIL>");
1613 fprintf (file, "\n");
1614 }
1615 }
1616
1617
1618 /* Dump the renaming stack (block_defs_stack) to stderr. Traverse the
1619 stack up to a maximum of N levels. If N is -1, the whole stack is
1620 dumped. New levels are created when the dominator tree traversal
1621 used for renaming enters a new sub-tree. */
1622
1623 DEBUG_FUNCTION void
1624 debug_defs_stack (int n)
1625 {
1626 dump_defs_stack (stderr, n);
1627 }
1628
1629
1630 /* Dump the current reaching definition of every symbol to FILE. */
1631
1632 void
1633 dump_currdefs (FILE *file)
1634 {
1635 unsigned i;
1636 tree var;
1637
1638 if (VEC_empty (tree, symbols_to_rename))
1639 return;
1640
1641 fprintf (file, "\n\nCurrent reaching definitions\n\n");
1642 FOR_EACH_VEC_ELT (tree, symbols_to_rename, i, var)
1643 {
1644 common_info_p info = get_common_info (var);
1645 fprintf (file, "CURRDEF (");
1646 print_generic_expr (file, var, 0);
1647 fprintf (file, ") = ");
1648 if (info->current_def)
1649 print_generic_expr (file, info->current_def, 0);
1650 else
1651 fprintf (file, "<NIL>");
1652 fprintf (file, "\n");
1653 }
1654 }
1655
1656
1657 /* Dump the current reaching definition of every symbol to stderr. */
1658
1659 DEBUG_FUNCTION void
1660 debug_currdefs (void)
1661 {
1662 dump_currdefs (stderr);
1663 }
1664
1665
1666 /* Dump SSA information to FILE. */
1667
1668 void
1669 dump_tree_ssa (FILE *file)
1670 {
1671 const char *funcname
1672 = lang_hooks.decl_printable_name (current_function_decl, 2);
1673
1674 fprintf (file, "SSA renaming information for %s\n\n", funcname);
1675
1676 dump_var_infos (file);
1677 dump_defs_stack (file, -1);
1678 dump_currdefs (file);
1679 dump_tree_ssa_stats (file);
1680 }
1681
1682
1683 /* Dump SSA information to stderr. */
1684
1685 DEBUG_FUNCTION void
1686 debug_tree_ssa (void)
1687 {
1688 dump_tree_ssa (stderr);
1689 }
1690
1691
1692 /* Dump statistics for the hash table HTAB. */
1693
1694 static void
1695 htab_statistics (FILE *file, htab_t htab)
1696 {
1697 fprintf (file, "size %ld, %ld elements, %f collision/search ratio\n",
1698 (long) htab_size (htab),
1699 (long) htab_elements (htab),
1700 htab_collisions (htab));
1701 }
1702
1703
1704 /* Dump SSA statistics on FILE. */
1705
1706 void
1707 dump_tree_ssa_stats (FILE *file)
1708 {
1709 if (var_infos)
1710 {
1711 fprintf (file, "\nHash table statistics:\n");
1712 fprintf (file, " var_infos: ");
1713 htab_statistics (file, var_infos);
1714 fprintf (file, "\n");
1715 }
1716 }
1717
1718
1719 /* Dump SSA statistics on stderr. */
1720
1721 DEBUG_FUNCTION void
1722 debug_tree_ssa_stats (void)
1723 {
1724 dump_tree_ssa_stats (stderr);
1725 }
1726
1727
1728 /* Hashing and equality functions for VAR_INFOS. */
1729
1730 static hashval_t
1731 var_info_hash (const void *p)
1732 {
1733 return DECL_UID (((const struct var_info_d *)p)->var);
1734 }
1735
1736 static int
1737 var_info_eq (const void *p1, const void *p2)
1738 {
1739 return ((const struct var_info_d *)p1)->var
1740 == ((const struct var_info_d *)p2)->var;
1741 }
1742
1743
1744 /* Callback for htab_traverse to dump the VAR_INFOS hash table. */
1745
1746 static int
1747 debug_var_infos_r (void **slot, void *data)
1748 {
1749 FILE *file = (FILE *) data;
1750 struct var_info_d *info = (struct var_info_d *) *slot;
1751
1752 fprintf (file, "VAR: ");
1753 print_generic_expr (file, info->var, dump_flags);
1754 bitmap_print (file, info->info.def_blocks.def_blocks,
1755 ", DEF_BLOCKS: { ", "}");
1756 bitmap_print (file, info->info.def_blocks.livein_blocks,
1757 ", LIVEIN_BLOCKS: { ", "}");
1758 bitmap_print (file, info->info.def_blocks.phi_blocks,
1759 ", PHI_BLOCKS: { ", "}\n");
1760
1761 return 1;
1762 }
1763
1764
1765 /* Dump the VAR_INFOS hash table on FILE. */
1766
1767 void
1768 dump_var_infos (FILE *file)
1769 {
1770 fprintf (file, "\n\nDefinition and live-in blocks:\n\n");
1771 if (var_infos)
1772 htab_traverse (var_infos, debug_var_infos_r, file);
1773 }
1774
1775
1776 /* Dump the VAR_INFOS hash table on stderr. */
1777
1778 DEBUG_FUNCTION void
1779 debug_var_infos (void)
1780 {
1781 dump_var_infos (stderr);
1782 }
1783
1784
1785 /* Register NEW_NAME to be the new reaching definition for OLD_NAME. */
1786
1787 static inline void
1788 register_new_update_single (tree new_name, tree old_name)
1789 {
1790 common_info_p info = get_common_info (old_name);
1791 tree currdef = info->current_def;
1792
1793 /* Push the current reaching definition into BLOCK_DEFS_STACK.
1794 This stack is later used by the dominator tree callbacks to
1795 restore the reaching definitions for all the variables
1796 defined in the block after a recursive visit to all its
1797 immediately dominated blocks. */
1798 VEC_reserve (tree, heap, block_defs_stack, 2);
1799 VEC_quick_push (tree, block_defs_stack, currdef);
1800 VEC_quick_push (tree, block_defs_stack, old_name);
1801
1802 /* Set the current reaching definition for OLD_NAME to be
1803 NEW_NAME. */
1804 info->current_def = new_name;
1805 }
1806
1807
1808 /* Register NEW_NAME to be the new reaching definition for all the
1809 names in OLD_NAMES. Used by the incremental SSA update routines to
1810 replace old SSA names with new ones. */
1811
1812 static inline void
1813 register_new_update_set (tree new_name, bitmap old_names)
1814 {
1815 bitmap_iterator bi;
1816 unsigned i;
1817
1818 EXECUTE_IF_SET_IN_BITMAP (old_names, 0, i, bi)
1819 register_new_update_single (new_name, ssa_name (i));
1820 }
1821
1822
1823
1824 /* If the operand pointed to by USE_P is a name in OLD_SSA_NAMES or
1825 it is a symbol marked for renaming, replace it with USE_P's current
1826 reaching definition. */
1827
1828 static inline void
1829 maybe_replace_use (use_operand_p use_p)
1830 {
1831 tree rdef = NULL_TREE;
1832 tree use = USE_FROM_PTR (use_p);
1833 tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
1834
1835 if (marked_for_renaming (sym))
1836 rdef = get_reaching_def (sym);
1837 else if (is_old_name (use))
1838 rdef = get_reaching_def (use);
1839
1840 if (rdef && rdef != use)
1841 SET_USE (use_p, rdef);
1842 }
1843
1844
1845 /* Same as maybe_replace_use, but without introducing default stmts,
1846 returning false to indicate a need to do so. */
1847
1848 static inline bool
1849 maybe_replace_use_in_debug_stmt (use_operand_p use_p)
1850 {
1851 tree rdef = NULL_TREE;
1852 tree use = USE_FROM_PTR (use_p);
1853 tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
1854
1855 if (marked_for_renaming (sym))
1856 rdef = get_var_info (sym)->info.current_def;
1857 else if (is_old_name (use))
1858 {
1859 rdef = get_ssa_name_ann (use)->info.current_def;
1860 /* We can't assume that, if there's no current definition, the
1861 default one should be used. It could be the case that we've
1862 rearranged blocks so that the earlier definition no longer
1863 dominates the use. */
1864 if (!rdef && SSA_NAME_IS_DEFAULT_DEF (use))
1865 rdef = use;
1866 }
1867 else
1868 rdef = use;
1869
1870 if (rdef && rdef != use)
1871 SET_USE (use_p, rdef);
1872
1873 return rdef != NULL_TREE;
1874 }
1875
1876
1877 /* If the operand pointed to by DEF_P is an SSA name in NEW_SSA_NAMES
1878 or OLD_SSA_NAMES, or if it is a symbol marked for renaming,
1879 register it as the current definition for the names replaced by
1880 DEF_P. */
1881
1882 static inline void
1883 maybe_register_def (def_operand_p def_p, gimple stmt,
1884 gimple_stmt_iterator gsi)
1885 {
1886 tree def = DEF_FROM_PTR (def_p);
1887 tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
1888
1889 /* If DEF is a naked symbol that needs renaming, create a new
1890 name for it. */
1891 if (marked_for_renaming (sym))
1892 {
1893 if (DECL_P (def))
1894 {
1895 tree tracked_var;
1896
1897 def = make_ssa_name (def, stmt);
1898 SET_DEF (def_p, def);
1899
1900 tracked_var = target_for_debug_bind (sym);
1901 if (tracked_var)
1902 {
1903 gimple note = gimple_build_debug_bind (tracked_var, def, stmt);
1904 /* If stmt ends the bb, insert the debug stmt on the single
1905 non-EH edge from the stmt. */
1906 if (gsi_one_before_end_p (gsi) && stmt_ends_bb_p (stmt))
1907 {
1908 basic_block bb = gsi_bb (gsi);
1909 edge_iterator ei;
1910 edge e, ef = NULL;
1911 FOR_EACH_EDGE (e, ei, bb->succs)
1912 if (!(e->flags & EDGE_EH))
1913 {
1914 gcc_assert (!ef);
1915 ef = e;
1916 }
1917 /* If there are other predecessors to ef->dest, then
1918 there must be PHI nodes for the modified
1919 variable, and therefore there will be debug bind
1920 stmts after the PHI nodes. The debug bind notes
1921 we'd insert would force the creation of a new
1922 block (diverging codegen) and be redundant with
1923 the post-PHI bind stmts, so don't add them.
1924
1925 As for the exit edge, there wouldn't be redundant
1926 bind stmts, but there wouldn't be a PC to bind
1927 them to either, so avoid diverging the CFG. */
1928 if (ef && single_pred_p (ef->dest)
1929 && ef->dest != EXIT_BLOCK_PTR)
1930 {
1931 /* If there were PHI nodes in the node, we'd
1932 have to make sure the value we're binding
1933 doesn't need rewriting. But there shouldn't
1934 be PHI nodes in a single-predecessor block,
1935 so we just add the note. */
1936 gsi_insert_on_edge_immediate (ef, note);
1937 }
1938 }
1939 else
1940 gsi_insert_after (&gsi, note, GSI_SAME_STMT);
1941 }
1942 }
1943
1944 register_new_update_single (def, sym);
1945 }
1946 else
1947 {
1948 /* If DEF is a new name, register it as a new definition
1949 for all the names replaced by DEF. */
1950 if (is_new_name (def))
1951 register_new_update_set (def, names_replaced_by (def));
1952
1953 /* If DEF is an old name, register DEF as a new
1954 definition for itself. */
1955 if (is_old_name (def))
1956 register_new_update_single (def, def);
1957 }
1958 }
1959
1960
1961 /* Update every variable used in the statement pointed-to by SI. The
1962 statement is assumed to be in SSA form already. Names in
1963 OLD_SSA_NAMES used by SI will be updated to their current reaching
1964 definition. Names in OLD_SSA_NAMES or NEW_SSA_NAMES defined by SI
1965 will be registered as a new definition for their corresponding name
1966 in OLD_SSA_NAMES. */
1967
1968 static void
1969 rewrite_update_stmt (gimple stmt, gimple_stmt_iterator gsi)
1970 {
1971 use_operand_p use_p;
1972 def_operand_p def_p;
1973 ssa_op_iter iter;
1974
1975 /* Only update marked statements. */
1976 if (!rewrite_uses_p (stmt) && !register_defs_p (stmt))
1977 return;
1978
1979 if (dump_file && (dump_flags & TDF_DETAILS))
1980 {
1981 fprintf (dump_file, "Updating SSA information for statement ");
1982 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
1983 }
1984
1985 /* Rewrite USES included in OLD_SSA_NAMES and USES whose underlying
1986 symbol is marked for renaming. */
1987 if (rewrite_uses_p (stmt))
1988 {
1989 if (is_gimple_debug (stmt))
1990 {
1991 bool failed = false;
1992
1993 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
1994 if (!maybe_replace_use_in_debug_stmt (use_p))
1995 {
1996 failed = true;
1997 break;
1998 }
1999
2000 if (failed)
2001 {
2002 /* DOM sometimes threads jumps in such a way that a
2003 debug stmt ends up referencing a SSA variable that no
2004 longer dominates the debug stmt, but such that all
2005 incoming definitions refer to the same definition in
2006 an earlier dominator. We could try to recover that
2007 definition somehow, but this will have to do for now.
2008
2009 Introducing a default definition, which is what
2010 maybe_replace_use() would do in such cases, may
2011 modify code generation, for the otherwise-unused
2012 default definition would never go away, modifying SSA
2013 version numbers all over. */
2014 gimple_debug_bind_reset_value (stmt);
2015 update_stmt (stmt);
2016 }
2017 }
2018 else
2019 {
2020 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES)
2021 maybe_replace_use (use_p);
2022 }
2023 }
2024
2025 /* Register definitions of names in NEW_SSA_NAMES and OLD_SSA_NAMES.
2026 Also register definitions for names whose underlying symbol is
2027 marked for renaming. */
2028 if (register_defs_p (stmt))
2029 FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, iter, SSA_OP_ALL_DEFS)
2030 maybe_register_def (def_p, stmt, gsi);
2031 }
2032
2033
2034 /* Visit all the successor blocks of BB looking for PHI nodes. For
2035 every PHI node found, check if any of its arguments is in
2036 OLD_SSA_NAMES. If so, and if the argument has a current reaching
2037 definition, replace it. */
2038
2039 static void
2040 rewrite_update_phi_arguments (basic_block bb)
2041 {
2042 edge e;
2043 edge_iterator ei;
2044 unsigned i;
2045
2046 FOR_EACH_EDGE (e, ei, bb->succs)
2047 {
2048 gimple phi;
2049 gimple_vec phis;
2050
2051 if (!bitmap_bit_p (blocks_with_phis_to_rewrite, e->dest->index))
2052 continue;
2053
2054 phis = VEC_index (gimple_vec, phis_to_rewrite, e->dest->index);
2055 FOR_EACH_VEC_ELT (gimple, phis, i, phi)
2056 {
2057 tree arg, lhs_sym, reaching_def = NULL;
2058 use_operand_p arg_p;
2059
2060 gcc_assert (rewrite_uses_p (phi));
2061
2062 arg_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, e);
2063 arg = USE_FROM_PTR (arg_p);
2064
2065 if (arg && !DECL_P (arg) && TREE_CODE (arg) != SSA_NAME)
2066 continue;
2067
2068 lhs_sym = SSA_NAME_VAR (gimple_phi_result (phi));
2069
2070 if (arg == NULL_TREE)
2071 {
2072 /* When updating a PHI node for a recently introduced
2073 symbol we may find NULL arguments. That's why we
2074 take the symbol from the LHS of the PHI node. */
2075 reaching_def = get_reaching_def (lhs_sym);
2076
2077 }
2078 else
2079 {
2080 tree sym = DECL_P (arg) ? arg : SSA_NAME_VAR (arg);
2081
2082 if (marked_for_renaming (sym))
2083 reaching_def = get_reaching_def (sym);
2084 else if (is_old_name (arg))
2085 reaching_def = get_reaching_def (arg);
2086 }
2087
2088 /* Update the argument if there is a reaching def. */
2089 if (reaching_def)
2090 {
2091 gimple stmt;
2092 source_location locus;
2093 int arg_i = PHI_ARG_INDEX_FROM_USE (arg_p);
2094
2095 SET_USE (arg_p, reaching_def);
2096 stmt = SSA_NAME_DEF_STMT (reaching_def);
2097
2098 /* Single element PHI nodes behave like copies, so get the
2099 location from the phi argument. */
2100 if (gimple_code (stmt) == GIMPLE_PHI &&
2101 gimple_phi_num_args (stmt) == 1)
2102 locus = gimple_phi_arg_location (stmt, 0);
2103 else
2104 locus = gimple_location (stmt);
2105
2106 gimple_phi_arg_set_location (phi, arg_i, locus);
2107 }
2108
2109
2110 if (e->flags & EDGE_ABNORMAL)
2111 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (USE_FROM_PTR (arg_p)) = 1;
2112 }
2113 }
2114 }
2115
2116
2117 /* Initialization of block data structures for the incremental SSA
2118 update pass. Create a block local stack of reaching definitions
2119 for new SSA names produced in this block (BLOCK_DEFS). Register
2120 new definitions for every PHI node in the block. */
2121
2122 static void
2123 rewrite_update_enter_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
2124 basic_block bb)
2125 {
2126 bool is_abnormal_phi;
2127 gimple_stmt_iterator gsi;
2128
2129 if (dump_file && (dump_flags & TDF_DETAILS))
2130 fprintf (dump_file, "Registering new PHI nodes in block #%d\n",
2131 bb->index);
2132
2133 /* Mark the unwind point for this block. */
2134 VEC_safe_push (tree, heap, block_defs_stack, NULL_TREE);
2135
2136 if (!bitmap_bit_p (blocks_to_update, bb->index))
2137 return;
2138
2139 /* Mark the LHS if any of the arguments flows through an abnormal
2140 edge. */
2141 is_abnormal_phi = bb_has_abnormal_pred (bb);
2142
2143 /* If any of the PHI nodes is a replacement for a name in
2144 OLD_SSA_NAMES or it's one of the names in NEW_SSA_NAMES, then
2145 register it as a new definition for its corresponding name. Also
2146 register definitions for names whose underlying symbols are
2147 marked for renaming. */
2148 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2149 {
2150 tree lhs, lhs_sym;
2151 gimple phi = gsi_stmt (gsi);
2152
2153 if (!register_defs_p (phi))
2154 continue;
2155
2156 lhs = gimple_phi_result (phi);
2157 lhs_sym = SSA_NAME_VAR (lhs);
2158
2159 if (marked_for_renaming (lhs_sym))
2160 register_new_update_single (lhs, lhs_sym);
2161 else
2162 {
2163
2164 /* If LHS is a new name, register a new definition for all
2165 the names replaced by LHS. */
2166 if (is_new_name (lhs))
2167 register_new_update_set (lhs, names_replaced_by (lhs));
2168
2169 /* If LHS is an OLD name, register it as a new definition
2170 for itself. */
2171 if (is_old_name (lhs))
2172 register_new_update_single (lhs, lhs);
2173 }
2174
2175 if (is_abnormal_phi)
2176 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs) = 1;
2177 }
2178
2179 /* Step 2. Rewrite every variable used in each statement in the block. */
2180 if (TEST_BIT (interesting_blocks, bb->index))
2181 {
2182 gcc_assert (bitmap_bit_p (blocks_to_update, bb->index));
2183 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2184 rewrite_update_stmt (gsi_stmt (gsi), gsi);
2185 }
2186
2187 /* Step 3. Update PHI nodes. */
2188 rewrite_update_phi_arguments (bb);
2189 }
2190
2191 /* Called after visiting block BB. Unwind BLOCK_DEFS_STACK to restore
2192 the current reaching definition of every name re-written in BB to
2193 the original reaching definition before visiting BB. This
2194 unwinding must be done in the opposite order to what is done in
2195 register_new_update_set. */
2196
2197 static void
2198 rewrite_update_leave_block (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
2199 basic_block bb ATTRIBUTE_UNUSED)
2200 {
2201 while (VEC_length (tree, block_defs_stack) > 0)
2202 {
2203 tree var = VEC_pop (tree, block_defs_stack);
2204 tree saved_def;
2205
2206 /* NULL indicates the unwind stop point for this block (see
2207 rewrite_update_enter_block). */
2208 if (var == NULL)
2209 return;
2210
2211 saved_def = VEC_pop (tree, block_defs_stack);
2212 get_common_info (var)->current_def = saved_def;
2213 }
2214 }
2215
2216
2217 /* Rewrite the actual blocks, statements, and PHI arguments, to be in SSA
2218 form.
2219
2220 ENTRY indicates the block where to start. Every block dominated by
2221 ENTRY will be rewritten.
2222
2223 WHAT indicates what actions will be taken by the renamer (see enum
2224 rewrite_mode).
2225
2226 BLOCKS are the set of interesting blocks for the dominator walker
2227 to process. If this set is NULL, then all the nodes dominated
2228 by ENTRY are walked. Otherwise, blocks dominated by ENTRY that
2229 are not present in BLOCKS are ignored. */
2230
2231 static void
2232 rewrite_blocks (basic_block entry, enum rewrite_mode what)
2233 {
2234 struct dom_walk_data walk_data;
2235
2236 /* Rewrite all the basic blocks in the program. */
2237 timevar_push (TV_TREE_SSA_REWRITE_BLOCKS);
2238
2239 /* Setup callbacks for the generic dominator tree walker. */
2240 memset (&walk_data, 0, sizeof (walk_data));
2241
2242 walk_data.dom_direction = CDI_DOMINATORS;
2243
2244 if (what == REWRITE_ALL)
2245 {
2246 walk_data.before_dom_children = rewrite_enter_block;
2247 walk_data.after_dom_children = rewrite_leave_block;
2248 }
2249 else if (what == REWRITE_UPDATE)
2250 {
2251 walk_data.before_dom_children = rewrite_update_enter_block;
2252 walk_data.after_dom_children = rewrite_update_leave_block;
2253 }
2254 else
2255 gcc_unreachable ();
2256
2257 block_defs_stack = VEC_alloc (tree, heap, 10);
2258
2259 /* Initialize the dominator walker. */
2260 init_walk_dominator_tree (&walk_data);
2261
2262 /* Recursively walk the dominator tree rewriting each statement in
2263 each basic block. */
2264 walk_dominator_tree (&walk_data, entry);
2265
2266 /* Finalize the dominator walker. */
2267 fini_walk_dominator_tree (&walk_data);
2268
2269 /* Debugging dumps. */
2270 if (dump_file && (dump_flags & TDF_STATS))
2271 {
2272 dump_dfa_stats (dump_file);
2273 if (var_infos)
2274 dump_tree_ssa_stats (dump_file);
2275 }
2276
2277 VEC_free (tree, heap, block_defs_stack);
2278
2279 timevar_pop (TV_TREE_SSA_REWRITE_BLOCKS);
2280 }
2281
2282
2283 /* Block processing routine for mark_def_sites. Clear the KILLS bitmap
2284 at the start of each block, and call mark_def_sites for each statement. */
2285
2286 static void
2287 mark_def_sites_block (struct dom_walk_data *walk_data, basic_block bb)
2288 {
2289 struct mark_def_sites_global_data *gd;
2290 bitmap kills;
2291 gimple_stmt_iterator gsi;
2292
2293 gd = (struct mark_def_sites_global_data *) walk_data->global_data;
2294 kills = gd->kills;
2295
2296 bitmap_clear (kills);
2297 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2298 mark_def_sites (bb, gsi_stmt (gsi), kills);
2299 }
2300
2301
2302 /* Mark the definition site blocks for each variable, so that we know
2303 where the variable is actually live.
2304
2305 The INTERESTING_BLOCKS global will be filled in with all the blocks
2306 that should be processed by the renamer. It is assumed that the
2307 caller has already initialized and zeroed it. */
2308
2309 static void
2310 mark_def_site_blocks (void)
2311 {
2312 struct dom_walk_data walk_data;
2313 struct mark_def_sites_global_data mark_def_sites_global_data;
2314
2315 /* Setup callbacks for the generic dominator tree walker to find and
2316 mark definition sites. */
2317 walk_data.dom_direction = CDI_DOMINATORS;
2318 walk_data.initialize_block_local_data = NULL;
2319 walk_data.before_dom_children = mark_def_sites_block;
2320 walk_data.after_dom_children = NULL;
2321
2322 /* Notice that this bitmap is indexed using variable UIDs, so it must be
2323 large enough to accommodate all the variables referenced in the
2324 function, not just the ones we are renaming. */
2325 mark_def_sites_global_data.kills = BITMAP_ALLOC (NULL);
2326 walk_data.global_data = &mark_def_sites_global_data;
2327
2328 /* We do not have any local data. */
2329 walk_data.block_local_data_size = 0;
2330
2331 /* Initialize the dominator walker. */
2332 init_walk_dominator_tree (&walk_data);
2333
2334 /* Recursively walk the dominator tree. */
2335 walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR);
2336
2337 /* Finalize the dominator walker. */
2338 fini_walk_dominator_tree (&walk_data);
2339
2340 /* We no longer need this bitmap, clear and free it. */
2341 BITMAP_FREE (mark_def_sites_global_data.kills);
2342 }
2343
2344
2345 /* Initialize internal data needed during renaming. */
2346
2347 static void
2348 init_ssa_renamer (void)
2349 {
2350 cfun->gimple_df->in_ssa_p = false;
2351
2352 /* Allocate memory for the DEF_BLOCKS hash table. */
2353 gcc_assert (var_infos == NULL);
2354 var_infos = htab_create (VEC_length (tree, cfun->local_decls),
2355 var_info_hash, var_info_eq, NULL);
2356
2357 bitmap_obstack_initialize (&update_ssa_obstack);
2358 }
2359
2360
2361 /* Deallocate internal data structures used by the renamer. */
2362
2363 static void
2364 fini_ssa_renamer (void)
2365 {
2366 if (var_infos)
2367 {
2368 htab_delete (var_infos);
2369 var_infos = NULL;
2370 }
2371
2372 bitmap_obstack_release (&update_ssa_obstack);
2373
2374 cfun->gimple_df->ssa_renaming_needed = 0;
2375 cfun->gimple_df->rename_vops = 0;
2376 cfun->gimple_df->in_ssa_p = true;
2377 }
2378
2379 /* Main entry point into the SSA builder. The renaming process
2380 proceeds in four main phases:
2381
2382 1- Compute dominance frontier and immediate dominators, needed to
2383 insert PHI nodes and rename the function in dominator tree
2384 order.
2385
2386 2- Find and mark all the blocks that define variables
2387 (mark_def_site_blocks).
2388
2389 3- Insert PHI nodes at dominance frontiers (insert_phi_nodes).
2390
2391 4- Rename all the blocks (rewrite_blocks) and statements in the program.
2392
2393 Steps 3 and 4 are done using the dominator tree walker
2394 (walk_dominator_tree). */
2395
2396 static unsigned int
2397 rewrite_into_ssa (void)
2398 {
2399 bitmap_head *dfs;
2400 basic_block bb;
2401 unsigned i;
2402
2403 /* Initialize operand data structures. */
2404 init_ssa_operands (cfun);
2405
2406 /* Initialize internal data needed by the renamer. */
2407 init_ssa_renamer ();
2408
2409 /* Initialize the set of interesting blocks. The callback
2410 mark_def_sites will add to this set those blocks that the renamer
2411 should process. */
2412 interesting_blocks = sbitmap_alloc (last_basic_block);
2413 sbitmap_zero (interesting_blocks);
2414
2415 /* Initialize dominance frontier. */
2416 dfs = XNEWVEC (bitmap_head, last_basic_block);
2417 FOR_EACH_BB (bb)
2418 bitmap_initialize (&dfs[bb->index], &bitmap_default_obstack);
2419
2420 /* 1- Compute dominance frontiers. */
2421 calculate_dominance_info (CDI_DOMINATORS);
2422 compute_dominance_frontiers (dfs);
2423
2424 /* 2- Find and mark definition sites. */
2425 mark_def_site_blocks ();
2426
2427 /* 3- Insert PHI nodes at dominance frontiers of definition blocks. */
2428 insert_phi_nodes (dfs);
2429
2430 /* 4- Rename all the blocks. */
2431 rewrite_blocks (ENTRY_BLOCK_PTR, REWRITE_ALL);
2432
2433 /* Free allocated memory. */
2434 FOR_EACH_BB (bb)
2435 bitmap_clear (&dfs[bb->index]);
2436 free (dfs);
2437
2438 sbitmap_free (interesting_blocks);
2439
2440 fini_ssa_renamer ();
2441
2442 /* Try to get rid of all gimplifier generated temporaries by making
2443 its SSA names anonymous. This way we can garbage collect them
2444 all after removing unused locals which we do in our TODO. */
2445 for (i = 1; i < num_ssa_names; ++i)
2446 {
2447 tree decl, name = ssa_name (i);
2448 if (!name
2449 || SSA_NAME_IS_DEFAULT_DEF (name))
2450 continue;
2451 decl = SSA_NAME_VAR (name);
2452 if (decl
2453 && TREE_CODE (decl) == VAR_DECL
2454 && !VAR_DECL_IS_VIRTUAL_OPERAND (decl)
2455 && DECL_ARTIFICIAL (decl)
2456 && DECL_IGNORED_P (decl)
2457 && !DECL_NAME (decl))
2458 SET_SSA_NAME_VAR_OR_IDENTIFIER (name, NULL_TREE);
2459 }
2460
2461 return 0;
2462 }
2463
2464
2465 struct gimple_opt_pass pass_build_ssa =
2466 {
2467 {
2468 GIMPLE_PASS,
2469 "ssa", /* name */
2470 NULL, /* gate */
2471 rewrite_into_ssa, /* execute */
2472 NULL, /* sub */
2473 NULL, /* next */
2474 0, /* static_pass_number */
2475 TV_TREE_SSA_OTHER, /* tv_id */
2476 PROP_cfg, /* properties_required */
2477 PROP_ssa, /* properties_provided */
2478 0, /* properties_destroyed */
2479 0, /* todo_flags_start */
2480 TODO_verify_ssa
2481 | TODO_remove_unused_locals /* todo_flags_finish */
2482 }
2483 };
2484
2485
2486 /* Mark the definition of VAR at STMT and BB as interesting for the
2487 renamer. BLOCKS is the set of blocks that need updating. */
2488
2489 static void
2490 mark_def_interesting (tree var, gimple stmt, basic_block bb, bool insert_phi_p)
2491 {
2492 gcc_assert (bitmap_bit_p (blocks_to_update, bb->index));
2493 set_register_defs (stmt, true);
2494
2495 if (insert_phi_p)
2496 {
2497 bool is_phi_p = gimple_code (stmt) == GIMPLE_PHI;
2498
2499 set_def_block (var, bb, is_phi_p);
2500
2501 /* If VAR is an SSA name in NEW_SSA_NAMES, this is a definition
2502 site for both itself and all the old names replaced by it. */
2503 if (TREE_CODE (var) == SSA_NAME && is_new_name (var))
2504 {
2505 bitmap_iterator bi;
2506 unsigned i;
2507 bitmap set = names_replaced_by (var);
2508 if (set)
2509 EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
2510 set_def_block (ssa_name (i), bb, is_phi_p);
2511 }
2512 }
2513 }
2514
2515
2516 /* Mark the use of VAR at STMT and BB as interesting for the
2517 renamer. INSERT_PHI_P is true if we are going to insert new PHI
2518 nodes. */
2519
2520 static inline void
2521 mark_use_interesting (tree var, gimple stmt, basic_block bb, bool insert_phi_p)
2522 {
2523 basic_block def_bb = gimple_bb (stmt);
2524
2525 mark_block_for_update (def_bb);
2526 mark_block_for_update (bb);
2527
2528 if (gimple_code (stmt) == GIMPLE_PHI)
2529 mark_phi_for_rewrite (def_bb, stmt);
2530 else
2531 {
2532 set_rewrite_uses (stmt, true);
2533
2534 if (is_gimple_debug (stmt))
2535 return;
2536 }
2537
2538 /* If VAR has not been defined in BB, then it is live-on-entry
2539 to BB. Note that we cannot just use the block holding VAR's
2540 definition because if VAR is one of the names in OLD_SSA_NAMES,
2541 it will have several definitions (itself and all the names that
2542 replace it). */
2543 if (insert_phi_p)
2544 {
2545 struct def_blocks_d *db_p = get_def_blocks_for (get_common_info (var));
2546 if (!bitmap_bit_p (db_p->def_blocks, bb->index))
2547 set_livein_block (var, bb);
2548 }
2549 }
2550
2551
2552 /* Do a dominator walk starting at BB processing statements that
2553 reference symbols in SSA operands. This is very similar to
2554 mark_def_sites, but the scan handles statements whose operands may
2555 already be SSA names.
2556
2557 If INSERT_PHI_P is true, mark those uses as live in the
2558 corresponding block. This is later used by the PHI placement
2559 algorithm to make PHI pruning decisions.
2560
2561 FIXME. Most of this would be unnecessary if we could associate a
2562 symbol to all the SSA names that reference it. But that
2563 sounds like it would be expensive to maintain. Still, it
2564 would be interesting to see if it makes better sense to do
2565 that. */
2566
2567 static void
2568 prepare_block_for_update (basic_block bb, bool insert_phi_p)
2569 {
2570 basic_block son;
2571 gimple_stmt_iterator si;
2572 edge e;
2573 edge_iterator ei;
2574
2575 mark_block_for_update (bb);
2576
2577 /* Process PHI nodes marking interesting those that define or use
2578 the symbols that we are interested in. */
2579 for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
2580 {
2581 gimple phi = gsi_stmt (si);
2582 tree lhs_sym, lhs = gimple_phi_result (phi);
2583
2584 if (TREE_CODE (lhs) == SSA_NAME
2585 && (! virtual_operand_p (lhs)
2586 || ! cfun->gimple_df->rename_vops))
2587 continue;
2588
2589 lhs_sym = DECL_P (lhs) ? lhs : SSA_NAME_VAR (lhs);
2590 mark_for_renaming (lhs_sym);
2591 mark_def_interesting (lhs_sym, phi, bb, insert_phi_p);
2592
2593 /* Mark the uses in phi nodes as interesting. It would be more correct
2594 to process the arguments of the phi nodes of the successor edges of
2595 BB at the end of prepare_block_for_update, however, that turns out
2596 to be significantly more expensive. Doing it here is conservatively
2597 correct -- it may only cause us to believe a value to be live in a
2598 block that also contains its definition, and thus insert a few more
2599 phi nodes for it. */
2600 FOR_EACH_EDGE (e, ei, bb->preds)
2601 mark_use_interesting (lhs_sym, phi, e->src, insert_phi_p);
2602 }
2603
2604 /* Process the statements. */
2605 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
2606 {
2607 gimple stmt;
2608 ssa_op_iter i;
2609 use_operand_p use_p;
2610 def_operand_p def_p;
2611
2612 stmt = gsi_stmt (si);
2613
2614 if (cfun->gimple_df->rename_vops
2615 && gimple_vuse (stmt))
2616 {
2617 tree use = gimple_vuse (stmt);
2618 tree sym = DECL_P (use) ? use : SSA_NAME_VAR (use);
2619 mark_for_renaming (sym);
2620 mark_use_interesting (sym, stmt, bb, insert_phi_p);
2621 }
2622
2623 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_USE)
2624 {
2625 tree use = USE_FROM_PTR (use_p);
2626 if (!DECL_P (use))
2627 continue;
2628 mark_for_renaming (use);
2629 mark_use_interesting (use, stmt, bb, insert_phi_p);
2630 }
2631
2632 if (cfun->gimple_df->rename_vops
2633 && gimple_vdef (stmt))
2634 {
2635 tree def = gimple_vdef (stmt);
2636 tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
2637 mark_for_renaming (sym);
2638 mark_def_interesting (sym, stmt, bb, insert_phi_p);
2639 }
2640
2641 FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, i, SSA_OP_DEF)
2642 {
2643 tree def = DEF_FROM_PTR (def_p);
2644 if (!DECL_P (def))
2645 continue;
2646 mark_for_renaming (def);
2647 mark_def_interesting (def, stmt, bb, insert_phi_p);
2648 }
2649 }
2650
2651 /* Now visit all the blocks dominated by BB. */
2652 for (son = first_dom_son (CDI_DOMINATORS, bb);
2653 son;
2654 son = next_dom_son (CDI_DOMINATORS, son))
2655 prepare_block_for_update (son, insert_phi_p);
2656 }
2657
2658
2659 /* Helper for prepare_names_to_update. Mark all the use sites for
2660 NAME as interesting. BLOCKS and INSERT_PHI_P are as in
2661 prepare_names_to_update. */
2662
2663 static void
2664 prepare_use_sites_for (tree name, bool insert_phi_p)
2665 {
2666 use_operand_p use_p;
2667 imm_use_iterator iter;
2668
2669 FOR_EACH_IMM_USE_FAST (use_p, iter, name)
2670 {
2671 gimple stmt = USE_STMT (use_p);
2672 basic_block bb = gimple_bb (stmt);
2673
2674 if (gimple_code (stmt) == GIMPLE_PHI)
2675 {
2676 int ix = PHI_ARG_INDEX_FROM_USE (use_p);
2677 edge e = gimple_phi_arg_edge (stmt, ix);
2678 mark_use_interesting (name, stmt, e->src, insert_phi_p);
2679 }
2680 else
2681 {
2682 /* For regular statements, mark this as an interesting use
2683 for NAME. */
2684 mark_use_interesting (name, stmt, bb, insert_phi_p);
2685 }
2686 }
2687 }
2688
2689
2690 /* Helper for prepare_names_to_update. Mark the definition site for
2691 NAME as interesting. BLOCKS and INSERT_PHI_P are as in
2692 prepare_names_to_update. */
2693
2694 static void
2695 prepare_def_site_for (tree name, bool insert_phi_p)
2696 {
2697 gimple stmt;
2698 basic_block bb;
2699
2700 gcc_assert (names_to_release == NULL
2701 || !bitmap_bit_p (names_to_release, SSA_NAME_VERSION (name)));
2702
2703 stmt = SSA_NAME_DEF_STMT (name);
2704 bb = gimple_bb (stmt);
2705 if (bb)
2706 {
2707 gcc_assert (bb->index < last_basic_block);
2708 mark_block_for_update (bb);
2709 mark_def_interesting (name, stmt, bb, insert_phi_p);
2710 }
2711 }
2712
2713
2714 /* Mark definition and use sites of names in NEW_SSA_NAMES and
2715 OLD_SSA_NAMES. INSERT_PHI_P is true if the caller wants to insert
2716 PHI nodes for newly created names. */
2717
2718 static void
2719 prepare_names_to_update (bool insert_phi_p)
2720 {
2721 unsigned i = 0;
2722 bitmap_iterator bi;
2723 sbitmap_iterator sbi;
2724
2725 /* If a name N from NEW_SSA_NAMES is also marked to be released,
2726 remove it from NEW_SSA_NAMES so that we don't try to visit its
2727 defining basic block (which most likely doesn't exist). Notice
2728 that we cannot do the same with names in OLD_SSA_NAMES because we
2729 want to replace existing instances. */
2730 if (names_to_release)
2731 EXECUTE_IF_SET_IN_BITMAP (names_to_release, 0, i, bi)
2732 RESET_BIT (new_ssa_names, i);
2733
2734 /* First process names in NEW_SSA_NAMES. Otherwise, uses of old
2735 names may be considered to be live-in on blocks that contain
2736 definitions for their replacements. */
2737 EXECUTE_IF_SET_IN_SBITMAP (new_ssa_names, 0, i, sbi)
2738 prepare_def_site_for (ssa_name (i), insert_phi_p);
2739
2740 /* If an old name is in NAMES_TO_RELEASE, we cannot remove it from
2741 OLD_SSA_NAMES, but we have to ignore its definition site. */
2742 EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i, sbi)
2743 {
2744 if (names_to_release == NULL || !bitmap_bit_p (names_to_release, i))
2745 prepare_def_site_for (ssa_name (i), insert_phi_p);
2746 prepare_use_sites_for (ssa_name (i), insert_phi_p);
2747 }
2748 }
2749
2750
2751 /* Dump all the names replaced by NAME to FILE. */
2752
2753 void
2754 dump_names_replaced_by (FILE *file, tree name)
2755 {
2756 unsigned i;
2757 bitmap old_set;
2758 bitmap_iterator bi;
2759
2760 print_generic_expr (file, name, 0);
2761 fprintf (file, " -> { ");
2762
2763 old_set = names_replaced_by (name);
2764 EXECUTE_IF_SET_IN_BITMAP (old_set, 0, i, bi)
2765 {
2766 print_generic_expr (file, ssa_name (i), 0);
2767 fprintf (file, " ");
2768 }
2769
2770 fprintf (file, "}\n");
2771 }
2772
2773
2774 /* Dump all the names replaced by NAME to stderr. */
2775
2776 DEBUG_FUNCTION void
2777 debug_names_replaced_by (tree name)
2778 {
2779 dump_names_replaced_by (stderr, name);
2780 }
2781
2782
2783 /* Dump SSA update information to FILE. */
2784
2785 void
2786 dump_update_ssa (FILE *file)
2787 {
2788 unsigned i = 0;
2789 bitmap_iterator bi;
2790
2791 if (!need_ssa_update_p (cfun))
2792 return;
2793
2794 if (new_ssa_names && sbitmap_first_set_bit (new_ssa_names) >= 0)
2795 {
2796 sbitmap_iterator sbi;
2797
2798 fprintf (file, "\nSSA replacement table\n");
2799 fprintf (file, "N_i -> { O_1 ... O_j } means that N_i replaces "
2800 "O_1, ..., O_j\n\n");
2801
2802 EXECUTE_IF_SET_IN_SBITMAP (new_ssa_names, 0, i, sbi)
2803 dump_names_replaced_by (file, ssa_name (i));
2804 }
2805
2806 if (symbols_to_rename_set && !bitmap_empty_p (symbols_to_rename_set))
2807 {
2808 fprintf (file, "\nSymbols to be put in SSA form\n");
2809 dump_decl_set (file, symbols_to_rename_set);
2810 fprintf (file, "\n");
2811 }
2812
2813 if (names_to_release && !bitmap_empty_p (names_to_release))
2814 {
2815 fprintf (file, "\nSSA names to release after updating the SSA web\n\n");
2816 EXECUTE_IF_SET_IN_BITMAP (names_to_release, 0, i, bi)
2817 {
2818 print_generic_expr (file, ssa_name (i), 0);
2819 fprintf (file, " ");
2820 }
2821 fprintf (file, "\n");
2822 }
2823 }
2824
2825
2826 /* Dump SSA update information to stderr. */
2827
2828 DEBUG_FUNCTION void
2829 debug_update_ssa (void)
2830 {
2831 dump_update_ssa (stderr);
2832 }
2833
2834
2835 /* Initialize data structures used for incremental SSA updates. */
2836
2837 static void
2838 init_update_ssa (struct function *fn)
2839 {
2840 /* Reserve more space than the current number of names. The calls to
2841 add_new_name_mapping are typically done after creating new SSA
2842 names, so we'll need to reallocate these arrays. */
2843 old_ssa_names = sbitmap_alloc (num_ssa_names + NAME_SETS_GROWTH_FACTOR);
2844 sbitmap_zero (old_ssa_names);
2845
2846 new_ssa_names = sbitmap_alloc (num_ssa_names + NAME_SETS_GROWTH_FACTOR);
2847 sbitmap_zero (new_ssa_names);
2848
2849 bitmap_obstack_initialize (&update_ssa_obstack);
2850
2851 names_to_release = NULL;
2852 update_ssa_initialized_fn = fn;
2853 }
2854
2855
2856 /* Deallocate data structures used for incremental SSA updates. */
2857
2858 void
2859 delete_update_ssa (void)
2860 {
2861 unsigned i;
2862 bitmap_iterator bi;
2863
2864 sbitmap_free (old_ssa_names);
2865 old_ssa_names = NULL;
2866
2867 sbitmap_free (new_ssa_names);
2868 new_ssa_names = NULL;
2869
2870 BITMAP_FREE (symbols_to_rename_set);
2871 symbols_to_rename_set = NULL;
2872 VEC_free (tree, heap, symbols_to_rename);
2873
2874 if (names_to_release)
2875 {
2876 EXECUTE_IF_SET_IN_BITMAP (names_to_release, 0, i, bi)
2877 release_ssa_name (ssa_name (i));
2878 BITMAP_FREE (names_to_release);
2879 }
2880
2881 clear_ssa_name_info ();
2882
2883 fini_ssa_renamer ();
2884
2885 if (blocks_with_phis_to_rewrite)
2886 EXECUTE_IF_SET_IN_BITMAP (blocks_with_phis_to_rewrite, 0, i, bi)
2887 {
2888 gimple_vec phis = VEC_index (gimple_vec, phis_to_rewrite, i);
2889
2890 VEC_free (gimple, heap, phis);
2891 VEC_replace (gimple_vec, phis_to_rewrite, i, NULL);
2892 }
2893
2894 BITMAP_FREE (blocks_with_phis_to_rewrite);
2895 BITMAP_FREE (blocks_to_update);
2896
2897 update_ssa_initialized_fn = NULL;
2898 }
2899
2900
2901 /* Create a new name for OLD_NAME in statement STMT and replace the
2902 operand pointed to by DEF_P with the newly created name. Return
2903 the new name and register the replacement mapping <NEW, OLD> in
2904 update_ssa's tables. */
2905
2906 tree
2907 create_new_def_for (tree old_name, gimple stmt, def_operand_p def)
2908 {
2909 tree new_name = duplicate_ssa_name (old_name, stmt);
2910
2911 SET_DEF (def, new_name);
2912
2913 if (gimple_code (stmt) == GIMPLE_PHI)
2914 {
2915 basic_block bb = gimple_bb (stmt);
2916
2917 /* If needed, mark NEW_NAME as occurring in an abnormal PHI node. */
2918 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_name) = bb_has_abnormal_pred (bb);
2919 }
2920
2921 register_new_name_mapping (new_name, old_name);
2922
2923 /* For the benefit of passes that will be updating the SSA form on
2924 their own, set the current reaching definition of OLD_NAME to be
2925 NEW_NAME. */
2926 get_ssa_name_ann (old_name)->info.current_def = new_name;
2927
2928 return new_name;
2929 }
2930
2931
2932 /* Register name NEW to be a replacement for name OLD. This function
2933 must be called for every replacement that should be performed by
2934 update_ssa. */
2935
2936 void
2937 register_new_name_mapping (tree new_tree, tree old)
2938 {
2939 if (!update_ssa_initialized_fn)
2940 init_update_ssa (cfun);
2941
2942 gcc_assert (update_ssa_initialized_fn == cfun);
2943
2944 add_new_name_mapping (new_tree, old);
2945 }
2946
2947
2948 /* Mark virtual operands of FN for renaming by update_ssa. */
2949
2950 void
2951 mark_virtual_operands_for_renaming (struct function *fn)
2952 {
2953 fn->gimple_df->ssa_renaming_needed = 1;
2954 fn->gimple_df->rename_vops = 1;
2955 }
2956
2957
2958 /* Return true if there is any work to be done by update_ssa
2959 for function FN. */
2960
2961 bool
2962 need_ssa_update_p (struct function *fn)
2963 {
2964 gcc_assert (fn != NULL);
2965 return (update_ssa_initialized_fn == fn
2966 || (fn->gimple_df && fn->gimple_df->ssa_renaming_needed));
2967 }
2968
2969 /* Return true if name N has been registered in the replacement table. */
2970
2971 bool
2972 name_registered_for_update_p (tree n ATTRIBUTE_UNUSED)
2973 {
2974 if (!update_ssa_initialized_fn)
2975 return false;
2976
2977 gcc_assert (update_ssa_initialized_fn == cfun);
2978
2979 return is_new_name (n) || is_old_name (n);
2980 }
2981
2982
2983 /* Mark NAME to be released after update_ssa has finished. */
2984
2985 void
2986 release_ssa_name_after_update_ssa (tree name)
2987 {
2988 gcc_assert (cfun && update_ssa_initialized_fn == cfun);
2989
2990 if (names_to_release == NULL)
2991 names_to_release = BITMAP_ALLOC (NULL);
2992
2993 bitmap_set_bit (names_to_release, SSA_NAME_VERSION (name));
2994 }
2995
2996
2997 /* Insert new PHI nodes to replace VAR. DFS contains dominance
2998 frontier information. BLOCKS is the set of blocks to be updated.
2999
3000 This is slightly different than the regular PHI insertion
3001 algorithm. The value of UPDATE_FLAGS controls how PHI nodes for
3002 real names (i.e., GIMPLE registers) are inserted:
3003
3004 - If UPDATE_FLAGS == TODO_update_ssa, we are only interested in PHI
3005 nodes inside the region affected by the block that defines VAR
3006 and the blocks that define all its replacements. All these
3007 definition blocks are stored in DEF_BLOCKS[VAR]->DEF_BLOCKS.
3008
3009 First, we compute the entry point to the region (ENTRY). This is
3010 given by the nearest common dominator to all the definition
3011 blocks. When computing the iterated dominance frontier (IDF), any
3012 block not strictly dominated by ENTRY is ignored.
3013
3014 We then call the standard PHI insertion algorithm with the pruned
3015 IDF.
3016
3017 - If UPDATE_FLAGS == TODO_update_ssa_full_phi, the IDF for real
3018 names is not pruned. PHI nodes are inserted at every IDF block. */
3019
3020 static void
3021 insert_updated_phi_nodes_for (tree var, bitmap_head *dfs, bitmap blocks,
3022 unsigned update_flags)
3023 {
3024 basic_block entry;
3025 struct def_blocks_d *db;
3026 bitmap idf, pruned_idf;
3027 bitmap_iterator bi;
3028 unsigned i;
3029
3030 if (TREE_CODE (var) == SSA_NAME)
3031 gcc_checking_assert (is_old_name (var));
3032 else
3033 gcc_checking_assert (marked_for_renaming (var));
3034
3035 /* Get all the definition sites for VAR. */
3036 db = find_def_blocks_for (var);
3037
3038 /* No need to do anything if there were no definitions to VAR. */
3039 if (db == NULL || bitmap_empty_p (db->def_blocks))
3040 return;
3041
3042 /* Compute the initial iterated dominance frontier. */
3043 idf = compute_idf (db->def_blocks, dfs);
3044 pruned_idf = BITMAP_ALLOC (NULL);
3045
3046 if (TREE_CODE (var) == SSA_NAME)
3047 {
3048 if (update_flags == TODO_update_ssa)
3049 {
3050 /* If doing regular SSA updates for GIMPLE registers, we are
3051 only interested in IDF blocks dominated by the nearest
3052 common dominator of all the definition blocks. */
3053 entry = nearest_common_dominator_for_set (CDI_DOMINATORS,
3054 db->def_blocks);
3055 if (entry != ENTRY_BLOCK_PTR)
3056 EXECUTE_IF_SET_IN_BITMAP (idf, 0, i, bi)
3057 if (BASIC_BLOCK (i) != entry
3058 && dominated_by_p (CDI_DOMINATORS, BASIC_BLOCK (i), entry))
3059 bitmap_set_bit (pruned_idf, i);
3060 }
3061 else
3062 {
3063 /* Otherwise, do not prune the IDF for VAR. */
3064 gcc_assert (update_flags == TODO_update_ssa_full_phi);
3065 bitmap_copy (pruned_idf, idf);
3066 }
3067 }
3068 else
3069 {
3070 /* Otherwise, VAR is a symbol that needs to be put into SSA form
3071 for the first time, so we need to compute the full IDF for
3072 it. */
3073 bitmap_copy (pruned_idf, idf);
3074 }
3075
3076 if (!bitmap_empty_p (pruned_idf))
3077 {
3078 /* Make sure that PRUNED_IDF blocks and all their feeding blocks
3079 are included in the region to be updated. The feeding blocks
3080 are important to guarantee that the PHI arguments are renamed
3081 properly. */
3082
3083 /* FIXME, this is not needed if we are updating symbols. We are
3084 already starting at the ENTRY block anyway. */
3085 bitmap_ior_into (blocks, pruned_idf);
3086 EXECUTE_IF_SET_IN_BITMAP (pruned_idf, 0, i, bi)
3087 {
3088 edge e;
3089 edge_iterator ei;
3090 basic_block bb = BASIC_BLOCK (i);
3091
3092 FOR_EACH_EDGE (e, ei, bb->preds)
3093 if (e->src->index >= 0)
3094 bitmap_set_bit (blocks, e->src->index);
3095 }
3096
3097 insert_phi_nodes_for (var, pruned_idf, true);
3098 }
3099
3100 BITMAP_FREE (pruned_idf);
3101 BITMAP_FREE (idf);
3102 }
3103
3104
3105 /* Given a set of newly created SSA names (NEW_SSA_NAMES) and a set of
3106 existing SSA names (OLD_SSA_NAMES), update the SSA form so that:
3107
3108 1- The names in OLD_SSA_NAMES dominated by the definitions of
3109 NEW_SSA_NAMES are all re-written to be reached by the
3110 appropriate definition from NEW_SSA_NAMES.
3111
3112 2- If needed, new PHI nodes are added to the iterated dominance
3113 frontier of the blocks where each of NEW_SSA_NAMES are defined.
3114
3115 The mapping between OLD_SSA_NAMES and NEW_SSA_NAMES is setup by
3116 calling register_new_name_mapping for every pair of names that the
3117 caller wants to replace.
3118
3119 The caller identifies the new names that have been inserted and the
3120 names that need to be replaced by calling register_new_name_mapping
3121 for every pair <NEW, OLD>. Note that the function assumes that the
3122 new names have already been inserted in the IL.
3123
3124 For instance, given the following code:
3125
3126 1 L0:
3127 2 x_1 = PHI (0, x_5)
3128 3 if (x_1 < 10)
3129 4 if (x_1 > 7)
3130 5 y_2 = 0
3131 6 else
3132 7 y_3 = x_1 + x_7
3133 8 endif
3134 9 x_5 = x_1 + 1
3135 10 goto L0;
3136 11 endif
3137
3138 Suppose that we insert new names x_10 and x_11 (lines 4 and 8).
3139
3140 1 L0:
3141 2 x_1 = PHI (0, x_5)
3142 3 if (x_1 < 10)
3143 4 x_10 = ...
3144 5 if (x_1 > 7)
3145 6 y_2 = 0
3146 7 else
3147 8 x_11 = ...
3148 9 y_3 = x_1 + x_7
3149 10 endif
3150 11 x_5 = x_1 + 1
3151 12 goto L0;
3152 13 endif
3153
3154 We want to replace all the uses of x_1 with the new definitions of
3155 x_10 and x_11. Note that the only uses that should be replaced are
3156 those at lines 5, 9 and 11. Also, the use of x_7 at line 9 should
3157 *not* be replaced (this is why we cannot just mark symbol 'x' for
3158 renaming).
3159
3160 Additionally, we may need to insert a PHI node at line 11 because
3161 that is a merge point for x_10 and x_11. So the use of x_1 at line
3162 11 will be replaced with the new PHI node. The insertion of PHI
3163 nodes is optional. They are not strictly necessary to preserve the
3164 SSA form, and depending on what the caller inserted, they may not
3165 even be useful for the optimizers. UPDATE_FLAGS controls various
3166 aspects of how update_ssa operates, see the documentation for
3167 TODO_update_ssa*. */
3168
3169 void
3170 update_ssa (unsigned update_flags)
3171 {
3172 basic_block bb, start_bb;
3173 bitmap_iterator bi;
3174 unsigned i = 0;
3175 bool insert_phi_p;
3176 sbitmap_iterator sbi;
3177 tree sym;
3178
3179 /* Only one update flag should be set. */
3180 gcc_assert (update_flags == TODO_update_ssa
3181 || update_flags == TODO_update_ssa_no_phi
3182 || update_flags == TODO_update_ssa_full_phi
3183 || update_flags == TODO_update_ssa_only_virtuals);
3184
3185 if (!need_ssa_update_p (cfun))
3186 return;
3187
3188 timevar_push (TV_TREE_SSA_INCREMENTAL);
3189
3190 if (dump_file && (dump_flags & TDF_DETAILS))
3191 fprintf (dump_file, "\nUpdating SSA:\n");
3192
3193 if (!update_ssa_initialized_fn)
3194 init_update_ssa (cfun);
3195 else if (update_flags == TODO_update_ssa_only_virtuals)
3196 {
3197 /* If we only need to update virtuals, remove all the mappings for
3198 real names before proceeding. The caller is responsible for
3199 having dealt with the name mappings before calling update_ssa. */
3200 sbitmap_zero (old_ssa_names);
3201 sbitmap_zero (new_ssa_names);
3202 }
3203
3204 gcc_assert (update_ssa_initialized_fn == cfun);
3205
3206 blocks_with_phis_to_rewrite = BITMAP_ALLOC (NULL);
3207 if (!phis_to_rewrite)
3208 phis_to_rewrite = VEC_alloc (gimple_vec, heap, last_basic_block + 1);
3209 blocks_to_update = BITMAP_ALLOC (NULL);
3210
3211 /* Ensure that the dominance information is up-to-date. */
3212 calculate_dominance_info (CDI_DOMINATORS);
3213
3214 insert_phi_p = (update_flags != TODO_update_ssa_no_phi);
3215
3216 /* If there are names defined in the replacement table, prepare
3217 definition and use sites for all the names in NEW_SSA_NAMES and
3218 OLD_SSA_NAMES. */
3219 if (sbitmap_first_set_bit (new_ssa_names) >= 0)
3220 {
3221 prepare_names_to_update (insert_phi_p);
3222
3223 /* If all the names in NEW_SSA_NAMES had been marked for
3224 removal, and there are no symbols to rename, then there's
3225 nothing else to do. */
3226 if (sbitmap_first_set_bit (new_ssa_names) < 0
3227 && !cfun->gimple_df->ssa_renaming_needed)
3228 goto done;
3229 }
3230
3231 /* Next, determine the block at which to start the renaming process. */
3232 if (cfun->gimple_df->ssa_renaming_needed)
3233 {
3234 /* If we rename bare symbols initialize the mapping to
3235 auxiliar info we need to keep track of. */
3236 var_infos = htab_create (47, var_info_hash, var_info_eq, NULL);
3237
3238 /* If we have to rename some symbols from scratch, we need to
3239 start the process at the root of the CFG. FIXME, it should
3240 be possible to determine the nearest block that had a
3241 definition for each of the symbols that are marked for
3242 updating. For now this seems more work than it's worth. */
3243 start_bb = ENTRY_BLOCK_PTR;
3244
3245 /* Traverse the CFG looking for existing definitions and uses of
3246 symbols in SSA operands. Mark interesting blocks and
3247 statements and set local live-in information for the PHI
3248 placement heuristics. */
3249 prepare_block_for_update (start_bb, insert_phi_p);
3250 }
3251 else
3252 {
3253 /* Otherwise, the entry block to the region is the nearest
3254 common dominator for the blocks in BLOCKS. */
3255 start_bb = nearest_common_dominator_for_set (CDI_DOMINATORS,
3256 blocks_to_update);
3257 }
3258
3259 /* If requested, insert PHI nodes at the iterated dominance frontier
3260 of every block, creating new definitions for names in OLD_SSA_NAMES
3261 and for symbols found. */
3262 if (insert_phi_p)
3263 {
3264 bitmap_head *dfs;
3265
3266 /* If the caller requested PHI nodes to be added, compute
3267 dominance frontiers. */
3268 dfs = XNEWVEC (bitmap_head, last_basic_block);
3269 FOR_EACH_BB (bb)
3270 bitmap_initialize (&dfs[bb->index], &bitmap_default_obstack);
3271 compute_dominance_frontiers (dfs);
3272
3273 if (sbitmap_first_set_bit (old_ssa_names) >= 0)
3274 {
3275 sbitmap_iterator sbi;
3276
3277 /* insert_update_phi_nodes_for will call add_new_name_mapping
3278 when inserting new PHI nodes, so the set OLD_SSA_NAMES
3279 will grow while we are traversing it (but it will not
3280 gain any new members). Copy OLD_SSA_NAMES to a temporary
3281 for traversal. */
3282 sbitmap tmp = sbitmap_alloc (SBITMAP_SIZE (old_ssa_names));
3283 sbitmap_copy (tmp, old_ssa_names);
3284 EXECUTE_IF_SET_IN_SBITMAP (tmp, 0, i, sbi)
3285 insert_updated_phi_nodes_for (ssa_name (i), dfs, blocks_to_update,
3286 update_flags);
3287 sbitmap_free (tmp);
3288 }
3289
3290 FOR_EACH_VEC_ELT (tree, symbols_to_rename, i, sym)
3291 insert_updated_phi_nodes_for (sym, dfs, blocks_to_update,
3292 update_flags);
3293
3294 FOR_EACH_BB (bb)
3295 bitmap_clear (&dfs[bb->index]);
3296 free (dfs);
3297
3298 /* Insertion of PHI nodes may have added blocks to the region.
3299 We need to re-compute START_BB to include the newly added
3300 blocks. */
3301 if (start_bb != ENTRY_BLOCK_PTR)
3302 start_bb = nearest_common_dominator_for_set (CDI_DOMINATORS,
3303 blocks_to_update);
3304 }
3305
3306 /* Reset the current definition for name and symbol before renaming
3307 the sub-graph. */
3308 EXECUTE_IF_SET_IN_SBITMAP (old_ssa_names, 0, i, sbi)
3309 get_ssa_name_ann (ssa_name (i))->info.current_def = NULL_TREE;
3310
3311 FOR_EACH_VEC_ELT (tree, symbols_to_rename, i, sym)
3312 get_var_info (sym)->info.current_def = NULL_TREE;
3313
3314 /* Now start the renaming process at START_BB. */
3315 interesting_blocks = sbitmap_alloc (last_basic_block);
3316 sbitmap_zero (interesting_blocks);
3317 EXECUTE_IF_SET_IN_BITMAP (blocks_to_update, 0, i, bi)
3318 SET_BIT (interesting_blocks, i);
3319
3320 rewrite_blocks (start_bb, REWRITE_UPDATE);
3321
3322 sbitmap_free (interesting_blocks);
3323
3324 /* Debugging dumps. */
3325 if (dump_file)
3326 {
3327 int c;
3328 unsigned i;
3329
3330 dump_update_ssa (dump_file);
3331
3332 fprintf (dump_file, "Incremental SSA update started at block: %d\n",
3333 start_bb->index);
3334
3335 c = 0;
3336 EXECUTE_IF_SET_IN_BITMAP (blocks_to_update, 0, i, bi)
3337 c++;
3338 fprintf (dump_file, "Number of blocks in CFG: %d\n", last_basic_block);
3339 fprintf (dump_file, "Number of blocks to update: %d (%3.0f%%)\n",
3340 c, PERCENT (c, last_basic_block));
3341
3342 if (dump_flags & TDF_DETAILS)
3343 {
3344 fprintf (dump_file, "Affected blocks:");
3345 EXECUTE_IF_SET_IN_BITMAP (blocks_to_update, 0, i, bi)
3346 fprintf (dump_file, " %u", i);
3347 fprintf (dump_file, "\n");
3348 }
3349
3350 fprintf (dump_file, "\n\n");
3351 }
3352
3353 /* Free allocated memory. */
3354 done:
3355 delete_update_ssa ();
3356
3357 timevar_pop (TV_TREE_SSA_INCREMENTAL);
3358 }