From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57182 invoked by alias); 16 Jun 2017 14:37:20 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 57167 invoked by uid 89); 16 Jun 2017 14:37:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=1609, keyed X-HELO: mail-yw0-f182.google.com Received: from mail-yw0-f182.google.com (HELO mail-yw0-f182.google.com) (209.85.161.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Jun 2017 14:37:18 +0000 Received: by mail-yw0-f182.google.com with SMTP id e142so19921534ywa.1 for ; Fri, 16 Jun 2017 07:37:22 -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=lWxmbg8HcnZV+GhZkRV2Iiox2tU/hcZLJ/xdHq8krDk=; b=j+2WzlCJ2y8vxosEfEXaimIIdPDq8tGL7d9CPaXd+738pAHmXpEUynui1Bi9TIrDeb /NvA118v/esfEZ9fQzRyxTt0ivctZPo6lpNpzHKFVdBPBLWByGTxUQ6fMeyCR2sY9u07 +tYmj11Fh1RYdfz/FwxefrIQU5aDaCTXyoyF0ow4AjCNUyBMiyvWfVchUwYxnohpuGrt uHbcY+O1B3TSRAZDFrcd3oAh/MNBSem4HW3cFB/GfHHezFlGwOs7+n4h73sBHkFQjdmk CJVahrhfzLi57/0vS1ZvKTaivaqipSL7fW+XT1Frn/5X8t/WE8j5w2DbdIiQb2OwVdat UTrA== X-Gm-Message-State: AKS2vOxaPUAcumUcHEjHwOELKBn8cuCLl07n4ihHUl+dQw4bfoNTmhWh tP0yyX995tKkaQ== X-Received: by 10.13.253.4 with SMTP id n4mr8769581ywf.310.1497623841218; Fri, 16 Jun 2017 07:37:21 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::144]) by smtp.googlemail.com with ESMTPSA id w4sm969976ywe.56.2017.06.16.07.37.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2017 07:37:20 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] Keyed classes list Message-ID: <1425f743-a938-8ced-39e7-c5d2e70f6ca5@acm.org> Date: Fri, 16 Jun 2017 14:37:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7CB70C98AB4F2180E26702C3" X-SW-Source: 2017-06/txt/msg01199.txt.bz2 This is a multi-part message in MIME format. --------------7CB70C98AB4F2180E26702C3 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 576 We need to keep a record of classes whose key-method has been emitted (or that lack one). This patch changes that from a TREE_LIST to a vector. The final processing has an elaborate structure, trying to optimize the point at which we have to start stitching out classes from the list. This patch simply reverse iterates over the vector and uses unordered_remove. Exactly like the next loop that does a similar processing for type info objects. Applied to trunk (also separately committed the typo that crept into the previous rtti commit) nathan -- Nathan Sidwell --------------7CB70C98AB4F2180E26702C3 Content-Type: text/x-patch; name="keyed.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="keyed.diff" Content-length: 4943 Index: class.c =================================================================== --- class.c (revision 249255) +++ class.c (working copy) @@ -7189,8 +7189,8 @@ finish_struct_1 (tree t) in every translation unit where the class definition appears. If we're devirtualizing, we can look into the vtable even if we aren't emitting it. */ - if (CLASSTYPE_KEY_METHOD (t) == NULL_TREE) - keyed_classes = tree_cons (NULL_TREE, t, keyed_classes); + if (!CLASSTYPE_KEY_METHOD (t)) + vec_safe_push (keyed_classes, t); } /* Layout the class itself. */ Index: cp-tree.h =================================================================== --- cp-tree.h (revision 249255) +++ cp-tree.h (working copy) @@ -169,8 +169,6 @@ enum cp_tree_index CPTI_DSO_HANDLE, CPTI_DCAST, - CPTI_KEYED_CLASSES, - CPTI_NULLPTR, CPTI_NULLPTR_TYPE, @@ -290,11 +288,6 @@ extern GTY(()) tree cp_global_trees[CPTI destructors. */ #define vtt_parm_type cp_global_trees[CPTI_VTT_PARM_TYPE] -/* A TREE_LIST of the dynamic classes whose vtables may have to be - emitted in this translation unit. */ - -#define keyed_classes cp_global_trees[CPTI_KEYED_CLASSES] - /* A node which matches any template argument. */ #define any_targ_node cp_global_trees[CPTI_ANY_TARG] @@ -5107,6 +5100,10 @@ extern GTY(()) vec *local_c /* An array of static vars & fns. */ extern GTY(()) vec *static_decls; +/* An array of vtable-needing types that have no key function, or have + an emitted key function. */ +extern GTY(()) vec *keyed_classes; + /* Here's where we control how name mangling takes place. */ Index: decl.c =================================================================== --- decl.c (revision 249255) +++ decl.c (working copy) @@ -160,6 +160,9 @@ tree integer_two_node; /* vector of static decls. */ vec *static_decls; +/* vector of keyed classes. */ +vec *keyed_classes; + /* Used only for jumps to as-yet undefined labels, since jumps to defined labels can have their validity checked immediately. */ @@ -4064,6 +4067,9 @@ cxx_init_decl_processing (void) /* Guess at the initial static decls size. */ vec_alloc (static_decls, 500); + /* ... and keyed classes. */ + vec_alloc (keyed_classes, 100); + record_builtin_type (RID_BOOL, "bool", boolean_type_node); truthvalue_type_node = boolean_type_node; truthvalue_false_node = boolean_false_node; @@ -15438,7 +15444,7 @@ record_key_method_defined (tree fndecl) { tree fnclass = DECL_CONTEXT (fndecl); if (fndecl == CLASSTYPE_KEY_METHOD (fnclass)) - keyed_classes = tree_cons (NULL_TREE, fnclass, keyed_classes); + vec_safe_push (keyed_classes, fnclass); } } Index: decl2.c =================================================================== --- decl2.c (revision 249255) +++ decl2.c (working copy) @@ -4511,37 +4511,18 @@ c_parse_final_cleanups (void) instantiate_pending_templates (retries); ggc_collect (); - /* Write out virtual tables as required. Note that writing out - the virtual table for a template class may cause the + /* Write out virtual tables as required. Writing out the + virtual table for a template class may cause the instantiation of members of that class. If we write out vtables then we remove the class from our list so we don't have to look at it again. */ - - while (keyed_classes != NULL_TREE - && maybe_emit_vtables (TREE_VALUE (keyed_classes))) - { - reconsider = true; - keyed_classes = TREE_CHAIN (keyed_classes); - } - - t = keyed_classes; - if (t != NULL_TREE) - { - tree next = TREE_CHAIN (t); - - while (next) - { - if (maybe_emit_vtables (TREE_VALUE (next))) - { - reconsider = true; - TREE_CHAIN (t) = TREE_CHAIN (next); - } - else - t = next; - - next = TREE_CHAIN (t); - } - } + for (i = keyed_classes->length (); + keyed_classes->iterate (--i, &t);) + if (maybe_emit_vtables (t)) + { + reconsider = true; + keyed_classes->unordered_remove (i); + } /* Write out needed type info variables. We have to be careful looping through unemitted decls, because emit_tinfo_decl may Index: pt.c =================================================================== --- pt.c (revision 249255) +++ pt.c (working copy) @@ -10864,9 +10864,9 @@ instantiate_class_template_1 (tree type) /* The vtable for a template class can be emitted in any translation unit in which the class is instantiated. When there is no key method, however, finish_struct_1 will already have added TYPE to - the keyed_classes list. */ + the keyed_classes. */ if (TYPE_CONTAINS_VPTR_P (type) && CLASSTYPE_KEY_METHOD (type)) - keyed_classes = tree_cons (NULL_TREE, type, keyed_classes); + vec_safe_push (keyed_classes, type); return type; } --------------7CB70C98AB4F2180E26702C3--