comparison gcc/tree-dfa.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
28 #include "tree.h" 28 #include "tree.h"
29 #include "tm_p.h" 29 #include "tm_p.h"
30 #include "basic-block.h" 30 #include "basic-block.h"
31 #include "output.h" 31 #include "output.h"
32 #include "timevar.h" 32 #include "timevar.h"
33 #include "expr.h"
34 #include "ggc.h" 33 #include "ggc.h"
35 #include "langhooks.h" 34 #include "langhooks.h"
36 #include "flags.h" 35 #include "flags.h"
37 #include "function.h" 36 #include "function.h"
38 #include "diagnostic.h"
39 #include "tree-pretty-print.h" 37 #include "tree-pretty-print.h"
40 #include "tree-dump.h" 38 #include "tree-dump.h"
41 #include "gimple.h" 39 #include "gimple.h"
42 #include "tree-flow.h" 40 #include "tree-flow.h"
43 #include "tree-inline.h" 41 #include "tree-inline.h"
134 gcc_assert (t); 132 gcc_assert (t);
135 gcc_assert (TREE_CODE (t) == VAR_DECL 133 gcc_assert (TREE_CODE (t) == VAR_DECL
136 || TREE_CODE (t) == PARM_DECL 134 || TREE_CODE (t) == PARM_DECL
137 || TREE_CODE (t) == RESULT_DECL); 135 || TREE_CODE (t) == RESULT_DECL);
138 136
139 ann = GGC_CNEW (struct var_ann_d); 137 ann = ggc_alloc_cleared_var_ann_d ();
140 *DECL_VAR_ANN_PTR (t) = ann; 138 *DECL_VAR_ANN_PTR (t) = ann;
141 139
142 return ann; 140 return ann;
143 } 141 }
144 142
218 referenced_var_iterator rvi; 216 referenced_var_iterator rvi;
219 217
220 fprintf (file, "\nReferenced variables in %s: %u\n\n", 218 fprintf (file, "\nReferenced variables in %s: %u\n\n",
221 get_name (current_function_decl), (unsigned) num_referenced_vars); 219 get_name (current_function_decl), (unsigned) num_referenced_vars);
222 220
223 FOR_EACH_REFERENCED_VAR (var, rvi) 221 FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
224 { 222 {
225 fprintf (file, "Variable: "); 223 fprintf (file, "Variable: ");
226 dump_variable (file, var); 224 dump_variable (file, var);
227 } 225 }
228 226
230 } 228 }
231 229
232 230
233 /* Dump the list of all the referenced variables to stderr. */ 231 /* Dump the list of all the referenced variables to stderr. */
234 232
235 void 233 DEBUG_FUNCTION void
236 debug_referenced_vars (void) 234 debug_referenced_vars (void)
237 { 235 {
238 dump_referenced_vars (stderr); 236 dump_referenced_vars (stderr);
239 } 237 }
240 238
242 /* Dump variable VAR and its may-aliases to FILE. */ 240 /* Dump variable VAR and its may-aliases to FILE. */
243 241
244 void 242 void
245 dump_variable (FILE *file, tree var) 243 dump_variable (FILE *file, tree var)
246 { 244 {
247 var_ann_t ann;
248
249 if (TREE_CODE (var) == SSA_NAME) 245 if (TREE_CODE (var) == SSA_NAME)
250 { 246 {
251 if (POINTER_TYPE_P (TREE_TYPE (var))) 247 if (POINTER_TYPE_P (TREE_TYPE (var)))
252 dump_points_to_info_for (file, var); 248 dump_points_to_info_for (file, var);
253 var = SSA_NAME_VAR (var); 249 var = SSA_NAME_VAR (var);
259 return; 255 return;
260 } 256 }
261 257
262 print_generic_expr (file, var, dump_flags); 258 print_generic_expr (file, var, dump_flags);
263 259
264 ann = var_ann (var);
265
266 fprintf (file, ", UID D.%u", (unsigned) DECL_UID (var)); 260 fprintf (file, ", UID D.%u", (unsigned) DECL_UID (var));
267 if (DECL_PT_UID (var) != DECL_UID (var)) 261 if (DECL_PT_UID (var) != DECL_UID (var))
268 fprintf (file, ", PT-UID D.%u", (unsigned) DECL_PT_UID (var)); 262 fprintf (file, ", PT-UID D.%u", (unsigned) DECL_PT_UID (var));
269 263
270 fprintf (file, ", "); 264 fprintf (file, ", ");
277 fprintf (file, ", is global"); 271 fprintf (file, ", is global");
278 272
279 if (TREE_THIS_VOLATILE (var)) 273 if (TREE_THIS_VOLATILE (var))
280 fprintf (file, ", is volatile"); 274 fprintf (file, ", is volatile");
281 275
282 if (ann && ann->noalias_state == NO_ALIAS)
283 fprintf (file, ", NO_ALIAS (does not alias other NO_ALIAS symbols)");
284 else if (ann && ann->noalias_state == NO_ALIAS_GLOBAL)
285 fprintf (file, ", NO_ALIAS_GLOBAL (does not alias other NO_ALIAS symbols"
286 " and global vars)");
287 else if (ann && ann->noalias_state == NO_ALIAS_ANYTHING)
288 fprintf (file, ", NO_ALIAS_ANYTHING (does not alias any other symbols)");
289
290 if (cfun && gimple_default_def (cfun, var)) 276 if (cfun && gimple_default_def (cfun, var))
291 { 277 {
292 fprintf (file, ", default def: "); 278 fprintf (file, ", default def: ");
293 print_generic_expr (file, gimple_default_def (cfun, var), dump_flags); 279 print_generic_expr (file, gimple_default_def (cfun, var), dump_flags);
294 } 280 }
303 } 289 }
304 290
305 291
306 /* Dump variable VAR and its may-aliases to stderr. */ 292 /* Dump variable VAR and its may-aliases to stderr. */
307 293
308 void 294 DEBUG_FUNCTION void
309 debug_variable (tree var) 295 debug_variable (tree var)
310 { 296 {
311 dump_variable (stderr, var); 297 dump_variable (stderr, var);
312 } 298 }
313 299
390 } 376 }
391 377
392 378
393 /* Dump DFA statistics on stderr. */ 379 /* Dump DFA statistics on stderr. */
394 380
395 void 381 DEBUG_FUNCTION void
396 debug_dfa_stats (void) 382 debug_dfa_stats (void)
397 { 383 {
398 dump_dfa_stats (stderr); 384 dump_dfa_stats (stderr);
399 } 385 }
400 386
412 gcc_assert (dfa_stats_p); 398 gcc_assert (dfa_stats_p);
413 399
414 memset ((void *)dfa_stats_p, 0, sizeof (struct dfa_stats_d)); 400 memset ((void *)dfa_stats_p, 0, sizeof (struct dfa_stats_d));
415 401
416 /* Count all the variable annotations. */ 402 /* Count all the variable annotations. */
417 FOR_EACH_REFERENCED_VAR (var, vi) 403 FOR_EACH_REFERENCED_VAR (cfun, var, vi)
418 if (var_ann (var)) 404 if (var_ann (var))
419 dfa_stats_p->num_var_anns++; 405 dfa_stats_p->num_var_anns++;
420 406
421 /* Walk all the statements in the function counting references. */ 407 /* Walk all the statements in the function counting references. */
422 FOR_EACH_BB (bb) 408 FOR_EACH_BB (bb)
500 486
501 /* Lookup UID in the referenced_vars hashtable and return the associated 487 /* Lookup UID in the referenced_vars hashtable and return the associated
502 variable. */ 488 variable. */
503 489
504 tree 490 tree
505 referenced_var_lookup (unsigned int uid) 491 referenced_var_lookup (struct function *fn, unsigned int uid)
506 { 492 {
507 tree h; 493 tree h;
508 struct tree_decl_minimal in; 494 struct tree_decl_minimal in;
509 in.uid = uid; 495 in.uid = uid;
510 h = (tree) htab_find_with_hash (gimple_referenced_vars (cfun), &in, uid); 496 h = (tree) htab_find_with_hash (gimple_referenced_vars (fn), &in, uid);
511 gcc_assert (h || uid == 0);
512 return h; 497 return h;
513 } 498 }
514 499
515 /* Check if TO is in the referenced_vars hash table and insert it if not. 500 /* Check if TO is in the referenced_vars hash table and insert it if not.
516 Return true if it required insertion. */ 501 Return true if it required insertion. */
781 of our field. */ 766 of our field. */
782 if (seen_variable_array_ref 767 if (seen_variable_array_ref
783 && maxsize != -1) 768 && maxsize != -1)
784 { 769 {
785 tree stype = TREE_TYPE (TREE_OPERAND (exp, 0)); 770 tree stype = TREE_TYPE (TREE_OPERAND (exp, 0));
786 tree next = TREE_CHAIN (field); 771 tree next = DECL_CHAIN (field);
787 while (next && TREE_CODE (next) != FIELD_DECL) 772 while (next && TREE_CODE (next) != FIELD_DECL)
788 next = TREE_CHAIN (next); 773 next = DECL_CHAIN (next);
789 if (!next 774 if (!next
790 || TREE_CODE (stype) != RECORD_TYPE) 775 || TREE_CODE (stype) != RECORD_TYPE)
791 { 776 {
792 tree fsize = DECL_SIZE_UNIT (field); 777 tree fsize = DECL_SIZE_UNIT (field);
793 tree ssize = TYPE_SIZE_UNIT (stype); 778 tree ssize = TYPE_SIZE_UNIT (stype);
867 break; 852 break;
868 853
869 case VIEW_CONVERT_EXPR: 854 case VIEW_CONVERT_EXPR:
870 break; 855 break;
871 856
857 case MEM_REF:
858 /* Hand back the decl for MEM[&decl, off]. */
859 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
860 {
861 if (integer_zerop (TREE_OPERAND (exp, 1)))
862 exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
863 else
864 {
865 double_int off = mem_ref_offset (exp);
866 off = double_int_lshift (off,
867 BITS_PER_UNIT == 8
868 ? 3 : exact_log2 (BITS_PER_UNIT),
869 HOST_BITS_PER_DOUBLE_INT, true);
870 off = double_int_add (off, shwi_to_double_int (bit_offset));
871 if (double_int_fits_in_shwi_p (off))
872 {
873 bit_offset = double_int_to_shwi (off);
874 exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
875 }
876 }
877 }
878 goto done;
879
880 case TARGET_MEM_REF:
881 /* Hand back the decl for MEM[&decl, off]. */
882 if (TREE_CODE (TMR_BASE (exp)) == ADDR_EXPR)
883 {
884 /* Via the variable index or index2 we can reach the
885 whole object. */
886 if (TMR_INDEX (exp) || TMR_INDEX2 (exp))
887 {
888 exp = TREE_OPERAND (TMR_BASE (exp), 0);
889 bit_offset = 0;
890 maxsize = -1;
891 goto done;
892 }
893 if (integer_zerop (TMR_OFFSET (exp)))
894 exp = TREE_OPERAND (TMR_BASE (exp), 0);
895 else
896 {
897 double_int off = mem_ref_offset (exp);
898 off = double_int_lshift (off,
899 BITS_PER_UNIT == 8
900 ? 3 : exact_log2 (BITS_PER_UNIT),
901 HOST_BITS_PER_DOUBLE_INT, true);
902 off = double_int_add (off, shwi_to_double_int (bit_offset));
903 if (double_int_fits_in_shwi_p (off))
904 {
905 bit_offset = double_int_to_shwi (off);
906 exp = TREE_OPERAND (TMR_BASE (exp), 0);
907 }
908 }
909 }
910 goto done;
911
872 default: 912 default:
873 goto done; 913 goto done;
874 } 914 }
875 915
876 exp = TREE_OPERAND (exp, 0); 916 exp = TREE_OPERAND (exp, 0);
913 *pmax_size = maxsize; 953 *pmax_size = maxsize;
914 954
915 return exp; 955 return exp;
916 } 956 }
917 957
958 /* Returns the base object and a constant BITS_PER_UNIT offset in *POFFSET that
959 denotes the starting address of the memory access EXP.
960 Returns NULL_TREE if the offset is not constant or any component
961 is not BITS_PER_UNIT-aligned. */
962
963 tree
964 get_addr_base_and_unit_offset (tree exp, HOST_WIDE_INT *poffset)
965 {
966 HOST_WIDE_INT byte_offset = 0;
967
968 /* Compute cumulative byte-offset for nested component-refs and array-refs,
969 and find the ultimate containing object. */
970 while (1)
971 {
972 switch (TREE_CODE (exp))
973 {
974 case BIT_FIELD_REF:
975 return NULL_TREE;
976
977 case COMPONENT_REF:
978 {
979 tree field = TREE_OPERAND (exp, 1);
980 tree this_offset = component_ref_field_offset (exp);
981 HOST_WIDE_INT hthis_offset;
982
983 if (!this_offset
984 || TREE_CODE (this_offset) != INTEGER_CST
985 || (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field))
986 % BITS_PER_UNIT))
987 return NULL_TREE;
988
989 hthis_offset = TREE_INT_CST_LOW (this_offset);
990 hthis_offset += (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field))
991 / BITS_PER_UNIT);
992 byte_offset += hthis_offset;
993 }
994 break;
995
996 case ARRAY_REF:
997 case ARRAY_RANGE_REF:
998 {
999 tree index = TREE_OPERAND (exp, 1);
1000 tree low_bound, unit_size;
1001
1002 /* If the resulting bit-offset is constant, track it. */
1003 if (TREE_CODE (index) == INTEGER_CST
1004 && (low_bound = array_ref_low_bound (exp),
1005 TREE_CODE (low_bound) == INTEGER_CST)
1006 && (unit_size = array_ref_element_size (exp),
1007 TREE_CODE (unit_size) == INTEGER_CST))
1008 {
1009 HOST_WIDE_INT hindex = TREE_INT_CST_LOW (index);
1010
1011 hindex -= TREE_INT_CST_LOW (low_bound);
1012 hindex *= TREE_INT_CST_LOW (unit_size);
1013 byte_offset += hindex;
1014 }
1015 else
1016 return NULL_TREE;
1017 }
1018 break;
1019
1020 case REALPART_EXPR:
1021 break;
1022
1023 case IMAGPART_EXPR:
1024 byte_offset += TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (exp)));
1025 break;
1026
1027 case VIEW_CONVERT_EXPR:
1028 break;
1029
1030 case MEM_REF:
1031 /* Hand back the decl for MEM[&decl, off]. */
1032 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
1033 {
1034 if (!integer_zerop (TREE_OPERAND (exp, 1)))
1035 {
1036 double_int off = mem_ref_offset (exp);
1037 gcc_assert (off.high == -1 || off.high == 0);
1038 byte_offset += double_int_to_shwi (off);
1039 }
1040 exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
1041 }
1042 goto done;
1043
1044 case TARGET_MEM_REF:
1045 /* Hand back the decl for MEM[&decl, off]. */
1046 if (TREE_CODE (TMR_BASE (exp)) == ADDR_EXPR)
1047 {
1048 if (TMR_INDEX (exp) || TMR_INDEX2 (exp))
1049 return NULL_TREE;
1050 if (!integer_zerop (TMR_OFFSET (exp)))
1051 {
1052 double_int off = mem_ref_offset (exp);
1053 gcc_assert (off.high == -1 || off.high == 0);
1054 byte_offset += double_int_to_shwi (off);
1055 }
1056 exp = TREE_OPERAND (TMR_BASE (exp), 0);
1057 }
1058 goto done;
1059
1060 default:
1061 goto done;
1062 }
1063
1064 exp = TREE_OPERAND (exp, 0);
1065 }
1066 done:
1067
1068 *poffset = byte_offset;
1069 return exp;
1070 }
1071
918 /* Returns true if STMT references an SSA_NAME that has 1072 /* Returns true if STMT references an SSA_NAME that has
919 SSA_NAME_OCCURS_IN_ABNORMAL_PHI set, otherwise false. */ 1073 SSA_NAME_OCCURS_IN_ABNORMAL_PHI set, otherwise false. */
920 1074
921 bool 1075 bool
922 stmt_references_abnormal_ssa_name (gimple stmt) 1076 stmt_references_abnormal_ssa_name (gimple stmt)