1 /* Miscellaneous SSA utility functions.
2 Copyright (C) 2001, 2002, 2003, 2004 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 2, or (at your option)
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 COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "coretypes.h"
30 #include "langhooks.h"
31 #include "hard-reg-set.h"
32 #include "basic-block.h"
37 #include "diagnostic.h"
39 #include "tree-flow.h"
40 #include "tree-gimple.h"
41 #include "tree-inline.h"
44 #include "tree-alias-common.h"
46 #include "tree-dump.h"
47 #include "tree-pass.h"
50 /* Remove edge E and remove the corresponding arguments from the PHI nodes
51 in E's destination block. */
54 ssa_remove_edge (edge e
)
58 /* Remove the appropriate PHI arguments in E's destination block. */
59 for (phi
= phi_nodes (e
->dest
); phi
; phi
= next
)
61 next
= TREE_CHAIN (phi
);
62 remove_phi_arg (phi
, e
->src
);
68 /* Remove remove the corresponding arguments from the PHI nodes
69 in E's destination block and redirect it to DEST. Return redirected edge.
70 The list of removed arguments is stored in PENDING_STMT (e). */
73 ssa_redirect_edge (edge e
, basic_block dest
)
76 tree list
= NULL
, *last
= &list
;
80 /* Remove the appropriate PHI arguments in E's destination block. */
81 for (phi
= phi_nodes (e
->dest
); phi
; phi
= next
)
83 next
= TREE_CHAIN (phi
);
85 i
= phi_arg_from_edge (phi
, e
);
89 src
= PHI_ARG_DEF (phi
, i
);
90 dst
= PHI_RESULT (phi
);
91 node
= build_tree_list (dst
, src
);
93 last
= &TREE_CHAIN (node
);
95 remove_phi_arg_num (phi
, i
);
98 e
= redirect_edge_succ_nodup (e
, dest
);
99 PENDING_STMT (e
) = list
;
105 /* Return true if the definition of SSA_NAME at block BB is malformed.
107 STMT is the statement where SSA_NAME is created.
109 DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME version
110 numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set, it means that the
111 block in that array slot contains the definition of SSA_NAME. */
114 verify_def (basic_block bb
, basic_block
*definition_block
, tree ssa_name
,
119 if (TREE_CODE (ssa_name
) != SSA_NAME
)
121 error ("Expected an SSA_NAME object");
122 debug_generic_stmt (ssa_name
);
123 debug_generic_stmt (stmt
);
126 if (definition_block
[SSA_NAME_VERSION (ssa_name
)])
128 error ("SSA_NAME created in two different blocks %i and %i",
129 definition_block
[SSA_NAME_VERSION (ssa_name
)]->index
, bb
->index
);
130 fprintf (stderr
, "SSA_NAME: ");
131 debug_generic_stmt (ssa_name
);
132 debug_generic_stmt (stmt
);
136 definition_block
[SSA_NAME_VERSION (ssa_name
)] = bb
;
138 if (SSA_NAME_DEF_STMT (ssa_name
) != stmt
)
140 error ("SSA_NAME_DEF_STMT is wrong");
141 fprintf (stderr
, "SSA_NAME: ");
142 debug_generic_stmt (ssa_name
);
143 fprintf (stderr
, "Expected definition statement:\n");
144 debug_generic_stmt (SSA_NAME_DEF_STMT (ssa_name
));
145 fprintf (stderr
, "\nActual definition statement:\n");
146 debug_generic_stmt (stmt
);
154 /* Return true if the use of SSA_NAME at statement STMT in block BB is
157 DEF_BB is the block where SSA_NAME was found to be created.
159 IDOM contains immediate dominator information for the flowgraph.
161 CHECK_ABNORMAL is true if the caller wants to check whether this use
162 is flowing through an abnormal edge (only used when checking PHI
166 verify_use (basic_block bb
, basic_block def_bb
, tree ssa_name
,
167 tree stmt
, bool check_abnormal
)
171 if (IS_EMPTY_STMT (SSA_NAME_DEF_STMT (ssa_name
)))
172 ; /* Nothing to do. */
175 error ("Missing definition");
178 else if (bb
!= def_bb
179 && !dominated_by_p (CDI_DOMINATORS
, bb
, def_bb
))
181 error ("Definition in block %i does not dominate use in block %i",
182 def_bb
->index
, bb
->index
);
187 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name
))
189 error ("SSA_NAME_OCCURS_IN_ABNORMAL_PHI should be set");
195 fprintf (stderr
, "for SSA_NAME: ");
196 debug_generic_stmt (ssa_name
);
197 fprintf (stderr
, "in statement:\n");
198 debug_generic_stmt (stmt
);
205 /* Return true if any of the arguments for PHI node PHI at block BB is
208 IDOM contains immediate dominator information for the flowgraph.
210 DEFINITION_BLOCK is an array of basic blocks indexed by SSA_NAME version
211 numbers. If DEFINITION_BLOCK[SSA_NAME_VERSION] is set, it means that the
212 block in that array slot contains the definition of SSA_NAME. */
215 verify_phi_args (tree phi
, basic_block bb
, basic_block
*definition_block
)
219 int i
, phi_num_args
= PHI_NUM_ARGS (phi
);
221 /* Mark all the incoming edges. */
222 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
225 for (i
= 0; i
< phi_num_args
; i
++)
227 tree op
= PHI_ARG_DEF (phi
, i
);
229 e
= PHI_ARG_EDGE (phi
, i
);
231 if (TREE_CODE (op
) == SSA_NAME
)
232 err
|= verify_use (e
->src
, definition_block
[SSA_NAME_VERSION (op
)], op
,
233 phi
, e
->flags
& EDGE_ABNORMAL
);
237 error ("Wrong edge %d->%d for PHI argument\n",
238 e
->src
->index
, e
->dest
->index
, bb
->index
);
242 if (e
->aux
== (void *) 0)
244 error ("PHI argument flowing through dead edge %d->%d\n",
245 e
->src
->index
, e
->dest
->index
);
249 if (e
->aux
== (void *) 2)
251 error ("PHI argument duplicated for edge %d->%d\n", e
->src
->index
,
258 fprintf (stderr
, "PHI argument\n");
259 debug_generic_stmt (op
);
265 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
267 if (e
->aux
!= (void *) 2)
269 error ("No argument flowing through edge %d->%d\n", e
->src
->index
,
278 fprintf (stderr
, "for PHI node\n");
279 debug_generic_stmt (phi
);
287 /* Verify common invariants in the SSA web.
288 TODO: verify the variable annotations. */
295 basic_block
*definition_block
= xcalloc (highest_ssa_version
,
296 sizeof (basic_block
));
298 timevar_push (TV_TREE_SSA_VERIFY
);
300 calculate_dominance_info (CDI_DOMINATORS
);
302 /* Verify and register all the SSA_NAME definitions found in the
307 block_stmt_iterator bsi
;
309 for (phi
= phi_nodes (bb
); phi
; phi
= TREE_CHAIN (phi
))
310 err
|= verify_def (bb
, definition_block
, PHI_RESULT (phi
), phi
);
312 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
320 stmt
= bsi_stmt (bsi
);
321 ann
= stmt_ann (stmt
);
322 get_stmt_operands (stmt
);
324 vdefs
= VDEF_OPS (ann
);
325 for (j
= 0; j
< NUM_VDEFS (vdefs
); j
++)
327 tree op
= VDEF_RESULT (vdefs
, j
);
328 if (is_gimple_reg (op
))
330 error ("Found a virtual definition for a GIMPLE register");
331 debug_generic_stmt (op
);
332 debug_generic_stmt (stmt
);
335 err
|= verify_def (bb
, definition_block
, op
, stmt
);
338 defs
= DEF_OPS (ann
);
339 for (j
= 0; j
< NUM_DEFS (defs
); j
++)
341 tree op
= DEF_OP (defs
, j
);
342 if (TREE_CODE (op
) == SSA_NAME
&& !is_gimple_reg (op
))
344 error ("Found a real definition for a non-GIMPLE register");
345 debug_generic_stmt (op
);
346 debug_generic_stmt (stmt
);
349 err
|= verify_def (bb
, definition_block
, op
, stmt
);
355 /* Now verify all the uses and make sure they agree with the definitions
356 found in the previous pass. */
361 block_stmt_iterator bsi
;
363 /* Make sure that all edges have a clear 'aux' field. */
364 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
368 error ("AUX pointer initialized for edge %d->%d\n", e
->src
->index
,
374 /* Verify the arguments for every PHI node in the block. */
375 for (phi
= phi_nodes (bb
); phi
; phi
= TREE_CHAIN (phi
))
376 err
|= verify_phi_args (phi
, bb
, definition_block
);
378 /* Now verify all the uses and vuses in every statement of the block.
380 Remember, the RHS of a VDEF is a use as well. */
381 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
383 tree stmt
= bsi_stmt (bsi
);
384 stmt_ann_t ann
= stmt_ann (stmt
);
390 vuses
= VUSE_OPS (ann
);
391 for (j
= 0; j
< NUM_VUSES (vuses
); j
++)
393 tree op
= VUSE_OP (vuses
, j
);
395 if (is_gimple_reg (op
))
397 error ("Found a virtual use for a GIMPLE register");
398 debug_generic_stmt (op
);
399 debug_generic_stmt (stmt
);
402 err
|= verify_use (bb
, definition_block
[SSA_NAME_VERSION (op
)],
406 vdefs
= VDEF_OPS (ann
);
407 for (j
= 0; j
< NUM_VDEFS (vdefs
); j
++)
409 tree op
= VDEF_OP (vdefs
, j
);
411 if (is_gimple_reg (op
))
413 error ("Found a virtual use for a GIMPLE register");
414 debug_generic_stmt (op
);
415 debug_generic_stmt (stmt
);
418 err
|= verify_use (bb
, definition_block
[SSA_NAME_VERSION (op
)],
422 uses
= USE_OPS (ann
);
423 for (j
= 0; j
< NUM_USES (uses
); j
++)
425 tree op
= USE_OP (uses
, j
);
427 if (TREE_CODE (op
) == SSA_NAME
&& !is_gimple_reg (op
))
429 error ("Found a real use of a non-GIMPLE register");
430 debug_generic_stmt (op
);
431 debug_generic_stmt (stmt
);
434 err
|= verify_use (bb
, definition_block
[SSA_NAME_VERSION (op
)],
440 free (definition_block
);
442 timevar_pop (TV_TREE_SSA_VERIFY
);
445 internal_error ("verify_ssa failed.");
449 /* Set the USED bit in the annotation for T. */
459 switch (TREE_CODE (t
))
467 t
= TREE_OPERAND (t
, 0);
475 if (TREE_CODE (t
) == SSA_NAME
)
476 t
= SSA_NAME_VAR (t
);
478 var_ann (t
)->used
= 1;
482 /* Initialize global DFA and SSA structures. */
487 VARRAY_TREE_INIT (referenced_vars
, 20, "referenced_vars");
488 call_clobbered_vars
= BITMAP_XMALLOC ();
489 init_ssa_operands ();
492 global_var
= NULL_TREE
;
493 aliases_computed_p
= false;
497 /* Deallocate memory associated with SSA data structures for FNDECL. */
500 delete_tree_ssa (void)
504 block_stmt_iterator bsi
;
506 /* Remove annotations from every tree in the function. */
508 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
509 bsi_stmt (bsi
)->common
.ann
= NULL
;
511 /* Remove annotations from every referenced variable. */
514 for (i
= 0; i
< num_referenced_vars
; i
++)
515 referenced_var (i
)->common
.ann
= NULL
;
516 referenced_vars
= NULL
;
521 fini_ssa_operands ();
523 global_var
= NULL_TREE
;
524 BITMAP_XFREE (call_clobbered_vars
);
525 call_clobbered_vars
= NULL
;
526 aliases_computed_p
= false;
530 /* Return true if EXPR is a useless type conversion, otherwise return
534 tree_ssa_useless_type_conversion_1 (tree outer_type
, tree inner_type
)
536 /* If the inner and outer types are effectively the same, then
537 strip the type conversion and enter the equivalence into
539 if (inner_type
== outer_type
540 || (lang_hooks
.types_compatible_p (inner_type
, outer_type
)))
543 /* If both types are pointers and the outer type is a (void *), then
544 the conversion is not necessary. The opposite is not true since
545 that conversion would result in a loss of information if the
546 equivalence was used. Consider an indirect function call where
547 we need to know the exact type of the function to correctly
548 implement the ABI. */
549 else if (POINTER_TYPE_P (inner_type
)
550 && POINTER_TYPE_P (outer_type
)
551 && TREE_CODE (TREE_TYPE (outer_type
)) == VOID_TYPE
)
554 /* Pointers and references are equivalent once we get to GENERIC,
555 so strip conversions that just switch between them. */
556 else if (POINTER_TYPE_P (inner_type
)
557 && POINTER_TYPE_P (outer_type
)
558 && lang_hooks
.types_compatible_p (inner_type
, outer_type
))
561 /* If both the inner and outer types are integral types, then the
562 conversion is not necessary if they have the same mode and
563 signedness and precision. Note that type _Bool can have size of
564 4 (only happens on powerpc-darwin right now but can happen on any
565 target that defines BOOL_TYPE_SIZE to be INT_TYPE_SIZE) and a
566 precision of 1 while unsigned int is the same expect for a
567 precision of 4 so testing of precision is necessary. */
568 else if (INTEGRAL_TYPE_P (inner_type
)
569 && INTEGRAL_TYPE_P (outer_type
)
570 && TYPE_MODE (inner_type
) == TYPE_MODE (outer_type
)
571 && TYPE_UNSIGNED (inner_type
) == TYPE_UNSIGNED (outer_type
)
572 && TYPE_PRECISION (inner_type
) == TYPE_PRECISION (outer_type
))
575 /* Recurse for complex types. */
576 else if (TREE_CODE (inner_type
) == COMPLEX_TYPE
577 && TREE_CODE (outer_type
) == COMPLEX_TYPE
578 && tree_ssa_useless_type_conversion_1 (TREE_TYPE (outer_type
),
579 TREE_TYPE (inner_type
)))
585 /* Return true if EXPR is a useless type conversion, otherwise return
589 tree_ssa_useless_type_conversion (tree expr
)
591 /* If we have an assignment that merely uses a NOP_EXPR to change
592 the top of the RHS to the type of the LHS and the type conversion
593 is "safe", then strip away the type conversion so that we can
594 enter LHS = RHS into the const_and_copies table. */
595 if (TREE_CODE (expr
) == NOP_EXPR
|| TREE_CODE (expr
) == CONVERT_EXPR
)
596 return tree_ssa_useless_type_conversion_1 (TREE_TYPE (expr
),
597 TREE_TYPE (TREE_OPERAND (expr
,
605 /* Internal helper for walk_use_def_chains. VAR, FN and DATA are as
606 described in walk_use_def_chains. VISITED is a bitmap used to mark
607 visited SSA_NAMEs to avoid infinite loops. */
610 walk_use_def_chains_1 (tree var
, walk_use_def_chains_fn fn
, void *data
,
615 if (bitmap_bit_p (visited
, SSA_NAME_VERSION (var
)))
618 bitmap_set_bit (visited
, SSA_NAME_VERSION (var
));
620 def_stmt
= SSA_NAME_DEF_STMT (var
);
622 if (TREE_CODE (def_stmt
) != PHI_NODE
)
624 /* If we reached the end of the use-def chain, call FN. */
625 return (*fn
) (var
, def_stmt
, data
);
631 /* Otherwise, follow use-def links out of each PHI argument and call
632 FN after visiting each one. */
633 for (i
= 0; i
< PHI_NUM_ARGS (def_stmt
); i
++)
635 tree arg
= PHI_ARG_DEF (def_stmt
, i
);
636 if (TREE_CODE (arg
) == SSA_NAME
637 && walk_use_def_chains_1 (arg
, fn
, data
, visited
))
640 if ((*fn
) (arg
, def_stmt
, data
))
649 /* Walk use-def chains starting at the SSA variable VAR. Call function FN
650 at each reaching definition found. FN takes three arguments: VAR, its
651 defining statement (DEF_STMT) and a generic pointer to whatever state
652 information that FN may want to maintain (DATA). FN is able to stop the
653 walk by returning true, otherwise in order to continue the walk, FN
656 Note, that if DEF_STMT is a PHI node, the semantics are slightly
657 different. For each argument ARG of the PHI node, this function will:
659 1- Walk the use-def chains for ARG.
660 2- Call (*FN) (ARG, PHI, DATA).
662 Note how the first argument to FN is no longer the original variable
663 VAR, but the PHI argument currently being examined. If FN wants to get
664 at VAR, it should call PHI_RESULT (PHI). */
667 walk_use_def_chains (tree var
, walk_use_def_chains_fn fn
, void *data
)
671 #if defined ENABLE_CHECKING
672 if (TREE_CODE (var
) != SSA_NAME
)
676 def_stmt
= SSA_NAME_DEF_STMT (var
);
678 /* We only need to recurse if the reaching definition comes from a PHI
680 if (TREE_CODE (def_stmt
) != PHI_NODE
)
681 (*fn
) (var
, def_stmt
, data
);
684 bitmap visited
= BITMAP_XMALLOC ();
685 walk_use_def_chains_1 (var
, fn
, data
, visited
);
686 BITMAP_XFREE (visited
);
691 /* Replaces immediate uses of VAR by REPL. */
694 replace_immediate_uses (tree var
, tree repl
)
704 df
= get_immediate_uses (SSA_NAME_DEF_STMT (var
));
705 n
= num_immediate_uses (df
);
707 for (i
= 0; i
< n
; i
++)
709 stmt
= immediate_use (df
, i
);
710 ann
= stmt_ann (stmt
);
712 if (TREE_CODE (stmt
) == PHI_NODE
)
714 for (j
= 0; j
< PHI_NUM_ARGS (stmt
); j
++)
715 if (PHI_ARG_DEF (stmt
, j
) == var
)
717 PHI_ARG_DEF (stmt
, j
) = repl
;
718 if (TREE_CODE (repl
) == SSA_NAME
719 && PHI_ARG_EDGE (stmt
, j
)->flags
& EDGE_ABNORMAL
)
720 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (repl
) = 1;
726 get_stmt_operands (stmt
);
727 if (is_gimple_reg (SSA_NAME_VAR (var
)))
729 uses
= USE_OPS (ann
);
730 for (j
= 0; j
< (int) NUM_USES (uses
); j
++)
731 if (USE_OP (uses
, j
) == var
)
732 propagate_value (USE_OP_PTR (uses
, j
), repl
);
736 vuses
= VUSE_OPS (ann
);
737 for (j
= 0; j
< (int) NUM_VUSES (vuses
); j
++)
738 if (VUSE_OP (vuses
, j
) == var
)
739 propagate_value (VUSE_OP_PTR (vuses
, j
), repl
);
741 vdefs
= VDEF_OPS (ann
);
742 for (j
= 0; j
< (int) NUM_VDEFS (vdefs
); j
++)
743 if (VDEF_OP (vdefs
, j
) == var
)
744 propagate_value (VDEF_OP_PTR (vdefs
, j
), repl
);
749 /* If REPL is a pointer, it may have different memory tags associated
750 with it. For instance, VAR may have had a name tag while REPL
751 only had a type tag. In these cases, the virtual operands (if
752 any) in the statement will refer to different symbols which need
754 if (POINTER_TYPE_P (TREE_TYPE (repl
)))
755 mark_new_vars_to_rename (stmt
, vars_to_rename
);
759 /* Raises value of phi node PHI by joining it with VAL. Processes immediate
760 uses of PHI recursively. */
763 raise_value (tree phi
, tree val
, tree
*eq_to
)
766 tree var
= PHI_RESULT (phi
), stmt
;
767 int ver
= SSA_NAME_VERSION (var
);
770 if (eq_to
[ver
] == var
)
773 switch (TREE_CODE (val
))
780 if (TREE_CODE (TREE_TYPE (var
)) != POINTER_TYPE
)
784 /* Do not propagate pointer constants. This might require folding
785 things like *&foo and rewriting the ssa, which is not worth the
792 if (operand_equal_p (eq_to
[ver
], val
, 0))
800 df
= get_immediate_uses (SSA_NAME_DEF_STMT (var
));
801 n
= num_immediate_uses (df
);
803 for (i
= 0; i
< n
; i
++)
805 stmt
= immediate_use (df
, i
);
807 if (TREE_CODE (stmt
) != PHI_NODE
)
810 raise_value (stmt
, eq_to
[ver
], eq_to
);
814 /* Removes redundant phi nodes.
816 A redundant PHI node is a PHI node where all of its PHI arguments
817 are the same value, excluding any PHI arguments which are the same
820 A redundant PHI node is effectively a copy, so we forward copy propagate
821 which removes all uses of the destination of the PHI node then
822 finally we delete the redundant PHI node.
824 Note that if we can not copy propagate the PHI node, then the PHI
825 will not be removed. Thus we do not have to worry about dependencies
826 between PHIs and the problems serializing PHIs into copies creates.
828 The most important effect of this pass is to remove degenerate PHI
829 nodes created by removing unreachable code. */
832 kill_redundant_phi_nodes (void)
834 tree
*eq_to
, *ssa_names
;
835 unsigned i
, ver
, aver
;
837 tree phi
, t
, stmt
, var
;
839 /* The EQ_TO array holds the current value of the ssa name in the
848 Bottom is represented by NULL and top by the variable itself.
850 Once the dataflow stabilizes, we know that the phi nodes we need to keep
851 are exactly those with top as their result.
853 The remaining phi nodes have their uses replaced with their value
854 in the lattice and the phi node itself is removed. */
855 eq_to
= xcalloc (highest_ssa_version
, sizeof (tree
));
857 /* The SSA_NAMES array holds each SSA_NAME node we encounter
858 in a PHI node (indexed by ssa version number).
860 One could argue that the SSA_NAME manager ought to provide a
861 generic interface to get at the SSA_NAME node for a given
862 ssa version number. */
863 ssa_names
= xcalloc (highest_ssa_version
, sizeof (tree
));
865 /* We have had cases where computing immediate uses takes a
866 significant amount of compile time. If we run into such
867 problems here, we may want to only compute immediate uses for
868 a subset of all the SSA_NAMEs instead of computing it for
869 all of the SSA_NAMEs. */
870 compute_immediate_uses (TDFA_USE_OPS
| TDFA_USE_VOPS
, NULL
);
874 for (phi
= phi_nodes (bb
); phi
; phi
= TREE_CHAIN (phi
))
876 var
= PHI_RESULT (phi
);
877 ver
= SSA_NAME_VERSION (var
);
878 ssa_names
[ver
] = var
;
880 for (i
= 0; i
< (unsigned) PHI_NUM_ARGS (phi
); i
++)
882 t
= PHI_ARG_DEF (phi
, i
);
884 if (TREE_CODE (t
) != SSA_NAME
)
886 raise_value (phi
, t
, eq_to
);
890 stmt
= SSA_NAME_DEF_STMT (t
);
891 aver
= SSA_NAME_VERSION (t
);
894 /* If the defining statement for this argument is not a
895 phi node or the argument is associated with an abnormal
896 edge, then we need to recursively start the forward
897 dataflow starting with PHI. */
898 if (TREE_CODE (stmt
) != PHI_NODE
899 || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (t
))
902 raise_value (phi
, t
, eq_to
);
908 /* Now propagate the values. */
909 for (i
= 0; i
< highest_ssa_version
; i
++)
911 && eq_to
[i
] != ssa_names
[i
])
912 replace_immediate_uses (ssa_names
[i
], eq_to
[i
]);
914 /* And remove the dead phis. */
915 for (i
= 0; i
< highest_ssa_version
; i
++)
917 && eq_to
[i
] != ssa_names
[i
])
919 stmt
= SSA_NAME_DEF_STMT (ssa_names
[i
]);
920 remove_phi_node (stmt
, 0, bb_for_stmt (stmt
));
928 struct tree_opt_pass pass_redundant_phi
=
932 kill_redundant_phi_nodes
, /* execute */
935 0, /* static_pass_number */
937 PROP_cfg
| PROP_ssa
, /* properties_required */
938 0, /* properties_provided */
939 0, /* properties_destroyed */
940 0, /* todo_flags_start */
941 TODO_dump_func
| TODO_rename_vars
942 | TODO_ggc_collect
| TODO_verify_ssa
/* todo_flags_finish */
945 /* Emit warnings for uninitialized variables. This is done in two passes.
947 The first pass notices real uses of SSA names with default definitions.
948 Such uses are unconditionally uninitialized, and we can be certain that
949 such a use is a mistake. This pass is run before most optimizations,
950 so that we catch as many as we can.
952 The second pass follows PHI nodes to find uses that are potentially
953 uninitialized. In this case we can't necessarily prove that the use
954 is really uninitialized. This pass is run after most optimizations,
955 so that we thread as many jumps and possible, and delete as much dead
956 code as possible, in order to reduce false positives. We also look
957 again for plain uninitialized variables, since optimization may have
958 changed conditionally uninitialized to unconditionally uninitialized. */
960 /* Emit a warning for T, an SSA_NAME, being uninitialized. The exact
961 warning text is in MSGID and LOCUS may contain a location or be null. */
964 warn_uninit (tree t
, const char *msgid
, location_t
*locus
)
966 tree var
= SSA_NAME_VAR (t
);
967 tree def
= SSA_NAME_DEF_STMT (t
);
969 /* Default uses (indicated by an empty definition statement),
970 are uninitialized. */
971 if (!IS_EMPTY_STMT (def
))
974 /* Except for PARMs of course, which are always initialized. */
975 if (TREE_CODE (var
) == PARM_DECL
)
978 /* Hard register variables get their initial value from the ether. */
979 if (DECL_HARD_REGISTER (var
))
982 /* TREE_NO_WARNING either means we already warned, or the front end
983 wishes to suppress the warning. */
984 if (TREE_NO_WARNING (var
))
988 locus
= &DECL_SOURCE_LOCATION (var
);
989 warning (msgid
, locus
, var
);
990 TREE_NO_WARNING (var
) = 1;
993 /* Called via walk_tree, look for SSA_NAMEs that have empty definitions
994 and warn about them. */
997 warn_uninitialized_var (tree
*tp
, int *walk_subtrees
, void *data
)
999 location_t
*locus
= data
;
1002 /* We only do data flow with SSA_NAMEs, so that's all we can warn about. */
1003 if (TREE_CODE (t
) == SSA_NAME
)
1005 warn_uninit (t
, "%H'%D' is used uninitialized in this function", locus
);
1008 else if (DECL_P (t
) || TYPE_P (t
))
1014 /* Look for inputs to PHI that are SSA_NAMEs that have empty definitions
1015 and warn about them. */
1018 warn_uninitialized_phi (tree phi
)
1020 int i
, n
= PHI_NUM_ARGS (phi
);
1022 /* Don't look at memory tags. */
1023 if (!is_gimple_reg (PHI_RESULT (phi
)))
1026 for (i
= 0; i
< n
; ++i
)
1028 tree op
= PHI_ARG_DEF (phi
, i
);
1029 if (TREE_CODE (op
) == SSA_NAME
)
1030 warn_uninit (op
, "%H'%D' may be used uninitialized in this function",
1036 execute_early_warn_uninitialized (void)
1038 block_stmt_iterator bsi
;
1042 for (bsi
= bsi_start (bb
); !bsi_end_p (bsi
); bsi_next (&bsi
))
1043 walk_tree (bsi_stmt_ptr (bsi
), warn_uninitialized_var
,
1044 EXPR_LOCUS (bsi_stmt (bsi
)), NULL
);
1048 execute_late_warn_uninitialized (void)
1053 /* Re-do the plain uninitialized variable check, as optimization may have
1054 straightened control flow. Do this first so that we don't accidentally
1055 get a "may be" warning when we'd have seen an "is" warning later. */
1056 execute_early_warn_uninitialized ();
1059 for (phi
= phi_nodes (bb
); phi
; phi
= TREE_CHAIN (phi
))
1060 warn_uninitialized_phi (phi
);
1064 gate_warn_uninitialized (void)
1066 return warn_uninitialized
!= 0;
1069 struct tree_opt_pass pass_early_warn_uninitialized
=
1072 gate_warn_uninitialized
, /* gate */
1073 execute_early_warn_uninitialized
, /* execute */
1076 0, /* static_pass_number */
1078 PROP_ssa
, /* properties_required */
1079 0, /* properties_provided */
1080 0, /* properties_destroyed */
1081 0, /* todo_flags_start */
1082 0 /* todo_flags_finish */
1085 struct tree_opt_pass pass_late_warn_uninitialized
=
1088 gate_warn_uninitialized
, /* gate */
1089 execute_late_warn_uninitialized
, /* execute */
1092 0, /* static_pass_number */
1094 PROP_ssa
, /* properties_required */
1095 0, /* properties_provided */
1096 0, /* properties_destroyed */
1097 0, /* todo_flags_start */
1098 0 /* todo_flags_finish */