Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-alias.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* Alias analysis for trees. | 1 /* Alias analysis for trees. |
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 | 2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 Contributed by Diego Novillo <dnovillo@redhat.com> | 4 Contributed by Diego Novillo <dnovillo@redhat.com> |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
22 #include "config.h" | 22 #include "config.h" |
23 #include "system.h" | 23 #include "system.h" |
24 #include "coretypes.h" | 24 #include "coretypes.h" |
25 #include "tm.h" | 25 #include "tm.h" |
26 #include "tree.h" | 26 #include "tree.h" |
27 #include "rtl.h" | |
28 #include "tm_p.h" | 27 #include "tm_p.h" |
29 #include "hard-reg-set.h" | |
30 #include "basic-block.h" | 28 #include "basic-block.h" |
31 #include "timevar.h" | 29 #include "timevar.h" |
32 #include "expr.h" | 30 #include "expr.h" |
33 #include "ggc.h" | 31 #include "ggc.h" |
34 #include "langhooks.h" | 32 #include "langhooks.h" |
35 #include "flags.h" | 33 #include "flags.h" |
36 #include "function.h" | 34 #include "function.h" |
37 #include "diagnostic.h" | 35 #include "diagnostic.h" |
36 #include "tree-pretty-print.h" | |
38 #include "tree-dump.h" | 37 #include "tree-dump.h" |
39 #include "gimple.h" | 38 #include "gimple.h" |
40 #include "tree-flow.h" | 39 #include "tree-flow.h" |
41 #include "tree-inline.h" | 40 #include "tree-inline.h" |
42 #include "tree-pass.h" | 41 #include "tree-pass.h" |
187 if (base | 186 if (base |
188 && INDIRECT_REF_P (base)) | 187 && INDIRECT_REF_P (base)) |
189 ptr = TREE_OPERAND (base, 0); | 188 ptr = TREE_OPERAND (base, 0); |
190 else if (base | 189 else if (base |
191 && SSA_VAR_P (base)) | 190 && SSA_VAR_P (base)) |
192 return operand_equal_p (base, decl, 0); | 191 return base == decl; |
193 else if (base | 192 else if (base |
194 && CONSTANT_CLASS_P (base)) | 193 && CONSTANT_CLASS_P (base)) |
195 return false; | 194 return false; |
196 else | 195 else |
197 return true; | 196 return true; |
212 pointer and that pointers points-to set doesn't contain this decl | 211 pointer and that pointers points-to set doesn't contain this decl |
213 then they can't alias. */ | 212 then they can't alias. */ |
214 if (DECL_RESTRICTED_P (decl) | 213 if (DECL_RESTRICTED_P (decl) |
215 && TYPE_RESTRICT (TREE_TYPE (ptr)) | 214 && TYPE_RESTRICT (TREE_TYPE (ptr)) |
216 && pi->pt.vars_contains_restrict) | 215 && pi->pt.vars_contains_restrict) |
217 return bitmap_bit_p (pi->pt.vars, DECL_UID (decl)); | 216 return bitmap_bit_p (pi->pt.vars, DECL_PT_UID (decl)); |
218 | 217 |
219 return pt_solution_includes (&pi->pt, decl); | 218 return pt_solution_includes (&pi->pt, decl); |
220 } | 219 } |
221 | 220 |
222 /* Return true if dereferenced PTR1 and PTR2 may alias. | 221 /* Return true if dereferenced PTR1 and PTR2 may alias. |
334 | 333 |
335 fprintf (file, "\nCall clobber information\n"); | 334 fprintf (file, "\nCall clobber information\n"); |
336 | 335 |
337 fprintf (file, "\nESCAPED"); | 336 fprintf (file, "\nESCAPED"); |
338 dump_points_to_solution (file, &cfun->gimple_df->escaped); | 337 dump_points_to_solution (file, &cfun->gimple_df->escaped); |
339 fprintf (file, "\nCALLUSED"); | |
340 dump_points_to_solution (file, &cfun->gimple_df->callused); | |
341 | 338 |
342 fprintf (file, "\n\nFlow-insensitive points-to information\n\n"); | 339 fprintf (file, "\n\nFlow-insensitive points-to information\n\n"); |
343 | 340 |
344 for (i = 1; i < num_ssa_names; i++) | 341 for (i = 1; i < num_ssa_names; i++) |
345 { | 342 { |
400 if (pt->nonlocal) | 397 if (pt->nonlocal) |
401 fprintf (file, ", points-to non-local"); | 398 fprintf (file, ", points-to non-local"); |
402 | 399 |
403 if (pt->escaped) | 400 if (pt->escaped) |
404 fprintf (file, ", points-to escaped"); | 401 fprintf (file, ", points-to escaped"); |
402 | |
403 if (pt->ipa_escaped) | |
404 fprintf (file, ", points-to unit escaped"); | |
405 | 405 |
406 if (pt->null) | 406 if (pt->null) |
407 fprintf (file, ", points-to NULL"); | 407 fprintf (file, ", points-to NULL"); |
408 | 408 |
409 if (pt->vars) | 409 if (pt->vars) |
410 { | 410 { |
411 fprintf (file, ", points-to vars: "); | 411 fprintf (file, ", points-to vars: "); |
412 dump_decl_set (file, pt->vars); | 412 dump_decl_set (file, pt->vars); |
413 if (pt->vars_contains_global) | 413 if (pt->vars_contains_global) |
414 fprintf (file, " (includes global vars)"); | 414 fprintf (file, " (includes global vars)"); |
415 if (pt->vars_contains_restrict) | |
416 fprintf (file, " (includes restrict tags)"); | |
415 } | 417 } |
416 } | 418 } |
417 | 419 |
418 /* Dump points-to information for SSA_NAME PTR into FILE. */ | 420 /* Dump points-to information for SSA_NAME PTR into FILE. */ |
419 | 421 |
535 | 537 |
536 /* Compare the canonical types. */ | 538 /* Compare the canonical types. */ |
537 if (TYPE_CANONICAL (type1) == TYPE_CANONICAL (type2)) | 539 if (TYPE_CANONICAL (type1) == TYPE_CANONICAL (type2)) |
538 return 1; | 540 return 1; |
539 | 541 |
540 /* ??? Array types are not properly unified in all cases as we have | 542 /* ??? Array types are not properly unified in all cases as we have |
541 spurious changes in the index types for example. Removing this | 543 spurious changes in the index types for example. Removing this |
542 causes all sorts of problems with the Fortran frontend. */ | 544 causes all sorts of problems with the Fortran frontend. */ |
543 if (TREE_CODE (type1) == ARRAY_TYPE | 545 if (TREE_CODE (type1) == ARRAY_TYPE |
544 && TREE_CODE (type2) == ARRAY_TYPE) | 546 && TREE_CODE (type2) == ARRAY_TYPE) |
547 return -1; | |
548 | |
549 /* ??? In Ada, an lvalue of an unconstrained type can be used to access an | |
550 object of one of its constrained subtypes, e.g. when a function with an | |
551 unconstrained parameter passed by reference is called on an object and | |
552 inlined. But, even in the case of a fixed size, type and subtypes are | |
553 not equivalent enough as to share the same TYPE_CANONICAL, since this | |
554 would mean that conversions between them are useless, whereas they are | |
555 not (e.g. type and subtypes can have different modes). So, in the end, | |
556 they are only guaranteed to have the same alias set. */ | |
557 if (get_alias_set (type1) == get_alias_set (type2)) | |
545 return -1; | 558 return -1; |
546 | 559 |
547 /* The types are known to be not equal. */ | 560 /* The types are known to be not equal. */ |
548 return 0; | 561 return 0; |
549 } | 562 } |
598 HOST_WIDE_INT offadj, sztmp, msztmp; | 611 HOST_WIDE_INT offadj, sztmp, msztmp; |
599 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp); | 612 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp); |
600 offset1 -= offadj; | 613 offset1 -= offadj; |
601 return ranges_overlap_p (offset1, max_size1, offset2, max_size2); | 614 return ranges_overlap_p (offset1, max_size1, offset2, max_size2); |
602 } | 615 } |
603 | 616 /* If we have two type access paths B1.path1 and B2.path2 they may |
604 /* We haven't found any common base to apply offset-based disambiguation. | 617 only alias if either B1 is in B2.path2 or B2 is in B1.path1. */ |
605 There are two cases: | 618 return false; |
606 1. The base access types have the same alias set. This can happen | |
607 in Ada when a function with an unconstrained parameter passed by | |
608 reference is called on a constrained object and inlined: the types | |
609 have the same alias set but aren't equivalent. The references may | |
610 alias in this case. | |
611 2. The base access types don't have the same alias set, i.e. one set | |
612 is a subset of the other. We have proved that B1 is not in the | |
613 access path B2.path and that B2 is not in the access path B1.path | |
614 so the references may not alias. */ | |
615 return get_alias_set (type1) == get_alias_set (type2); | |
616 } | 619 } |
617 | 620 |
618 /* Return true if two memory references based on the variables BASE1 | 621 /* Return true if two memory references based on the variables BASE1 |
619 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and | 622 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and |
620 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. */ | 623 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. */ |
626 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2) | 629 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2) |
627 { | 630 { |
628 gcc_assert (SSA_VAR_P (base1) && SSA_VAR_P (base2)); | 631 gcc_assert (SSA_VAR_P (base1) && SSA_VAR_P (base2)); |
629 | 632 |
630 /* If both references are based on different variables, they cannot alias. */ | 633 /* If both references are based on different variables, they cannot alias. */ |
631 if (!operand_equal_p (base1, base2, 0)) | 634 if (base1 != base2) |
632 return false; | 635 return false; |
633 | 636 |
634 /* If both references are based on the same variable, they cannot alias if | 637 /* If both references are based on the same variable, they cannot alias if |
635 the accesses do not overlap. */ | 638 the accesses do not overlap. */ |
636 return ranges_overlap_p (offset1, max_size1, offset2, max_size2); | 639 return ranges_overlap_p (offset1, max_size1, offset2, max_size2); |
817 var2_p = SSA_VAR_P (base2); | 820 var2_p = SSA_VAR_P (base2); |
818 if (var1_p && var2_p) | 821 if (var1_p && var2_p) |
819 return decl_refs_may_alias_p (base1, offset1, max_size1, | 822 return decl_refs_may_alias_p (base1, offset1, max_size1, |
820 base2, offset2, max_size2); | 823 base2, offset2, max_size2); |
821 | 824 |
825 ind1_p = INDIRECT_REF_P (base1); | |
826 ind2_p = INDIRECT_REF_P (base2); | |
827 /* Canonicalize the pointer-vs-decl case. */ | |
828 if (ind1_p && var2_p) | |
829 { | |
830 HOST_WIDE_INT tmp1; | |
831 tree tmp2; | |
832 ao_ref *tmp3; | |
833 tmp1 = offset1; offset1 = offset2; offset2 = tmp1; | |
834 tmp1 = max_size1; max_size1 = max_size2; max_size2 = tmp1; | |
835 tmp2 = base1; base1 = base2; base2 = tmp2; | |
836 tmp3 = ref1; ref1 = ref2; ref2 = tmp3; | |
837 var1_p = true; | |
838 ind1_p = false; | |
839 var2_p = false; | |
840 ind2_p = true; | |
841 } | |
842 | |
843 /* If we are about to disambiguate pointer-vs-decl try harder to | |
844 see must-aliases and give leeway to some invalid cases. | |
845 This covers a pretty minimal set of cases only and does not | |
846 when called from the RTL oracle. It handles cases like | |
847 | |
848 int i = 1; | |
849 return *(float *)&i; | |
850 | |
851 and also fixes gfortran.dg/lto/pr40725. */ | |
852 if (var1_p && ind2_p | |
853 && cfun | |
854 && gimple_in_ssa_p (cfun) | |
855 && TREE_CODE (TREE_OPERAND (base2, 0)) == SSA_NAME) | |
856 { | |
857 gimple def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (base2, 0)); | |
858 while (is_gimple_assign (def_stmt) | |
859 && (gimple_assign_rhs_code (def_stmt) == SSA_NAME | |
860 || CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt)))) | |
861 { | |
862 tree rhs = gimple_assign_rhs1 (def_stmt); | |
863 HOST_WIDE_INT offset, size, max_size; | |
864 | |
865 /* Look through SSA name copies and pointer conversions. */ | |
866 if (TREE_CODE (rhs) == SSA_NAME | |
867 && POINTER_TYPE_P (TREE_TYPE (rhs))) | |
868 { | |
869 def_stmt = SSA_NAME_DEF_STMT (rhs); | |
870 continue; | |
871 } | |
872 if (TREE_CODE (rhs) != ADDR_EXPR) | |
873 break; | |
874 | |
875 /* If the pointer is defined as an address based on a decl | |
876 use plain offset disambiguation and ignore TBAA. */ | |
877 rhs = TREE_OPERAND (rhs, 0); | |
878 rhs = get_ref_base_and_extent (rhs, &offset, &size, &max_size); | |
879 if (SSA_VAR_P (rhs)) | |
880 { | |
881 base2 = rhs; | |
882 offset2 += offset; | |
883 if (size != max_size | |
884 || max_size == -1) | |
885 max_size2 = -1; | |
886 return decl_refs_may_alias_p (base1, offset1, max_size1, | |
887 base2, offset2, max_size2); | |
888 } | |
889 | |
890 /* Do not continue looking through &p->x to limit time | |
891 complexity. */ | |
892 break; | |
893 } | |
894 } | |
895 | |
822 /* First defer to TBAA if possible. */ | 896 /* First defer to TBAA if possible. */ |
823 if (tbaa_p | 897 if (tbaa_p |
824 && flag_strict_aliasing | 898 && flag_strict_aliasing |
825 && !alias_sets_conflict_p (ao_ref_alias_set (ref1), | 899 && !alias_sets_conflict_p (ao_ref_alias_set (ref1), |
826 ao_ref_alias_set (ref2))) | 900 ao_ref_alias_set (ref2))) |
832 if ((ref1->ref && TREE_CODE (ref1->ref) == TARGET_MEM_REF) | 906 if ((ref1->ref && TREE_CODE (ref1->ref) == TARGET_MEM_REF) |
833 || (ref2->ref && TREE_CODE (ref2->ref) == TARGET_MEM_REF)) | 907 || (ref2->ref && TREE_CODE (ref2->ref) == TARGET_MEM_REF)) |
834 return true; | 908 return true; |
835 | 909 |
836 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */ | 910 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */ |
837 ind1_p = INDIRECT_REF_P (base1); | |
838 ind2_p = INDIRECT_REF_P (base2); | |
839 set = tbaa_p ? -1 : 0; | 911 set = tbaa_p ? -1 : 0; |
840 if (var1_p && ind2_p) | 912 if (var1_p && ind2_p) |
841 return indirect_ref_may_alias_decl_p (ref2->ref, TREE_OPERAND (base2, 0), | 913 return indirect_ref_may_alias_decl_p (ref2->ref, TREE_OPERAND (base2, 0), |
842 offset2, max_size2, set, | 914 offset2, max_size2, set, |
843 ref1->ref, base1, | 915 ref1->ref, base1, |
844 offset1, max_size1, set); | 916 offset1, max_size1, set); |
845 else if (ind1_p && var2_p) | |
846 return indirect_ref_may_alias_decl_p (ref1->ref, TREE_OPERAND (base1, 0), | |
847 offset1, max_size1, set, | |
848 ref2->ref, base2, | |
849 offset2, max_size2, set); | |
850 else if (ind1_p && ind2_p) | 917 else if (ind1_p && ind2_p) |
851 return indirect_refs_may_alias_p (ref1->ref, TREE_OPERAND (base1, 0), | 918 return indirect_refs_may_alias_p (ref1->ref, TREE_OPERAND (base1, 0), |
852 offset1, max_size1, set, | 919 offset1, max_size1, set, |
853 ref2->ref, TREE_OPERAND (base2, 0), | 920 ref2->ref, TREE_OPERAND (base2, 0), |
854 offset2, max_size2, set); | 921 offset2, max_size2, set); |
962 return refs_may_alias_p_1 (&dref, ref, false); | 1029 return refs_may_alias_p_1 (&dref, ref, false); |
963 } | 1030 } |
964 /* The following builtins do not read from memory. */ | 1031 /* The following builtins do not read from memory. */ |
965 case BUILT_IN_FREE: | 1032 case BUILT_IN_FREE: |
966 case BUILT_IN_MALLOC: | 1033 case BUILT_IN_MALLOC: |
1034 case BUILT_IN_CALLOC: | |
967 case BUILT_IN_MEMSET: | 1035 case BUILT_IN_MEMSET: |
968 case BUILT_IN_FREXP: | 1036 case BUILT_IN_FREXP: |
969 case BUILT_IN_FREXPF: | 1037 case BUILT_IN_FREXPF: |
970 case BUILT_IN_FREXPL: | 1038 case BUILT_IN_FREXPL: |
971 case BUILT_IN_GAMMA_R: | 1039 case BUILT_IN_GAMMA_R: |
990 } | 1058 } |
991 | 1059 |
992 /* Check if base is a global static variable that is not read | 1060 /* Check if base is a global static variable that is not read |
993 by the function. */ | 1061 by the function. */ |
994 if (TREE_CODE (base) == VAR_DECL | 1062 if (TREE_CODE (base) == VAR_DECL |
995 && TREE_STATIC (base) | 1063 && TREE_STATIC (base)) |
996 && !TREE_PUBLIC (base)) | |
997 { | 1064 { |
998 bitmap not_read; | 1065 bitmap not_read; |
999 | 1066 |
1000 if (callee != NULL_TREE | 1067 if (callee != NULL_TREE |
1001 && (not_read | 1068 && (not_read |
1002 = ipa_reference_get_not_read_global (cgraph_node (callee))) | 1069 = ipa_reference_get_not_read_global (cgraph_node (callee))) |
1003 && bitmap_bit_p (not_read, DECL_UID (base))) | 1070 && bitmap_bit_p (not_read, DECL_UID (base))) |
1004 goto process_args; | 1071 goto process_args; |
1005 } | 1072 } |
1006 | 1073 |
1007 /* If the base variable is call-used or call-clobbered then | 1074 /* Check if the base variable is call-used. */ |
1008 it may be used. */ | 1075 if (DECL_P (base)) |
1009 if (flags & (ECF_PURE|ECF_CONST|ECF_LOOPING_CONST_OR_PURE|ECF_NOVOPS)) | 1076 { |
1010 { | 1077 if (pt_solution_includes (gimple_call_use_set (call), base)) |
1011 if (DECL_P (base)) | |
1012 { | |
1013 if (is_call_used (base)) | |
1014 return true; | |
1015 } | |
1016 else if (INDIRECT_REF_P (base) | |
1017 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) | |
1018 { | |
1019 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)); | |
1020 if (!pi) | |
1021 return true; | |
1022 | |
1023 if (pt_solution_includes_global (&pi->pt) | |
1024 || pt_solutions_intersect (&cfun->gimple_df->callused, &pi->pt) | |
1025 || pt_solutions_intersect (&cfun->gimple_df->escaped, &pi->pt)) | |
1026 return true; | |
1027 } | |
1028 else | |
1029 return true; | 1078 return true; |
1030 } | 1079 } |
1080 else if (INDIRECT_REF_P (base) | |
1081 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) | |
1082 { | |
1083 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)); | |
1084 if (!pi) | |
1085 return true; | |
1086 | |
1087 if (pt_solutions_intersect (gimple_call_use_set (call), &pi->pt)) | |
1088 return true; | |
1089 } | |
1031 else | 1090 else |
1032 { | 1091 return true; |
1033 if (DECL_P (base)) | |
1034 { | |
1035 if (is_call_clobbered (base)) | |
1036 return true; | |
1037 } | |
1038 else if (INDIRECT_REF_P (base) | |
1039 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) | |
1040 { | |
1041 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)); | |
1042 if (!pi) | |
1043 return true; | |
1044 | |
1045 if (pt_solution_includes_global (&pi->pt) | |
1046 || pt_solutions_intersect (&cfun->gimple_df->escaped, &pi->pt)) | |
1047 return true; | |
1048 } | |
1049 else | |
1050 return true; | |
1051 } | |
1052 | 1092 |
1053 /* Inspect call arguments for passed-by-value aliases. */ | 1093 /* Inspect call arguments for passed-by-value aliases. */ |
1054 process_args: | 1094 process_args: |
1055 for (i = 0; i < gimple_call_num_args (call); ++i) | 1095 for (i = 0; i < gimple_call_num_args (call); ++i) |
1056 { | 1096 { |
1057 tree op = gimple_call_arg (call, i); | 1097 tree op = gimple_call_arg (call, i); |
1098 int flags = gimple_call_arg_flags (call, i); | |
1099 | |
1100 if (flags & EAF_UNUSED) | |
1101 continue; | |
1058 | 1102 |
1059 if (TREE_CODE (op) == WITH_SIZE_EXPR) | 1103 if (TREE_CODE (op) == WITH_SIZE_EXPR) |
1060 op = TREE_OPERAND (op, 0); | 1104 op = TREE_OPERAND (op, 0); |
1061 | 1105 |
1062 if (TREE_CODE (op) != SSA_NAME | 1106 if (TREE_CODE (op) != SSA_NAME |
1189 return refs_may_alias_p_1 (&dref, ref, false); | 1233 return refs_may_alias_p_1 (&dref, ref, false); |
1190 } | 1234 } |
1191 /* Allocating memory does not have any side-effects apart from | 1235 /* Allocating memory does not have any side-effects apart from |
1192 being the definition point for the pointer. */ | 1236 being the definition point for the pointer. */ |
1193 case BUILT_IN_MALLOC: | 1237 case BUILT_IN_MALLOC: |
1238 case BUILT_IN_CALLOC: | |
1239 /* Unix98 specifies that errno is set on allocation failure. | |
1240 Until we properly can track the errno location assume it | |
1241 is not a local decl but external or anonymous storage in | |
1242 a different translation unit. Also assume it is of | |
1243 type int as required by the standard. */ | |
1244 if (flag_errno_math | |
1245 && TREE_TYPE (base) == integer_type_node) | |
1246 { | |
1247 struct ptr_info_def *pi; | |
1248 if (DECL_P (base) | |
1249 && !TREE_STATIC (base)) | |
1250 return true; | |
1251 else if (INDIRECT_REF_P (base) | |
1252 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME | |
1253 && (pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)))) | |
1254 return pi->pt.anything || pi->pt.nonlocal; | |
1255 } | |
1194 return false; | 1256 return false; |
1195 /* Freeing memory kills the pointed-to memory. More importantly | 1257 /* Freeing memory kills the pointed-to memory. More importantly |
1196 the call has to serve as a barrier for moving loads and stores | 1258 the call has to serve as a barrier for moving loads and stores |
1197 across it. */ | 1259 across it. */ |
1198 case BUILT_IN_FREE: | 1260 case BUILT_IN_FREE: |
1250 | 1312 |
1251 /* Check if base is a global static variable that is not written | 1313 /* Check if base is a global static variable that is not written |
1252 by the function. */ | 1314 by the function. */ |
1253 if (callee != NULL_TREE | 1315 if (callee != NULL_TREE |
1254 && TREE_CODE (base) == VAR_DECL | 1316 && TREE_CODE (base) == VAR_DECL |
1255 && TREE_STATIC (base) | 1317 && TREE_STATIC (base)) |
1256 && !TREE_PUBLIC (base)) | |
1257 { | 1318 { |
1258 bitmap not_written; | 1319 bitmap not_written; |
1259 | 1320 |
1260 if ((not_written | 1321 if ((not_written |
1261 = ipa_reference_get_not_written_global (cgraph_node (callee))) | 1322 = ipa_reference_get_not_written_global (cgraph_node (callee))) |
1262 && bitmap_bit_p (not_written, DECL_UID (base))) | 1323 && bitmap_bit_p (not_written, DECL_UID (base))) |
1263 return false; | 1324 return false; |
1264 } | 1325 } |
1265 | 1326 |
1327 /* Check if the base variable is call-clobbered. */ | |
1266 if (DECL_P (base)) | 1328 if (DECL_P (base)) |
1267 return is_call_clobbered (base); | 1329 return pt_solution_includes (gimple_call_clobber_set (call), base); |
1268 else if (INDIRECT_REF_P (base) | 1330 else if (INDIRECT_REF_P (base) |
1269 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) | 1331 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) |
1270 { | 1332 { |
1271 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)); | 1333 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0)); |
1272 if (!pi) | 1334 if (!pi) |
1273 return true; | 1335 return true; |
1274 | 1336 |
1275 return (pt_solution_includes_global (&pi->pt) | 1337 return pt_solutions_intersect (gimple_call_clobber_set (call), &pi->pt); |
1276 || pt_solutions_intersect (&cfun->gimple_df->escaped, &pi->pt)); | |
1277 } | 1338 } |
1278 | 1339 |
1279 return true; | 1340 return true; |
1280 } | 1341 } |
1281 | 1342 |
1282 static bool ATTRIBUTE_UNUSED | 1343 /* If the call in statement CALL may clobber the memory reference REF |
1344 return true, otherwise return false. */ | |
1345 | |
1346 bool | |
1283 call_may_clobber_ref_p (gimple call, tree ref) | 1347 call_may_clobber_ref_p (gimple call, tree ref) |
1284 { | 1348 { |
1285 bool res; | 1349 bool res; |
1286 ao_ref r; | 1350 ao_ref r; |
1287 ao_ref_init (&r, ref); | 1351 ao_ref_init (&r, ref); |