Merge trunk version 193672 into gupc branch.
[official-gcc.git] / gcc / tree-ssa.c
blob5eb8bf58e12b7227b9f67656aa6a47055d2ad9f4
1 /* Miscellaneous SSA utility functions.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "flags.h"
27 #include "tm_p.h"
28 #include "target.h"
29 #include "ggc.h"
30 #include "langhooks.h"
31 #include "basic-block.h"
32 #include "function.h"
33 #include "gimple-pretty-print.h"
34 #include "bitmap.h"
35 #include "pointer-set.h"
36 #include "tree-flow.h"
37 #include "gimple.h"
38 #include "tree-inline.h"
39 #include "hashtab.h"
40 #include "tree-pass.h"
41 #include "diagnostic-core.h"
42 #include "cfgloop.h"
44 /* Pointer map of variable mappings, keyed by edge. */
45 static struct pointer_map_t *edge_var_maps;
48 /* Add a mapping with PHI RESULT and PHI DEF associated with edge E. */
50 void
51 redirect_edge_var_map_add (edge e, tree result, tree def, source_location locus)
53 void **slot;
54 edge_var_map_vector *head;
55 edge_var_map new_node;
57 if (edge_var_maps == NULL)
58 edge_var_maps = pointer_map_create ();
60 slot = pointer_map_insert (edge_var_maps, e);
61 head = (edge_var_map_vector *) *slot;
62 if (!head)
64 head = new edge_var_map_vector;
65 head->create (5);
66 *slot = head;
68 new_node.def = def;
69 new_node.result = result;
70 new_node.locus = locus;
72 head->safe_push (new_node);
76 /* Clear the var mappings in edge E. */
78 void
79 redirect_edge_var_map_clear (edge e)
81 void **slot;
82 edge_var_map_vector *head;
84 if (!edge_var_maps)
85 return;
87 slot = pointer_map_contains (edge_var_maps, e);
89 if (slot)
91 head = (edge_var_map_vector *) *slot;
92 delete head;
93 *slot = NULL;
98 /* Duplicate the redirected var mappings in OLDE in NEWE.
100 Since we can't remove a mapping, let's just duplicate it. This assumes a
101 pointer_map can have multiple edges mapping to the same var_map (many to
102 one mapping), since we don't remove the previous mappings. */
104 void
105 redirect_edge_var_map_dup (edge newe, edge olde)
107 void **new_slot, **old_slot;
108 edge_var_map_vector *head;
110 if (!edge_var_maps)
111 return;
113 new_slot = pointer_map_insert (edge_var_maps, newe);
114 old_slot = pointer_map_contains (edge_var_maps, olde);
115 if (!old_slot)
116 return;
117 head = (edge_var_map_vector *) *old_slot;
119 edge_var_map_vector *new_head = new edge_var_map_vector;
120 if (head)
121 *new_head = head->copy ();
122 else
123 new_head->create (5);
124 *new_slot = new_head;
128 /* Return the variable mappings for a given edge. If there is none, return
129 NULL. */
131 edge_var_map_vector *
132 redirect_edge_var_map_vector (edge e)
134 void **slot;
136 /* Hey, what kind of idiot would... you'd be surprised. */
137 if (!edge_var_maps)
138 return NULL;
140 slot = pointer_map_contains (edge_var_maps, e);
141 if (!slot)
142 return NULL;
144 return (edge_var_map_vector *) *slot;
147 /* Used by redirect_edge_var_map_destroy to free all memory. */
149 static bool
150 free_var_map_entry (const void *key ATTRIBUTE_UNUSED,
151 void **value,
152 void *data ATTRIBUTE_UNUSED)
154 edge_var_map_vector *head = (edge_var_map_vector *) *value;
155 delete head;
156 return true;
159 /* Clear the edge variable mappings. */
161 void
162 redirect_edge_var_map_destroy (void)
164 if (edge_var_maps)
166 pointer_map_traverse (edge_var_maps, free_var_map_entry, NULL);
167 pointer_map_destroy (edge_var_maps);
168 edge_var_maps = NULL;
173 /* Remove the corresponding arguments from the PHI nodes in E's
174 destination block and redirect it to DEST. Return redirected edge.
175 The list of removed arguments is stored in a vector accessed
176 through edge_var_maps. */
178 edge
179 ssa_redirect_edge (edge e, basic_block dest)
181 gimple_stmt_iterator gsi;
182 gimple phi;
184 redirect_edge_var_map_clear (e);
186 /* Remove the appropriate PHI arguments in E's destination block. */
187 for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
189 tree def;
190 source_location locus ;
192 phi = gsi_stmt (gsi);
193 def = gimple_phi_arg_def (phi, e->dest_idx);
194 locus = gimple_phi_arg_location (phi, e->dest_idx);
196 if (def == NULL_TREE)
197 continue;
199 redirect_edge_var_map_add (e, gimple_phi_result (phi), def, locus);
202 e = redirect_edge_succ_nodup (e, dest);
204 return e;
208 /* Add PHI arguments queued in PENDING_STMT list on edge E to edge
209 E->dest. */
211 void
212 flush_pending_stmts (edge e)
214 gimple phi;
215 edge_var_map_vector *v;
216 edge_var_map *vm;
217 int i;
218 gimple_stmt_iterator gsi;
220 v = redirect_edge_var_map_vector (e);
221 if (!v)
222 return;
224 for (gsi = gsi_start_phis (e->dest), i = 0;
225 !gsi_end_p (gsi) && v->iterate (i, &vm);
226 gsi_next (&gsi), i++)
228 tree def;
230 phi = gsi_stmt (gsi);
231 def = redirect_edge_var_map_def (vm);
232 add_phi_arg (phi, def, e, redirect_edge_var_map_location (vm));
235 redirect_edge_var_map_clear (e);
238 /* Given a tree for an expression for which we might want to emit
239 locations or values in debug information (generally a variable, but
240 we might deal with other kinds of trees in the future), return the
241 tree that should be used as the variable of a DEBUG_BIND STMT or
242 VAR_LOCATION INSN or NOTE. Return NULL if VAR is not to be tracked. */
244 tree
245 target_for_debug_bind (tree var)
247 if (!MAY_HAVE_DEBUG_STMTS)
248 return NULL_TREE;
250 if (TREE_CODE (var) == SSA_NAME)
252 var = SSA_NAME_VAR (var);
253 if (var == NULL_TREE)
254 return NULL_TREE;
257 if ((TREE_CODE (var) != VAR_DECL
258 || VAR_DECL_IS_VIRTUAL_OPERAND (var))
259 && TREE_CODE (var) != PARM_DECL)
260 return NULL_TREE;
262 if (DECL_HAS_VALUE_EXPR_P (var))
263 return target_for_debug_bind (DECL_VALUE_EXPR (var));
265 if (DECL_IGNORED_P (var))
266 return NULL_TREE;
268 /* var-tracking only tracks registers. */
269 if (!is_gimple_reg_type (TREE_TYPE (var)))
270 return NULL_TREE;
272 return var;
275 /* Called via walk_tree, look for SSA_NAMEs that have already been
276 released. */
278 static tree
279 find_released_ssa_name (tree *tp, int *walk_subtrees, void *data_)
281 struct walk_stmt_info *wi = (struct walk_stmt_info *) data_;
283 if (wi && wi->is_lhs)
284 return NULL_TREE;
286 if (TREE_CODE (*tp) == SSA_NAME)
288 if (SSA_NAME_IN_FREE_LIST (*tp))
289 return *tp;
291 *walk_subtrees = 0;
293 else if (IS_TYPE_OR_DECL_P (*tp))
294 *walk_subtrees = 0;
296 return NULL_TREE;
299 /* Insert a DEBUG BIND stmt before the DEF of VAR if VAR is referenced
300 by other DEBUG stmts, and replace uses of the DEF with the
301 newly-created debug temp. */
303 void
304 insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
306 imm_use_iterator imm_iter;
307 use_operand_p use_p;
308 gimple stmt;
309 gimple def_stmt = NULL;
310 int usecount = 0;
311 tree value = NULL;
313 if (!MAY_HAVE_DEBUG_STMTS)
314 return;
316 /* If this name has already been registered for replacement, do nothing
317 as anything that uses this name isn't in SSA form. */
318 if (name_registered_for_update_p (var))
319 return;
321 /* Check whether there are debug stmts that reference this variable and,
322 if there are, decide whether we should use a debug temp. */
323 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, var)
325 stmt = USE_STMT (use_p);
327 if (!gimple_debug_bind_p (stmt))
328 continue;
330 if (usecount++)
331 break;
333 if (gimple_debug_bind_get_value (stmt) != var)
335 /* Count this as an additional use, so as to make sure we
336 use a temp unless VAR's definition has a SINGLE_RHS that
337 can be shared. */
338 usecount++;
339 break;
343 if (!usecount)
344 return;
346 if (gsi)
347 def_stmt = gsi_stmt (*gsi);
348 else
349 def_stmt = SSA_NAME_DEF_STMT (var);
351 /* If we didn't get an insertion point, and the stmt has already
352 been removed, we won't be able to insert the debug bind stmt, so
353 we'll have to drop debug information. */
354 if (gimple_code (def_stmt) == GIMPLE_PHI)
356 value = degenerate_phi_result (def_stmt);
357 if (value && walk_tree (&value, find_released_ssa_name, NULL, NULL))
358 value = NULL;
359 /* error_mark_node is what fixup_noreturn_call changes PHI arguments
360 to. */
361 else if (value == error_mark_node)
362 value = NULL;
364 else if (is_gimple_assign (def_stmt))
366 bool no_value = false;
368 if (!dom_info_available_p (CDI_DOMINATORS))
370 struct walk_stmt_info wi;
372 memset (&wi, 0, sizeof (wi));
374 /* When removing blocks without following reverse dominance
375 order, we may sometimes encounter SSA_NAMEs that have
376 already been released, referenced in other SSA_DEFs that
377 we're about to release. Consider:
379 <bb X>:
380 v_1 = foo;
382 <bb Y>:
383 w_2 = v_1 + bar;
384 # DEBUG w => w_2
386 If we deleted BB X first, propagating the value of w_2
387 won't do us any good. It's too late to recover their
388 original definition of v_1: when it was deleted, it was
389 only referenced in other DEFs, it couldn't possibly know
390 it should have been retained, and propagating every
391 single DEF just in case it might have to be propagated
392 into a DEBUG STMT would probably be too wasteful.
394 When dominator information is not readily available, we
395 check for and accept some loss of debug information. But
396 if it is available, there's no excuse for us to remove
397 blocks in the wrong order, so we don't even check for
398 dead SSA NAMEs. SSA verification shall catch any
399 errors. */
400 if ((!gsi && !gimple_bb (def_stmt))
401 || walk_gimple_op (def_stmt, find_released_ssa_name, &wi))
402 no_value = true;
405 if (!no_value)
406 value = gimple_assign_rhs_to_tree (def_stmt);
409 if (value)
411 /* If there's a single use of VAR, and VAR is the entire debug
412 expression (usecount would have been incremented again
413 otherwise), and the definition involves only constants and
414 SSA names, then we can propagate VALUE into this single use,
415 avoiding the temp.
417 We can also avoid using a temp if VALUE can be shared and
418 propagated into all uses, without generating expressions that
419 wouldn't be valid gimple RHSs.
421 Other cases that would require unsharing or non-gimple RHSs
422 are deferred to a debug temp, although we could avoid temps
423 at the expense of duplication of expressions. */
425 if (CONSTANT_CLASS_P (value)
426 || gimple_code (def_stmt) == GIMPLE_PHI
427 || (usecount == 1
428 && (!gimple_assign_single_p (def_stmt)
429 || is_gimple_min_invariant (value)))
430 || is_gimple_reg (value))
431 value = unshare_expr (value);
432 else
434 gimple def_temp;
435 tree vexpr = make_node (DEBUG_EXPR_DECL);
437 def_temp = gimple_build_debug_bind (vexpr,
438 unshare_expr (value),
439 def_stmt);
441 DECL_ARTIFICIAL (vexpr) = 1;
442 TREE_TYPE (vexpr) = TREE_TYPE (value);
443 if (DECL_P (value))
444 DECL_MODE (vexpr) = DECL_MODE (value);
445 else
446 DECL_MODE (vexpr) = TYPE_MODE (TREE_TYPE (value));
448 if (gsi)
449 gsi_insert_before (gsi, def_temp, GSI_SAME_STMT);
450 else
452 gimple_stmt_iterator ngsi = gsi_for_stmt (def_stmt);
453 gsi_insert_before (&ngsi, def_temp, GSI_SAME_STMT);
456 value = vexpr;
460 FOR_EACH_IMM_USE_STMT (stmt, imm_iter, var)
462 if (!gimple_debug_bind_p (stmt))
463 continue;
465 if (value)
467 FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
468 /* unshare_expr is not needed here. vexpr is either a
469 SINGLE_RHS, that can be safely shared, some other RHS
470 that was unshared when we found it had a single debug
471 use, or a DEBUG_EXPR_DECL, that can be safely
472 shared. */
473 SET_USE (use_p, value);
474 /* If we didn't replace uses with a debug decl fold the
475 resulting expression. Otherwise we end up with invalid IL. */
476 if (TREE_CODE (value) != DEBUG_EXPR_DECL)
478 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
479 fold_stmt_inplace (&gsi);
482 else
483 gimple_debug_bind_reset_value (stmt);
485 update_stmt (stmt);
490 /* Insert a DEBUG BIND stmt before STMT for each DEF referenced by
491 other DEBUG stmts, and replace uses of the DEF with the
492 newly-created debug temp. */
494 void
495 insert_debug_temps_for_defs (gimple_stmt_iterator *gsi)
497 gimple stmt;
498 ssa_op_iter op_iter;
499 def_operand_p def_p;
501 if (!MAY_HAVE_DEBUG_STMTS)
502 return;
504 stmt = gsi_stmt (*gsi);
506 FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
508 tree var = DEF_FROM_PTR (def_p);
510 if (TREE_CODE (var) != SSA_NAME)
511 continue;
513 insert_debug_temp_for_var_def (gsi, var);
517 /* Reset all debug stmts that use SSA_NAME(s) defined in STMT. */
519 void
520 reset_debug_uses (gimple stmt)
522 ssa_op_iter op_iter;
523 def_operand_p def_p;
524 imm_use_iterator imm_iter;
525 gimple use_stmt;
527 if (!MAY_HAVE_DEBUG_STMTS)
528 return;
530 FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
532 tree var = DEF_FROM_PTR (def_p);
534 if (TREE_CODE (var) != SSA_NAME)
535 continue;
537 FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, var)
539 if (!gimple_debug_bind_p (use_stmt))
540 continue;
542 gimple_debug_bind_reset_value (use_stmt);
543 update_stmt (use_stmt);
548 /* Delete SSA DEFs for SSA versions in the TOREMOVE bitmap, removing
549 dominated stmts before their dominators, so that release_ssa_defs
550 stands a chance of propagating DEFs into debug bind stmts. */
552 void
553 release_defs_bitset (bitmap toremove)
555 unsigned j;
556 bitmap_iterator bi;
558 /* Performing a topological sort is probably overkill, this will
559 most likely run in slightly superlinear time, rather than the
560 pathological quadratic worst case. */
561 while (!bitmap_empty_p (toremove))
562 EXECUTE_IF_SET_IN_BITMAP (toremove, 0, j, bi)
564 bool remove_now = true;
565 tree var = ssa_name (j);
566 gimple stmt;
567 imm_use_iterator uit;
569 FOR_EACH_IMM_USE_STMT (stmt, uit, var)
571 ssa_op_iter dit;
572 def_operand_p def_p;
574 /* We can't propagate PHI nodes into debug stmts. */
575 if (gimple_code (stmt) == GIMPLE_PHI
576 || is_gimple_debug (stmt))
577 continue;
579 /* If we find another definition to remove that uses
580 the one we're looking at, defer the removal of this
581 one, so that it can be propagated into debug stmts
582 after the other is. */
583 FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, dit, SSA_OP_DEF)
585 tree odef = DEF_FROM_PTR (def_p);
587 if (bitmap_bit_p (toremove, SSA_NAME_VERSION (odef)))
589 remove_now = false;
590 break;
594 if (!remove_now)
595 BREAK_FROM_IMM_USE_STMT (uit);
598 if (remove_now)
600 gimple def = SSA_NAME_DEF_STMT (var);
601 gimple_stmt_iterator gsi = gsi_for_stmt (def);
603 if (gimple_code (def) == GIMPLE_PHI)
604 remove_phi_node (&gsi, true);
605 else
607 gsi_remove (&gsi, true);
608 release_defs (def);
611 bitmap_clear_bit (toremove, j);
616 /* Return true if SSA_NAME is malformed and mark it visited.
618 IS_VIRTUAL is true if this SSA_NAME was found inside a virtual
619 operand. */
621 static bool
622 verify_ssa_name (tree ssa_name, bool is_virtual)
624 if (TREE_CODE (ssa_name) != SSA_NAME)
626 error ("expected an SSA_NAME object");
627 return true;
630 if (SSA_NAME_VAR (ssa_name) != NULL_TREE
631 && TREE_TYPE (ssa_name) != TREE_TYPE (ssa_name))
633 error ("type mismatch between an SSA_NAME and its symbol");
634 return true;
637 if (SSA_NAME_IN_FREE_LIST (ssa_name))
639 error ("found an SSA_NAME that had been released into the free pool");
640 return true;
643 if (is_virtual && !virtual_operand_p (ssa_name))
645 error ("found a virtual definition for a GIMPLE register");
646 return true;
649 if (is_virtual && SSA_NAME_VAR (ssa_name) != gimple_vop (cfun))
651 error ("virtual SSA name for non-VOP decl");
652 return true;
655 if (!is_virtual && virtual_operand_p (ssa_name))
657 error ("found a real definition for a non-register");
658 return true;
661 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
662 && !gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name)))
664 error ("found a default name with a non-empty defining statement");
665 return true;
668 return false;
672 /* Return true if the definition of SSA_NAME at block BB is malformed.
674 STMT is the statement where SSA_NAME is created.
676 DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
677 version numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
678 it means that the block in that array slot contains the
679 definition of SSA_NAME.
681 IS_VIRTUAL is true if SSA_NAME is created by a VDEF. */
683 static bool
684 verify_def (basic_block bb, basic_block *definition_block, tree ssa_name,
685 gimple stmt, bool is_virtual)
687 if (verify_ssa_name (ssa_name, is_virtual))
688 goto err;
690 if (SSA_NAME_VAR (ssa_name)
691 && TREE_CODE (SSA_NAME_VAR (ssa_name)) == RESULT_DECL
692 && DECL_BY_REFERENCE (SSA_NAME_VAR (ssa_name)))
694 error ("RESULT_DECL should be read only when DECL_BY_REFERENCE is set");
695 goto err;
698 if (definition_block[SSA_NAME_VERSION (ssa_name)])
700 error ("SSA_NAME created in two different blocks %i and %i",
701 definition_block[SSA_NAME_VERSION (ssa_name)]->index, bb->index);
702 goto err;
705 definition_block[SSA_NAME_VERSION (ssa_name)] = bb;
707 if (SSA_NAME_DEF_STMT (ssa_name) != stmt)
709 error ("SSA_NAME_DEF_STMT is wrong");
710 fprintf (stderr, "Expected definition statement:\n");
711 print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (ssa_name), 4, TDF_VOPS);
712 fprintf (stderr, "\nActual definition statement:\n");
713 print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
714 goto err;
717 return false;
719 err:
720 fprintf (stderr, "while verifying SSA_NAME ");
721 print_generic_expr (stderr, ssa_name, 0);
722 fprintf (stderr, " in statement\n");
723 print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
725 return true;
729 /* Return true if the use of SSA_NAME at statement STMT in block BB is
730 malformed.
732 DEF_BB is the block where SSA_NAME was found to be created.
734 IDOM contains immediate dominator information for the flowgraph.
736 CHECK_ABNORMAL is true if the caller wants to check whether this use
737 is flowing through an abnormal edge (only used when checking PHI
738 arguments).
740 If NAMES_DEFINED_IN_BB is not NULL, it contains a bitmap of ssa names
741 that are defined before STMT in basic block BB. */
743 static bool
744 verify_use (basic_block bb, basic_block def_bb, use_operand_p use_p,
745 gimple stmt, bool check_abnormal, bitmap names_defined_in_bb)
747 bool err = false;
748 tree ssa_name = USE_FROM_PTR (use_p);
750 if (!TREE_VISITED (ssa_name))
751 if (verify_imm_links (stderr, ssa_name))
752 err = true;
754 TREE_VISITED (ssa_name) = 1;
756 if (gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name))
757 && SSA_NAME_IS_DEFAULT_DEF (ssa_name))
758 ; /* Default definitions have empty statements. Nothing to do. */
759 else if (!def_bb)
761 error ("missing definition");
762 err = true;
764 else if (bb != def_bb
765 && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
767 error ("definition in block %i does not dominate use in block %i",
768 def_bb->index, bb->index);
769 err = true;
771 else if (bb == def_bb
772 && names_defined_in_bb != NULL
773 && !bitmap_bit_p (names_defined_in_bb, SSA_NAME_VERSION (ssa_name)))
775 error ("definition in block %i follows the use", def_bb->index);
776 err = true;
779 if (check_abnormal
780 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
782 error ("SSA_NAME_OCCURS_IN_ABNORMAL_PHI should be set");
783 err = true;
786 /* Make sure the use is in an appropriate list by checking the previous
787 element to make sure it's the same. */
788 if (use_p->prev == NULL)
790 error ("no immediate_use list");
791 err = true;
793 else
795 tree listvar;
796 if (use_p->prev->use == NULL)
797 listvar = use_p->prev->loc.ssa_name;
798 else
799 listvar = USE_FROM_PTR (use_p->prev);
800 if (listvar != ssa_name)
802 error ("wrong immediate use list");
803 err = true;
807 if (err)
809 fprintf (stderr, "for SSA_NAME: ");
810 print_generic_expr (stderr, ssa_name, TDF_VOPS);
811 fprintf (stderr, " in statement:\n");
812 print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
815 return err;
819 /* Return true if any of the arguments for PHI node PHI at block BB is
820 malformed.
822 DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
823 version numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
824 it means that the block in that array slot contains the
825 definition of SSA_NAME. */
827 static bool
828 verify_phi_args (gimple phi, basic_block bb, basic_block *definition_block)
830 edge e;
831 bool err = false;
832 size_t i, phi_num_args = gimple_phi_num_args (phi);
834 if (EDGE_COUNT (bb->preds) != phi_num_args)
836 error ("incoming edge count does not match number of PHI arguments");
837 err = true;
838 goto error;
841 for (i = 0; i < phi_num_args; i++)
843 use_operand_p op_p = gimple_phi_arg_imm_use_ptr (phi, i);
844 tree op = USE_FROM_PTR (op_p);
846 e = EDGE_PRED (bb, i);
848 if (op == NULL_TREE)
850 error ("PHI argument is missing for edge %d->%d",
851 e->src->index,
852 e->dest->index);
853 err = true;
854 goto error;
857 if (TREE_CODE (op) != SSA_NAME && !is_gimple_min_invariant (op))
859 error ("PHI argument is not SSA_NAME, or invariant");
860 err = true;
863 if (TREE_CODE (op) == SSA_NAME)
865 err = verify_ssa_name (op, virtual_operand_p (gimple_phi_result (phi)));
866 err |= verify_use (e->src, definition_block[SSA_NAME_VERSION (op)],
867 op_p, phi, e->flags & EDGE_ABNORMAL, NULL);
870 if (TREE_CODE (op) == ADDR_EXPR)
872 tree base = TREE_OPERAND (op, 0);
873 while (handled_component_p (base))
874 base = TREE_OPERAND (base, 0);
875 if ((TREE_CODE (base) == VAR_DECL
876 || TREE_CODE (base) == PARM_DECL
877 || TREE_CODE (base) == RESULT_DECL)
878 && !TREE_ADDRESSABLE (base))
880 error ("address taken, but ADDRESSABLE bit not set");
881 err = true;
885 if (e->dest != bb)
887 error ("wrong edge %d->%d for PHI argument",
888 e->src->index, e->dest->index);
889 err = true;
892 if (err)
894 fprintf (stderr, "PHI argument\n");
895 print_generic_stmt (stderr, op, TDF_VOPS);
896 goto error;
900 error:
901 if (err)
903 fprintf (stderr, "for PHI node\n");
904 print_gimple_stmt (stderr, phi, 0, TDF_VOPS|TDF_MEMSYMS);
908 return err;
912 /* Verify common invariants in the SSA web.
913 TODO: verify the variable annotations. */
915 DEBUG_FUNCTION void
916 verify_ssa (bool check_modified_stmt)
918 size_t i;
919 basic_block bb;
920 basic_block *definition_block = XCNEWVEC (basic_block, num_ssa_names);
921 ssa_op_iter iter;
922 tree op;
923 enum dom_state orig_dom_state = dom_info_state (CDI_DOMINATORS);
924 bitmap names_defined_in_bb = BITMAP_ALLOC (NULL);
926 gcc_assert (!need_ssa_update_p (cfun));
928 timevar_push (TV_TREE_SSA_VERIFY);
930 /* Keep track of SSA names present in the IL. */
931 for (i = 1; i < num_ssa_names; i++)
933 tree name = ssa_name (i);
934 if (name)
936 gimple stmt;
937 TREE_VISITED (name) = 0;
939 verify_ssa_name (name, virtual_operand_p (name));
941 stmt = SSA_NAME_DEF_STMT (name);
942 if (!gimple_nop_p (stmt))
944 basic_block bb = gimple_bb (stmt);
945 verify_def (bb, definition_block,
946 name, stmt, virtual_operand_p (name));
952 calculate_dominance_info (CDI_DOMINATORS);
954 /* Now verify all the uses and make sure they agree with the definitions
955 found in the previous pass. */
956 FOR_EACH_BB (bb)
958 edge e;
959 gimple phi;
960 edge_iterator ei;
961 gimple_stmt_iterator gsi;
963 /* Make sure that all edges have a clear 'aux' field. */
964 FOR_EACH_EDGE (e, ei, bb->preds)
966 if (e->aux)
968 error ("AUX pointer initialized for edge %d->%d", e->src->index,
969 e->dest->index);
970 goto err;
974 /* Verify the arguments for every PHI node in the block. */
975 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
977 phi = gsi_stmt (gsi);
978 if (verify_phi_args (phi, bb, definition_block))
979 goto err;
981 bitmap_set_bit (names_defined_in_bb,
982 SSA_NAME_VERSION (gimple_phi_result (phi)));
985 /* Now verify all the uses and vuses in every statement of the block. */
986 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
988 gimple stmt = gsi_stmt (gsi);
989 use_operand_p use_p;
991 if (check_modified_stmt && gimple_modified_p (stmt))
993 error ("stmt (%p) marked modified after optimization pass: ",
994 (void *)stmt);
995 print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
996 goto err;
999 if (verify_ssa_operands (stmt))
1001 print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
1002 goto err;
1005 if (gimple_debug_bind_p (stmt)
1006 && !gimple_debug_bind_has_value_p (stmt))
1007 continue;
1009 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
1011 op = USE_FROM_PTR (use_p);
1012 if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)],
1013 use_p, stmt, false, names_defined_in_bb))
1014 goto err;
1017 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_DEFS)
1019 if (SSA_NAME_DEF_STMT (op) != stmt)
1021 error ("SSA_NAME_DEF_STMT is wrong");
1022 fprintf (stderr, "Expected definition statement:\n");
1023 print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
1024 fprintf (stderr, "\nActual definition statement:\n");
1025 print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (op),
1026 4, TDF_VOPS);
1027 goto err;
1029 bitmap_set_bit (names_defined_in_bb, SSA_NAME_VERSION (op));
1033 bitmap_clear (names_defined_in_bb);
1036 free (definition_block);
1038 /* Restore the dominance information to its prior known state, so
1039 that we do not perturb the compiler's subsequent behavior. */
1040 if (orig_dom_state == DOM_NONE)
1041 free_dominance_info (CDI_DOMINATORS);
1042 else
1043 set_dom_info_availability (CDI_DOMINATORS, orig_dom_state);
1045 BITMAP_FREE (names_defined_in_bb);
1046 timevar_pop (TV_TREE_SSA_VERIFY);
1047 return;
1049 err:
1050 internal_error ("verify_ssa failed");
1053 /* Return true if the uid in both int tree maps are equal. */
1056 int_tree_map_eq (const void *va, const void *vb)
1058 const struct int_tree_map *a = (const struct int_tree_map *) va;
1059 const struct int_tree_map *b = (const struct int_tree_map *) vb;
1060 return (a->uid == b->uid);
1063 /* Hash a UID in a int_tree_map. */
1065 unsigned int
1066 int_tree_map_hash (const void *item)
1068 return ((const struct int_tree_map *)item)->uid;
1071 /* Return true if the DECL_UID in both trees are equal. */
1074 uid_decl_map_eq (const void *va, const void *vb)
1076 const_tree a = (const_tree) va;
1077 const_tree b = (const_tree) vb;
1078 return (a->decl_minimal.uid == b->decl_minimal.uid);
1081 /* Hash a tree in a uid_decl_map. */
1083 unsigned int
1084 uid_decl_map_hash (const void *item)
1086 return ((const_tree)item)->decl_minimal.uid;
1089 /* Return true if the DECL_UID in both trees are equal. */
1091 static int
1092 uid_ssaname_map_eq (const void *va, const void *vb)
1094 const_tree a = (const_tree) va;
1095 const_tree b = (const_tree) vb;
1096 return (a->ssa_name.var->decl_minimal.uid == b->ssa_name.var->decl_minimal.uid);
1099 /* Hash a tree in a uid_decl_map. */
1101 static unsigned int
1102 uid_ssaname_map_hash (const void *item)
1104 return ((const_tree)item)->ssa_name.var->decl_minimal.uid;
1108 /* Initialize global DFA and SSA structures. */
1110 void
1111 init_tree_ssa (struct function *fn)
1113 fn->gimple_df = ggc_alloc_cleared_gimple_df ();
1114 fn->gimple_df->default_defs = htab_create_ggc (20, uid_ssaname_map_hash,
1115 uid_ssaname_map_eq, NULL);
1116 pt_solution_reset (&fn->gimple_df->escaped);
1117 init_ssanames (fn, 0);
1120 /* Do the actions required to initialize internal data structures used
1121 in tree-ssa optimization passes. */
1123 static unsigned int
1124 execute_init_datastructures (void)
1126 /* Allocate hash tables, arrays and other structures. */
1127 init_tree_ssa (cfun);
1128 return 0;
1131 struct gimple_opt_pass pass_init_datastructures =
1134 GIMPLE_PASS,
1135 "*init_datastructures", /* name */
1136 OPTGROUP_NONE, /* optinfo_flags */
1137 NULL, /* gate */
1138 execute_init_datastructures, /* execute */
1139 NULL, /* sub */
1140 NULL, /* next */
1141 0, /* static_pass_number */
1142 TV_NONE, /* tv_id */
1143 PROP_cfg, /* properties_required */
1144 0, /* properties_provided */
1145 0, /* properties_destroyed */
1146 0, /* todo_flags_start */
1147 0 /* todo_flags_finish */
1151 /* Deallocate memory associated with SSA data structures for FNDECL. */
1153 void
1154 delete_tree_ssa (void)
1156 fini_ssanames ();
1158 /* We no longer maintain the SSA operand cache at this point. */
1159 if (ssa_operands_active (cfun))
1160 fini_ssa_operands ();
1162 htab_delete (cfun->gimple_df->default_defs);
1163 cfun->gimple_df->default_defs = NULL;
1164 pt_solution_reset (&cfun->gimple_df->escaped);
1165 if (cfun->gimple_df->decls_to_pointers != NULL)
1166 pointer_map_destroy (cfun->gimple_df->decls_to_pointers);
1167 cfun->gimple_df->decls_to_pointers = NULL;
1168 cfun->gimple_df->modified_noreturn_calls = NULL;
1169 cfun->gimple_df = NULL;
1171 /* We no longer need the edge variable maps. */
1172 redirect_edge_var_map_destroy ();
1175 /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
1176 useless type conversion, otherwise return false.
1178 This function implicitly defines the middle-end type system. With
1179 the notion of 'a < b' meaning that useless_type_conversion_p (a, b)
1180 holds and 'a > b' meaning that useless_type_conversion_p (b, a) holds,
1181 the following invariants shall be fulfilled:
1183 1) useless_type_conversion_p is transitive.
1184 If a < b and b < c then a < c.
1186 2) useless_type_conversion_p is not symmetric.
1187 From a < b does not follow a > b.
1189 3) Types define the available set of operations applicable to values.
1190 A type conversion is useless if the operations for the target type
1191 is a subset of the operations for the source type. For example
1192 casts to void* are useless, casts from void* are not (void* can't
1193 be dereferenced or offsetted, but copied, hence its set of operations
1194 is a strict subset of that of all other data pointer types). Casts
1195 to const T* are useless (can't be written to), casts from const T*
1196 to T* are not. */
1198 bool
1199 useless_type_conversion_p (tree outer_type, tree inner_type)
1201 /* Do the following before stripping toplevel qualifiers. */
1202 if (POINTER_TYPE_P (inner_type)
1203 && POINTER_TYPE_P (outer_type))
1205 int i_shared = upc_shared_type_p (TREE_TYPE (inner_type));
1206 int o_shared = upc_shared_type_p (TREE_TYPE (outer_type));
1208 /* Retain conversions from a UPC shared pointer to
1209 a regular C pointer. */
1210 if (!o_shared && i_shared)
1211 return false;
1213 /* Retain conversions between incompatible UPC shared pointers. */
1214 if (o_shared && i_shared
1215 && !lang_hooks.types_compatible_p (inner_type, outer_type))
1216 return false;
1218 /* Do not lose casts between pointers to different address spaces. */
1219 if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
1220 != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
1221 return false;
1224 /* From now on qualifiers on value types do not matter. */
1225 inner_type = TYPE_MAIN_VARIANT (inner_type);
1226 outer_type = TYPE_MAIN_VARIANT (outer_type);
1228 if (inner_type == outer_type)
1229 return true;
1231 /* If we know the canonical types, compare them. */
1232 if (TYPE_CANONICAL (inner_type)
1233 && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type))
1234 return true;
1236 /* Changes in machine mode are never useless conversions unless we
1237 deal with aggregate types in which case we defer to later checks. */
1238 if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type)
1239 && !AGGREGATE_TYPE_P (inner_type))
1240 return false;
1242 /* If both the inner and outer types are integral types, then the
1243 conversion is not necessary if they have the same mode and
1244 signedness and precision, and both or neither are boolean. */
1245 if (INTEGRAL_TYPE_P (inner_type)
1246 && INTEGRAL_TYPE_P (outer_type))
1248 /* Preserve changes in signedness or precision. */
1249 if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
1250 || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
1251 return false;
1253 /* Preserve conversions to/from BOOLEAN_TYPE if types are not
1254 of precision one. */
1255 if (((TREE_CODE (inner_type) == BOOLEAN_TYPE)
1256 != (TREE_CODE (outer_type) == BOOLEAN_TYPE))
1257 && TYPE_PRECISION (outer_type) != 1)
1258 return false;
1260 /* We don't need to preserve changes in the types minimum or
1261 maximum value in general as these do not generate code
1262 unless the types precisions are different. */
1263 return true;
1266 /* Scalar floating point types with the same mode are compatible. */
1267 else if (SCALAR_FLOAT_TYPE_P (inner_type)
1268 && SCALAR_FLOAT_TYPE_P (outer_type))
1269 return true;
1271 /* Fixed point types with the same mode are compatible. */
1272 else if (FIXED_POINT_TYPE_P (inner_type)
1273 && FIXED_POINT_TYPE_P (outer_type))
1274 return true;
1276 /* We need to take special care recursing to pointed-to types. */
1277 else if (POINTER_TYPE_P (inner_type)
1278 && POINTER_TYPE_P (outer_type))
1280 /* Do not lose casts to function pointer types. */
1281 if ((TREE_CODE (TREE_TYPE (outer_type)) == FUNCTION_TYPE
1282 || TREE_CODE (TREE_TYPE (outer_type)) == METHOD_TYPE)
1283 && !(TREE_CODE (TREE_TYPE (inner_type)) == FUNCTION_TYPE
1284 || TREE_CODE (TREE_TYPE (inner_type)) == METHOD_TYPE))
1285 return false;
1287 /* We do not care for const qualification of the pointed-to types
1288 as const qualification has no semantic value to the middle-end. */
1290 /* Otherwise pointers/references are equivalent. */
1291 return true;
1294 /* Recurse for complex types. */
1295 else if (TREE_CODE (inner_type) == COMPLEX_TYPE
1296 && TREE_CODE (outer_type) == COMPLEX_TYPE)
1297 return useless_type_conversion_p (TREE_TYPE (outer_type),
1298 TREE_TYPE (inner_type));
1300 /* Recurse for vector types with the same number of subparts. */
1301 else if (TREE_CODE (inner_type) == VECTOR_TYPE
1302 && TREE_CODE (outer_type) == VECTOR_TYPE
1303 && TYPE_PRECISION (inner_type) == TYPE_PRECISION (outer_type))
1304 return useless_type_conversion_p (TREE_TYPE (outer_type),
1305 TREE_TYPE (inner_type));
1307 else if (TREE_CODE (inner_type) == ARRAY_TYPE
1308 && TREE_CODE (outer_type) == ARRAY_TYPE)
1310 /* Preserve string attributes. */
1311 if (TYPE_STRING_FLAG (inner_type) != TYPE_STRING_FLAG (outer_type))
1312 return false;
1314 /* Conversions from array types with unknown extent to
1315 array types with known extent are not useless. */
1316 if (!TYPE_DOMAIN (inner_type)
1317 && TYPE_DOMAIN (outer_type))
1318 return false;
1320 /* Nor are conversions from array types with non-constant size to
1321 array types with constant size or to different size. */
1322 if (TYPE_SIZE (outer_type)
1323 && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST
1324 && (!TYPE_SIZE (inner_type)
1325 || TREE_CODE (TYPE_SIZE (inner_type)) != INTEGER_CST
1326 || !tree_int_cst_equal (TYPE_SIZE (outer_type),
1327 TYPE_SIZE (inner_type))))
1328 return false;
1330 /* Check conversions between arrays with partially known extents.
1331 If the array min/max values are constant they have to match.
1332 Otherwise allow conversions to unknown and variable extents.
1333 In particular this declares conversions that may change the
1334 mode to BLKmode as useless. */
1335 if (TYPE_DOMAIN (inner_type)
1336 && TYPE_DOMAIN (outer_type)
1337 && TYPE_DOMAIN (inner_type) != TYPE_DOMAIN (outer_type))
1339 tree inner_min = TYPE_MIN_VALUE (TYPE_DOMAIN (inner_type));
1340 tree outer_min = TYPE_MIN_VALUE (TYPE_DOMAIN (outer_type));
1341 tree inner_max = TYPE_MAX_VALUE (TYPE_DOMAIN (inner_type));
1342 tree outer_max = TYPE_MAX_VALUE (TYPE_DOMAIN (outer_type));
1344 /* After gimplification a variable min/max value carries no
1345 additional information compared to a NULL value. All that
1346 matters has been lowered to be part of the IL. */
1347 if (inner_min && TREE_CODE (inner_min) != INTEGER_CST)
1348 inner_min = NULL_TREE;
1349 if (outer_min && TREE_CODE (outer_min) != INTEGER_CST)
1350 outer_min = NULL_TREE;
1351 if (inner_max && TREE_CODE (inner_max) != INTEGER_CST)
1352 inner_max = NULL_TREE;
1353 if (outer_max && TREE_CODE (outer_max) != INTEGER_CST)
1354 outer_max = NULL_TREE;
1356 /* Conversions NULL / variable <- cst are useless, but not
1357 the other way around. */
1358 if (outer_min
1359 && (!inner_min
1360 || !tree_int_cst_equal (inner_min, outer_min)))
1361 return false;
1362 if (outer_max
1363 && (!inner_max
1364 || !tree_int_cst_equal (inner_max, outer_max)))
1365 return false;
1368 /* Recurse on the element check. */
1369 return useless_type_conversion_p (TREE_TYPE (outer_type),
1370 TREE_TYPE (inner_type));
1373 else if ((TREE_CODE (inner_type) == FUNCTION_TYPE
1374 || TREE_CODE (inner_type) == METHOD_TYPE)
1375 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
1377 tree outer_parm, inner_parm;
1379 /* If the return types are not compatible bail out. */
1380 if (!useless_type_conversion_p (TREE_TYPE (outer_type),
1381 TREE_TYPE (inner_type)))
1382 return false;
1384 /* Method types should belong to a compatible base class. */
1385 if (TREE_CODE (inner_type) == METHOD_TYPE
1386 && !useless_type_conversion_p (TYPE_METHOD_BASETYPE (outer_type),
1387 TYPE_METHOD_BASETYPE (inner_type)))
1388 return false;
1390 /* A conversion to an unprototyped argument list is ok. */
1391 if (!prototype_p (outer_type))
1392 return true;
1394 /* If the unqualified argument types are compatible the conversion
1395 is useless. */
1396 if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type))
1397 return true;
1399 for (outer_parm = TYPE_ARG_TYPES (outer_type),
1400 inner_parm = TYPE_ARG_TYPES (inner_type);
1401 outer_parm && inner_parm;
1402 outer_parm = TREE_CHAIN (outer_parm),
1403 inner_parm = TREE_CHAIN (inner_parm))
1404 if (!useless_type_conversion_p
1405 (TYPE_MAIN_VARIANT (TREE_VALUE (outer_parm)),
1406 TYPE_MAIN_VARIANT (TREE_VALUE (inner_parm))))
1407 return false;
1409 /* If there is a mismatch in the number of arguments the functions
1410 are not compatible. */
1411 if (outer_parm || inner_parm)
1412 return false;
1414 /* Defer to the target if necessary. */
1415 if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
1416 return comp_type_attributes (outer_type, inner_type) != 0;
1418 return true;
1421 /* For aggregates we rely on TYPE_CANONICAL exclusively and require
1422 explicit conversions for types involving to be structurally
1423 compared types. */
1424 else if (AGGREGATE_TYPE_P (inner_type)
1425 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
1426 return false;
1428 return false;
1431 /* Return true if a conversion from either type of TYPE1 and TYPE2
1432 to the other is not required. Otherwise return false. */
1434 bool
1435 types_compatible_p (tree type1, tree type2)
1437 return (type1 == type2
1438 || (useless_type_conversion_p (type1, type2)
1439 && useless_type_conversion_p (type2, type1)));
1442 /* Return true if EXPR is a useless type conversion, otherwise return
1443 false. */
1445 bool
1446 tree_ssa_useless_type_conversion (tree expr)
1448 /* If we have an assignment that merely uses a NOP_EXPR to change
1449 the top of the RHS to the type of the LHS and the type conversion
1450 is "safe", then strip away the type conversion so that we can
1451 enter LHS = RHS into the const_and_copies table. */
1452 if (CONVERT_EXPR_P (expr)
1453 || TREE_CODE (expr) == VIEW_CONVERT_EXPR
1454 || TREE_CODE (expr) == NON_LVALUE_EXPR)
1455 return useless_type_conversion_p
1456 (TREE_TYPE (expr),
1457 TREE_TYPE (TREE_OPERAND (expr, 0)));
1459 return false;
1462 /* Strip conversions from EXP according to
1463 tree_ssa_useless_type_conversion and return the resulting
1464 expression. */
1466 tree
1467 tree_ssa_strip_useless_type_conversions (tree exp)
1469 while (tree_ssa_useless_type_conversion (exp))
1470 exp = TREE_OPERAND (exp, 0);
1471 return exp;
1475 /* Internal helper for walk_use_def_chains. VAR, FN and DATA are as
1476 described in walk_use_def_chains.
1478 VISITED is a pointer set used to mark visited SSA_NAMEs to avoid
1479 infinite loops. We used to have a bitmap for this to just mark
1480 SSA versions we had visited. But non-sparse bitmaps are way too
1481 expensive, while sparse bitmaps may cause quadratic behavior.
1483 IS_DFS is true if the caller wants to perform a depth-first search
1484 when visiting PHI nodes. A DFS will visit each PHI argument and
1485 call FN after each one. Otherwise, all the arguments are
1486 visited first and then FN is called with each of the visited
1487 arguments in a separate pass. */
1489 static bool
1490 walk_use_def_chains_1 (tree var, walk_use_def_chains_fn fn, void *data,
1491 struct pointer_set_t *visited, bool is_dfs)
1493 gimple def_stmt;
1495 if (pointer_set_insert (visited, var))
1496 return false;
1498 def_stmt = SSA_NAME_DEF_STMT (var);
1500 if (gimple_code (def_stmt) != GIMPLE_PHI)
1502 /* If we reached the end of the use-def chain, call FN. */
1503 return fn (var, def_stmt, data);
1505 else
1507 size_t i;
1509 /* When doing a breadth-first search, call FN before following the
1510 use-def links for each argument. */
1511 if (!is_dfs)
1512 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1513 if (fn (gimple_phi_arg_def (def_stmt, i), def_stmt, data))
1514 return true;
1516 /* Follow use-def links out of each PHI argument. */
1517 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1519 tree arg = gimple_phi_arg_def (def_stmt, i);
1521 /* ARG may be NULL for newly introduced PHI nodes. */
1522 if (arg
1523 && TREE_CODE (arg) == SSA_NAME
1524 && walk_use_def_chains_1 (arg, fn, data, visited, is_dfs))
1525 return true;
1528 /* When doing a depth-first search, call FN after following the
1529 use-def links for each argument. */
1530 if (is_dfs)
1531 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1532 if (fn (gimple_phi_arg_def (def_stmt, i), def_stmt, data))
1533 return true;
1536 return false;
1541 /* Walk use-def chains starting at the SSA variable VAR. Call
1542 function FN at each reaching definition found. FN takes three
1543 arguments: VAR, its defining statement (DEF_STMT) and a generic
1544 pointer to whatever state information that FN may want to maintain
1545 (DATA). FN is able to stop the walk by returning true, otherwise
1546 in order to continue the walk, FN should return false.
1548 Note, that if DEF_STMT is a PHI node, the semantics are slightly
1549 different. The first argument to FN is no longer the original
1550 variable VAR, but the PHI argument currently being examined. If FN
1551 wants to get at VAR, it should call PHI_RESULT (PHI).
1553 If IS_DFS is true, this function will:
1555 1- walk the use-def chains for all the PHI arguments, and,
1556 2- call (*FN) (ARG, PHI, DATA) on all the PHI arguments.
1558 If IS_DFS is false, the two steps above are done in reverse order
1559 (i.e., a breadth-first search). */
1561 void
1562 walk_use_def_chains (tree var, walk_use_def_chains_fn fn, void *data,
1563 bool is_dfs)
1565 gimple def_stmt;
1567 gcc_assert (TREE_CODE (var) == SSA_NAME);
1569 def_stmt = SSA_NAME_DEF_STMT (var);
1571 /* We only need to recurse if the reaching definition comes from a PHI
1572 node. */
1573 if (gimple_code (def_stmt) != GIMPLE_PHI)
1574 (*fn) (var, def_stmt, data);
1575 else
1577 struct pointer_set_t *visited = pointer_set_create ();
1578 walk_use_def_chains_1 (var, fn, data, visited, is_dfs);
1579 pointer_set_destroy (visited);
1584 /* Emit warnings for uninitialized variables. This is done in two passes.
1586 The first pass notices real uses of SSA names with undefined values.
1587 Such uses are unconditionally uninitialized, and we can be certain that
1588 such a use is a mistake. This pass is run before most optimizations,
1589 so that we catch as many as we can.
1591 The second pass follows PHI nodes to find uses that are potentially
1592 uninitialized. In this case we can't necessarily prove that the use
1593 is really uninitialized. This pass is run after most optimizations,
1594 so that we thread as many jumps and possible, and delete as much dead
1595 code as possible, in order to reduce false positives. We also look
1596 again for plain uninitialized variables, since optimization may have
1597 changed conditionally uninitialized to unconditionally uninitialized. */
1599 /* Emit a warning for EXPR based on variable VAR at the point in the
1600 program T, an SSA_NAME, is used being uninitialized. The exact
1601 warning text is in MSGID and LOCUS may contain a location or be null.
1602 WC is the warning code. */
1604 void
1605 warn_uninit (enum opt_code wc, tree t,
1606 tree expr, tree var, const char *gmsgid, void *data)
1608 gimple context = (gimple) data;
1609 location_t location, cfun_loc;
1610 expanded_location xloc, floc;
1612 if (!ssa_undefined_value_p (t))
1613 return;
1615 /* TREE_NO_WARNING either means we already warned, or the front end
1616 wishes to suppress the warning. */
1617 if ((context
1618 && (gimple_no_warning_p (context)
1619 || (gimple_assign_single_p (context)
1620 && TREE_NO_WARNING (gimple_assign_rhs1 (context)))))
1621 || TREE_NO_WARNING (expr))
1622 return;
1624 location = (context != NULL && gimple_has_location (context))
1625 ? gimple_location (context)
1626 : DECL_SOURCE_LOCATION (var);
1627 location = linemap_resolve_location (line_table, location,
1628 LRK_SPELLING_LOCATION,
1629 NULL);
1630 cfun_loc = DECL_SOURCE_LOCATION (cfun->decl);
1631 xloc = expand_location (location);
1632 floc = expand_location (cfun_loc);
1633 if (warning_at (location, wc, gmsgid, expr))
1635 TREE_NO_WARNING (expr) = 1;
1637 if (location == DECL_SOURCE_LOCATION (var))
1638 return;
1639 if (xloc.file != floc.file
1640 || linemap_location_before_p (line_table,
1641 location, cfun_loc)
1642 || linemap_location_before_p (line_table,
1643 cfun->function_end_locus,
1644 location))
1645 inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var);
1649 unsigned int
1650 warn_uninitialized_vars (bool warn_possibly_uninitialized)
1652 gimple_stmt_iterator gsi;
1653 basic_block bb;
1655 FOR_EACH_BB (bb)
1657 bool always_executed = dominated_by_p (CDI_POST_DOMINATORS,
1658 single_succ (ENTRY_BLOCK_PTR), bb);
1659 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1661 gimple stmt = gsi_stmt (gsi);
1662 use_operand_p use_p;
1663 ssa_op_iter op_iter;
1664 tree use;
1666 if (is_gimple_debug (stmt))
1667 continue;
1669 /* We only do data flow with SSA_NAMEs, so that's all we
1670 can warn about. */
1671 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, op_iter, SSA_OP_USE)
1673 use = USE_FROM_PTR (use_p);
1674 if (always_executed)
1675 warn_uninit (OPT_Wuninitialized, use,
1676 SSA_NAME_VAR (use), SSA_NAME_VAR (use),
1677 "%qD is used uninitialized in this function",
1678 stmt);
1679 else if (warn_possibly_uninitialized)
1680 warn_uninit (OPT_Wuninitialized, use,
1681 SSA_NAME_VAR (use), SSA_NAME_VAR (use),
1682 "%qD may be used uninitialized in this function",
1683 stmt);
1686 /* For memory the only cheap thing we can do is see if we
1687 have a use of the default def of the virtual operand.
1688 ??? Note that at -O0 we do not have virtual operands.
1689 ??? Not so cheap would be to use the alias oracle via
1690 walk_aliased_vdefs, if we don't find any aliasing vdef
1691 warn as is-used-uninitialized, if we don't find an aliasing
1692 vdef that kills our use (stmt_kills_ref_p), warn as
1693 may-be-used-uninitialized. But this walk is quadratic and
1694 so must be limited which means we would miss warning
1695 opportunities. */
1696 use = gimple_vuse (stmt);
1697 if (use
1698 && gimple_assign_single_p (stmt)
1699 && !gimple_vdef (stmt)
1700 && SSA_NAME_IS_DEFAULT_DEF (use))
1702 tree rhs = gimple_assign_rhs1 (stmt);
1703 tree base = get_base_address (rhs);
1705 /* Do not warn if it can be initialized outside this function. */
1706 if (TREE_CODE (base) != VAR_DECL
1707 || DECL_HARD_REGISTER (base)
1708 || is_global_var (base))
1709 continue;
1711 if (always_executed)
1712 warn_uninit (OPT_Wuninitialized, use, gimple_assign_rhs1 (stmt),
1713 base,
1714 "%qE is used uninitialized in this function",
1715 stmt);
1716 else if (warn_possibly_uninitialized)
1717 warn_uninit (OPT_Wuninitialized, use, gimple_assign_rhs1 (stmt),
1718 base,
1719 "%qE may be used uninitialized in this function",
1720 stmt);
1725 return 0;
1728 static unsigned int
1729 execute_early_warn_uninitialized (void)
1731 /* Currently, this pass runs always but
1732 execute_late_warn_uninitialized only runs with optimization. With
1733 optimization we want to warn about possible uninitialized as late
1734 as possible, thus don't do it here. However, without
1735 optimization we need to warn here about "may be uninitialized".
1737 calculate_dominance_info (CDI_POST_DOMINATORS);
1739 warn_uninitialized_vars (/*warn_possibly_uninitialized=*/!optimize);
1741 /* Post-dominator information can not be reliably updated. Free it
1742 after the use. */
1744 free_dominance_info (CDI_POST_DOMINATORS);
1745 return 0;
1748 static bool
1749 gate_warn_uninitialized (void)
1751 return warn_uninitialized != 0;
1754 struct gimple_opt_pass pass_early_warn_uninitialized =
1757 GIMPLE_PASS,
1758 "*early_warn_uninitialized", /* name */
1759 OPTGROUP_NONE, /* optinfo_flags */
1760 gate_warn_uninitialized, /* gate */
1761 execute_early_warn_uninitialized, /* execute */
1762 NULL, /* sub */
1763 NULL, /* next */
1764 0, /* static_pass_number */
1765 TV_TREE_UNINIT, /* tv_id */
1766 PROP_ssa, /* properties_required */
1767 0, /* properties_provided */
1768 0, /* properties_destroyed */
1769 0, /* todo_flags_start */
1770 0 /* todo_flags_finish */
1775 /* If necessary, rewrite the base of the reference tree *TP from
1776 a MEM_REF to a plain or converted symbol. */
1778 static void
1779 maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
1781 tree sym;
1783 while (handled_component_p (*tp))
1784 tp = &TREE_OPERAND (*tp, 0);
1785 if (TREE_CODE (*tp) == MEM_REF
1786 && TREE_CODE (TREE_OPERAND (*tp, 0)) == ADDR_EXPR
1787 && (sym = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0))
1788 && DECL_P (sym)
1789 && !TREE_ADDRESSABLE (sym)
1790 && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
1792 if (TREE_CODE (TREE_TYPE (sym)) == VECTOR_TYPE
1793 && useless_type_conversion_p (TREE_TYPE (*tp),
1794 TREE_TYPE (TREE_TYPE (sym)))
1795 && multiple_of_p (sizetype, TREE_OPERAND (*tp, 1),
1796 TYPE_SIZE_UNIT (TREE_TYPE (*tp))))
1798 *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
1799 TYPE_SIZE (TREE_TYPE (*tp)),
1800 int_const_binop (MULT_EXPR,
1801 bitsize_int (BITS_PER_UNIT),
1802 TREE_OPERAND (*tp, 1)));
1804 else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
1805 && useless_type_conversion_p (TREE_TYPE (*tp),
1806 TREE_TYPE (TREE_TYPE (sym))))
1808 *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
1809 ? REALPART_EXPR : IMAGPART_EXPR,
1810 TREE_TYPE (*tp), sym);
1812 else if (integer_zerop (TREE_OPERAND (*tp, 1)))
1814 if (!useless_type_conversion_p (TREE_TYPE (*tp),
1815 TREE_TYPE (sym)))
1816 *tp = build1 (VIEW_CONVERT_EXPR,
1817 TREE_TYPE (*tp), sym);
1818 else
1819 *tp = sym;
1824 /* For a tree REF return its base if it is the base of a MEM_REF
1825 that cannot be rewritten into SSA form. Otherwise return NULL_TREE. */
1827 static tree
1828 non_rewritable_mem_ref_base (tree ref)
1830 tree base = ref;
1832 /* A plain decl does not need it set. */
1833 if (DECL_P (ref))
1834 return NULL_TREE;
1836 while (handled_component_p (base))
1837 base = TREE_OPERAND (base, 0);
1839 /* But watch out for MEM_REFs we cannot lower to a
1840 VIEW_CONVERT_EXPR or a BIT_FIELD_REF. */
1841 if (TREE_CODE (base) == MEM_REF
1842 && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
1844 tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
1845 if ((TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
1846 || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
1847 && useless_type_conversion_p (TREE_TYPE (base),
1848 TREE_TYPE (TREE_TYPE (decl)))
1849 && mem_ref_offset (base).fits_uhwi ()
1850 && tree_to_double_int (TYPE_SIZE_UNIT (TREE_TYPE (decl)))
1851 .ugt (mem_ref_offset (base))
1852 && multiple_of_p (sizetype, TREE_OPERAND (base, 1),
1853 TYPE_SIZE_UNIT (TREE_TYPE (base))))
1854 return NULL_TREE;
1855 if (DECL_P (decl)
1856 && (!integer_zerop (TREE_OPERAND (base, 1))
1857 || (DECL_SIZE (decl)
1858 != TYPE_SIZE (TREE_TYPE (base)))
1859 || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base)))
1860 return decl;
1863 return NULL_TREE;
1866 /* For an lvalue tree LHS return true if it cannot be rewritten into SSA form.
1867 Otherwise return true. */
1869 static bool
1870 non_rewritable_lvalue_p (tree lhs)
1872 /* A plain decl is always rewritable. */
1873 if (DECL_P (lhs))
1874 return false;
1876 /* A decl that is wrapped inside a MEM-REF that covers
1877 it full is also rewritable.
1878 ??? The following could be relaxed allowing component
1879 references that do not change the access size. */
1880 if (TREE_CODE (lhs) == MEM_REF
1881 && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
1882 && integer_zerop (TREE_OPERAND (lhs, 1)))
1884 tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
1885 if (DECL_P (decl)
1886 && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
1887 && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
1888 return false;
1891 return true;
1894 /* When possible, clear TREE_ADDRESSABLE bit or set DECL_GIMPLE_REG_P bit and
1895 mark the variable VAR for conversion into SSA. Return true when updating
1896 stmts is required. */
1898 static void
1899 maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
1900 bitmap suitable_for_renaming)
1902 /* Global Variables, result decls cannot be changed. */
1903 if (is_global_var (var)
1904 || TREE_CODE (var) == RESULT_DECL
1905 || bitmap_bit_p (addresses_taken, DECL_UID (var)))
1906 return;
1908 if (TREE_ADDRESSABLE (var)
1909 /* Do not change TREE_ADDRESSABLE if we need to preserve var as
1910 a non-register. Otherwise we are confused and forget to
1911 add virtual operands for it. */
1912 && (!is_gimple_reg_type (TREE_TYPE (var))
1913 || TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE
1914 || TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE
1915 || !bitmap_bit_p (not_reg_needs, DECL_UID (var))))
1917 TREE_ADDRESSABLE (var) = 0;
1918 if (is_gimple_reg (var))
1919 bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
1920 if (dump_file)
1922 fprintf (dump_file, "No longer having address taken: ");
1923 print_generic_expr (dump_file, var, 0);
1924 fprintf (dump_file, "\n");
1928 if (!DECL_GIMPLE_REG_P (var)
1929 && !bitmap_bit_p (not_reg_needs, DECL_UID (var))
1930 && (TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE
1931 || TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE)
1932 && !TREE_THIS_VOLATILE (var)
1933 && (TREE_CODE (var) != VAR_DECL || !DECL_HARD_REGISTER (var)))
1935 DECL_GIMPLE_REG_P (var) = 1;
1936 bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
1937 if (dump_file)
1939 fprintf (dump_file, "Now a gimple register: ");
1940 print_generic_expr (dump_file, var, 0);
1941 fprintf (dump_file, "\n");
1946 /* Compute TREE_ADDRESSABLE and DECL_GIMPLE_REG_P for local variables. */
1948 void
1949 execute_update_addresses_taken (void)
1951 gimple_stmt_iterator gsi;
1952 basic_block bb;
1953 bitmap addresses_taken = BITMAP_ALLOC (NULL);
1954 bitmap not_reg_needs = BITMAP_ALLOC (NULL);
1955 bitmap suitable_for_renaming = BITMAP_ALLOC (NULL);
1956 tree var;
1957 unsigned i;
1959 timevar_push (TV_ADDRESS_TAKEN);
1961 /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
1962 the function body. */
1963 FOR_EACH_BB (bb)
1965 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1967 gimple stmt = gsi_stmt (gsi);
1968 enum gimple_code code = gimple_code (stmt);
1969 tree decl;
1971 /* Note all addresses taken by the stmt. */
1972 gimple_ior_addresses_taken (addresses_taken, stmt);
1974 /* If we have a call or an assignment, see if the lhs contains
1975 a local decl that requires not to be a gimple register. */
1976 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
1978 tree lhs = gimple_get_lhs (stmt);
1979 if (lhs
1980 && TREE_CODE (lhs) != SSA_NAME
1981 && non_rewritable_lvalue_p (lhs))
1983 decl = get_base_address (lhs);
1984 if (DECL_P (decl))
1985 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
1989 if (gimple_assign_single_p (stmt))
1991 tree rhs = gimple_assign_rhs1 (stmt);
1992 if ((decl = non_rewritable_mem_ref_base (rhs)))
1993 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
1996 else if (code == GIMPLE_CALL)
1998 for (i = 0; i < gimple_call_num_args (stmt); ++i)
2000 tree arg = gimple_call_arg (stmt, i);
2001 if ((decl = non_rewritable_mem_ref_base (arg)))
2002 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2006 else if (code == GIMPLE_ASM)
2008 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
2010 tree link = gimple_asm_output_op (stmt, i);
2011 tree lhs = TREE_VALUE (link);
2012 if (TREE_CODE (lhs) != SSA_NAME)
2014 decl = get_base_address (lhs);
2015 if (DECL_P (decl)
2016 && (non_rewritable_lvalue_p (lhs)
2017 /* We cannot move required conversions from
2018 the lhs to the rhs in asm statements, so
2019 require we do not need any. */
2020 || !useless_type_conversion_p
2021 (TREE_TYPE (lhs), TREE_TYPE (decl))))
2022 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2025 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
2027 tree link = gimple_asm_input_op (stmt, i);
2028 if ((decl = non_rewritable_mem_ref_base (TREE_VALUE (link))))
2029 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2034 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2036 size_t i;
2037 gimple phi = gsi_stmt (gsi);
2039 for (i = 0; i < gimple_phi_num_args (phi); i++)
2041 tree op = PHI_ARG_DEF (phi, i), var;
2042 if (TREE_CODE (op) == ADDR_EXPR
2043 && (var = get_base_address (TREE_OPERAND (op, 0))) != NULL
2044 && DECL_P (var))
2045 bitmap_set_bit (addresses_taken, DECL_UID (var));
2050 /* We cannot iterate over all referenced vars because that can contain
2051 unused vars from BLOCK trees, which causes code generation differences
2052 for -g vs. -g0. */
2053 for (var = DECL_ARGUMENTS (cfun->decl); var; var = DECL_CHAIN (var))
2054 maybe_optimize_var (var, addresses_taken, not_reg_needs,
2055 suitable_for_renaming);
2057 FOR_EACH_VEC_SAFE_ELT (cfun->local_decls, i, var)
2058 maybe_optimize_var (var, addresses_taken, not_reg_needs,
2059 suitable_for_renaming);
2061 /* Operand caches need to be recomputed for operands referencing the updated
2062 variables and operands need to be rewritten to expose bare symbols. */
2063 if (!bitmap_empty_p (suitable_for_renaming))
2065 FOR_EACH_BB (bb)
2066 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
2068 gimple stmt = gsi_stmt (gsi);
2070 /* Re-write TARGET_MEM_REFs of symbols we want to
2071 rewrite into SSA form. */
2072 if (gimple_assign_single_p (stmt))
2074 tree lhs = gimple_assign_lhs (stmt);
2075 tree rhs, *rhsp = gimple_assign_rhs1_ptr (stmt);
2076 tree sym;
2078 /* We shouldn't have any fancy wrapping of
2079 component-refs on the LHS, but look through
2080 VIEW_CONVERT_EXPRs as that is easy. */
2081 while (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
2082 lhs = TREE_OPERAND (lhs, 0);
2083 if (TREE_CODE (lhs) == MEM_REF
2084 && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
2085 && integer_zerop (TREE_OPERAND (lhs, 1))
2086 && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
2087 && DECL_P (sym)
2088 && !TREE_ADDRESSABLE (sym)
2089 && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
2090 lhs = sym;
2091 else
2092 lhs = gimple_assign_lhs (stmt);
2094 /* Rewrite the RHS and make sure the resulting assignment
2095 is validly typed. */
2096 maybe_rewrite_mem_ref_base (rhsp, suitable_for_renaming);
2097 rhs = gimple_assign_rhs1 (stmt);
2098 if (gimple_assign_lhs (stmt) != lhs
2099 && !useless_type_conversion_p (TREE_TYPE (lhs),
2100 TREE_TYPE (rhs)))
2101 rhs = fold_build1 (VIEW_CONVERT_EXPR,
2102 TREE_TYPE (lhs), rhs);
2104 if (gimple_assign_lhs (stmt) != lhs)
2105 gimple_assign_set_lhs (stmt, lhs);
2107 /* For var ={v} {CLOBBER}; where var lost
2108 TREE_ADDRESSABLE just remove the stmt. */
2109 if (DECL_P (lhs)
2110 && TREE_CLOBBER_P (rhs)
2111 && bitmap_bit_p (suitable_for_renaming, DECL_UID (lhs)))
2113 unlink_stmt_vdef (stmt);
2114 gsi_remove (&gsi, true);
2115 release_defs (stmt);
2116 continue;
2119 if (gimple_assign_rhs1 (stmt) != rhs)
2121 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
2122 gimple_assign_set_rhs_from_tree (&gsi, rhs);
2126 else if (gimple_code (stmt) == GIMPLE_CALL)
2128 unsigned i;
2129 for (i = 0; i < gimple_call_num_args (stmt); ++i)
2131 tree *argp = gimple_call_arg_ptr (stmt, i);
2132 maybe_rewrite_mem_ref_base (argp, suitable_for_renaming);
2136 else if (gimple_code (stmt) == GIMPLE_ASM)
2138 unsigned i;
2139 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
2141 tree link = gimple_asm_output_op (stmt, i);
2142 maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
2143 suitable_for_renaming);
2145 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
2147 tree link = gimple_asm_input_op (stmt, i);
2148 maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
2149 suitable_for_renaming);
2153 else if (gimple_debug_bind_p (stmt)
2154 && gimple_debug_bind_has_value_p (stmt))
2156 tree *valuep = gimple_debug_bind_get_value_ptr (stmt);
2157 tree decl;
2158 maybe_rewrite_mem_ref_base (valuep, suitable_for_renaming);
2159 decl = non_rewritable_mem_ref_base (*valuep);
2160 if (decl
2161 && bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
2162 gimple_debug_bind_reset_value (stmt);
2165 if (gimple_references_memory_p (stmt)
2166 || is_gimple_debug (stmt))
2167 update_stmt (stmt);
2169 gsi_next (&gsi);
2172 /* Update SSA form here, we are called as non-pass as well. */
2173 if (number_of_loops () > 1 && loops_state_satisfies_p (LOOP_CLOSED_SSA))
2174 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
2175 else
2176 update_ssa (TODO_update_ssa);
2179 BITMAP_FREE (not_reg_needs);
2180 BITMAP_FREE (addresses_taken);
2181 BITMAP_FREE (suitable_for_renaming);
2182 timevar_pop (TV_ADDRESS_TAKEN);
2185 struct gimple_opt_pass pass_update_address_taken =
2188 GIMPLE_PASS,
2189 "addressables", /* name */
2190 OPTGROUP_NONE, /* optinfo_flags */
2191 NULL, /* gate */
2192 NULL, /* execute */
2193 NULL, /* sub */
2194 NULL, /* next */
2195 0, /* static_pass_number */
2196 TV_ADDRESS_TAKEN, /* tv_id */
2197 PROP_ssa, /* properties_required */
2198 0, /* properties_provided */
2199 0, /* properties_destroyed */
2200 0, /* todo_flags_start */
2201 TODO_update_address_taken /* todo_flags_finish */