From patchwork Fri Sep 1 19:02:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 808977 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-461327-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="RH52D6v9"; 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 3xkTCP576Yz9sRY for ; Sat, 2 Sep 2017 05:02:56 +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=N0eg4xi2csVYbW5SGMBEXfXd6kjgvhnQMPuB50Tqm1rXdHFKAV 5vSUIXwvFkkPidVcdpvCRu3xdwaZF/gHt6fiDefCHazeGygvtAKCwStkE+Pb+oFh nviQ46HZ6WPnuOo97rfRCbRKdI119fn4E7XLZ9IZfeLUsGaftePYI7TAQ= 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=Hxe3e1Tqlx1nNA+Bg7Dt8CDl5IA=; b=RH52D6v91nQfuYi2uZvg DXLFBBYzK/JEPw4sCy0gaEDdV8sTZtJ+C0+dzDpPeoKB0aZ77NRzPBnBSczwHfPP NtAhd/xpNXf8e/Ls9Za507igmTQsMMEpXk/23EW2AO8CAsRd2153M7I1laCHavB2 JIxiM0Ssu2/m4KvbFKnZ/L0= Received: (qmail 62152 invoked by alias); 1 Sep 2017 19:02:49 -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 62136 invoked by uid 89); 1 Sep 2017 19:02:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, 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=Lose X-HELO: mail-yw0-f180.google.com Received: from mail-yw0-f180.google.com (HELO mail-yw0-f180.google.com) (209.85.161.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 01 Sep 2017 19:02:46 +0000 Received: by mail-yw0-f180.google.com with SMTP id b142so615838ywa.0 for ; Fri, 01 Sep 2017 12:02:46 -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=Xg/s7iR125iLTGeDUvMJjt1laXdjTDAcfhvdFUhgotc=; b=ZAIwOJ4Olhx+HhIbXZC30qXjwyviPdYLMgqlkFErWSqKLyWXZlI4vvylvxXNUXjjX7 /j14PmmZXX3frF55cR/7zprRz7gJV0wEeXEqnuWl1aQLk/eZbmmLZ8wv4vXAP1etN6NX Psl2wk1pzk0a7yZxd8ztgbJGGfkHsmD4cdW/X/ifSXvyGvxyeFlfZDQtBfPPrn8F33ER Y1NKgHklEu9E43xSw6EVtd80lSNpCx6akokpi2TBO+QcgcPlsEAWC7iyYQccJ6N8PCcX VuZ4sVXwh4RPJUPjmOq2+HFgCVxA1M/cLNj+CICcmEC9e1OOdoFbsk8MLwPl35lxeQ0T nVoQ== X-Gm-Message-State: AHPjjUiztKsixFcD34+kW/JtM92muMjU3Omula5cAPBZV00OZPL8h5t8 pwhLjjvkrEZ+jA== X-Google-Smtp-Source: ADKCNb6bRz+eRYjHRiLUQoD4Xi0sfobfLtWbeLVlT8WsfaY99cgti+8hdapjCpwGSac9kyU/MwdU7g== X-Received: by 10.37.48.133 with SMTP id w127mr2469743ybw.182.1504292565106; Fri, 01 Sep 2017 12:02:45 -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 u34sm309666ywh.99.2017.09.01.12.02.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Sep 2017 12:02:44 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH[ move METHOD_VEC handling Message-ID: <60382486-9f30-4c5f-59ab-5db22a0eacbd@acm.org> Date: Fri, 1 Sep 2017 15:02:42 -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 CLASSTYPE_METHOD_VEC sorting functions from class.c to name-lookup.c. It also merges the intial sort call into set_class_bindings, leaving that function in control of arranging the post-definition lookup data objects. Applied to trunk. nathan 2017-09-01 Nathan Sidwell * cp-tree.h (resort_type_method_vec): Move declaration to ... * name-lookup.h (resort_type_method_vec): ... here. (set_class_bindings): Lose 2nd arg. * class.c (finish_struct_1, finish_struct): Adjust set_class_bindings call. Don't call finish_struct_methods. (resort_data, method_name_cmp, resort_method_name_cmp, resort_type_method_vec, finish_struct_methods): Move to ... * name-lookup.c (resort_data, method_name_cmp, resort_method_name_cmp, resort_type_method_vec): ... here. (set_class_bindings): Lose fields arg. Swallow finish_struct_methods. Index: class.c =================================================================== --- class.c (revision 251608) +++ class.c (working copy) @@ -129,10 +129,7 @@ static void handle_using_decl (tree, tre static tree dfs_modify_vtables (tree, void *); static tree modify_all_vtables (tree, tree); static void determine_primary_bases (tree); -static void finish_struct_methods (tree); static void maybe_warn_about_overly_private_class (tree); -static int method_name_cmp (const void *, const void *); -static int resort_method_name_cmp (const void *, const void *); static void add_implicitly_declared_members (tree, tree*, int, int); static tree fixed_type_or_null (tree, int *, int *); static tree build_simple_base_path (tree expr, tree binfo); @@ -2247,76 +2244,6 @@ maybe_warn_about_overly_private_class (t } } -static struct { - gt_pointer_operator new_value; - void *cookie; -} resort_data; - -/* Comparison function to compare two TYPE_METHOD_VEC entries by name. */ - -static int -method_name_cmp (const void* m1_p, const void* m2_p) -{ - const tree *const m1 = (const tree *) m1_p; - const tree *const m2 = (const tree *) m2_p; - - if (OVL_NAME (*m1) < OVL_NAME (*m2)) - return -1; - return 1; -} - -/* This routine compares two fields like method_name_cmp but using the - pointer operator in resort_field_decl_data. */ - -static int -resort_method_name_cmp (const void* m1_p, const void* m2_p) -{ - const tree *const m1 = (const tree *) m1_p; - const tree *const m2 = (const tree *) m2_p; - - tree n1 = OVL_NAME (*m1); - tree n2 = OVL_NAME (*m2); - resort_data.new_value (&n1, resort_data.cookie); - resort_data.new_value (&n2, resort_data.cookie); - if (n1 < n2) - return -1; - return 1; -} - -/* Resort TYPE_METHOD_VEC because pointers have been reordered. */ - -void -resort_type_method_vec (void* obj, - void* /*orig_obj*/, - gt_pointer_operator new_value, - void* cookie) -{ - if (vec *method_vec = (vec *) obj) - { - resort_data.new_value = new_value; - resort_data.cookie = cookie; - qsort (method_vec->address (), method_vec->length (), sizeof (tree), - resort_method_name_cmp); - } -} - -/* Warn about duplicate methods in fn_fields. - - Sort methods that are not special (i.e., constructors, destructors, - and type conversion operators) so that we can find them faster in - search. */ - -static void -finish_struct_methods (tree t) -{ - vec *method_vec = CLASSTYPE_METHOD_VEC (t); - if (!method_vec) - return; - - qsort (method_vec->address (), method_vec->length (), - sizeof (tree), method_name_cmp); -} - /* Make BINFO's vtable have N entries, including RTTI entries, vbase and vcall offsets, etc. Set its type and call the back end to lay it out. */ @@ -6966,8 +6893,7 @@ finish_struct_1 (tree t) layout_class_type (t, &virtuals); /* COMPLETE_TYPE_P is now true. */ - finish_struct_methods (t); - set_class_bindings (t, TYPE_FIELDS (t)); + set_class_bindings (t); if (CLASSTYPE_AS_BASE (t) != t) /* We use the base type for trivial assignments, and hence it @@ -7187,8 +7113,7 @@ finish_struct (tree t, tree attributes) TYPE_SIZE_UNIT (t) = size_zero_node; /* COMPLETE_TYPE_P is now true. */ - finish_struct_methods (t); - set_class_bindings (t, TYPE_FIELDS (t)); + set_class_bindings (t); /* We need to emit an error message if this type was used as a parameter and it is an abstract type, even if it is a template. We construct Index: cp-tree.h =================================================================== --- cp-tree.h (revision 251592) +++ cp-tree.h (working copy) @@ -5952,8 +5952,6 @@ extern tree convert_to_base_statically extern tree build_vtbl_ref (tree, tree); extern tree build_vfn_ref (tree, tree); extern tree get_vtable_decl (tree, int); -extern void resort_type_method_vec (void *, void *, - gt_pointer_operator, void *); extern bool add_method (tree, tree, bool); extern tree declared_access (tree); extern tree currently_open_class (tree); Index: name-lookup.c =================================================================== --- name-lookup.c (revision 251592) +++ name-lookup.c (working copy) @@ -1312,6 +1312,59 @@ lookup_fnfields_slot (tree type, tree na return lookup_fnfields_slot_nolazy (type, name); } +static struct { + gt_pointer_operator new_value; + void *cookie; +} resort_data; + +/* Comparison function to compare two TYPE_METHOD_VEC entries by name. */ + +static int +method_name_cmp (const void* m1_p, const void* m2_p) +{ + const tree *const m1 = (const tree *) m1_p; + const tree *const m2 = (const tree *) m2_p; + + if (OVL_NAME (*m1) < OVL_NAME (*m2)) + return -1; + return 1; +} + +/* This routine compares two fields like method_name_cmp but using the + pointer operator in resort_field_decl_data. */ + +static int +resort_method_name_cmp (const void* m1_p, const void* m2_p) +{ + const tree *const m1 = (const tree *) m1_p; + const tree *const m2 = (const tree *) m2_p; + + tree n1 = OVL_NAME (*m1); + tree n2 = OVL_NAME (*m2); + resort_data.new_value (&n1, resort_data.cookie); + resort_data.new_value (&n2, resort_data.cookie); + if (n1 < n2) + return -1; + return 1; +} + +/* Resort TYPE_METHOD_VEC because pointers have been reordered. */ + +void +resort_type_method_vec (void* obj, + void* /*orig_obj*/, + gt_pointer_operator new_value, + void* cookie) +{ + if (vec *method_vec = (vec *) obj) + { + resort_data.new_value = new_value; + resort_data.cookie = cookie; + qsort (method_vec->address (), method_vec->length (), sizeof (tree), + resort_method_name_cmp); + } +} + /* Allocate and return an instance of struct sorted_fields_type with N fields. */ @@ -1383,11 +1436,16 @@ add_enum_fields_to_record_type (tree enu } /* Insert FIELDS into KLASS for the sorted case if the FIELDS count is - big enough. */ + big enough. Sort the METHOD_VEC too. */ void -set_class_bindings (tree klass, tree fields) +set_class_bindings (tree klass) { + if (vec *method_vec = CLASSTYPE_METHOD_VEC (klass)) + qsort (method_vec->address (), method_vec->length (), + sizeof (tree), method_name_cmp); + + tree fields = TYPE_FIELDS (klass); int n_fields = count_fields (fields); if (n_fields >= 8) { Index: name-lookup.h =================================================================== --- name-lookup.h (revision 251592) +++ name-lookup.h (working copy) @@ -322,7 +322,9 @@ 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 resort_type_method_vec (void *, void *, + gt_pointer_operator, void *); +extern void set_class_bindings (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);