2008-06-04 Xinliang David Li <davidxl@google.com>
[official-gcc.git] / gcc / tree-ssa.c
blobf71e3af7ff98b362491745a36faeb1ce3887e443
1 /* Miscellaneous SSA utility functions.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 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 "rtl.h"
27 #include "tm_p.h"
28 #include "ggc.h"
29 #include "langhooks.h"
30 #include "hard-reg-set.h"
31 #include "basic-block.h"
32 #include "output.h"
33 #include "expr.h"
34 #include "function.h"
35 #include "diagnostic.h"
36 #include "bitmap.h"
37 #include "pointer-set.h"
38 #include "tree-flow.h"
39 #include "tree-gimple.h"
40 #include "tree-inline.h"
41 #include "varray.h"
42 #include "timevar.h"
43 #include "hashtab.h"
44 #include "tree-dump.h"
45 #include "tree-pass.h"
46 #include "toplev.h"
48 /* Pointer map of variable mappings, keyed by edge. */
49 static struct pointer_map_t *edge_var_maps;
52 /* Add a mapping with PHI RESULT and PHI DEF associated with edge E. */
54 void
55 redirect_edge_var_map_add (edge e, tree result, tree def)
57 void **slot;
58 edge_var_map_vector old_head, head;
59 edge_var_map new_node;
61 if (edge_var_maps == NULL)
62 edge_var_maps = pointer_map_create ();
64 slot = pointer_map_insert (edge_var_maps, e);
65 old_head = head = *slot;
66 if (!head)
68 head = VEC_alloc (edge_var_map, heap, 5);
69 *slot = head;
71 new_node.def = def;
72 new_node.result = result;
74 VEC_safe_push (edge_var_map, heap, head, &new_node);
75 if (old_head != head)
77 /* The push did some reallocation. Update the pointer map. */
78 *slot = head;
83 /* Clear the var mappings in edge E. */
85 void
86 redirect_edge_var_map_clear (edge e)
88 void **slot;
89 edge_var_map_vector head;
91 if (!edge_var_maps)
92 return;
94 slot = pointer_map_contains (edge_var_maps, e);
96 if (slot)
98 head = *slot;
99 VEC_free (edge_var_map, heap, head);
100 *slot = NULL;
105 /* Duplicate the redirected var mappings in OLDE in NEWE.
107 Since we can't remove a mapping, let's just duplicate it. This assumes a
108 pointer_map can have multiple edges mapping to the same var_map (many to
109 one mapping), since we don't remove the previous mappings. */
111 void
112 redirect_edge_var_map_dup (edge newe, edge olde)
114 void **new_slot, **old_slot; edge_var_map_vector head;
116 if (!edge_var_maps)
117 return;
119 new_slot = pointer_map_insert (edge_var_maps, newe);
120 old_slot = pointer_map_contains (edge_var_maps, olde);
121 if (!old_slot)
122 return;
123 head = *old_slot;
125 if (head)
126 *new_slot = VEC_copy (edge_var_map, heap, head);
127 else
128 *new_slot = VEC_alloc (edge_var_map, heap, 5);
132 /* Return the varable mappings for a given edge. If there is none, return
133 NULL. */
135 edge_var_map_vector
136 redirect_edge_var_map_vector (edge e)
138 void **slot;
140 /* Hey, what kind of idiot would... you'd be surprised. */
141 if (!edge_var_maps)
142 return NULL;
144 slot = pointer_map_contains (edge_var_maps, e);
145 if (!slot)
146 return NULL;
148 return (edge_var_map_vector) *slot;
152 /* Clear the edge variable mappings. */
154 void
155 redirect_edge_var_map_destroy (void)
157 if (edge_var_maps)
159 pointer_map_destroy (edge_var_maps);
160 edge_var_maps = NULL;
165 /* Remove the corresponding arguments from the PHI nodes in E's
166 destination block and redirect it to DEST. Return redirected edge.
167 The list of removed arguments is stored in a vector accessed
168 through edge_var_maps. */
170 edge
171 ssa_redirect_edge (edge e, basic_block dest)
173 tree phi;
175 redirect_edge_var_map_clear (e);
177 /* Remove the appropriate PHI arguments in E's destination block. */
178 for (phi = phi_nodes (e->dest); phi; phi = PHI_CHAIN (phi))
180 tree def = PHI_ARG_DEF (phi, e->dest_idx);
182 if (def == NULL_TREE)
183 continue;
185 redirect_edge_var_map_add (e, PHI_RESULT (phi), def);
188 e = redirect_edge_succ_nodup (e, dest);
190 return e;
193 /* Add PHI arguments queued in PENDING_STMT list on edge E to edge
194 E->dest. */
196 void
197 flush_pending_stmts (edge e)
199 tree phi;
200 edge_var_map_vector v;
201 edge_var_map *vm;
202 int i;
204 v = redirect_edge_var_map_vector (e);
205 if (!v)
206 return;
208 for (phi = phi_nodes (e->dest), i = 0;
209 phi && VEC_iterate (edge_var_map, v, i, vm);
210 phi = PHI_CHAIN (phi), i++)
212 tree def = redirect_edge_var_map_def (vm);
213 add_phi_arg (phi, def, e);
216 redirect_edge_var_map_clear (e);
219 /* Return true if SSA_NAME is malformed and mark it visited.
221 IS_VIRTUAL is true if this SSA_NAME was found inside a virtual
222 operand. */
224 static bool
225 verify_ssa_name (tree ssa_name, bool is_virtual)
227 if (TREE_CODE (ssa_name) != SSA_NAME)
229 error ("expected an SSA_NAME object");
230 return true;
233 if (TREE_TYPE (ssa_name) != TREE_TYPE (SSA_NAME_VAR (ssa_name)))
235 error ("type mismatch between an SSA_NAME and its symbol");
236 return true;
239 if (SSA_NAME_IN_FREE_LIST (ssa_name))
241 error ("found an SSA_NAME that had been released into the free pool");
242 return true;
245 if (is_virtual && is_gimple_reg (ssa_name))
247 error ("found a virtual definition for a GIMPLE register");
248 return true;
251 if (!is_virtual && !is_gimple_reg (ssa_name))
253 error ("found a real definition for a non-register");
254 return true;
257 if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
258 && !IS_EMPTY_STMT (SSA_NAME_DEF_STMT (ssa_name)))
260 error ("found a default name with a non-empty defining statement");
261 return true;
264 return false;
268 /* Return true if the definition of SSA_NAME at block BB is malformed.
270 STMT is the statement where SSA_NAME is created.
272 DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
273 version numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
274 it means that the block in that array slot contains the
275 definition of SSA_NAME.
277 IS_VIRTUAL is true if SSA_NAME is created by a VDEF. */
279 static bool
280 verify_def (basic_block bb, basic_block *definition_block, tree ssa_name,
281 tree stmt, bool is_virtual)
283 if (verify_ssa_name (ssa_name, is_virtual))
284 goto err;
286 if (definition_block[SSA_NAME_VERSION (ssa_name)])
288 error ("SSA_NAME created in two different blocks %i and %i",
289 definition_block[SSA_NAME_VERSION (ssa_name)]->index, bb->index);
290 goto err;
293 definition_block[SSA_NAME_VERSION (ssa_name)] = bb;
295 if (SSA_NAME_DEF_STMT (ssa_name) != stmt)
297 error ("SSA_NAME_DEF_STMT is wrong");
298 fprintf (stderr, "Expected definition statement:\n");
299 print_generic_stmt (stderr, SSA_NAME_DEF_STMT (ssa_name), TDF_VOPS);
300 fprintf (stderr, "\nActual definition statement:\n");
301 print_generic_stmt (stderr, stmt, TDF_VOPS);
302 goto err;
305 return false;
307 err:
308 fprintf (stderr, "while verifying SSA_NAME ");
309 print_generic_expr (stderr, ssa_name, 0);
310 fprintf (stderr, " in statement\n");
311 print_generic_stmt (stderr, stmt, TDF_VOPS);
313 return true;
317 /* Return true if the use of SSA_NAME at statement STMT in block BB is
318 malformed.
320 DEF_BB is the block where SSA_NAME was found to be created.
322 IDOM contains immediate dominator information for the flowgraph.
324 CHECK_ABNORMAL is true if the caller wants to check whether this use
325 is flowing through an abnormal edge (only used when checking PHI
326 arguments).
328 If NAMES_DEFINED_IN_BB is not NULL, it contains a bitmap of ssa names
329 that are defined before STMT in basic block BB. */
331 static bool
332 verify_use (basic_block bb, basic_block def_bb, use_operand_p use_p,
333 tree stmt, bool check_abnormal, bitmap names_defined_in_bb)
335 bool err = false;
336 tree ssa_name = USE_FROM_PTR (use_p);
338 if (!TREE_VISITED (ssa_name))
339 if (verify_imm_links (stderr, ssa_name))
340 err = true;
342 TREE_VISITED (ssa_name) = 1;
344 if (IS_EMPTY_STMT (SSA_NAME_DEF_STMT (ssa_name))
345 && SSA_NAME_IS_DEFAULT_DEF (ssa_name))
346 ; /* Default definitions have empty statements. Nothing to do. */
347 else if (!def_bb)
349 error ("missing definition");
350 err = true;
352 else if (bb != def_bb
353 && !dominated_by_p (CDI_DOMINATORS, bb, def_bb))
355 error ("definition in block %i does not dominate use in block %i",
356 def_bb->index, bb->index);
357 err = true;
359 else if (bb == def_bb
360 && names_defined_in_bb != NULL
361 && !bitmap_bit_p (names_defined_in_bb, SSA_NAME_VERSION (ssa_name)))
363 error ("definition in block %i follows the use", def_bb->index);
364 err = true;
367 if (check_abnormal
368 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
370 error ("SSA_NAME_OCCURS_IN_ABNORMAL_PHI should be set");
371 err = true;
374 /* Make sure the use is in an appropriate list by checking the previous
375 element to make sure it's the same. */
376 if (use_p->prev == NULL)
378 error ("no immediate_use list");
379 err = true;
381 else
383 tree listvar ;
384 if (use_p->prev->use == NULL)
385 listvar = use_p->prev->stmt;
386 else
387 listvar = USE_FROM_PTR (use_p->prev);
388 if (listvar != ssa_name)
390 error ("wrong immediate use list");
391 err = true;
395 if (err)
397 fprintf (stderr, "for SSA_NAME: ");
398 print_generic_expr (stderr, ssa_name, TDF_VOPS);
399 fprintf (stderr, " in statement:\n");
400 print_generic_stmt (stderr, stmt, TDF_VOPS);
403 return err;
407 /* Return true if any of the arguments for PHI node PHI at block BB is
408 malformed.
410 DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME
411 version numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set,
412 it means that the block in that array slot contains the
413 definition of SSA_NAME. */
415 static bool
416 verify_phi_args (tree phi, basic_block bb, basic_block *definition_block)
418 edge e;
419 bool err = false;
420 unsigned i, phi_num_args = PHI_NUM_ARGS (phi);
422 if (EDGE_COUNT (bb->preds) != phi_num_args)
424 error ("incoming edge count does not match number of PHI arguments");
425 err = true;
426 goto error;
429 for (i = 0; i < phi_num_args; i++)
431 use_operand_p op_p = PHI_ARG_DEF_PTR (phi, i);
432 tree op = USE_FROM_PTR (op_p);
434 e = EDGE_PRED (bb, i);
436 if (op == NULL_TREE)
438 error ("PHI argument is missing for edge %d->%d",
439 e->src->index,
440 e->dest->index);
441 err = true;
442 goto error;
445 if (TREE_CODE (op) != SSA_NAME && !is_gimple_min_invariant (op))
447 error ("PHI argument is not SSA_NAME, or invariant");
448 err = true;
451 if (TREE_CODE (op) == SSA_NAME)
453 err = verify_ssa_name (op, !is_gimple_reg (PHI_RESULT (phi)));
454 err |= verify_use (e->src, definition_block[SSA_NAME_VERSION (op)],
455 op_p, phi, e->flags & EDGE_ABNORMAL, NULL);
458 if (e->dest != bb)
460 error ("wrong edge %d->%d for PHI argument",
461 e->src->index, e->dest->index);
462 err = true;
465 if (err)
467 fprintf (stderr, "PHI argument\n");
468 print_generic_stmt (stderr, op, TDF_VOPS);
469 goto error;
473 error:
474 if (err)
476 fprintf (stderr, "for PHI node\n");
477 print_generic_stmt (stderr, phi, TDF_VOPS|TDF_MEMSYMS);
481 return err;
485 static void
486 verify_flow_insensitive_alias_info (void)
488 tree var;
489 referenced_var_iterator rvi;
491 FOR_EACH_REFERENCED_VAR (var, rvi)
493 unsigned int j;
494 bitmap aliases;
495 tree alias;
496 bitmap_iterator bi;
498 if (!MTAG_P (var) || !MTAG_ALIASES (var))
499 continue;
501 aliases = MTAG_ALIASES (var);
503 EXECUTE_IF_SET_IN_BITMAP (aliases, 0, j, bi)
505 alias = referenced_var (j);
507 if (TREE_CODE (alias) != MEMORY_PARTITION_TAG
508 && !may_be_aliased (alias))
510 error ("non-addressable variable inside an alias set");
511 debug_variable (alias);
512 goto err;
517 return;
519 err:
520 debug_variable (var);
521 internal_error ("verify_flow_insensitive_alias_info failed");
525 static void
526 verify_flow_sensitive_alias_info (void)
528 size_t i;
529 tree ptr;
531 for (i = 1; i < num_ssa_names; i++)
533 tree var;
534 var_ann_t ann;
535 struct ptr_info_def *pi;
538 ptr = ssa_name (i);
539 if (!ptr)
540 continue;
542 /* We only care for pointers that are actually referenced in the
543 program. */
544 if (!POINTER_TYPE_P (TREE_TYPE (ptr)) || !TREE_VISITED (ptr))
545 continue;
547 /* RESULT_DECL is special. If it's a GIMPLE register, then it
548 is only written-to only once in the return statement.
549 Otherwise, aggregate RESULT_DECLs may be written-to more than
550 once in virtual operands. */
551 var = SSA_NAME_VAR (ptr);
552 if (TREE_CODE (var) == RESULT_DECL
553 && is_gimple_reg (ptr))
554 continue;
556 pi = SSA_NAME_PTR_INFO (ptr);
557 if (pi == NULL)
558 continue;
560 ann = var_ann (var);
561 if (pi->is_dereferenced && !pi->name_mem_tag && !ann->symbol_mem_tag)
563 error ("dereferenced pointers should have a name or a symbol tag");
564 goto err;
567 if (pi->name_mem_tag
568 && (pi->pt_vars == NULL || bitmap_empty_p (pi->pt_vars)))
570 error ("pointers with a memory tag, should have points-to sets");
571 goto err;
574 if (pi->value_escapes_p
575 && pi->escape_mask & ~ESCAPE_TO_RETURN
576 && pi->name_mem_tag)
578 tree t = memory_partition (pi->name_mem_tag);
579 if (t == NULL_TREE)
580 t = pi->name_mem_tag;
582 if (!is_call_clobbered (t))
584 error ("pointer escapes but its name tag is not call-clobbered");
585 goto err;
590 return;
592 err:
593 debug_variable (ptr);
594 internal_error ("verify_flow_sensitive_alias_info failed");
598 /* Verify the consistency of call clobbering information. */
600 static void
601 verify_call_clobbering (void)
603 unsigned int i;
604 bitmap_iterator bi;
605 tree var;
606 referenced_var_iterator rvi;
608 /* At all times, the result of the call_clobbered flag should
609 match the result of the call_clobbered_vars bitmap. Verify both
610 that everything in call_clobbered_vars is marked
611 call_clobbered, and that everything marked
612 call_clobbered is in call_clobbered_vars. */
613 EXECUTE_IF_SET_IN_BITMAP (gimple_call_clobbered_vars (cfun), 0, i, bi)
615 var = referenced_var (i);
617 if (memory_partition (var))
618 var = memory_partition (var);
620 if (!MTAG_P (var) && !var_ann (var)->call_clobbered)
622 error ("variable in call_clobbered_vars but not marked "
623 "call_clobbered");
624 debug_variable (var);
625 goto err;
629 FOR_EACH_REFERENCED_VAR (var, rvi)
631 if (is_gimple_reg (var))
632 continue;
634 if (memory_partition (var))
635 var = memory_partition (var);
637 if (!MTAG_P (var)
638 && var_ann (var)->call_clobbered
639 && !bitmap_bit_p (gimple_call_clobbered_vars (cfun), DECL_UID (var)))
641 error ("variable marked call_clobbered but not in "
642 "call_clobbered_vars bitmap.");
643 debug_variable (var);
644 goto err;
648 return;
650 err:
651 internal_error ("verify_call_clobbering failed");
655 /* Verify invariants in memory partitions. */
657 static void
658 verify_memory_partitions (void)
660 unsigned i;
661 tree mpt;
662 VEC(tree,heap) *mpt_table = gimple_ssa_operands (cfun)->mpt_table;
663 struct pointer_set_t *partitioned_syms = pointer_set_create ();
665 for (i = 0; VEC_iterate (tree, mpt_table, i, mpt); i++)
667 unsigned j;
668 bitmap_iterator bj;
670 if (MPT_SYMBOLS (mpt) == NULL)
672 error ("Memory partitions should have at least one symbol");
673 debug_variable (mpt);
674 goto err;
677 EXECUTE_IF_SET_IN_BITMAP (MPT_SYMBOLS (mpt), 0, j, bj)
679 tree var = referenced_var (j);
680 if (pointer_set_insert (partitioned_syms, var))
682 error ("Partitioned symbols should belong to exactly one "
683 "partition");
684 debug_variable (var);
685 goto err;
690 pointer_set_destroy (partitioned_syms);
692 return;
694 err:
695 internal_error ("verify_memory_partitions failed");
699 /* Verify the consistency of aliasing information. */
701 static void
702 verify_alias_info (void)
704 verify_flow_sensitive_alias_info ();
705 verify_call_clobbering ();
706 verify_flow_insensitive_alias_info ();
707 verify_memory_partitions ();
711 /* Verify common invariants in the SSA web.
712 TODO: verify the variable annotations. */
714 void
715 verify_ssa (bool check_modified_stmt)
717 size_t i;
718 basic_block bb;
719 basic_block *definition_block = XCNEWVEC (basic_block, num_ssa_names);
720 ssa_op_iter iter;
721 tree op;
722 enum dom_state orig_dom_state = dom_info_state (CDI_DOMINATORS);
723 bitmap names_defined_in_bb = BITMAP_ALLOC (NULL);
725 gcc_assert (!need_ssa_update_p ());
727 verify_stmts ();
729 timevar_push (TV_TREE_SSA_VERIFY);
731 /* Keep track of SSA names present in the IL. */
732 for (i = 1; i < num_ssa_names; i++)
734 tree name = ssa_name (i);
735 if (name)
737 tree stmt;
738 TREE_VISITED (name) = 0;
740 stmt = SSA_NAME_DEF_STMT (name);
741 if (!IS_EMPTY_STMT (stmt))
743 basic_block bb = bb_for_stmt (stmt);
744 verify_def (bb, definition_block,
745 name, stmt, !is_gimple_reg (name));
751 calculate_dominance_info (CDI_DOMINATORS);
753 /* Now verify all the uses and make sure they agree with the definitions
754 found in the previous pass. */
755 FOR_EACH_BB (bb)
757 edge e;
758 tree phi;
759 edge_iterator ei;
760 block_stmt_iterator bsi;
762 /* Make sure that all edges have a clear 'aux' field. */
763 FOR_EACH_EDGE (e, ei, bb->preds)
765 if (e->aux)
767 error ("AUX pointer initialized for edge %d->%d", e->src->index,
768 e->dest->index);
769 goto err;
773 /* Verify the arguments for every PHI node in the block. */
774 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
776 if (verify_phi_args (phi, bb, definition_block))
777 goto err;
779 bitmap_set_bit (names_defined_in_bb,
780 SSA_NAME_VERSION (PHI_RESULT (phi)));
783 /* Now verify all the uses and vuses in every statement of the block. */
784 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
786 tree stmt = bsi_stmt (bsi);
787 use_operand_p use_p;
789 if (check_modified_stmt && stmt_modified_p (stmt))
791 error ("stmt (%p) marked modified after optimization pass: ",
792 (void *)stmt);
793 print_generic_stmt (stderr, stmt, TDF_VOPS);
794 goto err;
797 if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT
798 && TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 0)) != SSA_NAME)
800 tree lhs, base_address;
802 lhs = GIMPLE_STMT_OPERAND (stmt, 0);
803 base_address = get_base_address (lhs);
805 if (base_address
806 && gimple_aliases_computed_p (cfun)
807 && SSA_VAR_P (base_address)
808 && !stmt_ann (stmt)->has_volatile_ops
809 && ZERO_SSA_OPERANDS (stmt, SSA_OP_VDEF))
811 error ("statement makes a memory store, but has no VDEFS");
812 print_generic_stmt (stderr, stmt, TDF_VOPS);
813 goto err;
817 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_VIRTUALS)
819 if (verify_ssa_name (op, true))
821 error ("in statement");
822 print_generic_stmt (stderr, stmt, TDF_VOPS|TDF_MEMSYMS);
823 goto err;
827 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE|SSA_OP_DEF)
829 if (verify_ssa_name (op, false))
831 error ("in statement");
832 print_generic_stmt (stderr, stmt, TDF_VOPS|TDF_MEMSYMS);
833 goto err;
837 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE|SSA_OP_VUSE)
839 op = USE_FROM_PTR (use_p);
840 if (verify_use (bb, definition_block[SSA_NAME_VERSION (op)],
841 use_p, stmt, false, names_defined_in_bb))
842 goto err;
845 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_ALL_DEFS)
846 bitmap_set_bit (names_defined_in_bb, SSA_NAME_VERSION (op));
849 bitmap_clear (names_defined_in_bb);
852 /* Finally, verify alias information. */
853 if (gimple_aliases_computed_p (cfun))
854 verify_alias_info ();
856 free (definition_block);
858 /* Restore the dominance information to its prior known state, so
859 that we do not perturb the compiler's subsequent behavior. */
860 if (orig_dom_state == DOM_NONE)
861 free_dominance_info (CDI_DOMINATORS);
862 else
863 set_dom_info_availability (CDI_DOMINATORS, orig_dom_state);
865 BITMAP_FREE (names_defined_in_bb);
866 timevar_pop (TV_TREE_SSA_VERIFY);
867 return;
869 err:
870 internal_error ("verify_ssa failed");
873 /* Return true if the uid in both int tree maps are equal. */
876 int_tree_map_eq (const void *va, const void *vb)
878 const struct int_tree_map *a = (const struct int_tree_map *) va;
879 const struct int_tree_map *b = (const struct int_tree_map *) vb;
880 return (a->uid == b->uid);
883 /* Hash a UID in a int_tree_map. */
885 unsigned int
886 int_tree_map_hash (const void *item)
888 return ((const struct int_tree_map *)item)->uid;
891 /* Return true if the DECL_UID in both trees are equal. */
894 uid_decl_map_eq (const void *va, const void *vb)
896 const_tree a = (const_tree) va;
897 const_tree b = (const_tree) vb;
898 return (a->decl_minimal.uid == b->decl_minimal.uid);
901 /* Hash a tree in a uid_decl_map. */
903 unsigned int
904 uid_decl_map_hash (const void *item)
906 return ((const_tree)item)->decl_minimal.uid;
909 /* Return true if the DECL_UID in both trees are equal. */
911 static int
912 uid_ssaname_map_eq (const void *va, const void *vb)
914 const_tree a = (const_tree) va;
915 const_tree b = (const_tree) vb;
916 return (a->ssa_name.var->decl_minimal.uid == b->ssa_name.var->decl_minimal.uid);
919 /* Hash a tree in a uid_decl_map. */
921 static unsigned int
922 uid_ssaname_map_hash (const void *item)
924 return ((const_tree)item)->ssa_name.var->decl_minimal.uid;
928 /* Initialize global DFA and SSA structures. */
930 void
931 init_tree_ssa (struct function *fn)
933 fn->gimple_df = GGC_CNEW (struct gimple_df);
934 fn->gimple_df->referenced_vars = htab_create_ggc (20, uid_decl_map_hash,
935 uid_decl_map_eq, NULL);
936 fn->gimple_df->default_defs = htab_create_ggc (20, uid_ssaname_map_hash,
937 uid_ssaname_map_eq, NULL);
938 fn->gimple_df->call_clobbered_vars = BITMAP_GGC_ALLOC ();
939 fn->gimple_df->addressable_vars = BITMAP_GGC_ALLOC ();
940 init_ssanames (fn, 0);
941 init_phinodes ();
945 /* Deallocate memory associated with SSA data structures for FNDECL. */
947 void
948 delete_tree_ssa (void)
950 size_t i;
951 basic_block bb;
952 block_stmt_iterator bsi;
953 referenced_var_iterator rvi;
954 tree var;
956 /* Release any ssa_names still in use. */
957 for (i = 0; i < num_ssa_names; i++)
959 tree var = ssa_name (i);
960 if (var && TREE_CODE (var) == SSA_NAME)
962 SSA_NAME_IMM_USE_NODE (var).prev = &(SSA_NAME_IMM_USE_NODE (var));
963 SSA_NAME_IMM_USE_NODE (var).next = &(SSA_NAME_IMM_USE_NODE (var));
965 release_ssa_name (var);
968 /* Remove annotations from every tree in the function. */
969 FOR_EACH_BB (bb)
971 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
973 tree stmt = bsi_stmt (bsi);
974 stmt_ann_t ann = get_stmt_ann (stmt);
976 free_ssa_operands (&ann->operands);
977 ann->addresses_taken = 0;
978 mark_stmt_modified (stmt);
980 set_phi_nodes (bb, NULL);
983 /* Remove annotations from every referenced local variable. */
984 FOR_EACH_REFERENCED_VAR (var, rvi)
986 if (!MTAG_P (var)
987 && (TREE_STATIC (var) || DECL_EXTERNAL (var)))
989 var_ann (var)->mpt = NULL_TREE;
990 var_ann (var)->symbol_mem_tag = NULL_TREE;
991 continue;
993 if (var->base.ann)
994 ggc_free (var->base.ann);
995 var->base.ann = NULL;
997 htab_delete (gimple_referenced_vars (cfun));
998 cfun->gimple_df->referenced_vars = NULL;
1000 fini_ssanames ();
1001 fini_phinodes ();
1002 /* we no longer maintain the SSA operand cache at this point. */
1003 if (ssa_operands_active ())
1004 fini_ssa_operands ();
1006 cfun->gimple_df->global_var = NULL_TREE;
1008 htab_delete (cfun->gimple_df->default_defs);
1009 cfun->gimple_df->default_defs = NULL;
1010 cfun->gimple_df->call_clobbered_vars = NULL;
1011 cfun->gimple_df->addressable_vars = NULL;
1012 cfun->gimple_df->modified_noreturn_calls = NULL;
1013 if (gimple_aliases_computed_p (cfun))
1015 delete_alias_heapvars ();
1016 gcc_assert (!need_ssa_update_p ());
1018 cfun->gimple_df->aliases_computed_p = false;
1019 delete_mem_ref_stats (cfun);
1021 cfun->gimple_df = NULL;
1023 /* We no longer need the edge variable maps. */
1024 redirect_edge_var_map_destroy ();
1027 /* Helper function for useless_type_conversion_p. */
1029 static bool
1030 useless_type_conversion_p_1 (tree outer_type, tree inner_type)
1032 /* Qualifiers on value types do not matter. */
1033 inner_type = TYPE_MAIN_VARIANT (inner_type);
1034 outer_type = TYPE_MAIN_VARIANT (outer_type);
1036 if (inner_type == outer_type)
1037 return true;
1039 /* If we know the canonical types, compare them. */
1040 if (TYPE_CANONICAL (inner_type)
1041 && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type))
1042 return true;
1044 /* Changes in machine mode are never useless conversions. */
1045 if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type))
1046 return false;
1048 /* If both the inner and outer types are integral types, then the
1049 conversion is not necessary if they have the same mode and
1050 signedness and precision, and both or neither are boolean. */
1051 if (INTEGRAL_TYPE_P (inner_type)
1052 && INTEGRAL_TYPE_P (outer_type))
1054 /* Preserve changes in signedness or precision. */
1055 if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
1056 || TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
1057 return false;
1059 /* Conversions from a non-base to a base type are not useless.
1060 This way we preserve the invariant to do arithmetic in
1061 base types only. */
1062 if (TREE_TYPE (inner_type)
1063 && TREE_TYPE (inner_type) != inner_type
1064 && (TREE_TYPE (outer_type) == outer_type
1065 || TREE_TYPE (outer_type) == NULL_TREE))
1066 return false;
1068 /* We don't need to preserve changes in the types minimum or
1069 maximum value in general as these do not generate code
1070 unless the types precisions are different. */
1072 return true;
1075 /* Scalar floating point types with the same mode are compatible. */
1076 else if (SCALAR_FLOAT_TYPE_P (inner_type)
1077 && SCALAR_FLOAT_TYPE_P (outer_type))
1078 return true;
1080 /* We need to take special care recursing to pointed-to types. */
1081 else if (POINTER_TYPE_P (inner_type)
1082 && POINTER_TYPE_P (outer_type))
1084 /* Don't lose casts between pointers to volatile and non-volatile
1085 qualified types. Doing so would result in changing the semantics
1086 of later accesses. */
1087 if ((TYPE_VOLATILE (TREE_TYPE (outer_type))
1088 != TYPE_VOLATILE (TREE_TYPE (inner_type)))
1089 && TYPE_VOLATILE (TREE_TYPE (outer_type)))
1090 return false;
1092 /* Do not lose casts between pointers with different
1093 TYPE_REF_CAN_ALIAS_ALL setting or alias sets. */
1094 if ((TYPE_REF_CAN_ALIAS_ALL (inner_type)
1095 != TYPE_REF_CAN_ALIAS_ALL (outer_type))
1096 || (get_alias_set (TREE_TYPE (inner_type))
1097 != get_alias_set (TREE_TYPE (outer_type))))
1098 return false;
1100 /* We do not care for const qualification of the pointed-to types
1101 as const qualification has no semantic value to the middle-end. */
1103 /* Do not lose casts to restrict qualified pointers. */
1104 if ((TYPE_RESTRICT (outer_type)
1105 != TYPE_RESTRICT (inner_type))
1106 && TYPE_RESTRICT (outer_type))
1107 return false;
1109 /* Otherwise pointers/references are equivalent if their pointed
1110 to types are effectively the same. We can strip qualifiers
1111 on pointed-to types for further comparison, which is done in
1112 the callee. */
1113 return useless_type_conversion_p_1 (TREE_TYPE (outer_type),
1114 TREE_TYPE (inner_type));
1117 /* Recurse for complex types. */
1118 else if (TREE_CODE (inner_type) == COMPLEX_TYPE
1119 && TREE_CODE (outer_type) == COMPLEX_TYPE)
1120 return useless_type_conversion_p_1 (TREE_TYPE (outer_type),
1121 TREE_TYPE (inner_type));
1123 /* Recurse for vector types with the same number of subparts. */
1124 else if (TREE_CODE (inner_type) == VECTOR_TYPE
1125 && TREE_CODE (outer_type) == VECTOR_TYPE
1126 && TYPE_PRECISION (inner_type) == TYPE_PRECISION (outer_type))
1127 return useless_type_conversion_p_1 (TREE_TYPE (outer_type),
1128 TREE_TYPE (inner_type));
1130 /* For aggregates we may need to fall back to structural equality
1131 checks. */
1132 else if (AGGREGATE_TYPE_P (inner_type)
1133 && AGGREGATE_TYPE_P (outer_type))
1135 /* Different types of aggregates are incompatible. */
1136 if (TREE_CODE (inner_type) != TREE_CODE (outer_type))
1137 return false;
1139 /* ??? Add structural equivalence check. */
1141 /* ??? This should eventually just return false. */
1142 return lang_hooks.types_compatible_p (inner_type, outer_type);
1145 return false;
1148 /* Return true if the conversion from INNER_TYPE to OUTER_TYPE is a
1149 useless type conversion, otherwise return false.
1151 This function implicitly defines the middle-end type system. With
1152 the notion of 'a < b' meaning that useless_type_conversion_p (a, b)
1153 holds and 'a > b' meaning that useless_type_conversion_p (b, a) holds,
1154 the following invariants shall be fulfilled:
1156 1) useless_type_conversion_p is transitive.
1157 If a < b and b < c then a < c.
1159 2) useless_type_conversion_p is not symmetric.
1160 From a < b does not follow a > b.
1162 3) Types define the available set of operations applicable to values.
1163 A type conversion is useless if the operations for the target type
1164 is a subset of the operations for the source type. For example
1165 casts to void* are useless, casts from void* are not (void* can't
1166 be dereferenced or offsetted, but copied, hence its set of operations
1167 is a strict subset of that of all other data pointer types). Casts
1168 to const T* are useless (can't be written to), casts from const T*
1169 to T* are not. */
1171 bool
1172 useless_type_conversion_p (tree outer_type, tree inner_type)
1174 /* If the outer type is (void *), then the conversion is not
1175 necessary. We have to make sure to not apply this while
1176 recursing though. */
1177 if (POINTER_TYPE_P (inner_type)
1178 && POINTER_TYPE_P (outer_type)
1179 && TREE_CODE (TREE_TYPE (outer_type)) == VOID_TYPE)
1180 return true;
1182 return useless_type_conversion_p_1 (outer_type, inner_type);
1185 /* Return true if a conversion from either type of TYPE1 and TYPE2
1186 to the other is not required. Otherwise return false. */
1188 bool
1189 types_compatible_p (tree type1, tree type2)
1191 return (type1 == type2
1192 || (useless_type_conversion_p (type1, type2)
1193 && useless_type_conversion_p (type2, type1)));
1196 /* Return true if EXPR is a useless type conversion, otherwise return
1197 false. */
1199 bool
1200 tree_ssa_useless_type_conversion (tree expr)
1202 /* If we have an assignment that merely uses a NOP_EXPR to change
1203 the top of the RHS to the type of the LHS and the type conversion
1204 is "safe", then strip away the type conversion so that we can
1205 enter LHS = RHS into the const_and_copies table. */
1206 if (CONVERT_EXPR_P (expr)
1207 || TREE_CODE (expr) == VIEW_CONVERT_EXPR
1208 || TREE_CODE (expr) == NON_LVALUE_EXPR)
1209 /* FIXME: Use of GENERIC_TREE_TYPE here is a temporary measure to work
1210 around known bugs with GIMPLE_MODIFY_STMTs appearing in places
1211 they shouldn't. See PR 30391. */
1212 return useless_type_conversion_p
1213 (TREE_TYPE (expr),
1214 GENERIC_TREE_TYPE (TREE_OPERAND (expr, 0)));
1216 return false;
1220 /* Internal helper for walk_use_def_chains. VAR, FN and DATA are as
1221 described in walk_use_def_chains.
1223 VISITED is a pointer set used to mark visited SSA_NAMEs to avoid
1224 infinite loops. We used to have a bitmap for this to just mark
1225 SSA versions we had visited. But non-sparse bitmaps are way too
1226 expensive, while sparse bitmaps may cause quadratic behavior.
1228 IS_DFS is true if the caller wants to perform a depth-first search
1229 when visiting PHI nodes. A DFS will visit each PHI argument and
1230 call FN after each one. Otherwise, all the arguments are
1231 visited first and then FN is called with each of the visited
1232 arguments in a separate pass. */
1234 static bool
1235 walk_use_def_chains_1 (tree var, walk_use_def_chains_fn fn, void *data,
1236 struct pointer_set_t *visited, bool is_dfs)
1238 tree def_stmt;
1240 if (pointer_set_insert (visited, var))
1241 return false;
1243 def_stmt = SSA_NAME_DEF_STMT (var);
1245 if (TREE_CODE (def_stmt) != PHI_NODE)
1247 /* If we reached the end of the use-def chain, call FN. */
1248 return fn (var, def_stmt, data);
1250 else
1252 int i;
1254 /* When doing a breadth-first search, call FN before following the
1255 use-def links for each argument. */
1256 if (!is_dfs)
1257 for (i = 0; i < PHI_NUM_ARGS (def_stmt); i++)
1258 if (fn (PHI_ARG_DEF (def_stmt, i), def_stmt, data))
1259 return true;
1261 /* Follow use-def links out of each PHI argument. */
1262 for (i = 0; i < PHI_NUM_ARGS (def_stmt); i++)
1264 tree arg = PHI_ARG_DEF (def_stmt, i);
1266 /* ARG may be NULL for newly introduced PHI nodes. */
1267 if (arg
1268 && TREE_CODE (arg) == SSA_NAME
1269 && walk_use_def_chains_1 (arg, fn, data, visited, is_dfs))
1270 return true;
1273 /* When doing a depth-first search, call FN after following the
1274 use-def links for each argument. */
1275 if (is_dfs)
1276 for (i = 0; i < PHI_NUM_ARGS (def_stmt); i++)
1277 if (fn (PHI_ARG_DEF (def_stmt, i), def_stmt, data))
1278 return true;
1281 return false;
1286 /* Walk use-def chains starting at the SSA variable VAR. Call
1287 function FN at each reaching definition found. FN takes three
1288 arguments: VAR, its defining statement (DEF_STMT) and a generic
1289 pointer to whatever state information that FN may want to maintain
1290 (DATA). FN is able to stop the walk by returning true, otherwise
1291 in order to continue the walk, FN should return false.
1293 Note, that if DEF_STMT is a PHI node, the semantics are slightly
1294 different. The first argument to FN is no longer the original
1295 variable VAR, but the PHI argument currently being examined. If FN
1296 wants to get at VAR, it should call PHI_RESULT (PHI).
1298 If IS_DFS is true, this function will:
1300 1- walk the use-def chains for all the PHI arguments, and,
1301 2- call (*FN) (ARG, PHI, DATA) on all the PHI arguments.
1303 If IS_DFS is false, the two steps above are done in reverse order
1304 (i.e., a breadth-first search). */
1306 void
1307 walk_use_def_chains (tree var, walk_use_def_chains_fn fn, void *data,
1308 bool is_dfs)
1310 tree def_stmt;
1312 gcc_assert (TREE_CODE (var) == SSA_NAME);
1314 def_stmt = SSA_NAME_DEF_STMT (var);
1316 /* We only need to recurse if the reaching definition comes from a PHI
1317 node. */
1318 if (TREE_CODE (def_stmt) != PHI_NODE)
1319 (*fn) (var, def_stmt, data);
1320 else
1322 struct pointer_set_t *visited = pointer_set_create ();
1323 walk_use_def_chains_1 (var, fn, data, visited, is_dfs);
1324 pointer_set_destroy (visited);
1329 /* Return true if T, an SSA_NAME, has an undefined value. */
1331 bool
1332 ssa_undefined_value_p (tree t)
1334 tree var = SSA_NAME_VAR (t);
1336 /* Parameters get their initial value from the function entry. */
1337 if (TREE_CODE (var) == PARM_DECL)
1338 return false;
1340 /* Hard register variables get their initial value from the ether. */
1341 if (TREE_CODE (var) == VAR_DECL && DECL_HARD_REGISTER (var))
1342 return false;
1344 /* The value is undefined iff its definition statement is empty. */
1345 return IS_EMPTY_STMT (SSA_NAME_DEF_STMT (t));
1348 /* Emit warnings for uninitialized variables. This is done in two passes.
1350 The first pass notices real uses of SSA names with undefined values.
1351 Such uses are unconditionally uninitialized, and we can be certain that
1352 such a use is a mistake. This pass is run before most optimizations,
1353 so that we catch as many as we can.
1355 The second pass follows PHI nodes to find uses that are potentially
1356 uninitialized. In this case we can't necessarily prove that the use
1357 is really uninitialized. This pass is run after most optimizations,
1358 so that we thread as many jumps and possible, and delete as much dead
1359 code as possible, in order to reduce false positives. We also look
1360 again for plain uninitialized variables, since optimization may have
1361 changed conditionally uninitialized to unconditionally uninitialized. */
1363 /* Emit a warning for T, an SSA_NAME, being uninitialized. The exact
1364 warning text is in MSGID and LOCUS may contain a location or be null. */
1366 static void
1367 warn_uninit (tree t, const char *gmsgid, void *data)
1369 tree var = SSA_NAME_VAR (t);
1370 tree context = (tree) data;
1371 location_t *locus;
1372 expanded_location xloc, floc;
1374 if (!ssa_undefined_value_p (t))
1375 return;
1377 /* TREE_NO_WARNING either means we already warned, or the front end
1378 wishes to suppress the warning. */
1379 if (TREE_NO_WARNING (var))
1380 return;
1382 locus = (context != NULL && EXPR_HAS_LOCATION (context)
1383 ? EXPR_LOCUS (context)
1384 : &DECL_SOURCE_LOCATION (var));
1385 warning (OPT_Wuninitialized, gmsgid, locus, var);
1386 xloc = expand_location (*locus);
1387 floc = expand_location (DECL_SOURCE_LOCATION (cfun->decl));
1388 if (xloc.file != floc.file
1389 || xloc.line < floc.line
1390 || xloc.line > LOCATION_LINE (cfun->function_end_locus))
1391 inform ("%J%qD was declared here", var, var);
1393 TREE_NO_WARNING (var) = 1;
1396 struct walk_data {
1397 tree stmt;
1398 bool always_executed;
1401 /* Called via walk_tree, look for SSA_NAMEs that have empty definitions
1402 and warn about them. */
1404 static tree
1405 warn_uninitialized_var (tree *tp, int *walk_subtrees, void *data_)
1407 struct walk_data *data = (struct walk_data *)data_;
1408 tree t = *tp;
1410 switch (TREE_CODE (t))
1412 case SSA_NAME:
1413 /* We only do data flow with SSA_NAMEs, so that's all we
1414 can warn about. */
1415 if (data->always_executed)
1416 warn_uninit (t, "%H%qD is used uninitialized in this function",
1417 data->stmt);
1418 else
1419 warn_uninit (t, "%H%qD may be used uninitialized in this function",
1420 data->stmt);
1421 *walk_subtrees = 0;
1422 break;
1424 case REALPART_EXPR:
1425 case IMAGPART_EXPR:
1426 /* The total store transformation performed during gimplification
1427 creates uninitialized variable uses. If all is well, these will
1428 be optimized away, so don't warn now. */
1429 if (TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME)
1430 *walk_subtrees = 0;
1431 break;
1433 default:
1434 if (IS_TYPE_OR_DECL_P (t))
1435 *walk_subtrees = 0;
1436 break;
1439 return NULL_TREE;
1442 /* Look for inputs to PHI that are SSA_NAMEs that have empty definitions
1443 and warn about them. */
1445 static void
1446 warn_uninitialized_phi (tree phi)
1448 int i, n = PHI_NUM_ARGS (phi);
1450 /* Don't look at memory tags. */
1451 if (!is_gimple_reg (PHI_RESULT (phi)))
1452 return;
1454 for (i = 0; i < n; ++i)
1456 tree op = PHI_ARG_DEF (phi, i);
1457 if (TREE_CODE (op) == SSA_NAME)
1458 warn_uninit (op, "%H%qD may be used uninitialized in this function",
1459 NULL);
1463 static unsigned int
1464 execute_early_warn_uninitialized (void)
1466 block_stmt_iterator bsi;
1467 basic_block bb;
1468 struct walk_data data;
1470 calculate_dominance_info (CDI_POST_DOMINATORS);
1472 FOR_EACH_BB (bb)
1474 data.always_executed = dominated_by_p (CDI_POST_DOMINATORS,
1475 single_succ (ENTRY_BLOCK_PTR), bb);
1476 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
1478 data.stmt = bsi_stmt (bsi);
1479 walk_tree (bsi_stmt_ptr (bsi), warn_uninitialized_var,
1480 &data, NULL);
1483 return 0;
1486 static unsigned int
1487 execute_late_warn_uninitialized (void)
1489 basic_block bb;
1490 tree phi;
1492 /* Re-do the plain uninitialized variable check, as optimization may have
1493 straightened control flow. Do this first so that we don't accidentally
1494 get a "may be" warning when we'd have seen an "is" warning later. */
1495 execute_early_warn_uninitialized ();
1497 FOR_EACH_BB (bb)
1498 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
1499 warn_uninitialized_phi (phi);
1500 return 0;
1503 static bool
1504 gate_warn_uninitialized (void)
1506 return warn_uninitialized != 0;
1509 struct gimple_opt_pass pass_early_warn_uninitialized =
1512 GIMPLE_PASS,
1513 NULL, /* name */
1514 gate_warn_uninitialized, /* gate */
1515 execute_early_warn_uninitialized, /* execute */
1516 NULL, /* sub */
1517 NULL, /* next */
1518 0, /* static_pass_number */
1519 0, /* tv_id */
1520 PROP_ssa, /* properties_required */
1521 0, /* properties_provided */
1522 0, /* properties_destroyed */
1523 0, /* todo_flags_start */
1524 0 /* todo_flags_finish */
1528 struct gimple_opt_pass pass_late_warn_uninitialized =
1531 GIMPLE_PASS,
1532 NULL, /* name */
1533 gate_warn_uninitialized, /* gate */
1534 execute_late_warn_uninitialized, /* execute */
1535 NULL, /* sub */
1536 NULL, /* next */
1537 0, /* static_pass_number */
1538 0, /* tv_id */
1539 PROP_ssa, /* properties_required */
1540 0, /* properties_provided */
1541 0, /* properties_destroyed */
1542 0, /* todo_flags_start */
1543 0 /* todo_flags_finish */
1547 /* Compute TREE_ADDRESSABLE for local variables. */
1549 static unsigned int
1550 execute_update_addresses_taken (void)
1552 tree var;
1553 referenced_var_iterator rvi;
1554 block_stmt_iterator bsi;
1555 basic_block bb;
1556 bitmap addresses_taken = BITMAP_ALLOC (NULL);
1557 bitmap vars_updated = BITMAP_ALLOC (NULL);
1558 bool update_vops = false;
1559 tree phi;
1561 /* Collect into ADDRESSES_TAKEN all variables whose address is taken within
1562 the function body. */
1563 FOR_EACH_BB (bb)
1565 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
1567 stmt_ann_t s_ann = stmt_ann (bsi_stmt (bsi));
1569 if (s_ann->addresses_taken)
1570 bitmap_ior_into (addresses_taken, s_ann->addresses_taken);
1572 for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
1574 unsigned i, phi_num_args = PHI_NUM_ARGS (phi);
1575 for (i = 0; i < phi_num_args; i++)
1577 tree op = PHI_ARG_DEF (phi, i), var;
1578 if (TREE_CODE (op) == ADDR_EXPR
1579 && (var = get_base_address (TREE_OPERAND (op, 0))) != NULL_TREE
1580 && DECL_P (var))
1581 bitmap_set_bit (addresses_taken, DECL_UID (var));
1586 /* When possible, clear ADDRESSABLE bit and mark variable for conversion into
1587 SSA. */
1588 FOR_EACH_REFERENCED_VAR (var, rvi)
1589 if (!is_global_var (var)
1590 && TREE_CODE (var) != RESULT_DECL
1591 && TREE_ADDRESSABLE (var)
1592 && !bitmap_bit_p (addresses_taken, DECL_UID (var)))
1594 TREE_ADDRESSABLE (var) = 0;
1595 if (is_gimple_reg (var))
1596 mark_sym_for_renaming (var);
1597 update_vops = true;
1598 bitmap_set_bit (vars_updated, DECL_UID (var));
1599 if (dump_file)
1601 fprintf (dump_file, "No longer having address taken ");
1602 print_generic_expr (dump_file, var, 0);
1603 fprintf (dump_file, "\n");
1607 /* Operand caches needs to be recomputed for operands referencing the updated
1608 variables. */
1609 if (update_vops)
1610 FOR_EACH_BB (bb)
1611 for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
1613 tree stmt = bsi_stmt (bsi);
1615 if ((LOADED_SYMS (stmt)
1616 && bitmap_intersect_p (LOADED_SYMS (stmt), vars_updated))
1617 || (STORED_SYMS (stmt)
1618 && bitmap_intersect_p (STORED_SYMS (stmt), vars_updated)))
1619 update_stmt (stmt);
1621 BITMAP_FREE (addresses_taken);
1622 BITMAP_FREE (vars_updated);
1623 return 0;
1626 struct gimple_opt_pass pass_update_address_taken =
1629 GIMPLE_PASS,
1630 "addressables", /* name */
1631 NULL, /* gate */
1632 execute_update_addresses_taken, /* execute */
1633 NULL, /* sub */
1634 NULL, /* next */
1635 0, /* static_pass_number */
1636 0, /* tv_id */
1637 PROP_ssa, /* properties_required */
1638 0, /* properties_provided */
1639 0, /* properties_destroyed */
1640 0, /* todo_flags_start */
1641 TODO_update_ssa /* todo_flags_finish */