From patchwork Mon Aug 28 14:54:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 806610 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461021-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IlypsuCg"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xgvtv5YBzz9s81 for ; Tue, 29 Aug 2017 00:54:46 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=HfpddULuYrBoXTune2CH5GPZKPjf+Uc+Mi5OYJv7FYOAjaG8w+ JLnVdRh/FwknXp1xQdjtEyzwQ/EiE93s7Saqn+b3z1OZJFDqnp0T6nlbwzqIPObl N3T1y1v0cL+WeeDibibFGpJ58RuhiwDtlPIJjK8IA3p4tGMBvrPUU7CwU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=7zhAH1O4Xf+AeYo9/JqblzcDXqs=; b=IlypsuCg4LgmQX9aa0Z3 aHT5AraSIKeCtnXPU3JfoTAToWWLDZkSsOw6zaHGZJi7WAj8IDyvCWRVmcV7azTw mEdpnluHz8SyosUJ9wxkbgfKPbkS6bXkPuZM3tWbNzSqD9ynPtjatIy89mL+V7xl j9tYgCTCmZ69QHwFURwoAhs= Received: (qmail 66637 invoked by alias); 28 Aug 2017 14:54:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 66055 invoked by uid 89); 28 Aug 2017 14:54:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=bores X-HELO: mail-yw0-f176.google.com Received: from mail-yw0-f176.google.com (HELO mail-yw0-f176.google.com) (209.85.161.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 28 Aug 2017 14:54:26 +0000 Received: by mail-yw0-f176.google.com with SMTP id t188so3701097ywb.1 for ; Mon, 28 Aug 2017 07:54:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=ZEq2nnuYxafwPqJ2r55/VZMXW8jlFoz83VUThezjOhA=; b=fek8fjUQtHXNPW7VcJr5XU12Vlk/HogcxFsl6cJzKLnZNBKrdHPUjUKWRwOW0S5m+w 89JVd79dz3URK+FC6NtjbiP0hnwACgxPcnI2M9428i5pvnSI8hJSYEXwBVwmVTFnC9lL bjd746S1Amjw8av3LxqLB4QfiCiL+/9yU45c9Aix7bDm2bszF/5C/emprbzVUw+3rh4R VcWae47ky8/LBb91aVj1txWqqYc2LZXk01YkSE3ULx4upHV3O18x04nJAt4Q+02gKUUE qi4CCpbHe/FxOILrsVB7QPPjkuKAmmmfYPdY4nw6rZdC+2uayrQstkz5V21qnhyOR6Dy /vIQ== X-Gm-Message-State: AHYfb5jJN0YOwnBqjC+3FVeenxqtItHUEGlEJDBDDNQ5dGyJAp847i+F 5GBuaT0+dBUUpA== X-Received: by 10.13.221.21 with SMTP id g21mr781345ywe.392.1503932064332; Mon, 28 Aug 2017 07:54:24 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::1:d19a]) by smtp.googlemail.com with ESMTPSA id n77sm215162ywd.42.2017.08.28.07.54.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Aug 2017 07:54:23 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] Move field_vec creation Message-ID: Date: Mon, 28 Aug 2017 10:54:16 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 this patch moves the FIELD_VEC creation routines from class.c to name-lookup.c It's slightly more than a simple move as I include the following renaming: insert_into_classtype_sorted_fields -> set_class_bindings insert_late_enum_def_into_classtype_sorted_fields -> insert_late_enum_def_bindings Most of this should eventually evaporate, as I intend adding the bindings progressively during class definition. (and late bindings during their definition). But we'll see how far that gets ... nathan 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. Index: class.c =================================================================== --- class.c (revision 251385) +++ class.c (working copy) @@ -139,9 +139,6 @@ static tree build_simple_base_path (tree 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, } } -/* 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. */ Index: cp-tree.h =================================================================== --- cp-tree.h (revision 251385) +++ cp-tree.h (working copy) @@ -6023,7 +6023,6 @@ extern tree* decl_cloned_function_p (co 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); Index: decl.c =================================================================== --- decl.c (revision 251385) +++ decl.c (working copy) @@ -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); } Index: name-lookup.c =================================================================== --- name-lookup.c (revision 251385) +++ name-lookup.c (working copy) @@ -1312,6 +1312,115 @@ lookup_fnfields_slot (tree type, tree na 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. */ Index: name-lookup.h =================================================================== --- name-lookup.h (revision 251385) +++ name-lookup.h (working copy) @@ -322,6 +322,8 @@ extern tree lookup_arg_dependent (tree, 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);