From 9f27b0caacbfc21963098a6d8e305c148ac8661a Mon Sep 17 00:00:00 2001 From: hubicka Date: Fri, 13 Mar 2015 06:30:04 +0000 Subject: * ipa-icf.c (sem_function::equals_wpa): Match CXX_CONSTRUCTOR_P and CXX_DESTURCTOR_P. For consutrctors match ODR type of class they are building; for methods check ODR type of class they belong to if they may lead to a polymorphic call. (sem_function::compare_polymorphic_p): Be bit smarter about testing when function may lead to a polymorphic call. (sem_function::compare_type_list): Remove. (sem_variable::equals): Update use of compatible_types_p. (sem_variable::parse_tree_refs): Remove. (sem_item_optimizer::filter_removed_items): Do not filter out CXX cdtor. * ipa-icf-gimple.c (func_checker::compare_decl): Do polymorphic matching here. (func_checker::compatible_polymorphic_types_p): Break out from ... (unc_checker::compatible_types_p): ... here. * ipa-icf-gimple.h (func_checker::compatible_polymorphic_types_p): Declare. (unc_checker::compatible_types_p): Update. * ipa-icf.h (compare_type_list, parse_tree_refs, compare_sections): Remove. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@221406 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ipa-icf-gimple.c | 71 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 22 deletions(-) (limited to 'gcc/ipa-icf-gimple.c') diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c index 4f1a8ce6e95..568407da2fd 100644 --- a/gcc/ipa-icf-gimple.c +++ b/gcc/ipa-icf-gimple.c @@ -200,8 +200,22 @@ func_checker::compare_decl (tree t1, tree t2) && DECL_BY_REFERENCE (t1) != DECL_BY_REFERENCE (t2)) return return_false_with_msg ("DECL_BY_REFERENCE flags are different"); - if (!compatible_types_p (TREE_TYPE (t1), TREE_TYPE (t2), - m_compare_polymorphic)) + if (!compatible_types_p (TREE_TYPE (t1), TREE_TYPE (t2))) + return return_false (); + + /* TODO: we are actually too strict here. We only need to compare if + T1 can be used in polymorphic call. */ + if (TREE_ADDRESSABLE (t1) + && m_compare_polymorphic + && !compatible_polymorphic_types_p (TREE_TYPE (t1), TREE_TYPE (t2), + false)) + return return_false (); + + if ((t == VAR_DECL || t == PARM_DECL || t == RESULT_DECL) + && DECL_BY_REFERENCE (t1) + && m_compare_polymorphic + && !compatible_polymorphic_types_p (TREE_TYPE (t1), TREE_TYPE (t2), + true)) return return_false (); bool existed_p; @@ -215,11 +229,41 @@ func_checker::compare_decl (tree t1, tree t2) return true; } +/* Return true if T1 and T2 are same for purposes of ipa-polymorphic-call + analysis. COMPARE_PTR indicates if types of pointers needs to be + considered. */ + +bool +func_checker::compatible_polymorphic_types_p (tree t1, tree t2, + bool compare_ptr) +{ + gcc_assert (TREE_CODE (t1) != FUNCTION_TYPE && TREE_CODE (t1) != METHOD_TYPE); + + /* Pointer types generally give no information. */ + if (POINTER_TYPE_P (t1)) + { + if (!compare_ptr) + return true; + return func_checker::compatible_polymorphic_types_p (TREE_TYPE (t1), + TREE_TYPE (t2), + false); + } + + /* If types contain a polymorphic types, match them. */ + bool c1 = contains_polymorphic_type_p (t1); + bool c2 = contains_polymorphic_type_p (t2); + if (!c1 && !c2) + return true; + if (!c1 || !c2) + return return_false_with_msg ("one type is not polymorphic"); + if (!types_must_be_same_for_odr (t1, t2)) + return return_false_with_msg ("types are not same for ODR"); + return true; +} + /* Return true if types are compatible from perspective of ICF. */ bool -func_checker::compatible_types_p (tree t1, tree t2, - bool compare_polymorphic, - bool first_argument) +func_checker::compatible_types_p (tree t1, tree t2) { if (TREE_CODE (t1) != TREE_CODE (t2)) return return_false_with_msg ("different tree types"); @@ -233,23 +277,6 @@ func_checker::compatible_types_p (tree t1, tree t2, if (get_alias_set (t1) != get_alias_set (t2)) return return_false_with_msg ("alias sets are different"); - /* We call contains_polymorphic_type_p with this pointer type. */ - if (first_argument && TREE_CODE (t1) == POINTER_TYPE) - { - t1 = TREE_TYPE (t1); - t2 = TREE_TYPE (t2); - } - - if (compare_polymorphic) - if (contains_polymorphic_type_p (t1) || contains_polymorphic_type_p (t2)) - { - if (!contains_polymorphic_type_p (t1) || !contains_polymorphic_type_p (t2)) - return return_false_with_msg ("one type is not polymorphic"); - - if (!types_must_be_same_for_odr (t1, t2)) - return return_false_with_msg ("types are not same for ODR"); - } - return true; } -- cgit v1.2.1