Merge trunk version 195164 into gupc branch.
[official-gcc.git] / gcc / tree-ssa.c
blobbd57886043aedfecaae82e35453f72995f42963e
1 /* Miscellaneous SSA utility functions.
2 Copyright (C) 2001-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "tree.h"
25 #include "flags.h"
26 #include "tm_p.h"
27 #include "target.h"
28 #include "ggc.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 "pointer-set.h"
35 #include "tree-flow.h"
36 #include "gimple.h"
37 #include "tree-inline.h"
38 #include "hashtab.h"
39 #include "tree-pass.h"
40 #include "diagnostic-core.h"
41 #include "cfgloop.h"
43 /* Pointer map of variable mappings, keyed by edge. */
44 static struct pointer_map_t *edge_var_maps;
47 /* Add a mapping with PHI RESULT and PHI DEF associated with edge E. */
49 void
50 redirect_edge_var_map_add (edge e, tree result, tree def, source_location locus)
52 void **slot;
53 edge_var_map_vector *head;
54 edge_var_map new_node;
56 if (edge_var_maps == NULL)
57 edge_var_maps = pointer_map_create ();
59 slot = pointer_map_insert (edge_var_maps, e);
60 head = (edge_var_map_vector *) *slot;
61 if (!head)
63 head = new edge_var_map_vector;
64 head->create (5);
65 *slot = head;
67 new_node.def = def;
68 new_node.result = result;
69 new_node.locus = locus;
71 head->safe_push (new_node);
75 /* Clear the var mappings in edge E. */
77 void
78 redirect_edge_var_map_clear (edge e)
80 void **slot;
81 edge_var_map_vector *head;
83 if (!edge_var_maps)
84 return;
86 slot = pointer_map_contains (edge_var_maps, e);
88 if (slot)
90 head = (edge_var_map_vector *) *slot;
91 delete head;
92 *slot = NULL;
97 /* Duplicate the redirected var mappings in OLDE in NEWE.
99 Since we can't remove a mapping, let's just duplicate it. This assumes a
100 pointer_map can have multiple edges mapping to the same var_map (many to
101 one mapping), since we don't remove the previous mappings. */
103 void
104 redirect_edge_var_map_dup (edge newe, edge olde)
106 void **new_slot, **old_slot;
107 edge_var_map_vector *head;
109 if (!edge_var_maps)
110 return;
112 new_slot = pointer_map_insert (edge_var_maps, newe);
113 old_slot = pointer_map_contains (edge_var_maps, olde);
114 if (!old_slot)
115 return;
116 head = (edge_var_map_vector *) *old_slot;
118 edge_var_map_vector *new_head = new edge_var_map_vector;
119 if (head)
120 *new_head = head->copy ();
121 else
122 new_head->create (5);
123 *new_slot = new_head;
127 /* Return the variable mappings for a given edge. If there is none, return
128 NULL. */
130 edge_var_map_vector *
131 redirect_edge_var_map_vector (edge e)
133 void **slot;
135 /* Hey, what kind of idiot would... you'd be surprised. */
136 if (!edge_var_maps)
137 return NULL;
139 slot = pointer_map_contains (edge_var_maps, e);
140 if (!slot)
141 return NULL;
143 return (edge_var_map_vector *) *slot;
146 /* Used by redirect_edge_var_map_destroy to free all memory. */
148 static bool
149 free_var_map_entry (const void *key ATTRIBUTE_UNUSED,
150 void **value,
151 void *data ATTRIBUTE_UNUSED)
153 edge_var_map_vector *head = (edge_var_map_vector *) *value;
154 delete head;
155 return true;
158 /* Clear the edge variable mappings. */
160 void
161 redirect_edge_var_map_destroy (void)
163 if (edge_var_maps)
165 pointer_map_traverse (edge_var_maps, free_var_map_entry, NULL);
166 pointer_map_destroy (edge_var_maps);
167 edge_var_maps = NULL;
172 /* Remove the corresponding arguments from the PHI nodes in E's
173 destination block and redirect it to DEST. Return redirected edge.
174 The list of removed arguments is stored in a vector accessed
175 through edge_var_maps. */
177 edge
178 ssa_redirect_edge (edge e, basic_block dest)
180 gimple_stmt_iterator gsi;
181 gimple phi;
183 redirect_edge_var_map_clear (e);
185 /* Remove the appropriate PHI arguments in E's destination block. */
186 for (gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); gsi_next (&gsi))
188 tree def;
189 source_location locus ;
191 phi = gsi_stmt (gsi);
192 def = gimple_phi_arg_def (phi, e->dest_idx);
193 locus = gimple_phi_arg_location (phi, e->dest_idx);
195 if (def == NULL_TREE)
196 continue;
198 redirect_edge_var_map_add (e, gimple_phi_result (phi), def, locus);
201 e = redirect_edge_succ_nodup (e, dest);
203 return e;
207 /* Add PHI arguments queued in PENDING_STMT list on edge E to edge
208 E->dest. */
210 void
211 flush_pending_stmts (edge e)
213 gimple phi;
214 edge_var_map_vector *v;
215 edge_var_map *vm;
216 int i;
217 gimple_stmt_iterator gsi;
219 v = redirect_edge_var_map_vector (e);
220 if (!v)
221 return;
223 for (gsi = gsi_start_phis (e->dest), i = 0;
224 !gsi_end_p (gsi) && v->iterate (i, &vm);
225 gsi_next (&gsi), i++)
227 tree def;
229 phi = gsi_stmt (gsi);
230 def = redirect_edge_var_map_def (vm);
231 add_phi_arg (phi, def, e, redirect_edge_var_map_location (vm));
234 redirect_edge_var_map_clear (e);
237 /* Given a tree for an expression for which we might want to emit
238 locations or values in debug information (generally a variable, but
239 we might deal with other kinds of trees in the future), return the
240 tree that should be used as the variable of a DEBUG_BIND STMT or
241 VAR_LOCATION INSN or NOTE. Return NULL if VAR is not to be tracked. */
243 tree
244 target_for_debug_bind (tree var)
246 if (!MAY_HAVE_DEBUG_STMTS)
247 return NULL_TREE;
249 if (TREE_CODE (var) == SSA_NAME)
251 var = SSA_NAME_VAR (var);
252 if (var == NULL_TREE)
253 return NULL_TREE;
256 if ((TREE_CODE (var) != VAR_DECL
257 || VAR_DECL_IS_VIRTUAL_OPERAND (var))
258 && TREE_CODE (var) != PARM_DECL)
259 return NULL_TREE;
261 if (DECL_HAS_VALUE_EXPR_P (var))
262 return target_for_debug_bind (DECL_VALUE_EXPR (var));
264 if (DECL_IGNORED_P (var))
265 return NULL_TREE;
267 /* var-tracking only tracks registers. */
268 if (!is_gimple_reg_type (TREE_TYPE (var)))
269 return NULL_TREE;
271 return var;
274 /* Called via walk_tree, look for SSA_NAMEs that have already been
275 released. */
277 static tree
278 find_released_ssa_name (tree *tp, int *walk_subtrees, void *data_)
280 struct walk_stmt_info *wi = (struct walk_stmt_info *) data_;
282 if (wi && wi->is_lhs)
283 return NULL_TREE;
285 if (TREE_CODE (*tp) == SSA_NAME)
287 if (SSA_NAME_IN_FREE_LIST (*tp))
288 return *tp;
290 *walk_subtrees = 0;
292 else if (IS_TYPE_OR_DECL_P (*tp))
293 *walk_subtrees = 0;
295 return NULL_TREE;
298 /* Insert a DEBUG BIND stmt before the DEF of VAR if VAR is referenced
299 by other DEBUG stmts, and replace uses of the DEF with the
300 newly-created debug temp. */
302 void
303 insert_debug_temp_for_var_def (gimple_stmt_iterator *gsi, tree var)
305 imm_use_iterator imm_iter;
306 use_operand_p use_p;
307 gimple stmt;
308 gimple def_stmt = NULL;
309 int usecount = 0;
310 tree value = NULL;
312 if (!MAY_HAVE_DEBUG_STMTS)
313 return;
315 /* If this name has already been registered for replacement, do nothing
316 as anything that uses this name isn't in SSA form. */
317 if (name_registered_for_update_p (var))
318 return;
320 /* Check whether there are debug stmts that reference this variable and,
321 if there are, decide whether we should use a debug temp. */
322 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, var)
324 stmt = USE_STMT (use_p);
326 if (!gimple_debug_bind_p (stmt))
327 continue;
329 if (usecount++)
330 break;
332 if (gimple_debug_bind_get_value (stmt) != var)
334 /* Count this as an additional use, so as to make sure we
335 use a temp unless VAR's definition has a SINGLE_RHS that
336 can be shared. */
337 usecount++;
338 break;
342 if (!usecount)
343 return;
345 if (gsi)
346 def_stmt = gsi_stmt (*gsi);
347 else
348 def_stmt = SSA_NAME_DEF_STMT (var);
350 /* If we didn't get an insertion point, and the stmt has already
351 been removed, we won't be able to insert the debug bind stmt, so
352 we'll have to drop debug information. */
353 if (gimple_code (def_stmt) == GIMPLE_PHI)
355 value = degenerate_phi_result (def_stmt);
356 if (value && walk_tree (&value, find_released_ssa_name, NULL, NULL))
357 value = NULL;
358 /* error_mark_node is what fixup_noreturn_call changes PHI arguments
359 to. */
360 else if (value == error_mark_node)
361 value = NULL;
363 else if (is_gimple_assign (def_stmt))
365 bool no_value = false;
367 if (!dom_info_available_p (CDI_DOMINATORS))
369 struct walk_stmt_info wi;
371 memset (&wi, 0, sizeof (wi));
373 /* When removing blocks without following reverse dominance
374 order, we may sometimes encounter SSA_NAMEs that have
375 already been released, referenced in other SSA_DEFs that
376 we're about to release. Consider:
378 <bb X>:
379 v_1 = foo;
381 <bb Y>:
382 w_2 = v_1 + bar;
383 # DEBUG w => w_2
385 If we deleted BB X first, propagating the value of w_2
386 won't do us any good. It's too late to recover their
387 original definition of v_1: when it was deleted, it was
388 only referenced in other DEFs, it couldn't possibly know
389 it should have been retained, and propagating every
390 single DEF just in case it might have to be propagated
391 into a DEBUG STMT would probably be too wasteful.
393 When dominator information is not readily available, we
394 check for and accept some loss of debug information. But
395 if it is available, there's no excuse for us to remove
396 blocks in the wrong order, so we don't even check for
397 dead SSA NAMEs. SSA verification shall catch any
398 errors. */
399 if ((!gsi && !gimple_bb (def_stmt))
400 || walk_gimple_op (def_stmt, find_released_ssa_name, &wi))
401 no_value = true;
404 if (!no_value)
405 value = gimple_assign_rhs_to_tree (def_stmt);
408 if (value)
410 /* If there's a single use of VAR, and VAR is the entire debug
411 expression (usecount would have been incremented again
412 otherwise), and the definition involves only constants and
413 SSA names, then we can propagate VALUE into this single use,
414 avoiding the temp.
416 We can also avoid using a temp if VALUE can be shared and
417 propagated into all uses, without generating expressions that
418 wouldn't be valid gimple RHSs.
420 Other cases that would require unsharing or non-gimple RHSs
421 are deferred to a debug temp, although we could avoid temps
422 at the expense of duplication of expressions. */
424 if (CONSTANT_CLASS_P (value)
425 || gimple_code (def_stmt) == GIMPLE_PHI
426 || (usecount == 1
427 && (!gimple_assign_single_p (def_stmt)
428 || is_gimple_min_invariant (value)))
429 || is_gimple_reg (value))
431 else
433 gimple def_temp;
434 tree vexpr = make_node (DEBUG_EXPR_DECL);
436 def_temp = gimple_build_debug_bind (vexpr,
437 unshare_expr (value),
438 def_stmt);
440 DECL_ARTIFICIAL (vexpr) = 1;
441 TREE_TYPE (vexpr) = TREE_TYPE (value);
442 if (DECL_P (value))
443 DECL_MODE (vexpr) = DECL_MODE (value);
444 else
445 DECL_MODE (vexpr) = TYPE_MODE (TREE_TYPE (value));
447 if (gsi)
448 gsi_insert_before (gsi, def_temp, GSI_SAME_STMT);
449 else
451 gimple_stmt_iterator ngsi = gsi_for_stmt (def_stmt);
452 gsi_insert_before (&ngsi, def_temp, GSI_SAME_STMT);
455 value = vexpr;
459 FOR_EACH_IMM_USE_STMT (stmt, imm_iter, var)
461 if (!gimple_debug_bind_p (stmt))
462 continue;
464 if (value)
466 FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
467 /* unshare_expr is not needed here. vexpr is either a
468 SINGLE_RHS, that can be safely shared, some other RHS
469 that was unshared when we found it had a single debug
470 use, or a DEBUG_EXPR_DECL, that can be safely
471 shared. */
472 SET_USE (use_p, unshare_expr (value));
473 /* If we didn't replace uses with a debug decl fold the
474 resulting expression. Otherwise we end up with invalid IL. */
475 if (TREE_CODE (value) != DEBUG_EXPR_DECL)
477 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
478 fold_stmt_inplace (&gsi);
481 else
482 gimple_debug_bind_reset_value (stmt);
484 update_stmt (stmt);
489 /* Insert a DEBUG BIND stmt before STMT for each DEF referenced by
490 other DEBUG stmts, and replace uses of the DEF with the
491 newly-created debug temp. */
493 void
494 insert_debug_temps_for_defs (gimple_stmt_iterator *gsi)
496 gimple stmt;
497 ssa_op_iter op_iter;
498 def_operand_p def_p;
500 if (!MAY_HAVE_DEBUG_STMTS)
501 return;
503 stmt = gsi_stmt (*gsi);
505 FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
507 tree var = DEF_FROM_PTR (def_p);
509 if (TREE_CODE (var) != SSA_NAME)
510 continue;
512 insert_debug_temp_for_var_def (gsi, var);
516 /* Reset all debug stmts that use SSA_NAME(s) defined in STMT. */
518 void
519 reset_debug_uses (gimple stmt)
521 ssa_op_iter op_iter;
522 def_operand_p def_p;
523 imm_use_iterator imm_iter;
524 gimple use_stmt;
526 if (!MAY_HAVE_DEBUG_STMTS)
527 return;
529 FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt, op_iter, SSA_OP_DEF)
531 tree var = DEF_FROM_PTR (def_p);
533 if (TREE_CODE (var) != SSA_NAME)
534 continue;
536 FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, var)
538 if (!gimple_debug_bind_p (use_stmt))
539 continue;
541 gimple_debug_bind_reset_value (use_stmt);
542 update_stmt (use_stmt);
547 /* Delete SSA DEFs for SSA versions in the TOREMOVE bitmap, removing
548 dominated stmts before their dominators, so that release_ssa_defs
549 stands a chance of propagating DEFs into debug bind stmts. */
551 void
552 release_defs_bitset (bitmap toremove)
554 unsigned j;
555 bitmap_iterator bi;
557 /* Performing a topological sort is probably overkill, this will
558 most likely run in slightly superlinear time, rather than the
559 pathological quadratic worst case. */
560 while (!bitmap_empty_p (toremove))
561 EXECUTE_IF_SET_IN_BITMAP (toremove, 0, j, bi)
563 bool remove_now = true;
564 tree var = ssa_name (j);
565 gimple stmt;
566 imm_use_iterator uit;
568 FOR_EACH_IMM_USE_STMT (stmt, uit, var)
570 ssa_op_iter dit;
571 def_operand_p def_p;
573 /* We can't propagate PHI nodes into debug stmts. */
574 if (gimple_code (stmt) == GIMPLE_PHI
575 || is_gimple_debug (stmt))
576 continue;
578 /* If we find another definition to remove that uses
579 the one we're looking at, defer the removal of this
580 one, so that it can be propagated into debug stmts
581 after the other is. */
582 FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, dit, SSA_OP_DEF)
584 tree odef = DEF_FROM_PTR (def_p);
586 if (bitmap_bit_p (toremove, SSA_NAME_VERSION (odef)))
588 remove_now = false;
589 break;
593 if (!remove_now)
594 BREAK_FROM_IMM_USE_STMT (uit);
597 if (remove_now)
599 gimple def = SSA_NAME_DEF_STMT (var);
600 gimple_stmt_iterator gsi = gsi_for_stmt (def);
602 if (gimple_code (def) == GIMPLE_PHI)
603 remove_phi_node (&gsi, true);
604 else
606 gsi_remove (&gsi, true);
607 release_defs (def);
610 bitmap_clear_bit (toremove, j);
615 /* Return true if SSA_NAME is malformed and mark it visited.
617 IS_VIRTUAL is true if this SSA_NAME was found inside a virtual
618 operand. */
620 static bool
621 verify_ssa_name (tree ssa_name, bool is_virtual)
623 if (TREE_CODE (ssa_name) != SSA_NAME)
625 error ("expected an SSA_NAME object");
626 return true;
629 if (SSA_NAME_VAR (ssa_name) != NULL_TREE
630 && TREE_TYPE (ssa_name) != TREE_TYPE (ssa_name))
632 error ("type mismatch between an SSA_NAME and its symbol");
633 return true;
636 if (SSA_NAME_IN_FREE_LIST (ssa_name))
638 error ("found an SSA_NAME that had been released into the free pool");
639 return true;
642 if (is_virtual && !virtual_operand_p (ssa_name))
644 error ("found a virtual definition for a GIMPLE register");
645 return true;
648 if (is_virtual && SSA_NAME_VAR (ssa_name) != gimple_vop (cfun))
650 error ("virtual SSA name for non-VOP decl");
651 return true;
654 if (!is_virtual && virtual_operand_p (ssa_name))
656 error ("found a real definition for a non-register");
657 return true;
660 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
661 && !gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name)))
663 error ("found a default name with a non-empty defining statement");
664 return true;
667 return false;
671 /* Return true if the definition of SSA_NAME at block BB is malformed.
673 STMT is the statement where SSA_NAME is created.
675 DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
676 version numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
677 it means that the block in that array slot contains the
678 definition of SSA_NAME.
680 IS_VIRTUAL is true if SSA_NAME is created by a VDEF. */
682 static bool
683 verify_def (basic_block bb, basic_block *definition_block, tree ssa_name,
684 gimple stmt, bool is_virtual)
686 if (verify_ssa_name (ssa_name, is_virtual))
687 goto err;
689 if (SSA_NAME_VAR (ssa_name)
690 && TREE_CODE (SSA_NAME_VAR (ssa_name)) == RESULT_DECL
691 && DECL_BY_REFERENCE (SSA_NAME_VAR (ssa_name)))
693 error ("RESULT_DECL should be read only when DECL_BY_REFERENCE is set");
694 goto err;
697 if (definition_block[SSA_NAME_VERSION (ssa_name)])
699 error ("SSA_NAME created in two different blocks %i and %i",
700 definition_block[SSA_NAME_VERSION (ssa_name)]->index, bb->index);
701 goto err;
704 definition_block[SSA_NAME_VERSION (ssa_name)] = bb;
706 if (SSA_NAME_DEF_STMT (ssa_name) != stmt)
708 error ("SSA_NAME_DEF_STMT is wrong");
709 fprintf (stderr, "Expected definition statement:\n");
710 print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (ssa_name), 4, TDF_VOPS);
711 fprintf (stderr, "\nActual definition statement:\n");
712 print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
713 goto err;
716 return false;
718 err:
719 fprintf (stderr, "while verifying SSA_NAME ");
720 print_generic_expr (stderr, ssa_name, 0);
721 fprintf (stderr, " in statement\n");
722 print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
724 return true;
728 /* Return true if the use of SSA_NAME at statement STMT in block BB is
729 malformed.
731 DEF_BB is the block where SSA_NAME was found to be created.
733 IDOM contains immediate dominator information for the flowgraph.
735 CHECK_ABNORMAL is true if the caller wants to check whether this use
736 is flowing through an abnormal edge (only used when checking PHI
737 arguments).
739 If NAMES_DEFINED_IN_BB is not NULL, it contains a bitmap of ssa names
740 that are defined before STMT in basic block BB. */
742 static bool
743 verify_use (basic_block bb, basic_block def_bb, use_operand_p use_p,
744 gimple stmt, bool check_abnormal, bitmap names_defined_in_bb)
746 bool err = false;
747 tree ssa_name = USE_FROM_PTR (use_p);
749 if (!TREE_VISITED (ssa_name))
750 if (verify_imm_links (stderr, ssa_name))
751 err = true;
753 TREE_VISITED (ssa_name) = 1;
755 if (gimple_nop_p (SSA_NAME_DEF_STMT (ssa_name))
756 && SSA_NAME_IS_DEFAULT_DEF (ssa_name))
757 ; /* Default definitions have empty statements. Nothing to do. */
758 else if (!def_bb)
760 error ("missing definition");
761 err = true;
763 else if (bb != def_bb
764 && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
766 error ("definition in block %i does not dominate use in block %i",
767 def_bb->index, bb->index);
768 err = true;
770 else if (bb == def_bb
771 && names_defined_in_bb != NULL
772 && !bitmap_bit_p (names_defined_in_bb, SSA_NAME_VERSION (ssa_name)))
774 error ("definition in block %i follows the use", def_bb->index);
775 err = true;
778 if (check_abnormal
779 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
781 error ("SSA_NAME_OCCURS_IN_ABNORMAL_PHI should be set");
782 err = true;
785 /* Make sure the use is in an appropriate list by checking the previous
786 element to make sure it's the same. */
787 if (use_p->prev == NULL)
789 error ("no immediate_use list");
790 err = true;
792 else
794 tree listvar;
795 if (use_p->prev->use == NULL)
796 listvar = use_p->prev->loc.ssa_name;
797 else
798 listvar = USE_FROM_PTR (use_p->prev);
799 if (listvar != ssa_name)
801 error ("wrong immediate use list");
802 err = true;
806 if (err)
808 fprintf (stderr, "for SSA_NAME: ");
809 print_generic_expr (stderr, ssa_name, TDF_VOPS);
810 fprintf (stderr, " in statement:\n");
811 print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
814 return err;
818 /* Return true if any of the arguments for PHI node PHI at block BB is
819 malformed.
821 DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
822 version numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
823 it means that the block in that array slot contains the
824 definition of SSA_NAME. */
826 static bool
827 verify_phi_args (gimple phi, basic_block bb, basic_block *definition_block)
829 edge e;
830 bool err = false;
831 size_t i, phi_num_args = gimple_phi_num_args (phi);
833 if (EDGE_COUNT (bb->preds) != phi_num_args)
835 error ("incoming edge count does not match number of PHI arguments");
836 err = true;
837 goto error;
840 for (i = 0; i < phi_num_args; i++)
842 use_operand_p op_p = gimple_phi_arg_imm_use_ptr (phi, i);
843 tree op = USE_FROM_PTR (op_p);
845 e = EDGE_PRED (bb, i);
847 if (op == NULL_TREE)
849 error ("PHI argument is missing for edge %d->%d",
850 e->src->index,
851 e->dest->index);
852 err = true;
853 goto error;
856 if (TREE_CODE (op) != SSA_NAME && !is_gimple_min_invariant (op))
858 error ("PHI argument is not SSA_NAME, or invariant");
859 err = true;
862 if (TREE_CODE (op) == SSA_NAME)
864 err = verify_ssa_name (op, virtual_operand_p (gimple_phi_result (phi)));
865 err |= verify_use (e->src, definition_block[SSA_NAME_VERSION (op)],
866 op_p, phi, e->flags & EDGE_ABNORMAL, NULL);
869 if (TREE_CODE (op) == ADDR_EXPR)
871 tree base = TREE_OPERAND (op, 0);
872 while (handled_component_p (base))
873 base = TREE_OPERAND (base, 0);
874 if ((TREE_CODE (base) == VAR_DECL
875 || TREE_CODE (base) == PARM_DECL
876 || TREE_CODE (base) == RESULT_DECL)
877 && !TREE_ADDRESSABLE (base))
879 error ("address taken, but ADDRESSABLE bit not set");
880 err = true;
884 if (e->dest != bb)
886 error ("wrong edge %d->%d for PHI argument",
887 e->src->index, e->dest->index);
888 err = true;
891 if (err)
893 fprintf (stderr, "PHI argument\n");
894 print_generic_stmt (stderr, op, TDF_VOPS);
895 goto error;
899 error:
900 if (err)
902 fprintf (stderr, "for PHI node\n");
903 print_gimple_stmt (stderr, phi, 0, TDF_VOPS|TDF_MEMSYMS);
907 return err;
911 /* Verify common invariants in the SSA web.
912 TODO: verify the variable annotations. */
914 DEBUG_FUNCTION void
915 verify_ssa (bool check_modified_stmt)
917 size_t i;
918 basic_block bb;
919 basic_block *definition_block = XCNEWVEC (basic_block, num_ssa_names);
920 ssa_op_iter iter;
921 tree op;
922 enum dom_state orig_dom_state = dom_info_state (CDI_DOMINATORS);
923 bitmap names_defined_in_bb = BITMAP_ALLOC (NULL);
925 gcc_assert (!need_ssa_update_p (cfun));
927 timevar_push (TV_TREE_SSA_VERIFY);
929 /* Keep track of SSA names present in the IL. */
930 for (i = 1; i < num_ssa_names; i++)
932 tree name = ssa_name (i);
933 if (name)
935 gimple stmt;
936 TREE_VISITED (name) = 0;
938 verify_ssa_name (name, virtual_operand_p (name));
940 stmt = SSA_NAME_DEF_STMT (name);
941 if (!gimple_nop_p (stmt))
943 basic_block bb = gimple_bb (stmt);
944 verify_def (bb, definition_block,
945 name, stmt, virtual_operand_p (name));
951 calculate_dominance_info (CDI_DOMINATORS);
953 /* Now verify all the uses and make sure they agree with the definitions
954 found in the previous pass. */
955 FOR_EACH_BB (bb)
957 edge e;
958 gimple phi;
959 edge_iterator ei;
960 gimple_stmt_iterator gsi;
962 /* Make sure that all edges have a clear 'aux' field. */
963 FOR_EACH_EDGE (e, ei, bb->preds)
965 if (e->aux)
967 error ("AUX pointer initialized for edge %d->%d", e->src->index,
968 e->dest->index);
969 goto err;
973 /* Verify the arguments for every PHI node in the block. */
974 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
976 phi = gsi_stmt (gsi);
977 if (verify_phi_args (phi, bb, definition_block))
978 goto err;
980 bitmap_set_bit (names_defined_in_bb,
981 SSA_NAME_VERSION (gimple_phi_result (phi)));
984 /* Now verify all the uses and vuses in every statement of the block. */
985 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
987 gimple stmt = gsi_stmt (gsi);
988 use_operand_p use_p;
990 if (check_modified_stmt && gimple_modified_p (stmt))
992 error ("stmt (%p) marked modified after optimization pass: ",
993 (void *)stmt);
994 print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
995 goto err;
998 if (verify_ssa_operands (stmt))
1000 print_gimple_stmt (stderr, stmt, 0, TDF_VOPS);
1001 goto err;
1004 if (gimple_debug_bind_p (stmt)
1005 && !gimple_debug_bind_has_value_p (stmt))
1006 continue;
1008 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
1010 op = USE_FROM_PTR (use_p);
1011 if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)],
1012 use_p, stmt, false, names_defined_in_bb))
1013 goto err;
1016 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_DEFS)
1018 if (SSA_NAME_DEF_STMT (op) != stmt)
1020 error ("SSA_NAME_DEF_STMT is wrong");
1021 fprintf (stderr, "Expected definition statement:\n");
1022 print_gimple_stmt (stderr, stmt, 4, TDF_VOPS);
1023 fprintf (stderr, "\nActual definition statement:\n");
1024 print_gimple_stmt (stderr, SSA_NAME_DEF_STMT (op),
1025 4, TDF_VOPS);
1026 goto err;
1028 bitmap_set_bit (names_defined_in_bb, SSA_NAME_VERSION (op));
1032 bitmap_clear (names_defined_in_bb);
1035 free (definition_block);
1037 /* Restore the dominance information to its prior known state, so
1038 that we do not perturb the compiler's subsequent behavior. */
1039 if (orig_dom_state == DOM_NONE)
1040 free_dominance_info (CDI_DOMINATORS);
1041 else
1042 set_dom_info_availability (CDI_DOMINATORS, orig_dom_state);
1044 BITMAP_FREE (names_defined_in_bb);
1045 timevar_pop (TV_TREE_SSA_VERIFY);
1046 return;
1048 err:
1049 internal_error ("verify_ssa failed");
1052 /* Return true if the uid in both int tree maps are equal. */
1055 int_tree_map_eq (const void *va, const void *vb)
1057 const struct int_tree_map *a = (const struct int_tree_map *) va;
1058 const struct int_tree_map *b = (const struct int_tree_map *) vb;
1059 return (a->uid == b->uid);
1062 /* Hash a UID in a int_tree_map. */
1064 unsigned int
1065 int_tree_map_hash (const void *item)
1067 return ((const struct int_tree_map *)item)->uid;
1070 /* Return true if the DECL_UID in both trees are equal. */
1073 uid_decl_map_eq (const void *va, const void *vb)
1075 const_tree a = (const_tree) va;
1076 const_tree b = (const_tree) vb;
1077 return (a->decl_minimal.uid == b->decl_minimal.uid);
1080 /* Hash a tree in a uid_decl_map. */
1082 unsigned int
1083 uid_decl_map_hash (const void *item)
1085 return ((const_tree)item)->decl_minimal.uid;
1088 /* Return true if the DECL_UID in both trees are equal. */
1090 static int
1091 uid_ssaname_map_eq (const void *va, const void *vb)
1093 const_tree a = (const_tree) va;
1094 const_tree b = (const_tree) vb;
1095 return (a->ssa_name.var->decl_minimal.uid == b->ssa_name.var->decl_minimal.uid);
1098 /* Hash a tree in a uid_decl_map. */
1100 static unsigned int
1101 uid_ssaname_map_hash (const void *item)
1103 return ((const_tree)item)->ssa_name.var->decl_minimal.uid;
1107 /* Initialize global DFA and SSA structures. */
1109 void
1110 init_tree_ssa (struct function *fn)
1112 fn->gimple_df = ggc_alloc_cleared_gimple_df ();
1113 fn->gimple_df->default_defs = htab_create_ggc (20, uid_ssaname_map_hash,
1114 uid_ssaname_map_eq, NULL);
1115 pt_solution_reset (&fn->gimple_df->escaped);
1116 init_ssanames (fn, 0);
1119 /* Do the actions required to initialize internal data structures used
1120 in tree-ssa optimization passes. */
1122 static unsigned int
1123 execute_init_datastructures (void)
1125 /* Allocate hash tables, arrays and other structures. */
1126 init_tree_ssa (cfun);
1127 return 0;
1130 struct gimple_opt_pass pass_init_datastructures =
1133 GIMPLE_PASS,
1134 "*init_datastructures", /* name */
1135 OPTGROUP_NONE, /* optinfo_flags */
1136 NULL, /* gate */
1137 execute_init_datastructures, /* execute */
1138 NULL, /* sub */
1139 NULL, /* next */
1140 0, /* static_pass_number */
1141 TV_NONE, /* tv_id */
1142 PROP_cfg, /* properties_required */
1143 0, /* properties_provided */
1144 0, /* properties_destroyed */
1145 0, /* todo_flags_start */
1146 0 /* todo_flags_finish */
1150 /* Deallocate memory associated with SSA data structures for FNDECL. */
1152 void
1153 delete_tree_ssa (void)
1155 fini_ssanames ();
1157 /* We no longer maintain the SSA operand cache at this point. */
1158 if (ssa_operands_active (cfun))
1159 fini_ssa_operands ();
1161 htab_delete (cfun->gimple_df->default_defs);
1162 cfun->gimple_df->default_defs = NULL;
1163 pt_solution_reset (&cfun->gimple_df->escaped);
1164 if (cfun->gimple_df->decls_to_pointers != NULL)
1165 pointer_map_destroy (cfun->gimple_df->decls_to_pointers);
1166 cfun->gimple_df->decls_to_pointers = NULL;
1167 cfun->gimple_df->modified_noreturn_calls = NULL;
1168 cfun->gimple_df = NULL;
1170 /* We no longer need the edge variable maps. */
1171 redirect_edge_var_map_destroy ();
1174 /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
1175 useless type conversion, otherwise return false.
1177 This function implicitly defines the middle-end type system. With
1178 the notion of 'a < b' meaning that useless_type_conversion_p (a, b)
1179 holds and 'a > b' meaning that useless_type_conversion_p (b, a) holds,
1180 the following invariants shall be fulfilled:
1182 1) useless_type_conversion_p is transitive.
1183 If a < b and b < c then a < c.
1185 2) useless_type_conversion_p is not symmetric.
1186 From a < b does not follow a > b.
1188 3) Types define the available set of operations applicable to values.
1189 A type conversion is useless if the operations for the target type
1190 is a subset of the operations for the source type. For example
1191 casts to void* are useless, casts from void* are not (void* can't
1192 be dereferenced or offsetted, but copied, hence its set of operations
1193 is a strict subset of that of all other data pointer types). Casts
1194 to const T* are useless (can't be written to), casts from const T*
1195 to T* are not. */
1197 bool
1198 useless_type_conversion_p (tree outer_type, tree inner_type)
1200 /* Do the following before stripping toplevel qualifiers. */
1201 if (POINTER_TYPE_P (inner_type)
1202 && POINTER_TYPE_P (outer_type))
1204 int i_shared = upc_shared_type_p (TREE_TYPE (inner_type));
1205 int o_shared = upc_shared_type_p (TREE_TYPE (outer_type));
1207 /* Retain conversions from a UPC shared pointer to
1208 a regular C pointer. */
1209 if (!o_shared && i_shared)
1210 return false;
1212 /* Retain conversions between incompatible UPC shared pointers. */
1213 if (o_shared && i_shared
1214 && !lang_hooks.types_compatible_p (inner_type, outer_type))
1215 return false;
1217 /* Do not lose casts between pointers to different address spaces. */
1218 if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
1219 != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
1220 return false;
1223 /* From now on qualifiers on value types do not matter. */
1224 inner_type = TYPE_MAIN_VARIANT (inner_type);
1225 outer_type = TYPE_MAIN_VARIANT (outer_type);
1227 if (inner_type == outer_type)
1228 return true;
1230 /* If we know the canonical types, compare them. */
1231 if (TYPE_CANONICAL (inner_type)
1232 && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type))
1233 return true;
1235 /* Changes in machine mode are never useless conversions unless we
1236 deal with aggregate types in which case we defer to later checks. */
1237 if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type)
1238 && !AGGREGATE_TYPE_P (inner_type))
1239 return false;
1241 /* If both the inner and outer types are integral types, then the
1242 conversion is not necessary if they have the same mode and
1243 signedness and precision, and both or neither are boolean. */
1244 if (INTEGRAL_TYPE_P (inner_type)
1245 && INTEGRAL_TYPE_P (outer_type))
1247 /* Preserve changes in signedness or precision. */
1248 if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
1249 || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
1250 return false;
1252 /* Preserve conversions to/from BOOLEAN_TYPE if types are not
1253 of precision one. */
1254 if (((TREE_CODE (inner_type) == BOOLEAN_TYPE)
1255 != (TREE_CODE (outer_type) == BOOLEAN_TYPE))
1256 && TYPE_PRECISION (outer_type) != 1)
1257 return false;
1259 /* We don't need to preserve changes in the types minimum or
1260 maximum value in general as these do not generate code
1261 unless the types precisions are different. */
1262 return true;
1265 /* Scalar floating point types with the same mode are compatible. */
1266 else if (SCALAR_FLOAT_TYPE_P (inner_type)
1267 && SCALAR_FLOAT_TYPE_P (outer_type))
1268 return true;
1270 /* Fixed point types with the same mode are compatible. */
1271 else if (FIXED_POINT_TYPE_P (inner_type)
1272 && FIXED_POINT_TYPE_P (outer_type))
1273 return true;
1275 /* We need to take special care recursing to pointed-to types. */
1276 else if (POINTER_TYPE_P (inner_type)
1277 && POINTER_TYPE_P (outer_type))
1279 /* Do not lose casts to function pointer types. */
1280 if ((TREE_CODE (TREE_TYPE (outer_type)) == FUNCTION_TYPE
1281 || TREE_CODE (TREE_TYPE (outer_type)) == METHOD_TYPE)
1282 && !(TREE_CODE (TREE_TYPE (inner_type)) == FUNCTION_TYPE
1283 || TREE_CODE (TREE_TYPE (inner_type)) == METHOD_TYPE))
1284 return false;
1286 /* We do not care for const qualification of the pointed-to types
1287 as const qualification has no semantic value to the middle-end. */
1289 /* Otherwise pointers/references are equivalent. */
1290 return true;
1293 /* Recurse for complex types. */
1294 else if (TREE_CODE (inner_type) == COMPLEX_TYPE
1295 && TREE_CODE (outer_type) == COMPLEX_TYPE)
1296 return useless_type_conversion_p (TREE_TYPE (outer_type),
1297 TREE_TYPE (inner_type));
1299 /* Recurse for vector types with the same number of subparts. */
1300 else if (TREE_CODE (inner_type) == VECTOR_TYPE
1301 && TREE_CODE (outer_type) == VECTOR_TYPE
1302 && TYPE_PRECISION (inner_type) == TYPE_PRECISION (outer_type))
1303 return useless_type_conversion_p (TREE_TYPE (outer_type),
1304 TREE_TYPE (inner_type));
1306 else if (TREE_CODE (inner_type) == ARRAY_TYPE
1307 && TREE_CODE (outer_type) == ARRAY_TYPE)
1309 /* Preserve string attributes. */
1310 if (TYPE_STRING_FLAG (inner_type) != TYPE_STRING_FLAG (outer_type))
1311 return false;
1313 /* Conversions from array types with unknown extent to
1314 array types with known extent are not useless. */
1315 if (!TYPE_DOMAIN (inner_type)
1316 && TYPE_DOMAIN (outer_type))
1317 return false;
1319 /* Nor are conversions from array types with non-constant size to
1320 array types with constant size or to different size. */
1321 if (TYPE_SIZE (outer_type)
1322 && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST
1323 && (!TYPE_SIZE (inner_type)
1324 || TREE_CODE (TYPE_SIZE (inner_type)) != INTEGER_CST
1325 || !tree_int_cst_equal (TYPE_SIZE (outer_type),
1326 TYPE_SIZE (inner_type))))
1327 return false;
1329 /* Check conversions between arrays with partially known extents.
1330 If the array min/max values are constant they have to match.
1331 Otherwise allow conversions to unknown and variable extents.
1332 In particular this declares conversions that may change the
1333 mode to BLKmode as useless. */
1334 if (TYPE_DOMAIN (inner_type)
1335 && TYPE_DOMAIN (outer_type)
1336 && TYPE_DOMAIN (inner_type) != TYPE_DOMAIN (outer_type))
1338 tree inner_min = TYPE_MIN_VALUE (TYPE_DOMAIN (inner_type));
1339 tree outer_min = TYPE_MIN_VALUE (TYPE_DOMAIN (outer_type));
1340 tree inner_max = TYPE_MAX_VALUE (TYPE_DOMAIN (inner_type));
1341 tree outer_max = TYPE_MAX_VALUE (TYPE_DOMAIN (outer_type));
1343 /* After gimplification a variable min/max value carries no
1344 additional information compared to a NULL value. All that
1345 matters has been lowered to be part of the IL. */
1346 if (inner_min && TREE_CODE (inner_min) != INTEGER_CST)
1347 inner_min = NULL_TREE;
1348 if (outer_min && TREE_CODE (outer_min) != INTEGER_CST)
1349 outer_min = NULL_TREE;
1350 if (inner_max && TREE_CODE (inner_max) != INTEGER_CST)
1351 inner_max = NULL_TREE;
1352 if (outer_max && TREE_CODE (outer_max) != INTEGER_CST)
1353 outer_max = NULL_TREE;
1355 /* Conversions NULL / variable <- cst are useless, but not
1356 the other way around. */
1357 if (outer_min
1358 && (!inner_min
1359 || !tree_int_cst_equal (inner_min, outer_min)))
1360 return false;
1361 if (outer_max
1362 && (!inner_max
1363 || !tree_int_cst_equal (inner_max, outer_max)))
1364 return false;
1367 /* Recurse on the element check. */
1368 return useless_type_conversion_p (TREE_TYPE (outer_type),
1369 TREE_TYPE (inner_type));
1372 else if ((TREE_CODE (inner_type) == FUNCTION_TYPE
1373 || TREE_CODE (inner_type) == METHOD_TYPE)
1374 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
1376 tree outer_parm, inner_parm;
1378 /* If the return types are not compatible bail out. */
1379 if (!useless_type_conversion_p (TREE_TYPE (outer_type),
1380 TREE_TYPE (inner_type)))
1381 return false;
1383 /* Method types should belong to a compatible base class. */
1384 if (TREE_CODE (inner_type) == METHOD_TYPE
1385 && !useless_type_conversion_p (TYPE_METHOD_BASETYPE (outer_type),
1386 TYPE_METHOD_BASETYPE (inner_type)))
1387 return false;
1389 /* A conversion to an unprototyped argument list is ok. */
1390 if (!prototype_p (outer_type))
1391 return true;
1393 /* If the unqualified argument types are compatible the conversion
1394 is useless. */
1395 if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type))
1396 return true;
1398 for (outer_parm = TYPE_ARG_TYPES (outer_type),
1399 inner_parm = TYPE_ARG_TYPES (inner_type);
1400 outer_parm && inner_parm;
1401 outer_parm = TREE_CHAIN (outer_parm),
1402 inner_parm = TREE_CHAIN (inner_parm))
1403 if (!useless_type_conversion_p
1404 (TYPE_MAIN_VARIANT (TREE_VALUE (outer_parm)),
1405 TYPE_MAIN_VARIANT (TREE_VALUE (inner_parm))))
1406 return false;
1408 /* If there is a mismatch in the number of arguments the functions
1409 are not compatible. */
1410 if (outer_parm || inner_parm)
1411 return false;
1413 /* Defer to the target if necessary. */
1414 if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
1415 return comp_type_attributes (outer_type, inner_type) != 0;
1417 return true;
1420 /* For aggregates we rely on TYPE_CANONICAL exclusively and require
1421 explicit conversions for types involving to be structurally
1422 compared types. */
1423 else if (AGGREGATE_TYPE_P (inner_type)
1424 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
1425 return false;
1427 return false;
1430 /* Return true if a conversion from either type of TYPE1 and TYPE2
1431 to the other is not required. Otherwise return false. */
1433 bool
1434 types_compatible_p (tree type1, tree type2)
1436 return (type1 == type2
1437 || (useless_type_conversion_p (type1, type2)
1438 && useless_type_conversion_p (type2, type1)));
1441 /* Return true if EXPR is a useless type conversion, otherwise return
1442 false. */
1444 bool
1445 tree_ssa_useless_type_conversion (tree expr)
1447 /* If we have an assignment that merely uses a NOP_EXPR to change
1448 the top of the RHS to the type of the LHS and the type conversion
1449 is "safe", then strip away the type conversion so that we can
1450 enter LHS = RHS into the const_and_copies table. */
1451 if (CONVERT_EXPR_P (expr)
1452 || TREE_CODE (expr) == VIEW_CONVERT_EXPR
1453 || TREE_CODE (expr) == NON_LVALUE_EXPR)
1454 return useless_type_conversion_p
1455 (TREE_TYPE (expr),
1456 TREE_TYPE (TREE_OPERAND (expr, 0)));
1458 return false;
1461 /* Strip conversions from EXP according to
1462 tree_ssa_useless_type_conversion and return the resulting
1463 expression. */
1465 tree
1466 tree_ssa_strip_useless_type_conversions (tree exp)
1468 while (tree_ssa_useless_type_conversion (exp))
1469 exp = TREE_OPERAND (exp, 0);
1470 return exp;
1474 /* Internal helper for walk_use_def_chains. VAR, FN and DATA are as
1475 described in walk_use_def_chains.
1477 VISITED is a pointer set used to mark visited SSA_NAMEs to avoid
1478 infinite loops. We used to have a bitmap for this to just mark
1479 SSA versions we had visited. But non-sparse bitmaps are way too
1480 expensive, while sparse bitmaps may cause quadratic behavior.
1482 IS_DFS is true if the caller wants to perform a depth-first search
1483 when visiting PHI nodes. A DFS will visit each PHI argument and
1484 call FN after each one. Otherwise, all the arguments are
1485 visited first and then FN is called with each of the visited
1486 arguments in a separate pass. */
1488 static bool
1489 walk_use_def_chains_1 (tree var, walk_use_def_chains_fn fn, void *data,
1490 struct pointer_set_t *visited, bool is_dfs)
1492 gimple def_stmt;
1494 if (pointer_set_insert (visited, var))
1495 return false;
1497 def_stmt = SSA_NAME_DEF_STMT (var);
1499 if (gimple_code (def_stmt) != GIMPLE_PHI)
1501 /* If we reached the end of the use-def chain, call FN. */
1502 return fn (var, def_stmt, data);
1504 else
1506 size_t i;
1508 /* When doing a breadth-first search, call FN before following the
1509 use-def links for each argument. */
1510 if (!is_dfs)
1511 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1512 if (fn (gimple_phi_arg_def (def_stmt, i), def_stmt, data))
1513 return true;
1515 /* Follow use-def links out of each PHI argument. */
1516 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1518 tree arg = gimple_phi_arg_def (def_stmt, i);
1520 /* ARG may be NULL for newly introduced PHI nodes. */
1521 if (arg
1522 && TREE_CODE (arg) == SSA_NAME
1523 && walk_use_def_chains_1 (arg, fn, data, visited, is_dfs))
1524 return true;
1527 /* When doing a depth-first search, call FN after following the
1528 use-def links for each argument. */
1529 if (is_dfs)
1530 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1531 if (fn (gimple_phi_arg_def (def_stmt, i), def_stmt, data))
1532 return true;
1535 return false;
1540 /* Walk use-def chains starting at the SSA variable VAR. Call
1541 function FN at each reaching definition found. FN takes three
1542 arguments: VAR, its defining statement (DEF_STMT) and a generic
1543 pointer to whatever state information that FN may want to maintain
1544 (DATA). FN is able to stop the walk by returning true, otherwise
1545 in order to continue the walk, FN should return false.
1547 Note, that if DEF_STMT is a PHI node, the semantics are slightly
1548 different. The first argument to FN is no longer the original
1549 variable VAR, but the PHI argument currently being examined. If FN
1550 wants to get at VAR, it should call PHI_RESULT (PHI).
1552 If IS_DFS is true, this function will:
1554 1- walk the use-def chains for all the PHI arguments, and,
1555 2- call (*FN) (ARG, PHI, DATA) on all the PHI arguments.
1557 If IS_DFS is false, the two steps above are done in reverse order
1558 (i.e., a breadth-first search). */
1560 void
1561 walk_use_def_chains (tree var, walk_use_def_chains_fn fn, void *data,
1562 bool is_dfs)
1564 gimple def_stmt;
1566 gcc_assert (TREE_CODE (var) == SSA_NAME);
1568 def_stmt = SSA_NAME_DEF_STMT (var);
1570 /* We only need to recurse if the reaching definition comes from a PHI
1571 node. */
1572 if (gimple_code (def_stmt) != GIMPLE_PHI)
1573 (*fn) (var, def_stmt, data);
1574 else
1576 struct pointer_set_t *visited = pointer_set_create ();
1577 walk_use_def_chains_1 (var, fn, data, visited, is_dfs);
1578 pointer_set_destroy (visited);
1583 /* Emit warnings for uninitialized variables. This is done in two passes.
1585 The first pass notices real uses of SSA names with undefined values.
1586 Such uses are unconditionally uninitialized, and we can be certain that
1587 such a use is a mistake. This pass is run before most optimizations,
1588 so that we catch as many as we can.
1590 The second pass follows PHI nodes to find uses that are potentially
1591 uninitialized. In this case we can't necessarily prove that the use
1592 is really uninitialized. This pass is run after most optimizations,
1593 so that we thread as many jumps and possible, and delete as much dead
1594 code as possible, in order to reduce false positives. We also look
1595 again for plain uninitialized variables, since optimization may have
1596 changed conditionally uninitialized to unconditionally uninitialized. */
1598 /* Emit a warning for EXPR based on variable VAR at the point in the
1599 program T, an SSA_NAME, is used being uninitialized. The exact
1600 warning text is in MSGID and LOCUS may contain a location or be null.
1601 WC is the warning code. */
1603 void
1604 warn_uninit (enum opt_code wc, tree t,
1605 tree expr, tree var, const char *gmsgid, void *data)
1607 gimple context = (gimple) data;
1608 location_t location, cfun_loc;
1609 expanded_location xloc, floc;
1611 if (!ssa_undefined_value_p (t))
1612 return;
1614 /* TREE_NO_WARNING either means we already warned, or the front end
1615 wishes to suppress the warning. */
1616 if ((context
1617 && (gimple_no_warning_p (context)
1618 || (gimple_assign_single_p (context)
1619 && TREE_NO_WARNING (gimple_assign_rhs1 (context)))))
1620 || TREE_NO_WARNING (expr))
1621 return;
1623 location = (context != NULL && gimple_has_location (context))
1624 ? gimple_location (context)
1625 : DECL_SOURCE_LOCATION (var);
1626 location = linemap_resolve_location (line_table, location,
1627 LRK_SPELLING_LOCATION,
1628 NULL);
1629 cfun_loc = DECL_SOURCE_LOCATION (cfun->decl);
1630 xloc = expand_location (location);
1631 floc = expand_location (cfun_loc);
1632 if (warning_at (location, wc, gmsgid, expr))
1634 TREE_NO_WARNING (expr) = 1;
1636 if (location == DECL_SOURCE_LOCATION (var))
1637 return;
1638 if (xloc.file != floc.file
1639 || linemap_location_before_p (line_table,
1640 location, cfun_loc)
1641 || linemap_location_before_p (line_table,
1642 cfun->function_end_locus,
1643 location))
1644 inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var);
1648 unsigned int
1649 warn_uninitialized_vars (bool warn_possibly_uninitialized)
1651 gimple_stmt_iterator gsi;
1652 basic_block bb;
1654 FOR_EACH_BB (bb)
1656 bool always_executed = dominated_by_p (CDI_POST_DOMINATORS,
1657 single_succ (ENTRY_BLOCK_PTR), bb);
1658 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1660 gimple stmt = gsi_stmt (gsi);
1661 use_operand_p use_p;
1662 ssa_op_iter op_iter;
1663 tree use;
1665 if (is_gimple_debug (stmt))
1666 continue;
1668 /* We only do data flow with SSA_NAMEs, so that's all we
1669 can warn about. */
1670 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, op_iter, SSA_OP_USE)
1672 use = USE_FROM_PTR (use_p);
1673 if (always_executed)
1674 warn_uninit (OPT_Wuninitialized, use,
1675 SSA_NAME_VAR (use), SSA_NAME_VAR (use),
1676 "%qD is used uninitialized in this function",
1677 stmt);
1678 else if (warn_possibly_uninitialized)
1679 warn_uninit (OPT_Wmaybe_uninitialized, use,
1680 SSA_NAME_VAR (use), SSA_NAME_VAR (use),
1681 "%qD may be used uninitialized in this function",
1682 stmt);
1685 /* For memory the only cheap thing we can do is see if we
1686 have a use of the default def of the virtual operand.
1687 ??? Note that at -O0 we do not have virtual operands.
1688 ??? Not so cheap would be to use the alias oracle via
1689 walk_aliased_vdefs, if we don't find any aliasing vdef
1690 warn as is-used-uninitialized, if we don't find an aliasing
1691 vdef that kills our use (stmt_kills_ref_p), warn as
1692 may-be-used-uninitialized. But this walk is quadratic and
1693 so must be limited which means we would miss warning
1694 opportunities. */
1695 use = gimple_vuse (stmt);
1696 if (use
1697 && gimple_assign_single_p (stmt)
1698 && !gimple_vdef (stmt)
1699 && SSA_NAME_IS_DEFAULT_DEF (use))
1701 tree rhs = gimple_assign_rhs1 (stmt);
1702 tree base = get_base_address (rhs);
1704 /* Do not warn if it can be initialized outside this function. */
1705 if (TREE_CODE (base) != VAR_DECL
1706 || DECL_HARD_REGISTER (base)
1707 || is_global_var (base))
1708 continue;
1710 if (always_executed)
1711 warn_uninit (OPT_Wuninitialized, use,
1712 gimple_assign_rhs1 (stmt), base,
1713 "%qE is used uninitialized in this function",
1714 stmt);
1715 else if (warn_possibly_uninitialized)
1716 warn_uninit (OPT_Wmaybe_uninitialized, use,
1717 gimple_assign_rhs1 (stmt), base,
1718 "%qE may be used uninitialized in this function",
1719 stmt);
1724 return 0;
1727 static unsigned int
1728 execute_early_warn_uninitialized (void)
1730 /* Currently, this pass runs always but
1731 execute_late_warn_uninitialized only runs with optimization. With
1732 optimization we want to warn about possible uninitialized as late
1733 as possible, thus don't do it here. However, without
1734 optimization we need to warn here about "may be uninitialized".
1736 calculate_dominance_info (CDI_POST_DOMINATORS);
1738 warn_uninitialized_vars (/*warn_possibly_uninitialized=*/!optimize);
1740 /* Post-dominator information can not be reliably updated. Free it
1741 after the use. */
1743 free_dominance_info (CDI_POST_DOMINATORS);
1744 return 0;
1747 static bool
1748 gate_warn_uninitialized (void)
1750 return warn_uninitialized != 0;
1753 struct gimple_opt_pass pass_early_warn_uninitialized =
1756 GIMPLE_PASS,
1757 "*early_warn_uninitialized", /* name */
1758 OPTGROUP_NONE, /* optinfo_flags */
1759 gate_warn_uninitialized, /* gate */
1760 execute_early_warn_uninitialized, /* execute */
1761 NULL, /* sub */
1762 NULL, /* next */
1763 0, /* static_pass_number */
1764 TV_TREE_UNINIT, /* tv_id */
1765 PROP_ssa, /* properties_required */
1766 0, /* properties_provided */
1767 0, /* properties_destroyed */
1768 0, /* todo_flags_start */
1769 0 /* todo_flags_finish */
1774 /* If necessary, rewrite the base of the reference tree *TP from
1775 a MEM_REF to a plain or converted symbol. */
1777 static void
1778 maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
1780 tree sym;
1782 while (handled_component_p (*tp))
1783 tp = &TREE_OPERAND (*tp, 0);
1784 if (TREE_CODE (*tp) == MEM_REF
1785 && TREE_CODE (TREE_OPERAND (*tp, 0)) == ADDR_EXPR
1786 && (sym = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0))
1787 && DECL_P (sym)
1788 && !TREE_ADDRESSABLE (sym)
1789 && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
1791 if (TREE_CODE (TREE_TYPE (sym)) == VECTOR_TYPE
1792 && useless_type_conversion_p (TREE_TYPE (*tp),
1793 TREE_TYPE (TREE_TYPE (sym)))
1794 && multiple_of_p (sizetype, TREE_OPERAND (*tp, 1),
1795 TYPE_SIZE_UNIT (TREE_TYPE (*tp))))
1797 *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
1798 TYPE_SIZE (TREE_TYPE (*tp)),
1799 int_const_binop (MULT_EXPR,
1800 bitsize_int (BITS_PER_UNIT),
1801 TREE_OPERAND (*tp, 1)));
1803 else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
1804 && useless_type_conversion_p (TREE_TYPE (*tp),
1805 TREE_TYPE (TREE_TYPE (sym))))
1807 *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
1808 ? REALPART_EXPR : IMAGPART_EXPR,
1809 TREE_TYPE (*tp), sym);
1811 else if (integer_zerop (TREE_OPERAND (*tp, 1)))
1813 if (!useless_type_conversion_p (TREE_TYPE (*tp),
1814 TREE_TYPE (sym)))
1815 *tp = build1 (VIEW_CONVERT_EXPR,
1816 TREE_TYPE (*tp), sym);
1817 else
1818 *tp = sym;
1823 /* For a tree REF return its base if it is the base of a MEM_REF
1824 that cannot be rewritten into SSA form. Otherwise return NULL_TREE. */
1826 static tree
1827 non_rewritable_mem_ref_base (tree ref)
1829 tree base = ref;
1831 /* A plain decl does not need it set. */
1832 if (DECL_P (ref))
1833 return NULL_TREE;
1835 while (handled_component_p (base))
1836 base = TREE_OPERAND (base, 0);
1838 /* But watch out for MEM_REFs we cannot lower to a
1839 VIEW_CONVERT_EXPR or a BIT_FIELD_REF. */
1840 if (TREE_CODE (base) == MEM_REF
1841 && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
1843 tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
1844 if ((TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
1845 || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
1846 && useless_type_conversion_p (TREE_TYPE (base),
1847 TREE_TYPE (TREE_TYPE (decl)))
1848 && mem_ref_offset (base).fits_uhwi ()
1849 && tree_to_double_int (TYPE_SIZE_UNIT (TREE_TYPE (decl)))
1850 .ugt (mem_ref_offset (base))
1851 && multiple_of_p (sizetype, TREE_OPERAND (base, 1),
1852 TYPE_SIZE_UNIT (TREE_TYPE (base))))
1853 return NULL_TREE;
1854 if (DECL_P (decl)
1855 && (!integer_zerop (TREE_OPERAND (base, 1))
1856 || (DECL_SIZE (decl)
1857 != TYPE_SIZE (TREE_TYPE (base)))
1858 || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base)))
1859 return decl;
1862 return NULL_TREE;
1865 /* For an lvalue tree LHS return true if it cannot be rewritten into SSA form.
1866 Otherwise return true. */
1868 static bool
1869 non_rewritable_lvalue_p (tree lhs)
1871 /* A plain decl is always rewritable. */
1872 if (DECL_P (lhs))
1873 return false;
1875 /* A decl that is wrapped inside a MEM-REF that covers
1876 it full is also rewritable.
1877 ??? The following could be relaxed allowing component
1878 references that do not change the access size. */
1879 if (TREE_CODE (lhs) == MEM_REF
1880 && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
1881 && integer_zerop (TREE_OPERAND (lhs, 1)))
1883 tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
1884 if (DECL_P (decl)
1885 && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
1886 && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
1887 return false;
1890 return true;
1893 /* When possible, clear TREE_ADDRESSABLE bit or set DECL_GIMPLE_REG_P bit and
1894 mark the variable VAR for conversion into SSA. Return true when updating
1895 stmts is required. */
1897 static void
1898 maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
1899 bitmap suitable_for_renaming)
1901 /* Global Variables, result decls cannot be changed. */
1902 if (is_global_var (var)
1903 || TREE_CODE (var) == RESULT_DECL
1904 || bitmap_bit_p (addresses_taken, DECL_UID (var)))
1905 return;
1907 if (TREE_ADDRESSABLE (var)
1908 /* Do not change TREE_ADDRESSABLE if we need to preserve var as
1909 a non-register. Otherwise we are confused and forget to
1910 add virtual operands for it. */
1911 && (!is_gimple_reg_type (TREE_TYPE (var))
1912 || TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE
1913 || TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE
1914 || !bitmap_bit_p (not_reg_needs, DECL_UID (var))))
1916 TREE_ADDRESSABLE (var) = 0;
1917 if (is_gimple_reg (var))
1918 bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
1919 if (dump_file)
1921 fprintf (dump_file, "No longer having address taken: ");
1922 print_generic_expr (dump_file, var, 0);
1923 fprintf (dump_file, "\n");
1927 if (!DECL_GIMPLE_REG_P (var)
1928 && !bitmap_bit_p (not_reg_needs, DECL_UID (var))
1929 && (TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE
1930 || TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE)
1931 && !TREE_THIS_VOLATILE (var)
1932 && (TREE_CODE (var) != VAR_DECL || !DECL_HARD_REGISTER (var)))
1934 DECL_GIMPLE_REG_P (var) = 1;
1935 bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
1936 if (dump_file)
1938 fprintf (dump_file, "Now a gimple register: ");
1939 print_generic_expr (dump_file, var, 0);
1940 fprintf (dump_file, "\n");
1945 /* Compute TREE_ADDRESSABLE and DECL_GIMPLE_REG_P for local variables. */
1947 void
1948 execute_update_addresses_taken (void)
1950 gimple_stmt_iterator gsi;
1951 basic_block bb;
1952 bitmap addresses_taken = BITMAP_ALLOC (NULL);
1953 bitmap not_reg_needs = BITMAP_ALLOC (NULL);
1954 bitmap suitable_for_renaming = BITMAP_ALLOC (NULL);
1955 tree var;
1956 unsigned i;
1958 timevar_push (TV_ADDRESS_TAKEN);
1960 /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
1961 the function body. */
1962 FOR_EACH_BB (bb)
1964 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1966 gimple stmt = gsi_stmt (gsi);
1967 enum gimple_code code = gimple_code (stmt);
1968 tree decl;
1970 /* Note all addresses taken by the stmt. */
1971 gimple_ior_addresses_taken (addresses_taken, stmt);
1973 /* If we have a call or an assignment, see if the lhs contains
1974 a local decl that requires not to be a gimple register. */
1975 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
1977 tree lhs = gimple_get_lhs (stmt);
1978 if (lhs
1979 && TREE_CODE (lhs) != SSA_NAME
1980 && non_rewritable_lvalue_p (lhs))
1982 decl = get_base_address (lhs);
1983 if (DECL_P (decl))
1984 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
1988 if (gimple_assign_single_p (stmt))
1990 tree rhs = gimple_assign_rhs1 (stmt);
1991 if ((decl = non_rewritable_mem_ref_base (rhs)))
1992 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
1995 else if (code == GIMPLE_CALL)
1997 for (i = 0; i < gimple_call_num_args (stmt); ++i)
1999 tree arg = gimple_call_arg (stmt, i);
2000 if ((decl = non_rewritable_mem_ref_base (arg)))
2001 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2005 else if (code == GIMPLE_ASM)
2007 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
2009 tree link = gimple_asm_output_op (stmt, i);
2010 tree lhs = TREE_VALUE (link);
2011 if (TREE_CODE (lhs) != SSA_NAME)
2013 decl = get_base_address (lhs);
2014 if (DECL_P (decl)
2015 && (non_rewritable_lvalue_p (lhs)
2016 /* We cannot move required conversions from
2017 the lhs to the rhs in asm statements, so
2018 require we do not need any. */
2019 || !useless_type_conversion_p
2020 (TREE_TYPE (lhs), TREE_TYPE (decl))))
2021 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2024 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
2026 tree link = gimple_asm_input_op (stmt, i);
2027 if ((decl = non_rewritable_mem_ref_base (TREE_VALUE (link))))
2028 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2033 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2035 size_t i;
2036 gimple phi = gsi_stmt (gsi);
2038 for (i = 0; i < gimple_phi_num_args (phi); i++)
2040 tree op = PHI_ARG_DEF (phi, i), var;
2041 if (TREE_CODE (op) == ADDR_EXPR
2042 && (var = get_base_address (TREE_OPERAND (op, 0))) != NULL
2043 && DECL_P (var))
2044 bitmap_set_bit (addresses_taken, DECL_UID (var));
2049 /* We cannot iterate over all referenced vars because that can contain
2050 unused vars from BLOCK trees, which causes code generation differences
2051 for -g vs. -g0. */
2052 for (var = DECL_ARGUMENTS (cfun->decl); var; var = DECL_CHAIN (var))
2053 maybe_optimize_var (var, addresses_taken, not_reg_needs,
2054 suitable_for_renaming);
2056 FOR_EACH_VEC_SAFE_ELT (cfun->local_decls, i, var)
2057 maybe_optimize_var (var, addresses_taken, not_reg_needs,
2058 suitable_for_renaming);
2060 /* Operand caches need to be recomputed for operands referencing the updated
2061 variables and operands need to be rewritten to expose bare symbols. */
2062 if (!bitmap_empty_p (suitable_for_renaming))
2064 FOR_EACH_BB (bb)
2065 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
2067 gimple stmt = gsi_stmt (gsi);
2069 /* Re-write TARGET_MEM_REFs of symbols we want to
2070 rewrite into SSA form. */
2071 if (gimple_assign_single_p (stmt))
2073 tree lhs = gimple_assign_lhs (stmt);
2074 tree rhs, *rhsp = gimple_assign_rhs1_ptr (stmt);
2075 tree sym;
2077 /* We shouldn't have any fancy wrapping of
2078 component-refs on the LHS, but look through
2079 VIEW_CONVERT_EXPRs as that is easy. */
2080 while (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
2081 lhs = TREE_OPERAND (lhs, 0);
2082 if (TREE_CODE (lhs) == MEM_REF
2083 && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
2084 && integer_zerop (TREE_OPERAND (lhs, 1))
2085 && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
2086 && DECL_P (sym)
2087 && !TREE_ADDRESSABLE (sym)
2088 && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
2089 lhs = sym;
2090 else
2091 lhs = gimple_assign_lhs (stmt);
2093 /* Rewrite the RHS and make sure the resulting assignment
2094 is validly typed. */
2095 maybe_rewrite_mem_ref_base (rhsp, suitable_for_renaming);
2096 rhs = gimple_assign_rhs1 (stmt);
2097 if (gimple_assign_lhs (stmt) != lhs
2098 && !useless_type_conversion_p (TREE_TYPE (lhs),
2099 TREE_TYPE (rhs)))
2100 rhs = fold_build1 (VIEW_CONVERT_EXPR,
2101 TREE_TYPE (lhs), rhs);
2103 if (gimple_assign_lhs (stmt) != lhs)
2104 gimple_assign_set_lhs (stmt, lhs);
2106 /* For var ={v} {CLOBBER}; where var lost
2107 TREE_ADDRESSABLE just remove the stmt. */
2108 if (DECL_P (lhs)
2109 && TREE_CLOBBER_P (rhs)
2110 && bitmap_bit_p (suitable_for_renaming, DECL_UID (lhs)))
2112 unlink_stmt_vdef (stmt);
2113 gsi_remove (&gsi, true);
2114 release_defs (stmt);
2115 continue;
2118 if (gimple_assign_rhs1 (stmt) != rhs)
2120 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
2121 gimple_assign_set_rhs_from_tree (&gsi, rhs);
2125 else if (gimple_code (stmt) == GIMPLE_CALL)
2127 unsigned i;
2128 for (i = 0; i < gimple_call_num_args (stmt); ++i)
2130 tree *argp = gimple_call_arg_ptr (stmt, i);
2131 maybe_rewrite_mem_ref_base (argp, suitable_for_renaming);
2135 else if (gimple_code (stmt) == GIMPLE_ASM)
2137 unsigned i;
2138 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
2140 tree link = gimple_asm_output_op (stmt, i);
2141 maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
2142 suitable_for_renaming);
2144 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
2146 tree link = gimple_asm_input_op (stmt, i);
2147 maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
2148 suitable_for_renaming);
2152 else if (gimple_debug_bind_p (stmt)
2153 && gimple_debug_bind_has_value_p (stmt))
2155 tree *valuep = gimple_debug_bind_get_value_ptr (stmt);
2156 tree decl;
2157 maybe_rewrite_mem_ref_base (valuep, suitable_for_renaming);
2158 decl = non_rewritable_mem_ref_base (*valuep);
2159 if (decl
2160 && bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
2161 gimple_debug_bind_reset_value (stmt);
2164 if (gimple_references_memory_p (stmt)
2165 || is_gimple_debug (stmt))
2166 update_stmt (stmt);
2168 gsi_next (&gsi);
2171 /* Update SSA form here, we are called as non-pass as well. */
2172 if (number_of_loops () > 1 && loops_state_satisfies_p (LOOP_CLOSED_SSA))
2173 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
2174 else
2175 update_ssa (TODO_update_ssa);
2178 BITMAP_FREE (not_reg_needs);
2179 BITMAP_FREE (addresses_taken);
2180 BITMAP_FREE (suitable_for_renaming);
2181 timevar_pop (TV_ADDRESS_TAKEN);
2184 struct gimple_opt_pass pass_update_address_taken =
2187 GIMPLE_PASS,
2188 "addressables", /* name */
2189 OPTGROUP_NONE, /* optinfo_flags */
2190 NULL, /* gate */
2191 NULL, /* execute */
2192 NULL, /* sub */
2193 NULL, /* next */
2194 0, /* static_pass_number */
2195 TV_ADDRESS_TAKEN, /* tv_id */
2196 PROP_ssa, /* properties_required */
2197 0, /* properties_provided */
2198 0, /* properties_destroyed */
2199 0, /* todo_flags_start */
2200 TODO_update_address_taken /* todo_flags_finish */