1 /* Data flow functions for trees.
2 Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
30 #include "hard-reg-set.h"
31 #include "basic-block.h"
37 #include "langhooks.h"
40 #include "diagnostic.h"
41 #include "tree-dump.h"
42 #include "tree-gimple.h"
43 #include "tree-flow.h"
44 #include "tree-inline.h"
45 #include "tree-alias-common.h"
46 #include "tree-pass.h"
50 /* Build and maintain data flow information for trees. */
52 /* Counters used to display DFA and SSA statistics. */
68 /* State information for find_vars_r. */
71 /* Hash table used to avoid adding the same variable more than once. */
76 /* Local functions. */
77 static void collect_dfa_stats (struct dfa_stats_d
*);
78 static tree
collect_dfa_stats_r (tree
*, int *, void *);
79 static void add_immediate_use (tree
, tree
);
80 static tree
find_vars_r (tree
*, int *, void *);
81 static void add_referenced_var (tree
, struct walk_state
*);
82 static void compute_immediate_uses_for_phi (tree
, bool (*)(tree
));
83 static void compute_immediate_uses_for_stmt (tree
, int, bool (*)(tree
));
86 /* Global declarations. */
88 /* Array of all variables referenced in the function. */
89 varray_type referenced_vars
;
92 /*---------------------------------------------------------------------------
93 Dataflow analysis (DFA) routines
94 ---------------------------------------------------------------------------*/
95 /* Find all the variables referenced in the function. This function
96 builds the global arrays REFERENCED_VARS and CALL_CLOBBERED_VARS.
98 Note that this function does not look for statement operands, it simply
99 determines what variables are referenced in the program and detects
100 various attributes for each variable used by alias analysis and the
104 find_referenced_vars (void)
108 block_stmt_iterator si
;
109 struct walk_state walk_state
;
111 vars_found
= htab_create (50, htab_hash_pointer
, htab_eq_pointer
, NULL
);
112 memset (&walk_state
, 0, sizeof (walk_state
));
113 walk_state
.vars_found
= vars_found
;
116 for (si
= bsi_start (bb
); !bsi_end_p (si
); bsi_next (&si
))
118 tree
*stmt_p
= bsi_stmt_ptr (si
);
119 walk_tree (stmt_p
, find_vars_r
, &walk_state
, NULL
);
122 htab_delete (vars_found
);
125 struct tree_opt_pass pass_referenced_vars
=
129 find_referenced_vars
, /* execute */
132 0, /* static_pass_number */
134 PROP_gimple_leh
| PROP_cfg
, /* properties_required */
135 PROP_referenced_vars
, /* properties_provided */
136 0, /* properties_destroyed */
137 0, /* todo_flags_start */
138 0, /* todo_flags_finish */
142 /* Compute immediate uses.
144 CALC_FOR is an optional function pointer which indicates whether
145 immediate uses information should be calculated for a given SSA
146 variable. If NULL, then information is computed for all
149 FLAGS is one of {TDFA_USE_OPS, TDFA_USE_VOPS}. It is used by
150 compute_immediate_uses_for_stmt to determine whether to look at
151 virtual and/or real operands while computing def-use chains. */
154 compute_immediate_uses (int flags
, bool (*calc_for
)(tree
))
157 block_stmt_iterator si
;
163 for (phi
= phi_nodes (bb
); phi
; phi
= PHI_CHAIN (phi
))
165 if (is_gimple_reg (PHI_RESULT (phi
)))
167 if (!(flags
& TDFA_USE_OPS
))
172 if (!(flags
& TDFA_USE_VOPS
))
176 compute_immediate_uses_for_phi (phi
, calc_for
);
179 for (si
= bsi_start (bb
); !bsi_end_p (si
); bsi_next (&si
))
181 tree stmt
= bsi_stmt (si
);
182 get_stmt_operands (stmt
);
183 compute_immediate_uses_for_stmt (stmt
, flags
, calc_for
);
189 /* Invalidates dataflow information for a statement STMT. */
192 free_df_for_stmt (tree stmt
)
194 stmt_ann_t ann
= stmt_ann (stmt
);
198 /* If we have a varray of immediate uses, then go ahead and release
200 if (ann
->df
->immediate_uses
)
201 ggc_free (ann
->df
->immediate_uses
);
203 /* Similarly for the main dataflow structure. */
210 /* Invalidate dataflow information for the whole function. */
216 block_stmt_iterator si
;
222 for (phi
= phi_nodes (bb
); phi
; phi
= PHI_CHAIN (phi
))
223 free_df_for_stmt (phi
);
225 for (si
= bsi_start (bb
); !bsi_end_p (si
); bsi_next (&si
))
227 tree stmt
= bsi_stmt (si
);
228 free_df_for_stmt (stmt
);
234 /* Helper for compute_immediate_uses. Check all the USE and/or VUSE
235 operands in phi node PHI and add a def-use edge between their
236 defining statement and PHI. CALC_FOR is as in
237 compute_immediate_uses.
239 PHI nodes are easy, we only need to look at their arguments. */
242 compute_immediate_uses_for_phi (tree phi
, bool (*calc_for
)(tree
))
246 #ifdef ENABLE_CHECKING
247 if (TREE_CODE (phi
) != PHI_NODE
)
251 for (i
= 0; i
< PHI_NUM_ARGS (phi
); i
++)
253 tree arg
= PHI_ARG_DEF (phi
, i
);
255 if (TREE_CODE (arg
) == SSA_NAME
&& (!calc_for
|| calc_for (arg
)))
257 tree imm_rdef_stmt
= SSA_NAME_DEF_STMT (PHI_ARG_DEF (phi
, i
));
258 if (!IS_EMPTY_STMT (imm_rdef_stmt
))
259 add_immediate_use (imm_rdef_stmt
, phi
);
265 /* Another helper for compute_immediate_uses. Depending on the value
266 of FLAGS, check all the USE and/or VUSE operands in STMT and add a
267 def-use edge between their defining statement and STMT. CALC_FOR
268 is as in compute_immediate_uses. */
271 compute_immediate_uses_for_stmt (tree stmt
, int flags
, bool (*calc_for
)(tree
))
276 v_may_def_optype v_may_defs
;
279 #ifdef ENABLE_CHECKING
280 /* PHI nodes are handled elsewhere. */
281 if (TREE_CODE (stmt
) == PHI_NODE
)
285 /* Look at USE_OPS or VUSE_OPS according to FLAGS. */
286 ann
= stmt_ann (stmt
);
287 if (flags
& TDFA_USE_OPS
)
289 uses
= USE_OPS (ann
);
290 for (i
= 0; i
< NUM_USES (uses
); i
++)
292 tree use
= USE_OP (uses
, i
);
293 tree imm_stmt
= SSA_NAME_DEF_STMT (use
);
294 if (!IS_EMPTY_STMT (imm_stmt
) && (!calc_for
|| calc_for (use
)))
295 add_immediate_use (imm_stmt
, stmt
);
299 if (flags
& TDFA_USE_VOPS
)
301 vuses
= VUSE_OPS (ann
);
302 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
304 tree vuse
= VUSE_OP (vuses
, i
);
305 tree imm_rdef_stmt
= SSA_NAME_DEF_STMT (vuse
);
306 if (!IS_EMPTY_STMT (imm_rdef_stmt
) && (!calc_for
|| calc_for (vuse
)))
307 add_immediate_use (imm_rdef_stmt
, stmt
);
310 v_may_defs
= V_MAY_DEF_OPS (ann
);
311 for (i
= 0; i
< NUM_V_MAY_DEFS (v_may_defs
); i
++)
313 tree vuse
= V_MAY_DEF_OP (v_may_defs
, i
);
314 tree imm_rdef_stmt
= SSA_NAME_DEF_STMT (vuse
);
315 if (!IS_EMPTY_STMT (imm_rdef_stmt
) && (!calc_for
|| calc_for (vuse
)))
316 add_immediate_use (imm_rdef_stmt
, stmt
);
322 /* Add statement USE_STMT to the list of statements that use definitions
326 add_immediate_use (tree stmt
, tree use_stmt
)
328 stmt_ann_t ann
= get_stmt_ann (stmt
);
329 struct dataflow_d
*df
;
334 df
= ann
->df
= ggc_alloc (sizeof (struct dataflow_d
));
335 memset ((void *) df
, 0, sizeof (struct dataflow_d
));
336 df
->uses
[0] = use_stmt
;
342 df
->uses
[1] = use_stmt
;
346 if (ann
->df
->immediate_uses
== NULL
)
347 VARRAY_TREE_INIT (ann
->df
->immediate_uses
, 4, "immediate_uses");
349 VARRAY_PUSH_TREE (ann
->df
->immediate_uses
, use_stmt
);
353 /* If the immediate use of USE points to OLD, then redirect it to NEW. */
356 redirect_immediate_use (tree use
, tree old
, tree
new)
358 tree imm_stmt
= SSA_NAME_DEF_STMT (use
);
359 struct dataflow_d
*df
= get_stmt_ann (imm_stmt
)->df
;
360 unsigned int num_uses
= num_immediate_uses (df
);
363 for (i
= 0; i
< num_uses
; i
++)
365 if (immediate_use (df
, i
) == old
)
367 if (i
== 0 || i
== 1)
370 VARRAY_TREE (df
->immediate_uses
, i
- 2) = new;
376 /* Redirect all immediate uses for operands in OLD so that they point
377 to NEW. This routine should have no knowledge of how immediate
381 redirect_immediate_uses (tree old
, tree
new)
383 stmt_ann_t ann
= get_stmt_ann (old
);
384 use_optype uses
= USE_OPS (ann
);
385 vuse_optype vuses
= VUSE_OPS (ann
);
386 v_may_def_optype v_may_defs
= V_MAY_DEF_OPS (ann
);
389 /* Look at USE_OPS or VUSE_OPS according to FLAGS. */
390 for (i
= 0; i
< NUM_USES (uses
); i
++)
391 redirect_immediate_use (USE_OP (uses
, i
), old
, new);
393 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
394 redirect_immediate_use (VUSE_OP (vuses
, i
), old
, new);
396 for (i
= 0; i
< NUM_V_MAY_DEFS (v_may_defs
); i
++)
397 redirect_immediate_use (V_MAY_DEF_OP (v_may_defs
, i
), old
, new);
401 /*---------------------------------------------------------------------------
403 ---------------------------------------------------------------------------*/
404 /* Create a new annotation for a _DECL node T. */
407 create_var_ann (tree t
)
411 #if defined ENABLE_CHECKING
415 && t
->common
.ann
->common
.type
!= VAR_ANN
))
419 ann
= ggc_alloc (sizeof (*ann
));
420 memset ((void *) ann
, 0, sizeof (*ann
));
422 ann
->common
.type
= VAR_ANN
;
424 t
->common
.ann
= (tree_ann_t
) ann
;
430 /* Create a new annotation for a statement node T. */
433 create_stmt_ann (tree t
)
437 #if defined ENABLE_CHECKING
438 if ((!is_gimple_stmt (t
))
440 && t
->common
.ann
->common
.type
!= STMT_ANN
))
444 ann
= ggc_alloc (sizeof (*ann
));
445 memset ((void *) ann
, 0, sizeof (*ann
));
447 ann
->common
.type
= STMT_ANN
;
449 /* Since we just created the annotation, mark the statement modified. */
450 ann
->modified
= true;
452 t
->common
.ann
= (tree_ann_t
) ann
;
458 /* Create a new annotation for a tree T. */
461 create_tree_ann (tree t
)
465 #if defined ENABLE_CHECKING
468 && t
->common
.ann
->common
.type
!= TREE_ANN_COMMON
))
472 ann
= ggc_alloc (sizeof (*ann
));
473 memset ((void *) ann
, 0, sizeof (*ann
));
475 ann
->common
.type
= TREE_ANN_COMMON
;
481 /* Build a temporary. Make sure and register it to be renamed. */
484 make_rename_temp (tree type
, const char *prefix
)
486 tree t
= create_tmp_var (type
, prefix
);
489 add_referenced_tmp_var (t
);
490 bitmap_set_bit (vars_to_rename
, var_ann (t
)->uid
);
497 /*---------------------------------------------------------------------------
499 ---------------------------------------------------------------------------*/
500 /* Dump the list of all the referenced variables in the current function to
504 dump_referenced_vars (FILE *file
)
508 fprintf (file
, "\nReferenced variables in %s: %u\n\n",
509 get_name (current_function_decl
), (unsigned) num_referenced_vars
);
511 for (i
= 0; i
< num_referenced_vars
; i
++)
513 tree var
= referenced_var (i
);
514 fprintf (file
, "Variable: ");
515 dump_variable (file
, var
);
516 fprintf (file
, "\n");
521 /* Dump the list of all the referenced variables to stderr. */
524 debug_referenced_vars (void)
526 dump_referenced_vars (stderr
);
530 /* Dump variable VAR and its may-aliases to FILE. */
533 dump_variable (FILE *file
, tree var
)
537 if (TREE_CODE (var
) == SSA_NAME
)
539 if (POINTER_TYPE_P (TREE_TYPE (var
)))
540 dump_points_to_info_for (file
, var
);
541 var
= SSA_NAME_VAR (var
);
544 if (var
== NULL_TREE
)
546 fprintf (file
, "<nil>");
550 print_generic_expr (file
, var
, dump_flags
);
554 fprintf (file
, ", UID %u", (unsigned) ann
->uid
);
556 if (ann
->type_mem_tag
)
558 fprintf (file
, ", type memory tag: ");
559 print_generic_expr (file
, ann
->type_mem_tag
, dump_flags
);
562 if (ann
->is_alias_tag
)
563 fprintf (file
, ", is an alias tag");
565 if (needs_to_live_in_memory (var
))
566 fprintf (file
, ", is %s", TREE_STATIC (var
) ? "static" : "global");
568 if (is_call_clobbered (var
))
569 fprintf (file
, ", call clobbered");
571 if (ann
->default_def
)
573 fprintf (file
, ", default def: ");
574 print_generic_expr (file
, ann
->default_def
, dump_flags
);
577 if (ann
->may_aliases
)
579 fprintf (file
, ", may aliases: ");
580 dump_may_aliases_for (file
, var
);
583 fprintf (file
, "\n");
587 /* Dump variable VAR and its may-aliases to stderr. */
590 debug_variable (tree var
)
592 dump_variable (stderr
, var
);
596 /* Dump def-use edges on FILE. */
599 dump_immediate_uses (FILE *file
)
602 block_stmt_iterator si
;
604 = lang_hooks
.decl_printable_name (current_function_decl
, 2);
606 fprintf (file
, "\nDef-use edges for function %s\n", funcname
);
612 for (phi
= phi_nodes (bb
); phi
; phi
= PHI_CHAIN (phi
))
613 dump_immediate_uses_for (file
, phi
);
615 for (si
= bsi_start (bb
); !bsi_end_p (si
); bsi_next (&si
))
616 dump_immediate_uses_for (file
, bsi_stmt (si
));
619 fprintf (file
, "\n");
623 /* Dump def-use edges on stderr. */
626 debug_immediate_uses (void)
628 dump_immediate_uses (stderr
);
632 /* Dump all immediate uses for STMT on FILE. */
635 dump_immediate_uses_for (FILE *file
, tree stmt
)
637 dataflow_t df
= get_immediate_uses (stmt
);
638 int num_imm_uses
= num_immediate_uses (df
);
640 if (num_imm_uses
> 0)
644 fprintf (file
, "-> ");
645 print_generic_stmt (file
, stmt
, TDF_SLIM
);
646 fprintf (file
, "\n");
648 for (i
= 0; i
< num_imm_uses
; i
++)
650 fprintf (file
, "\t");
651 print_generic_stmt (file
, immediate_use (df
, i
), TDF_SLIM
);
652 fprintf (file
, "\n");
655 fprintf (file
, "\n");
660 /* Dump immediate uses for STMT on stderr. */
663 debug_immediate_uses_for (tree stmt
)
665 dump_immediate_uses_for (stderr
, stmt
);
669 /* Dump various DFA statistics to FILE. */
672 dump_dfa_stats (FILE *file
)
674 struct dfa_stats_d dfa_stats
;
676 unsigned long size
, total
= 0;
677 const char * const fmt_str
= "%-30s%-13s%12s\n";
678 const char * const fmt_str_1
= "%-30s%13lu%11lu%c\n";
679 const char * const fmt_str_3
= "%-43s%11lu%c\n";
681 = lang_hooks
.decl_printable_name (current_function_decl
, 2);
683 collect_dfa_stats (&dfa_stats
);
685 fprintf (file
, "\nDFA Statistics for %s\n\n", funcname
);
687 fprintf (file
, "---------------------------------------------------------\n");
688 fprintf (file
, fmt_str
, "", " Number of ", "Memory");
689 fprintf (file
, fmt_str
, "", " instances ", "used ");
690 fprintf (file
, "---------------------------------------------------------\n");
692 size
= num_referenced_vars
* sizeof (tree
);
694 fprintf (file
, fmt_str_1
, "Referenced variables", num_referenced_vars
,
695 SCALE (size
), LABEL (size
));
697 size
= dfa_stats
.num_stmt_anns
* sizeof (struct stmt_ann_d
);
699 fprintf (file
, fmt_str_1
, "Statements annotated", dfa_stats
.num_stmt_anns
,
700 SCALE (size
), LABEL (size
));
702 size
= dfa_stats
.num_var_anns
* sizeof (struct var_ann_d
);
704 fprintf (file
, fmt_str_1
, "Variables annotated", dfa_stats
.num_var_anns
,
705 SCALE (size
), LABEL (size
));
707 size
= dfa_stats
.num_uses
* sizeof (tree
*);
709 fprintf (file
, fmt_str_1
, "USE operands", dfa_stats
.num_uses
,
710 SCALE (size
), LABEL (size
));
712 size
= dfa_stats
.num_defs
* sizeof (tree
*);
714 fprintf (file
, fmt_str_1
, "DEF operands", dfa_stats
.num_defs
,
715 SCALE (size
), LABEL (size
));
717 size
= dfa_stats
.num_vuses
* sizeof (tree
*);
719 fprintf (file
, fmt_str_1
, "VUSE operands", dfa_stats
.num_vuses
,
720 SCALE (size
), LABEL (size
));
722 size
= dfa_stats
.num_v_may_defs
* sizeof (tree
*);
724 fprintf (file
, fmt_str_1
, "V_MAY_DEF operands", dfa_stats
.num_v_may_defs
,
725 SCALE (size
), LABEL (size
));
727 size
= dfa_stats
.num_v_must_defs
* sizeof (tree
*);
729 fprintf (file
, fmt_str_1
, "V_MUST_DEF operands", dfa_stats
.num_v_must_defs
,
730 SCALE (size
), LABEL (size
));
732 size
= dfa_stats
.num_phis
* sizeof (struct tree_phi_node
);
734 fprintf (file
, fmt_str_1
, "PHI nodes", dfa_stats
.num_phis
,
735 SCALE (size
), LABEL (size
));
737 size
= dfa_stats
.num_phi_args
* sizeof (struct phi_arg_d
);
739 fprintf (file
, fmt_str_1
, "PHI arguments", dfa_stats
.num_phi_args
,
740 SCALE (size
), LABEL (size
));
742 fprintf (file
, "---------------------------------------------------------\n");
743 fprintf (file
, fmt_str_3
, "Total memory used by DFA/SSA data", SCALE (total
),
745 fprintf (file
, "---------------------------------------------------------\n");
746 fprintf (file
, "\n");
748 if (dfa_stats
.num_phis
)
749 fprintf (file
, "Average number of arguments per PHI node: %.1f (max: %d)\n",
750 (float) dfa_stats
.num_phi_args
/ (float) dfa_stats
.num_phis
,
751 dfa_stats
.max_num_phi_args
);
753 fprintf (file
, "\n");
757 /* Dump DFA statistics on stderr. */
760 debug_dfa_stats (void)
762 dump_dfa_stats (stderr
);
766 /* Collect DFA statistics and store them in the structure pointed by
770 collect_dfa_stats (struct dfa_stats_d
*dfa_stats_p
)
774 block_stmt_iterator i
;
776 if (dfa_stats_p
== NULL
)
779 memset ((void *)dfa_stats_p
, 0, sizeof (struct dfa_stats_d
));
781 /* Walk all the trees in the function counting references. Start at
782 basic block 0, but don't stop at block boundaries. */
783 htab
= htab_create (30, htab_hash_pointer
, htab_eq_pointer
, NULL
);
785 for (i
= bsi_start (BASIC_BLOCK (0)); !bsi_end_p (i
); bsi_next (&i
))
786 walk_tree (bsi_stmt_ptr (i
), collect_dfa_stats_r
, (void *) dfa_stats_p
,
794 for (phi
= phi_nodes (bb
); phi
; phi
= PHI_CHAIN (phi
))
796 dfa_stats_p
->num_phis
++;
797 dfa_stats_p
->num_phi_args
+= PHI_NUM_ARGS (phi
);
798 if (PHI_NUM_ARGS (phi
) > dfa_stats_p
->max_num_phi_args
)
799 dfa_stats_p
->max_num_phi_args
= PHI_NUM_ARGS (phi
);
805 /* Callback for walk_tree to collect DFA statistics for a tree and its
809 collect_dfa_stats_r (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
813 struct dfa_stats_d
*dfa_stats_p
= (struct dfa_stats_d
*)data
;
817 switch (ann_type (t
->common
.ann
))
821 stmt_ann_t ann
= (stmt_ann_t
) t
->common
.ann
;
822 dfa_stats_p
->num_stmt_anns
++;
823 dfa_stats_p
->num_defs
+= NUM_DEFS (DEF_OPS (ann
));
824 dfa_stats_p
->num_uses
+= NUM_USES (USE_OPS (ann
));
825 dfa_stats_p
->num_v_may_defs
+=
826 NUM_V_MAY_DEFS (V_MAY_DEF_OPS (ann
));
827 dfa_stats_p
->num_vuses
+= NUM_VUSES (VUSE_OPS (ann
));
828 dfa_stats_p
->num_v_must_defs
+=
829 NUM_V_MUST_DEFS (V_MUST_DEF_OPS (ann
));
834 dfa_stats_p
->num_var_anns
++;
846 /*---------------------------------------------------------------------------
847 Miscellaneous helpers
848 ---------------------------------------------------------------------------*/
849 /* Callback for walk_tree. Used to collect variables referenced in
853 find_vars_r (tree
*tp
, int *walk_subtrees
, void *data
)
855 struct walk_state
*walk_state
= (struct walk_state
*) data
;
857 /* If T is a regular variable that the optimizers are interested
858 in, add it to the list of variables. */
860 add_referenced_var (*tp
, walk_state
);
862 /* Type, _DECL and constant nodes have no interesting children.
864 else if (DECL_P (*tp
)
866 || TREE_CODE_CLASS (TREE_CODE (*tp
)) == 'c')
873 /* Add VAR to the list of dereferenced variables.
875 WALK_STATE contains a hash table used to avoid adding the same
876 variable more than once. Note that this function assumes that
877 VAR is a valid SSA variable. If WALK_STATE is NULL, no
878 duplicate checking is done. */
881 add_referenced_var (tree var
, struct walk_state
*walk_state
)
886 v_ann
= get_var_ann (var
);
889 slot
= htab_find_slot (walk_state
->vars_found
, (void *) var
, INSERT
);
893 if (slot
== NULL
|| *slot
== NULL
)
895 /* This is the first time we find this variable, add it to the
896 REFERENCED_VARS array and annotate it with attributes that are
897 intrinsic to the variable. */
899 *slot
= (void *) var
;
900 v_ann
->uid
= num_referenced_vars
;
901 VARRAY_PUSH_TREE (referenced_vars
, var
);
903 /* Global and static variables are call-clobbered, always. */
904 if (needs_to_live_in_memory (var
))
905 mark_call_clobbered (var
);
907 /* If an initialized global variable then register the initializer
909 if (POINTER_TYPE_P (TREE_TYPE (var
))
910 && TREE_READONLY (var
)
911 && DECL_INITIAL (var
)
912 && TREE_CODE (DECL_INITIAL (var
)) == ADDR_EXPR
)
913 walk_tree (&DECL_INITIAL (var
), find_vars_r
, walk_state
, 0);
918 /* Return the virtual variable associated to the non-scalar variable VAR. */
921 get_virtual_var (tree var
)
925 if (TREE_CODE (var
) == SSA_NAME
)
926 var
= SSA_NAME_VAR (var
);
928 while (TREE_CODE (var
) == REALPART_EXPR
|| TREE_CODE (var
) == IMAGPART_EXPR
929 || handled_component_p (var
))
930 var
= TREE_OPERAND (var
, 0);
932 #ifdef ENABLE_CHECKING
933 /* Treating GIMPLE registers as virtual variables makes no sense.
934 Also complain if we couldn't extract a _DECL out of the original
937 || is_gimple_reg (var
))
944 /* Add a temporary variable to REFERENCED_VARS. This is similar to
945 add_referenced_var, but is used by passes that need to add new temps to
946 the REFERENCED_VARS array after the program has been scanned for
947 variables. The variable will just receive a new UID and be added
948 to the REFERENCED_VARS array without checking for duplicates. */
951 add_referenced_tmp_var (tree var
)
953 add_referenced_var (var
, NULL
);
956 /* Return true if V_MAY_DEFS_AFTER contains fewer entries than
957 V_MAY_DEFS_BEFORE. Note that this assumes that both varrays
958 are V_MAY_DEF operands for the same statement. */
961 v_may_defs_disappeared_p (v_may_def_optype v_may_defs_before
,
962 v_may_def_optype v_may_defs_after
)
964 /* If there was nothing before, nothing could've disappeared. */
965 if (v_may_defs_before
== NULL
)
968 /* All/some of them gone. */
969 if (v_may_defs_after
== NULL
970 || NUM_V_MAY_DEFS (v_may_defs_before
) >
971 NUM_V_MAY_DEFS (v_may_defs_after
))
977 /* Return true if V_MUST_DEFS_AFTER contains fewer entries than
978 V_MUST_DEFS_BEFORE. Note that this assumes that both varrays
979 are V_MUST_DEF operands for the same statement. */
982 v_must_defs_disappeared_p (v_must_def_optype v_must_defs_before
,
983 v_must_def_optype v_must_defs_after
)
985 /* If there was nothing before, nothing could've disappeared. */
986 if (v_must_defs_before
== NULL
)
989 /* All/some of them gone. */
990 if (v_must_defs_after
== NULL
991 || NUM_V_MUST_DEFS (v_must_defs_before
) >
992 NUM_V_MUST_DEFS (v_must_defs_after
))
999 /* Add all the non-SSA variables found in STMT's operands to the bitmap
1003 mark_new_vars_to_rename (tree stmt
, bitmap vars_to_rename
)
1007 v_may_def_optype v_may_defs
;
1009 v_must_def_optype v_must_defs
;
1011 bitmap vars_in_vops_to_rename
;
1012 bool found_exposed_symbol
= false;
1013 v_may_def_optype v_may_defs_before
, v_may_defs_after
;
1014 v_must_def_optype v_must_defs_before
, v_must_defs_after
;
1017 vars_in_vops_to_rename
= BITMAP_XMALLOC ();
1019 /* Before re-scanning the statement for operands, mark the existing
1020 virtual operands to be renamed again. We do this because when new
1021 symbols are exposed, the virtual operands that were here before due to
1022 aliasing will probably be removed by the call to get_stmt_operand.
1023 Therefore, we need to flag them to be renamed beforehand.
1025 We flag them in a separate bitmap because we don't really want to
1026 rename them if there are not any newly exposed symbols in the
1027 statement operands. */
1028 ann
= stmt_ann (stmt
);
1029 v_may_defs_before
= v_may_defs
= V_MAY_DEF_OPS (ann
);
1030 for (i
= 0; i
< NUM_V_MAY_DEFS (v_may_defs
); i
++)
1032 tree var
= V_MAY_DEF_RESULT (v_may_defs
, i
);
1034 var
= SSA_NAME_VAR (var
);
1035 bitmap_set_bit (vars_in_vops_to_rename
, var_ann (var
)->uid
);
1038 vuses
= VUSE_OPS (ann
);
1039 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
1041 tree var
= VUSE_OP (vuses
, i
);
1043 var
= SSA_NAME_VAR (var
);
1044 bitmap_set_bit (vars_in_vops_to_rename
, var_ann (var
)->uid
);
1047 v_must_defs_before
= v_must_defs
= V_MUST_DEF_OPS (ann
);
1048 for (i
= 0; i
< NUM_V_MUST_DEFS (v_must_defs
); i
++)
1050 tree var
= V_MUST_DEF_OP (v_must_defs
, i
);
1052 var
= SSA_NAME_VAR (var
);
1053 bitmap_set_bit (vars_in_vops_to_rename
, var_ann (var
)->uid
);
1056 /* Now force an operand re-scan on the statement and mark any newly
1057 exposed variables. */
1059 get_stmt_operands (stmt
);
1061 defs
= DEF_OPS (ann
);
1062 for (i
= 0; i
< NUM_DEFS (defs
); i
++)
1064 tree var
= DEF_OP (defs
, i
);
1067 found_exposed_symbol
= true;
1068 bitmap_set_bit (vars_to_rename
, var_ann (var
)->uid
);
1072 uses
= USE_OPS (ann
);
1073 for (i
= 0; i
< NUM_USES (uses
); i
++)
1075 tree var
= USE_OP (uses
, i
);
1078 found_exposed_symbol
= true;
1079 bitmap_set_bit (vars_to_rename
, var_ann (var
)->uid
);
1083 v_may_defs_after
= v_may_defs
= V_MAY_DEF_OPS (ann
);
1084 for (i
= 0; i
< NUM_V_MAY_DEFS (v_may_defs
); i
++)
1086 tree var
= V_MAY_DEF_RESULT (v_may_defs
, i
);
1089 found_exposed_symbol
= true;
1090 bitmap_set_bit (vars_to_rename
, var_ann (var
)->uid
);
1094 vuses
= VUSE_OPS (ann
);
1095 for (i
= 0; i
< NUM_VUSES (vuses
); i
++)
1097 tree var
= VUSE_OP (vuses
, i
);
1100 found_exposed_symbol
= true;
1101 bitmap_set_bit (vars_to_rename
, var_ann (var
)->uid
);
1105 v_must_defs_after
= v_must_defs
= V_MUST_DEF_OPS (ann
);
1106 for (i
= 0; i
< NUM_V_MUST_DEFS (v_must_defs
); i
++)
1108 tree var
= V_MUST_DEF_OP (v_must_defs
, i
);
1111 found_exposed_symbol
= true;
1112 bitmap_set_bit (vars_to_rename
, var_ann (var
)->uid
);
1116 /* If we found any newly exposed symbols, or if there are fewer VDEF
1117 operands in the statement, add the variables we had set in
1118 VARS_IN_VOPS_TO_RENAME to VARS_TO_RENAME. We need to check for
1119 vanishing VDEFs because in those cases, the names that were formerly
1120 generated by this statement are not going to be available anymore. */
1121 if (found_exposed_symbol
1122 || v_may_defs_disappeared_p (v_may_defs_before
, v_may_defs_after
)
1123 || v_must_defs_disappeared_p (v_must_defs_before
, v_must_defs_after
))
1124 bitmap_a_or_b (vars_to_rename
, vars_to_rename
, vars_in_vops_to_rename
);
1126 BITMAP_XFREE (vars_in_vops_to_rename
);