From a6c5361c08c88e0db15bec581813b8910ba62116 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Tue, 1 Dec 2015 07:36:02 +0100 Subject: [PATCH] ipa-devirt.c (type_with_linkage_p, [...]): Move to ... * ipa-devirt.c (type_with_linkage_p, type_in_anonymous_namespace_p, odr_type_p): Move to ... * ipa-utils.h (type_with_linkage_p, type_in_anonymous_namespace_p, odr_type_p): here; miscro-optimize. From-SVN: r231098 --- gcc/ChangeLog | 7 ++++ gcc/ipa-devirt.c | 87 ----------------------------------------------- gcc/ipa-utils.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 93 insertions(+), 89 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5f675f1f643..c1114532c2e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-12-01 Jan Hubicka + + * ipa-devirt.c (type_with_linkage_p, type_in_anonymous_namespace_p, + odr_type_p): Move to ... + * ipa-utils.h (type_with_linkage_p, type_in_anonymous_namespace_p, + odr_type_p): here; miscro-optimize. + 2015-12-01 Bin Cheng PR tree-optimization/68529 diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index 2d78952ddbf..7a77b5a10d6 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -209,93 +209,6 @@ struct GTY(()) odr_type_d bool rtti_broken; }; -/* Return true if T is a type with linkage defined. */ - -bool -type_with_linkage_p (const_tree t) -{ - /* Builtin types do not define linkage, their TYPE_CONTEXT is NULL. */ - if (!TYPE_CONTEXT (t) - || !TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL - || !TYPE_STUB_DECL (t)) - return false; - - /* In LTO do not get confused by non-C++ produced types or types built - with -fno-lto-odr-type-merigng. */ - if (in_lto_p) - { - /* To support -fno-lto-odr-type-merigng recognize types with vtables - to have linkage. */ - if (RECORD_OR_UNION_TYPE_P (t) - && TYPE_BINFO (t) && BINFO_VTABLE (TYPE_BINFO (t))) - return true; - /* Do not accept any other types - we do not know if they were produced - by C++ FE. */ - if (!DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))) - return false; - } - - return (RECORD_OR_UNION_TYPE_P (t) - || TREE_CODE (t) == ENUMERAL_TYPE); -} - -/* Return true if T is in anonymous namespace. - This works only on those C++ types with linkage defined. */ - -bool -type_in_anonymous_namespace_p (const_tree t) -{ - gcc_assert (type_with_linkage_p (t)); - - /* Keep -fno-lto-odr-type-merging working by recognizing classes with vtables - properly into anonymous namespaces. */ - if (RECORD_OR_UNION_TYPE_P (t) - && TYPE_BINFO (t) && BINFO_VTABLE (TYPE_BINFO (t))) - return (TYPE_STUB_DECL (t) && !TREE_PUBLIC (TYPE_STUB_DECL (t))); - - if (TYPE_STUB_DECL (t) && !TREE_PUBLIC (TYPE_STUB_DECL (t))) - { - /* C++ FE uses magic as assembler names of anonymous types. - verify that this match with type_in_anonymous_namespace_p. */ - if (in_lto_p) - gcc_checking_assert (!strcmp ("", - IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (TYPE_NAME (t))))); - return true; - } - return false; -} - -/* Return true of T is type with One Definition Rule info attached. - It means that either it is anonymous type or it has assembler name - set. */ - -bool -odr_type_p (const_tree t) -{ - /* We do not have this information when not in LTO, but we do not need - to care, since it is used only for type merging. */ - gcc_checking_assert (in_lto_p || flag_lto); - - /* To support -fno-lto-odr-type-merging consider types with vtables ODR. */ - if (type_with_linkage_p (t) && type_in_anonymous_namespace_p (t)) - return true; - - if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL - && (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))) - { - /* C++ FE uses magic as assembler names of anonymous types. - verify that this match with type_in_anonymous_namespace_p. */ - gcc_checking_assert (!type_with_linkage_p (t) - || strcmp ("", - IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (TYPE_NAME (t)))) - || type_in_anonymous_namespace_p (t)); - return true; - } - return false; -} - /* Return TRUE if all derived types of T are known and thus we may consider the walk of derived type complete. diff --git a/gcc/ipa-utils.h b/gcc/ipa-utils.h index 1604641e1b5..b537f3c8f31 100644 --- a/gcc/ipa-utils.h +++ b/gcc/ipa-utils.h @@ -63,8 +63,6 @@ possible_polymorphic_call_targets (tree, HOST_WIDE_INT, void **cache_token = NULL, bool speuclative = false); odr_type get_odr_type (tree, bool insert = false); -bool type_in_anonymous_namespace_p (const_tree); -bool type_with_linkage_p (const_tree); bool odr_type_p (const_tree); bool possible_polymorphic_call_target_p (tree ref, gimple *stmt, struct cgraph_node *n); void dump_possible_polymorphic_call_targets (FILE *, tree, HOST_WIDE_INT, @@ -176,6 +174,92 @@ polymorphic_type_binfo_p (const_tree binfo) return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo)) && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo)))); } + +/* Return true if T is a type with linkage defined. */ + +inline bool +type_with_linkage_p (const_tree t) +{ + if (!TYPE_NAME (t) || TREE_CODE (TYPE_NAME (t)) != TYPE_DECL + || !TYPE_STUB_DECL (t)) + return false; + /* In LTO do not get confused by non-C++ produced types or types built + with -fno-lto-odr-type-merigng. */ + if (in_lto_p) + { + /* To support -fno-lto-odr-type-merigng recognize types with vtables + to have linkage. */ + if (RECORD_OR_UNION_TYPE_P (t) + && TYPE_BINFO (t) && BINFO_VTABLE (TYPE_BINFO (t))) + return true; + /* With -flto-odr-type-merging C++ FE specify mangled names + for all types with the linkage. */ + return DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)); + } + + if (!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE) + return false; + + /* Builtin types do not define linkage, their TYPE_CONTEXT is NULL. */ + if (!TYPE_CONTEXT (t)) + return false; + + return true; +} + +/* Return true if T is in anonymous namespace. + This works only on those C++ types with linkage defined. */ + +inline bool +type_in_anonymous_namespace_p (const_tree t) +{ + gcc_checking_assert (type_with_linkage_p (t)); + + if (!TREE_PUBLIC (TYPE_STUB_DECL (t))) + { + /* C++ FE uses magic as assembler names of anonymous types. + verify that this match with type_in_anonymous_namespace_p. */ + gcc_checking_assert (!in_lto_p || !DECL_ASSEMBLER_NAME_SET_P (t) + || !strcmp + ("", + IDENTIFIER_POINTER + (DECL_ASSEMBLER_NAME (TYPE_NAME (t))))); + return true; + } + return false; +} + +/* Return true of T is type with One Definition Rule info attached. + It means that either it is anonymous type or it has assembler name + set. */ + +inline bool +odr_type_p (const_tree t) +{ + /* We do not have this information when not in LTO, but we do not need + to care, since it is used only for type merging. */ + gcc_checking_assert (in_lto_p || flag_lto); + + if (!type_with_linkage_p (t)) + return false; + + /* To support -fno-lto-odr-type-merging consider types with vtables ODR. */ + if (type_in_anonymous_namespace_p (t)) + return true; + + if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL + && DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))) + { + /* C++ FE uses magic as assembler names of anonymous types. + verify that this match with type_in_anonymous_namespace_p. */ + gcc_checking_assert (strcmp ("", + IDENTIFIER_POINTER + (DECL_ASSEMBLER_NAME (TYPE_NAME (t))))); + return true; + } + return false; +} + #endif /* GCC_IPA_UTILS_H */ -- 2.30.2