PR target/54640
[official-gcc.git] / gcc / tree-ssa.c
blobe08bcf89970be10b9b8be5ca821f5885dbe40064
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_IN_FREE_LIST (ssa_name))
631 error ("found an SSA_NAME that had been released into the free pool");
632 return true;
635 if (SSA_NAME_VAR (ssa_name) != NULL_TREE
636 && TREE_TYPE (ssa_name) != TREE_TYPE (SSA_NAME_VAR (ssa_name)))
638 error ("type mismatch between an SSA_NAME and its symbol");
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 /* Do not lose casts between pointers to different address spaces. */
1205 if (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
1206 != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
1207 return false;
1210 /* From now on qualifiers on value types do not matter. */
1211 inner_type = TYPE_MAIN_VARIANT (inner_type);
1212 outer_type = TYPE_MAIN_VARIANT (outer_type);
1214 if (inner_type == outer_type)
1215 return true;
1217 /* If we know the canonical types, compare them. */
1218 if (TYPE_CANONICAL (inner_type)
1219 && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type))
1220 return true;
1222 /* Changes in machine mode are never useless conversions unless we
1223 deal with aggregate types in which case we defer to later checks. */
1224 if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type)
1225 && !AGGREGATE_TYPE_P (inner_type))
1226 return false;
1228 /* If both the inner and outer types are integral types, then the
1229 conversion is not necessary if they have the same mode and
1230 signedness and precision, and both or neither are boolean. */
1231 if (INTEGRAL_TYPE_P (inner_type)
1232 && INTEGRAL_TYPE_P (outer_type))
1234 /* Preserve changes in signedness or precision. */
1235 if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
1236 || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
1237 return false;
1239 /* Preserve conversions to/from BOOLEAN_TYPE if types are not
1240 of precision one. */
1241 if (((TREE_CODE (inner_type) == BOOLEAN_TYPE)
1242 != (TREE_CODE (outer_type) == BOOLEAN_TYPE))
1243 && TYPE_PRECISION (outer_type) != 1)
1244 return false;
1246 /* We don't need to preserve changes in the types minimum or
1247 maximum value in general as these do not generate code
1248 unless the types precisions are different. */
1249 return true;
1252 /* Scalar floating point types with the same mode are compatible. */
1253 else if (SCALAR_FLOAT_TYPE_P (inner_type)
1254 && SCALAR_FLOAT_TYPE_P (outer_type))
1255 return true;
1257 /* Fixed point types with the same mode are compatible. */
1258 else if (FIXED_POINT_TYPE_P (inner_type)
1259 && FIXED_POINT_TYPE_P (outer_type))
1260 return true;
1262 /* We need to take special care recursing to pointed-to types. */
1263 else if (POINTER_TYPE_P (inner_type)
1264 && POINTER_TYPE_P (outer_type))
1266 /* Do not lose casts to function pointer types. */
1267 if ((TREE_CODE (TREE_TYPE (outer_type)) == FUNCTION_TYPE
1268 || TREE_CODE (TREE_TYPE (outer_type)) == METHOD_TYPE)
1269 && !(TREE_CODE (TREE_TYPE (inner_type)) == FUNCTION_TYPE
1270 || TREE_CODE (TREE_TYPE (inner_type)) == METHOD_TYPE))
1271 return false;
1273 /* We do not care for const qualification of the pointed-to types
1274 as const qualification has no semantic value to the middle-end. */
1276 /* Otherwise pointers/references are equivalent. */
1277 return true;
1280 /* Recurse for complex types. */
1281 else if (TREE_CODE (inner_type) == COMPLEX_TYPE
1282 && TREE_CODE (outer_type) == COMPLEX_TYPE)
1283 return useless_type_conversion_p (TREE_TYPE (outer_type),
1284 TREE_TYPE (inner_type));
1286 /* Recurse for vector types with the same number of subparts. */
1287 else if (TREE_CODE (inner_type) == VECTOR_TYPE
1288 && TREE_CODE (outer_type) == VECTOR_TYPE
1289 && TYPE_PRECISION (inner_type) == TYPE_PRECISION (outer_type))
1290 return useless_type_conversion_p (TREE_TYPE (outer_type),
1291 TREE_TYPE (inner_type));
1293 else if (TREE_CODE (inner_type) == ARRAY_TYPE
1294 && TREE_CODE (outer_type) == ARRAY_TYPE)
1296 /* Preserve string attributes. */
1297 if (TYPE_STRING_FLAG (inner_type) != TYPE_STRING_FLAG (outer_type))
1298 return false;
1300 /* Conversions from array types with unknown extent to
1301 array types with known extent are not useless. */
1302 if (!TYPE_DOMAIN (inner_type)
1303 && TYPE_DOMAIN (outer_type))
1304 return false;
1306 /* Nor are conversions from array types with non-constant size to
1307 array types with constant size or to different size. */
1308 if (TYPE_SIZE (outer_type)
1309 && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST
1310 && (!TYPE_SIZE (inner_type)
1311 || TREE_CODE (TYPE_SIZE (inner_type)) != INTEGER_CST
1312 || !tree_int_cst_equal (TYPE_SIZE (outer_type),
1313 TYPE_SIZE (inner_type))))
1314 return false;
1316 /* Check conversions between arrays with partially known extents.
1317 If the array min/max values are constant they have to match.
1318 Otherwise allow conversions to unknown and variable extents.
1319 In particular this declares conversions that may change the
1320 mode to BLKmode as useless. */
1321 if (TYPE_DOMAIN (inner_type)
1322 && TYPE_DOMAIN (outer_type)
1323 && TYPE_DOMAIN (inner_type) != TYPE_DOMAIN (outer_type))
1325 tree inner_min = TYPE_MIN_VALUE (TYPE_DOMAIN (inner_type));
1326 tree outer_min = TYPE_MIN_VALUE (TYPE_DOMAIN (outer_type));
1327 tree inner_max = TYPE_MAX_VALUE (TYPE_DOMAIN (inner_type));
1328 tree outer_max = TYPE_MAX_VALUE (TYPE_DOMAIN (outer_type));
1330 /* After gimplification a variable min/max value carries no
1331 additional information compared to a NULL value. All that
1332 matters has been lowered to be part of the IL. */
1333 if (inner_min && TREE_CODE (inner_min) != INTEGER_CST)
1334 inner_min = NULL_TREE;
1335 if (outer_min && TREE_CODE (outer_min) != INTEGER_CST)
1336 outer_min = NULL_TREE;
1337 if (inner_max && TREE_CODE (inner_max) != INTEGER_CST)
1338 inner_max = NULL_TREE;
1339 if (outer_max && TREE_CODE (outer_max) != INTEGER_CST)
1340 outer_max = NULL_TREE;
1342 /* Conversions NULL / variable <- cst are useless, but not
1343 the other way around. */
1344 if (outer_min
1345 && (!inner_min
1346 || !tree_int_cst_equal (inner_min, outer_min)))
1347 return false;
1348 if (outer_max
1349 && (!inner_max
1350 || !tree_int_cst_equal (inner_max, outer_max)))
1351 return false;
1354 /* Recurse on the element check. */
1355 return useless_type_conversion_p (TREE_TYPE (outer_type),
1356 TREE_TYPE (inner_type));
1359 else if ((TREE_CODE (inner_type) == FUNCTION_TYPE
1360 || TREE_CODE (inner_type) == METHOD_TYPE)
1361 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
1363 tree outer_parm, inner_parm;
1365 /* If the return types are not compatible bail out. */
1366 if (!useless_type_conversion_p (TREE_TYPE (outer_type),
1367 TREE_TYPE (inner_type)))
1368 return false;
1370 /* Method types should belong to a compatible base class. */
1371 if (TREE_CODE (inner_type) == METHOD_TYPE
1372 && !useless_type_conversion_p (TYPE_METHOD_BASETYPE (outer_type),
1373 TYPE_METHOD_BASETYPE (inner_type)))
1374 return false;
1376 /* A conversion to an unprototyped argument list is ok. */
1377 if (!prototype_p (outer_type))
1378 return true;
1380 /* If the unqualified argument types are compatible the conversion
1381 is useless. */
1382 if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type))
1383 return true;
1385 for (outer_parm = TYPE_ARG_TYPES (outer_type),
1386 inner_parm = TYPE_ARG_TYPES (inner_type);
1387 outer_parm && inner_parm;
1388 outer_parm = TREE_CHAIN (outer_parm),
1389 inner_parm = TREE_CHAIN (inner_parm))
1390 if (!useless_type_conversion_p
1391 (TYPE_MAIN_VARIANT (TREE_VALUE (outer_parm)),
1392 TYPE_MAIN_VARIANT (TREE_VALUE (inner_parm))))
1393 return false;
1395 /* If there is a mismatch in the number of arguments the functions
1396 are not compatible. */
1397 if (outer_parm || inner_parm)
1398 return false;
1400 /* Defer to the target if necessary. */
1401 if (TYPE_ATTRIBUTES (inner_type) || TYPE_ATTRIBUTES (outer_type))
1402 return comp_type_attributes (outer_type, inner_type) != 0;
1404 return true;
1407 /* For aggregates we rely on TYPE_CANONICAL exclusively and require
1408 explicit conversions for types involving to be structurally
1409 compared types. */
1410 else if (AGGREGATE_TYPE_P (inner_type)
1411 && TREE_CODE (inner_type) == TREE_CODE (outer_type))
1412 return false;
1414 return false;
1417 /* Return true if a conversion from either type of TYPE1 and TYPE2
1418 to the other is not required. Otherwise return false. */
1420 bool
1421 types_compatible_p (tree type1, tree type2)
1423 return (type1 == type2
1424 || (useless_type_conversion_p (type1, type2)
1425 && useless_type_conversion_p (type2, type1)));
1428 /* Return true if EXPR is a useless type conversion, otherwise return
1429 false. */
1431 bool
1432 tree_ssa_useless_type_conversion (tree expr)
1434 /* If we have an assignment that merely uses a NOP_EXPR to change
1435 the top of the RHS to the type of the LHS and the type conversion
1436 is "safe", then strip away the type conversion so that we can
1437 enter LHS = RHS into the const_and_copies table. */
1438 if (CONVERT_EXPR_P (expr)
1439 || TREE_CODE (expr) == VIEW_CONVERT_EXPR
1440 || TREE_CODE (expr) == NON_LVALUE_EXPR)
1441 return useless_type_conversion_p
1442 (TREE_TYPE (expr),
1443 TREE_TYPE (TREE_OPERAND (expr, 0)));
1445 return false;
1448 /* Strip conversions from EXP according to
1449 tree_ssa_useless_type_conversion and return the resulting
1450 expression. */
1452 tree
1453 tree_ssa_strip_useless_type_conversions (tree exp)
1455 while (tree_ssa_useless_type_conversion (exp))
1456 exp = TREE_OPERAND (exp, 0);
1457 return exp;
1461 /* Internal helper for walk_use_def_chains. VAR, FN and DATA are as
1462 described in walk_use_def_chains.
1464 VISITED is a pointer set used to mark visited SSA_NAMEs to avoid
1465 infinite loops. We used to have a bitmap for this to just mark
1466 SSA versions we had visited. But non-sparse bitmaps are way too
1467 expensive, while sparse bitmaps may cause quadratic behavior.
1469 IS_DFS is true if the caller wants to perform a depth-first search
1470 when visiting PHI nodes. A DFS will visit each PHI argument and
1471 call FN after each one. Otherwise, all the arguments are
1472 visited first and then FN is called with each of the visited
1473 arguments in a separate pass. */
1475 static bool
1476 walk_use_def_chains_1 (tree var, walk_use_def_chains_fn fn, void *data,
1477 struct pointer_set_t *visited, bool is_dfs)
1479 gimple def_stmt;
1481 if (pointer_set_insert (visited, var))
1482 return false;
1484 def_stmt = SSA_NAME_DEF_STMT (var);
1486 if (gimple_code (def_stmt) != GIMPLE_PHI)
1488 /* If we reached the end of the use-def chain, call FN. */
1489 return fn (var, def_stmt, data);
1491 else
1493 size_t i;
1495 /* When doing a breadth-first search, call FN before following the
1496 use-def links for each argument. */
1497 if (!is_dfs)
1498 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1499 if (fn (gimple_phi_arg_def (def_stmt, i), def_stmt, data))
1500 return true;
1502 /* Follow use-def links out of each PHI argument. */
1503 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1505 tree arg = gimple_phi_arg_def (def_stmt, i);
1507 /* ARG may be NULL for newly introduced PHI nodes. */
1508 if (arg
1509 && TREE_CODE (arg) == SSA_NAME
1510 && walk_use_def_chains_1 (arg, fn, data, visited, is_dfs))
1511 return true;
1514 /* When doing a depth-first search, call FN after following the
1515 use-def links for each argument. */
1516 if (is_dfs)
1517 for (i = 0; i < gimple_phi_num_args (def_stmt); i++)
1518 if (fn (gimple_phi_arg_def (def_stmt, i), def_stmt, data))
1519 return true;
1522 return false;
1527 /* Walk use-def chains starting at the SSA variable VAR. Call
1528 function FN at each reaching definition found. FN takes three
1529 arguments: VAR, its defining statement (DEF_STMT) and a generic
1530 pointer to whatever state information that FN may want to maintain
1531 (DATA). FN is able to stop the walk by returning true, otherwise
1532 in order to continue the walk, FN should return false.
1534 Note, that if DEF_STMT is a PHI node, the semantics are slightly
1535 different. The first argument to FN is no longer the original
1536 variable VAR, but the PHI argument currently being examined. If FN
1537 wants to get at VAR, it should call PHI_RESULT (PHI).
1539 If IS_DFS is true, this function will:
1541 1- walk the use-def chains for all the PHI arguments, and,
1542 2- call (*FN) (ARG, PHI, DATA) on all the PHI arguments.
1544 If IS_DFS is false, the two steps above are done in reverse order
1545 (i.e., a breadth-first search). */
1547 void
1548 walk_use_def_chains (tree var, walk_use_def_chains_fn fn, void *data,
1549 bool is_dfs)
1551 gimple def_stmt;
1553 gcc_assert (TREE_CODE (var) == SSA_NAME);
1555 def_stmt = SSA_NAME_DEF_STMT (var);
1557 /* We only need to recurse if the reaching definition comes from a PHI
1558 node. */
1559 if (gimple_code (def_stmt) != GIMPLE_PHI)
1560 (*fn) (var, def_stmt, data);
1561 else
1563 struct pointer_set_t *visited = pointer_set_create ();
1564 walk_use_def_chains_1 (var, fn, data, visited, is_dfs);
1565 pointer_set_destroy (visited);
1570 /* Emit warnings for uninitialized variables. This is done in two passes.
1572 The first pass notices real uses of SSA names with undefined values.
1573 Such uses are unconditionally uninitialized, and we can be certain that
1574 such a use is a mistake. This pass is run before most optimizations,
1575 so that we catch as many as we can.
1577 The second pass follows PHI nodes to find uses that are potentially
1578 uninitialized. In this case we can't necessarily prove that the use
1579 is really uninitialized. This pass is run after most optimizations,
1580 so that we thread as many jumps and possible, and delete as much dead
1581 code as possible, in order to reduce false positives. We also look
1582 again for plain uninitialized variables, since optimization may have
1583 changed conditionally uninitialized to unconditionally uninitialized. */
1585 /* Emit a warning for EXPR based on variable VAR at the point in the
1586 program T, an SSA_NAME, is used being uninitialized. The exact
1587 warning text is in MSGID and LOCUS may contain a location or be null.
1588 WC is the warning code. */
1590 void
1591 warn_uninit (enum opt_code wc, tree t,
1592 tree expr, tree var, const char *gmsgid, void *data)
1594 gimple context = (gimple) data;
1595 location_t location, cfun_loc;
1596 expanded_location xloc, floc;
1598 if (!ssa_undefined_value_p (t))
1599 return;
1601 /* TREE_NO_WARNING either means we already warned, or the front end
1602 wishes to suppress the warning. */
1603 if ((context
1604 && (gimple_no_warning_p (context)
1605 || (gimple_assign_single_p (context)
1606 && TREE_NO_WARNING (gimple_assign_rhs1 (context)))))
1607 || TREE_NO_WARNING (expr))
1608 return;
1610 location = (context != NULL && gimple_has_location (context))
1611 ? gimple_location (context)
1612 : DECL_SOURCE_LOCATION (var);
1613 location = linemap_resolve_location (line_table, location,
1614 LRK_SPELLING_LOCATION,
1615 NULL);
1616 cfun_loc = DECL_SOURCE_LOCATION (cfun->decl);
1617 xloc = expand_location (location);
1618 floc = expand_location (cfun_loc);
1619 if (warning_at (location, wc, gmsgid, expr))
1621 TREE_NO_WARNING (expr) = 1;
1623 if (location == DECL_SOURCE_LOCATION (var))
1624 return;
1625 if (xloc.file != floc.file
1626 || linemap_location_before_p (line_table,
1627 location, cfun_loc)
1628 || linemap_location_before_p (line_table,
1629 cfun->function_end_locus,
1630 location))
1631 inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var);
1635 unsigned int
1636 warn_uninitialized_vars (bool warn_possibly_uninitialized)
1638 gimple_stmt_iterator gsi;
1639 basic_block bb;
1641 FOR_EACH_BB (bb)
1643 bool always_executed = dominated_by_p (CDI_POST_DOMINATORS,
1644 single_succ (ENTRY_BLOCK_PTR), bb);
1645 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1647 gimple stmt = gsi_stmt (gsi);
1648 use_operand_p use_p;
1649 ssa_op_iter op_iter;
1650 tree use;
1652 if (is_gimple_debug (stmt))
1653 continue;
1655 /* We only do data flow with SSA_NAMEs, so that's all we
1656 can warn about. */
1657 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, op_iter, SSA_OP_USE)
1659 use = USE_FROM_PTR (use_p);
1660 if (always_executed)
1661 warn_uninit (OPT_Wuninitialized, use,
1662 SSA_NAME_VAR (use), SSA_NAME_VAR (use),
1663 "%qD is used uninitialized in this function",
1664 stmt);
1665 else if (warn_possibly_uninitialized)
1666 warn_uninit (OPT_Wmaybe_uninitialized, use,
1667 SSA_NAME_VAR (use), SSA_NAME_VAR (use),
1668 "%qD may be used uninitialized in this function",
1669 stmt);
1672 /* For memory the only cheap thing we can do is see if we
1673 have a use of the default def of the virtual operand.
1674 ??? Note that at -O0 we do not have virtual operands.
1675 ??? Not so cheap would be to use the alias oracle via
1676 walk_aliased_vdefs, if we don't find any aliasing vdef
1677 warn as is-used-uninitialized, if we don't find an aliasing
1678 vdef that kills our use (stmt_kills_ref_p), warn as
1679 may-be-used-uninitialized. But this walk is quadratic and
1680 so must be limited which means we would miss warning
1681 opportunities. */
1682 use = gimple_vuse (stmt);
1683 if (use
1684 && gimple_assign_single_p (stmt)
1685 && !gimple_vdef (stmt)
1686 && SSA_NAME_IS_DEFAULT_DEF (use))
1688 tree rhs = gimple_assign_rhs1 (stmt);
1689 tree base = get_base_address (rhs);
1691 /* Do not warn if it can be initialized outside this function. */
1692 if (TREE_CODE (base) != VAR_DECL
1693 || DECL_HARD_REGISTER (base)
1694 || is_global_var (base))
1695 continue;
1697 if (always_executed)
1698 warn_uninit (OPT_Wuninitialized, use,
1699 gimple_assign_rhs1 (stmt), base,
1700 "%qE is used uninitialized in this function",
1701 stmt);
1702 else if (warn_possibly_uninitialized)
1703 warn_uninit (OPT_Wmaybe_uninitialized, use,
1704 gimple_assign_rhs1 (stmt), base,
1705 "%qE may be used uninitialized in this function",
1706 stmt);
1711 return 0;
1714 static unsigned int
1715 execute_early_warn_uninitialized (void)
1717 /* Currently, this pass runs always but
1718 execute_late_warn_uninitialized only runs with optimization. With
1719 optimization we want to warn about possible uninitialized as late
1720 as possible, thus don't do it here. However, without
1721 optimization we need to warn here about "may be uninitialized".
1723 calculate_dominance_info (CDI_POST_DOMINATORS);
1725 warn_uninitialized_vars (/*warn_possibly_uninitialized=*/!optimize);
1727 /* Post-dominator information can not be reliably updated. Free it
1728 after the use. */
1730 free_dominance_info (CDI_POST_DOMINATORS);
1731 return 0;
1734 static bool
1735 gate_warn_uninitialized (void)
1737 return warn_uninitialized != 0;
1740 struct gimple_opt_pass pass_early_warn_uninitialized =
1743 GIMPLE_PASS,
1744 "*early_warn_uninitialized", /* name */
1745 OPTGROUP_NONE, /* optinfo_flags */
1746 gate_warn_uninitialized, /* gate */
1747 execute_early_warn_uninitialized, /* execute */
1748 NULL, /* sub */
1749 NULL, /* next */
1750 0, /* static_pass_number */
1751 TV_TREE_UNINIT, /* tv_id */
1752 PROP_ssa, /* properties_required */
1753 0, /* properties_provided */
1754 0, /* properties_destroyed */
1755 0, /* todo_flags_start */
1756 0 /* todo_flags_finish */
1761 /* If necessary, rewrite the base of the reference tree *TP from
1762 a MEM_REF to a plain or converted symbol. */
1764 static void
1765 maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
1767 tree sym;
1769 while (handled_component_p (*tp))
1770 tp = &TREE_OPERAND (*tp, 0);
1771 if (TREE_CODE (*tp) == MEM_REF
1772 && TREE_CODE (TREE_OPERAND (*tp, 0)) == ADDR_EXPR
1773 && (sym = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0))
1774 && DECL_P (sym)
1775 && !TREE_ADDRESSABLE (sym)
1776 && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
1778 if (TREE_CODE (TREE_TYPE (sym)) == VECTOR_TYPE
1779 && useless_type_conversion_p (TREE_TYPE (*tp),
1780 TREE_TYPE (TREE_TYPE (sym)))
1781 && multiple_of_p (sizetype, TREE_OPERAND (*tp, 1),
1782 TYPE_SIZE_UNIT (TREE_TYPE (*tp))))
1784 *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
1785 TYPE_SIZE (TREE_TYPE (*tp)),
1786 int_const_binop (MULT_EXPR,
1787 bitsize_int (BITS_PER_UNIT),
1788 TREE_OPERAND (*tp, 1)));
1790 else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
1791 && useless_type_conversion_p (TREE_TYPE (*tp),
1792 TREE_TYPE (TREE_TYPE (sym))))
1794 *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
1795 ? REALPART_EXPR : IMAGPART_EXPR,
1796 TREE_TYPE (*tp), sym);
1798 else if (integer_zerop (TREE_OPERAND (*tp, 1)))
1800 if (!useless_type_conversion_p (TREE_TYPE (*tp),
1801 TREE_TYPE (sym)))
1802 *tp = build1 (VIEW_CONVERT_EXPR,
1803 TREE_TYPE (*tp), sym);
1804 else
1805 *tp = sym;
1810 /* For a tree REF return its base if it is the base of a MEM_REF
1811 that cannot be rewritten into SSA form. Otherwise return NULL_TREE. */
1813 static tree
1814 non_rewritable_mem_ref_base (tree ref)
1816 tree base = ref;
1818 /* A plain decl does not need it set. */
1819 if (DECL_P (ref))
1820 return NULL_TREE;
1822 while (handled_component_p (base))
1823 base = TREE_OPERAND (base, 0);
1825 /* But watch out for MEM_REFs we cannot lower to a
1826 VIEW_CONVERT_EXPR or a BIT_FIELD_REF. */
1827 if (TREE_CODE (base) == MEM_REF
1828 && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
1830 tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
1831 if ((TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
1832 || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
1833 && useless_type_conversion_p (TREE_TYPE (base),
1834 TREE_TYPE (TREE_TYPE (decl)))
1835 && mem_ref_offset (base).fits_uhwi ()
1836 && tree_to_double_int (TYPE_SIZE_UNIT (TREE_TYPE (decl)))
1837 .ugt (mem_ref_offset (base))
1838 && multiple_of_p (sizetype, TREE_OPERAND (base, 1),
1839 TYPE_SIZE_UNIT (TREE_TYPE (base))))
1840 return NULL_TREE;
1841 if (DECL_P (decl)
1842 && (!integer_zerop (TREE_OPERAND (base, 1))
1843 || (DECL_SIZE (decl)
1844 != TYPE_SIZE (TREE_TYPE (base)))
1845 || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base)))
1846 return decl;
1849 return NULL_TREE;
1852 /* For an lvalue tree LHS return true if it cannot be rewritten into SSA form.
1853 Otherwise return true. */
1855 static bool
1856 non_rewritable_lvalue_p (tree lhs)
1858 /* A plain decl is always rewritable. */
1859 if (DECL_P (lhs))
1860 return false;
1862 /* A decl that is wrapped inside a MEM-REF that covers
1863 it full is also rewritable.
1864 ??? The following could be relaxed allowing component
1865 references that do not change the access size. */
1866 if (TREE_CODE (lhs) == MEM_REF
1867 && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
1868 && integer_zerop (TREE_OPERAND (lhs, 1)))
1870 tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
1871 if (DECL_P (decl)
1872 && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
1873 && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
1874 return false;
1877 return true;
1880 /* When possible, clear TREE_ADDRESSABLE bit or set DECL_GIMPLE_REG_P bit and
1881 mark the variable VAR for conversion into SSA. Return true when updating
1882 stmts is required. */
1884 static void
1885 maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
1886 bitmap suitable_for_renaming)
1888 /* Global Variables, result decls cannot be changed. */
1889 if (is_global_var (var)
1890 || TREE_CODE (var) == RESULT_DECL
1891 || bitmap_bit_p (addresses_taken, DECL_UID (var)))
1892 return;
1894 if (TREE_ADDRESSABLE (var)
1895 /* Do not change TREE_ADDRESSABLE if we need to preserve var as
1896 a non-register. Otherwise we are confused and forget to
1897 add virtual operands for it. */
1898 && (!is_gimple_reg_type (TREE_TYPE (var))
1899 || TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE
1900 || TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE
1901 || !bitmap_bit_p (not_reg_needs, DECL_UID (var))))
1903 TREE_ADDRESSABLE (var) = 0;
1904 if (is_gimple_reg (var))
1905 bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
1906 if (dump_file)
1908 fprintf (dump_file, "No longer having address taken: ");
1909 print_generic_expr (dump_file, var, 0);
1910 fprintf (dump_file, "\n");
1914 if (!DECL_GIMPLE_REG_P (var)
1915 && !bitmap_bit_p (not_reg_needs, DECL_UID (var))
1916 && (TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE
1917 || TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE)
1918 && !TREE_THIS_VOLATILE (var)
1919 && (TREE_CODE (var) != VAR_DECL || !DECL_HARD_REGISTER (var)))
1921 DECL_GIMPLE_REG_P (var) = 1;
1922 bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
1923 if (dump_file)
1925 fprintf (dump_file, "Now a gimple register: ");
1926 print_generic_expr (dump_file, var, 0);
1927 fprintf (dump_file, "\n");
1932 /* Compute TREE_ADDRESSABLE and DECL_GIMPLE_REG_P for local variables. */
1934 void
1935 execute_update_addresses_taken (void)
1937 gimple_stmt_iterator gsi;
1938 basic_block bb;
1939 bitmap addresses_taken = BITMAP_ALLOC (NULL);
1940 bitmap not_reg_needs = BITMAP_ALLOC (NULL);
1941 bitmap suitable_for_renaming = BITMAP_ALLOC (NULL);
1942 tree var;
1943 unsigned i;
1945 timevar_push (TV_ADDRESS_TAKEN);
1947 /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
1948 the function body. */
1949 FOR_EACH_BB (bb)
1951 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1953 gimple stmt = gsi_stmt (gsi);
1954 enum gimple_code code = gimple_code (stmt);
1955 tree decl;
1957 /* Note all addresses taken by the stmt. */
1958 gimple_ior_addresses_taken (addresses_taken, stmt);
1960 /* If we have a call or an assignment, see if the lhs contains
1961 a local decl that requires not to be a gimple register. */
1962 if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
1964 tree lhs = gimple_get_lhs (stmt);
1965 if (lhs
1966 && TREE_CODE (lhs) != SSA_NAME
1967 && non_rewritable_lvalue_p (lhs))
1969 decl = get_base_address (lhs);
1970 if (DECL_P (decl))
1971 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
1975 if (gimple_assign_single_p (stmt))
1977 tree rhs = gimple_assign_rhs1 (stmt);
1978 if ((decl = non_rewritable_mem_ref_base (rhs)))
1979 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
1982 else if (code == GIMPLE_CALL)
1984 for (i = 0; i < gimple_call_num_args (stmt); ++i)
1986 tree arg = gimple_call_arg (stmt, i);
1987 if ((decl = non_rewritable_mem_ref_base (arg)))
1988 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
1992 else if (code == GIMPLE_ASM)
1994 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
1996 tree link = gimple_asm_output_op (stmt, i);
1997 tree lhs = TREE_VALUE (link);
1998 if (TREE_CODE (lhs) != SSA_NAME)
2000 decl = get_base_address (lhs);
2001 if (DECL_P (decl)
2002 && (non_rewritable_lvalue_p (lhs)
2003 /* We cannot move required conversions from
2004 the lhs to the rhs in asm statements, so
2005 require we do not need any. */
2006 || !useless_type_conversion_p
2007 (TREE_TYPE (lhs), TREE_TYPE (decl))))
2008 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2011 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
2013 tree link = gimple_asm_input_op (stmt, i);
2014 if ((decl = non_rewritable_mem_ref_base (TREE_VALUE (link))))
2015 bitmap_set_bit (not_reg_needs, DECL_UID (decl));
2020 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
2022 size_t i;
2023 gimple phi = gsi_stmt (gsi);
2025 for (i = 0; i < gimple_phi_num_args (phi); i++)
2027 tree op = PHI_ARG_DEF (phi, i), var;
2028 if (TREE_CODE (op) == ADDR_EXPR
2029 && (var = get_base_address (TREE_OPERAND (op, 0))) != NULL
2030 && DECL_P (var))
2031 bitmap_set_bit (addresses_taken, DECL_UID (var));
2036 /* We cannot iterate over all referenced vars because that can contain
2037 unused vars from BLOCK trees, which causes code generation differences
2038 for -g vs. -g0. */
2039 for (var = DECL_ARGUMENTS (cfun->decl); var; var = DECL_CHAIN (var))
2040 maybe_optimize_var (var, addresses_taken, not_reg_needs,
2041 suitable_for_renaming);
2043 FOR_EACH_VEC_SAFE_ELT (cfun->local_decls, i, var)
2044 maybe_optimize_var (var, addresses_taken, not_reg_needs,
2045 suitable_for_renaming);
2047 /* Operand caches need to be recomputed for operands referencing the updated
2048 variables and operands need to be rewritten to expose bare symbols. */
2049 if (!bitmap_empty_p (suitable_for_renaming))
2051 FOR_EACH_BB (bb)
2052 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
2054 gimple stmt = gsi_stmt (gsi);
2056 /* Re-write TARGET_MEM_REFs of symbols we want to
2057 rewrite into SSA form. */
2058 if (gimple_assign_single_p (stmt))
2060 tree lhs = gimple_assign_lhs (stmt);
2061 tree rhs, *rhsp = gimple_assign_rhs1_ptr (stmt);
2062 tree sym;
2064 /* We shouldn't have any fancy wrapping of
2065 component-refs on the LHS, but look through
2066 VIEW_CONVERT_EXPRs as that is easy. */
2067 while (TREE_CODE (lhs) == VIEW_CONVERT_EXPR)
2068 lhs = TREE_OPERAND (lhs, 0);
2069 if (TREE_CODE (lhs) == MEM_REF
2070 && TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
2071 && integer_zerop (TREE_OPERAND (lhs, 1))
2072 && (sym = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0))
2073 && DECL_P (sym)
2074 && !TREE_ADDRESSABLE (sym)
2075 && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
2076 lhs = sym;
2077 else
2078 lhs = gimple_assign_lhs (stmt);
2080 /* Rewrite the RHS and make sure the resulting assignment
2081 is validly typed. */
2082 maybe_rewrite_mem_ref_base (rhsp, suitable_for_renaming);
2083 rhs = gimple_assign_rhs1 (stmt);
2084 if (gimple_assign_lhs (stmt) != lhs
2085 && !useless_type_conversion_p (TREE_TYPE (lhs),
2086 TREE_TYPE (rhs)))
2087 rhs = fold_build1 (VIEW_CONVERT_EXPR,
2088 TREE_TYPE (lhs), rhs);
2090 if (gimple_assign_lhs (stmt) != lhs)
2091 gimple_assign_set_lhs (stmt, lhs);
2093 /* For var ={v} {CLOBBER}; where var lost
2094 TREE_ADDRESSABLE just remove the stmt. */
2095 if (DECL_P (lhs)
2096 && TREE_CLOBBER_P (rhs)
2097 && bitmap_bit_p (suitable_for_renaming, DECL_UID (lhs)))
2099 unlink_stmt_vdef (stmt);
2100 gsi_remove (&gsi, true);
2101 release_defs (stmt);
2102 continue;
2105 if (gimple_assign_rhs1 (stmt) != rhs)
2107 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
2108 gimple_assign_set_rhs_from_tree (&gsi, rhs);
2112 else if (gimple_code (stmt) == GIMPLE_CALL)
2114 unsigned i;
2115 for (i = 0; i < gimple_call_num_args (stmt); ++i)
2117 tree *argp = gimple_call_arg_ptr (stmt, i);
2118 maybe_rewrite_mem_ref_base (argp, suitable_for_renaming);
2122 else if (gimple_code (stmt) == GIMPLE_ASM)
2124 unsigned i;
2125 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
2127 tree link = gimple_asm_output_op (stmt, i);
2128 maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
2129 suitable_for_renaming);
2131 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
2133 tree link = gimple_asm_input_op (stmt, i);
2134 maybe_rewrite_mem_ref_base (&TREE_VALUE (link),
2135 suitable_for_renaming);
2139 else if (gimple_debug_bind_p (stmt)
2140 && gimple_debug_bind_has_value_p (stmt))
2142 tree *valuep = gimple_debug_bind_get_value_ptr (stmt);
2143 tree decl;
2144 maybe_rewrite_mem_ref_base (valuep, suitable_for_renaming);
2145 decl = non_rewritable_mem_ref_base (*valuep);
2146 if (decl
2147 && bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
2148 gimple_debug_bind_reset_value (stmt);
2151 if (gimple_references_memory_p (stmt)
2152 || is_gimple_debug (stmt))
2153 update_stmt (stmt);
2155 gsi_next (&gsi);
2158 /* Update SSA form here, we are called as non-pass as well. */
2159 if (number_of_loops () > 1 && loops_state_satisfies_p (LOOP_CLOSED_SSA))
2160 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa);
2161 else
2162 update_ssa (TODO_update_ssa);
2165 BITMAP_FREE (not_reg_needs);
2166 BITMAP_FREE (addresses_taken);
2167 BITMAP_FREE (suitable_for_renaming);
2168 timevar_pop (TV_ADDRESS_TAKEN);
2171 struct gimple_opt_pass pass_update_address_taken =
2174 GIMPLE_PASS,
2175 "addressables", /* name */
2176 OPTGROUP_NONE, /* optinfo_flags */
2177 NULL, /* gate */
2178 NULL, /* execute */
2179 NULL, /* sub */
2180 NULL, /* next */
2181 0, /* static_pass_number */
2182 TV_ADDRESS_TAKEN, /* tv_id */
2183 PROP_ssa, /* properties_required */
2184 0, /* properties_provided */
2185 0, /* properties_destroyed */
2186 0, /* todo_flags_start */
2187 TODO_update_address_taken /* todo_flags_finish */