From 41970ff1bc05e8f27b0e58d42782939a18769af1 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 28 Aug 2017 14:51:45 +0000 Subject: [PATCH] cp-tree.h (insert_late_enum_def_into_classtype_sorted_fields): Delete. * cp-tree.h (insert_late_enum_def_into_classtype_sorted_fields): Delete. * name-lookup.h (set_class_bindings, insert_late_enum_def_bindings): Declare. * decl.c (finish_enum_value_list): Adjust for insert_late_enum_def_bindings name change. * class.c (finish_struct_1): Call set_class_bindings. (count_fields, add_fields_to_record_type, add_enum_fields_to_record_type, sorted_fields_type_new, insert_into_classtype_sorted_fields, insert_late_enum_def_into_classtype_sorted_fields): Move to ... * name-lookup.h (count_fields, add_fields_to_record_type, add_enum_fields_to_record_type, sorted_fields_type_new, set_class_bindings, insert_late_enum_def_bindings): ... here. From-SVN: r251387 --- gcc/cp/ChangeLog | 19 ++++++- gcc/cp/class.c | 121 +------------------------------------------ gcc/cp/cp-tree.h | 1 - gcc/cp/decl.c | 3 +- gcc/cp/name-lookup.c | 109 ++++++++++++++++++++++++++++++++++++++ gcc/cp/name-lookup.h | 2 + 6 files changed, 131 insertions(+), 124 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b9e6441316a..16d4635305a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,23 @@ +2017-08-28 Nathan Sidwell + + * cp-tree.h (insert_late_enum_def_into_classtype_sorted_fields): + Delete. + * name-lookup.h (set_class_bindings, + insert_late_enum_def_bindings): Declare. + * decl.c (finish_enum_value_list): Adjust for + insert_late_enum_def_bindings name change. + * class.c (finish_struct_1): Call set_class_bindings. + (count_fields, add_fields_to_record_type, + add_enum_fields_to_record_type, sorted_fields_type_new, + insert_into_classtype_sorted_fields, + insert_late_enum_def_into_classtype_sorted_fields): Move to ... + * name-lookup.h (count_fields, add_fields_to_record_type, + add_enum_fields_to_record_type, sorted_fields_type_new, + set_class_bindings, insert_late_enum_def_bindings): ... here. + 2017-08-25 Nathan Sidwell - * class.c (method_name_cmp, resort_method_name_cmp): Method names + * class.c (method_name_cmp, resort_method_name_cmp): Methods can never be NULL. Conversion operators have a special name diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 4d7c76bdace..28cf7dcdb5f 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -139,9 +139,6 @@ static tree build_simple_base_path (tree expr, tree binfo); static tree build_vtbl_ref_1 (tree, tree); static void build_vtbl_initializer (tree, tree, tree, tree, int *, vec **); -static int count_fields (tree); -static int add_fields_to_record_type (tree, struct sorted_fields_type*, int); -static void insert_into_classtype_sorted_fields (tree, tree, int); static bool check_bitfield_decl (tree); static bool check_field_decl (tree, tree, int *, int *); static void check_field_decls (tree, tree *, int *, int *); @@ -3378,61 +3375,6 @@ add_implicitly_declared_members (tree t, tree* access_decls, } } -/* Subroutine of insert_into_classtype_sorted_fields. Recursively - count the number of fields in TYPE, including anonymous union - members. */ - -static int -count_fields (tree fields) -{ - tree x; - int n_fields = 0; - for (x = fields; x; x = DECL_CHAIN (x)) - { - if (DECL_DECLARES_FUNCTION_P (x)) - /* Functions are dealt with separately. */; - else if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x))) - n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x))); - else - n_fields += 1; - } - return n_fields; -} - -/* Subroutine of insert_into_classtype_sorted_fields. Recursively add - all the fields in the TREE_LIST FIELDS to the SORTED_FIELDS_TYPE - elts, starting at offset IDX. */ - -static int -add_fields_to_record_type (tree fields, struct sorted_fields_type *field_vec, int idx) -{ - tree x; - for (x = fields; x; x = DECL_CHAIN (x)) - { - if (DECL_DECLARES_FUNCTION_P (x)) - /* Functions are handled separately. */; - else if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x))) - idx = add_fields_to_record_type (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx); - else - field_vec->elts[idx++] = x; - } - return idx; -} - -/* Add all of the enum values of ENUMTYPE, to the FIELD_VEC elts, - starting at offset IDX. */ - -static int -add_enum_fields_to_record_type (tree enumtype, - struct sorted_fields_type *field_vec, - int idx) -{ - tree values; - for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values)) - field_vec->elts[idx++] = TREE_VALUE (values); - return idx; -} - /* FIELD is a bit-field. We are finishing the processing for its enclosing type. Issue any appropriate messages and set appropriate flags. Returns false if an error has been diagnosed. */ @@ -6592,21 +6534,6 @@ determine_key_method (tree type) return; } - -/* Allocate and return an instance of struct sorted_fields_type with - N fields. */ - -static struct sorted_fields_type * -sorted_fields_type_new (int n) -{ - struct sorted_fields_type *sft; - sft = (sorted_fields_type *) ggc_internal_alloc (sizeof (sorted_fields_type) - + n * sizeof (tree)); - sft->len = n; - - return sft; -} - /* Helper of find_flexarrays. Return true when FLD refers to a non-static class data member of non-zero size, otherwise false. */ @@ -7145,14 +7072,7 @@ finish_struct_1 (tree t) && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t)) SET_DECL_MODE (x, TYPE_MODE (t)); - /* Done with FIELDS...now decide whether to sort these for - faster lookups later. - - We use a small number because most searches fail (succeeding - ultimately as the search bores through the inheritance - hierarchy), and we want this failure to occur quickly. */ - - insert_into_classtype_sorted_fields (TYPE_FIELDS (t), t, 8); + set_class_bindings (t, TYPE_FIELDS (t)); /* Complain if one of the field types requires lower visibility. */ constrain_class_visibility (t); @@ -7220,45 +7140,6 @@ finish_struct_1 (tree t) } } -/* Insert FIELDS into T for the sorted case if the FIELDS count is - equal to THRESHOLD or greater than THRESHOLD. */ - -static void -insert_into_classtype_sorted_fields (tree fields, tree t, int threshold) -{ - int n_fields = count_fields (fields); - if (n_fields >= threshold) - { - struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields); - add_fields_to_record_type (fields, field_vec, 0); - qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp); - CLASSTYPE_SORTED_FIELDS (t) = field_vec; - } -} - -/* Insert lately defined enum ENUMTYPE into T for the sorted case. */ - -void -insert_late_enum_def_into_classtype_sorted_fields (tree enumtype, tree t) -{ - struct sorted_fields_type *sorted_fields = CLASSTYPE_SORTED_FIELDS (t); - if (sorted_fields) - { - int i; - int n_fields - = list_length (TYPE_VALUES (enumtype)) + sorted_fields->len; - struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields); - - for (i = 0; i < sorted_fields->len; ++i) - field_vec->elts[i] = sorted_fields->elts[i]; - - add_enum_fields_to_record_type (enumtype, field_vec, - sorted_fields->len); - qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp); - CLASSTYPE_SORTED_FIELDS (t) = field_vec; - } -} - /* When T was built up, the member declarations were added in reverse order. Rearrange them to declaration order. */ diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index d04c00cf4cf..8f882d6eb6c 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6023,7 +6023,6 @@ extern tree* decl_cloned_function_p (const_tree, bool); extern void clone_function_decl (tree, bool); extern void adjust_clone_args (tree); extern void deduce_noexcept_on_destructor (tree); -extern void insert_late_enum_def_into_classtype_sorted_fields (tree, tree); extern bool uniquely_derived_from_p (tree, tree); extern bool publicly_uniquely_derived_p (tree, tree); extern tree common_enclosing_class (tree, tree); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index bd6926a486a..73b61b58d99 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14316,8 +14316,7 @@ finish_enum_value_list (tree enumtype) && COMPLETE_TYPE_P (current_class_type) && UNSCOPED_ENUM_P (enumtype)) { - insert_late_enum_def_into_classtype_sorted_fields (enumtype, - current_class_type); + insert_late_enum_def_bindings (enumtype, current_class_type); fixup_type_variants (current_class_type); } diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index df29331b95d..3c4781eef5d 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1312,6 +1312,115 @@ lookup_fnfields_slot (tree type, tree name) return lookup_fnfields_slot_nolazy (type, name); } +/* Allocate and return an instance of struct sorted_fields_type with + N fields. */ + +static struct sorted_fields_type * +sorted_fields_type_new (int n) +{ + struct sorted_fields_type *sft; + sft = (sorted_fields_type *) ggc_internal_alloc (sizeof (sorted_fields_type) + + n * sizeof (tree)); + sft->len = n; + + return sft; +} + +/* Subroutine of insert_into_classtype_sorted_fields. Recursively + count the number of fields in TYPE, including anonymous union + members. */ + +static int +count_fields (tree fields) +{ + tree x; + int n_fields = 0; + for (x = fields; x; x = DECL_CHAIN (x)) + { + if (DECL_DECLARES_FUNCTION_P (x)) + /* Functions are dealt with separately. */; + else if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x))) + n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x))); + else + n_fields += 1; + } + return n_fields; +} + +/* Subroutine of insert_into_classtype_sorted_fields. Recursively add + all the fields in the TREE_LIST FIELDS to the SORTED_FIELDS_TYPE + elts, starting at offset IDX. */ + +static int +add_fields_to_record_type (tree fields, struct sorted_fields_type *field_vec, + int idx) +{ + tree x; + for (x = fields; x; x = DECL_CHAIN (x)) + { + if (DECL_DECLARES_FUNCTION_P (x)) + /* Functions are handled separately. */; + else if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x))) + idx = add_fields_to_record_type (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx); + else + field_vec->elts[idx++] = x; + } + return idx; +} + +/* Add all of the enum values of ENUMTYPE, to the FIELD_VEC elts, + starting at offset IDX. */ + +static int +add_enum_fields_to_record_type (tree enumtype, + struct sorted_fields_type *field_vec, + int idx) +{ + tree values; + for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values)) + field_vec->elts[idx++] = TREE_VALUE (values); + return idx; +} + +/* Insert FIELDS into T for the sorted case if the FIELDS count is + equal to THRESHOLD or greater than THRESHOLD. */ + +void +set_class_bindings (tree klass, tree fields) +{ + int n_fields = count_fields (fields); + if (n_fields >= 8) + { + struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields); + add_fields_to_record_type (fields, field_vec, 0); + qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp); + CLASSTYPE_SORTED_FIELDS (klass) = field_vec; + } +} + +/* Insert lately defined enum ENUMTYPE into T for the sorted case. */ + +void +insert_late_enum_def_bindings (tree enumtype, tree t) +{ + struct sorted_fields_type *sorted_fields = CLASSTYPE_SORTED_FIELDS (t); + if (sorted_fields) + { + int i; + int n_fields + = list_length (TYPE_VALUES (enumtype)) + sorted_fields->len; + struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields); + + for (i = 0; i < sorted_fields->len; ++i) + field_vec->elts[i] = sorted_fields->elts[i]; + + add_enum_fields_to_record_type (enumtype, field_vec, + sorted_fields->len); + qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp); + CLASSTYPE_SORTED_FIELDS (t) = field_vec; + } +} + /* Compute the chain index of a binding_entry given the HASH value of its name and the total COUNT of chains. COUNT is assumed to be a power of 2. */ diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 99f9b9bb45d..a6bbd4af5f5 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -322,6 +322,8 @@ extern tree lookup_arg_dependent (tree, tree, vec *); extern tree lookup_field_1 (tree, tree, bool); extern tree lookup_fnfields_slot (tree, tree); extern tree lookup_fnfields_slot_nolazy (tree, tree); +extern void set_class_bindings (tree, tree); +extern void insert_late_enum_def_bindings (tree, tree); extern tree innermost_non_namespace_value (tree); extern cxx_binding *outer_binding (tree, cxx_binding *, bool); extern void cp_emit_debug_info_for_using (tree, tree); -- 2.30.2