From patchwork Tue Oct 15 12:26:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1176993 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-511013-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jfhgCrrC"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="m9Bk5k5l"; 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 46svmj1m4Mz9sPJ for ; Tue, 15 Oct 2019 23:26:27 +1100 (AEDT) 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=X/cvUAUHt7HxOrPfzUWmkw3xAa2uMR4n75GMNzwCWI9g8EtPg9 dovBX1a46Gn3KXYPm8qQ8UB0C0T5SNr6DjXSMuA/WsQGhJVnTqRI4jdktqTX+Xqk gT+/T4DLfJhAH54/ZXLiltSJxuXByW+KVuul8ysol7MB6iGWaUPFPaIOw= 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=IcxvIQzt0eYjbeP4I1rndtiF3nY=; b=jfhgCrrCMH+LHyACIbgR xFwBjy0Eth64IiQWm7zWBt2TcIvGw0CagVjSutmp3neHQaF5NiLpVowIf6NsiBmh eyxcrmyGX4IXKKZa2TfdjbSl0nxBpJ3QdO6HRBCDo3eAMLu0XCynzGOwhVKe8BZd MmfvEGQpIix6LX0E69Fzr6s= Received: (qmail 111882 invoked by alias); 15 Oct 2019 12:26:19 -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 111874 invoked by uid 89); 15 Oct 2019 12:26:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=Break, incharge, in-charge X-HELO: mail-qt1-f171.google.com Received: from mail-qt1-f171.google.com (HELO mail-qt1-f171.google.com) (209.85.160.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Oct 2019 12:26:16 +0000 Received: by mail-qt1-f171.google.com with SMTP id n17so10851914qtr.4 for ; Tue, 15 Oct 2019 05:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=MOUc3/HsndYUFx6U35mfzNm5GV8ypl/na7Wzpwi6pJs=; b=m9Bk5k5lWPt4cIdJ5gaAG96Vgrjblk//mHEkqLavejm87PpWZG3L4ADeCqLI3nuyU6 nEpE8K8+7bmQGBXhrC5NvH+UYBE3lBnLgilUXJQ3JuMRoWfgTPZevb+QMqyI6b6K4bV3 VE7I0y5mYmEIk3plCEEVNtWMwfm+GTBEwQXi6flsuF6rtGrFAGUF/3EYrEdLRvpKbYpn KNXX7a1OWJSGTXAaeALopxACRuMtIYdUD8F/2R9cbkPlOvIIOB7Na8vvlMiQl9D3s133 zs0w1KNhQ2x8Vh8UrasW3gkxKe7wVF1AlkRZzJ3MBg3OH6+RrtWVo1tGPbn/KnbIVcrY /9+g== Received: from ?IPv6:2620:10d:c0a3:1407:f888:8672:b7f1:b6cf? ([2620:10d:c091:500::1:ca40]) by smtp.googlemail.com with ESMTPSA id t4sm9191389qkt.45.2019.10.15.05.26.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Oct 2019 05:26:13 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] clone_function_decl breakup Message-ID: <2085ba53-d8c0-eb48-b146-d1d50f95486f@acm.org> Date: Tue, 15 Oct 2019 08:26:12 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 This patch, from the modules branch, breaks out function cloning from the method vector updating. We have a new function, build_clones, which does the building, returning a count of the number of clones (2 or 3). clone_function_decl separately adds them to the method vector, if they should be added. I suppose this could have used FOR_EVERY_CLONE, but I went with the counting scheme. On the module branch, build_clones is not static and has a few more parameters, but that's a different patch. installing on trunk. nathan 2019-10-15 Nathan Sidwell * class.c (build_clones): Break out of clone_function_decl. Just build the clones. (clone_function_decl): Call build_clones, then maybe add them to the method vector. Index: class.c =================================================================== --- class.c (revision 276992) +++ class.c (working copy) @@ -4700,17 +4700,11 @@ build_clone (tree fn, tree name) } -/* Produce declarations for all appropriate clones of FN. If - UPDATE_METHODS is true, the clones are added to the - CLASSTYPE_MEMBER_VEC. */ +/* Build the clones of FN, return the number of clones built. These + will be inserted onto DECL_CHAIN of FN. */ -void -clone_function_decl (tree fn, bool update_methods) +unsigned +build_clones (tree fn) { - tree clone; - - /* Avoid inappropriate cloning. */ - if (DECL_CHAIN (fn) - && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn))) - return; + unsigned count = 0; if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)) @@ -4718,10 +4712,7 @@ clone_function_decl (tree fn, bool updat /* For each constructor, we need two variants: an in-charge version and a not-in-charge version. */ - clone = build_clone (fn, complete_ctor_identifier); - if (update_methods) - add_method (DECL_CONTEXT (clone), clone, false); - clone = build_clone (fn, base_ctor_identifier); - if (update_methods) - add_method (DECL_CONTEXT (clone), clone, false); + build_clone (fn, complete_ctor_identifier); + build_clone (fn, base_ctor_identifier); + count += 2; } else @@ -4740,18 +4731,38 @@ clone_function_decl (tree fn, bool updat if (DECL_VIRTUAL_P (fn)) { - clone = build_clone (fn, deleting_dtor_identifier); - if (update_methods) - add_method (DECL_CONTEXT (clone), clone, false); + build_clone (fn, deleting_dtor_identifier); + count++; } - clone = build_clone (fn, complete_dtor_identifier); - if (update_methods) - add_method (DECL_CONTEXT (clone), clone, false); - clone = build_clone (fn, base_dtor_identifier); - if (update_methods) - add_method (DECL_CONTEXT (clone), clone, false); + build_clone (fn, complete_dtor_identifier); + build_clone (fn, base_dtor_identifier); + count += 2; } + return count; +} + +/* Produce declarations for all appropriate clones of FN. If + UPDATE_METHODS is true, the clones are added to the + CLASSTYPE_MEMBER_VEC. */ + +void +clone_function_decl (tree fn, bool update_methods) +{ + /* Avoid inappropriate cloning. */ + if (DECL_CHAIN (fn) + && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn))) + return; + + unsigned count = build_clones (fn); + /* Note that this is an abstract function that is never emitted. */ DECL_ABSTRACT_P (fn) = true; + + if (update_methods) + for (tree clone = fn; count--;) + { + clone = DECL_CHAIN (clone); + add_method (DECL_CONTEXT (clone), clone, false); + } }