From patchwork Mon Jul 16 19:38:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ploujnikov X-Patchwork-Id: 944580 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-481659-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="p9GveB6g"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="Na+UGxLK"; 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 41Tty52G91z9s0w for ; Tue, 17 Jul 2018 05:38:51 +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:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=N0D0ViK7bPqYZ3uJBZT9/2TxwpuoYUfnQmYftJe3BXybuekvwpxah uDyyjxSiCZdtQWK4Vw0poBqBsPpTeO4qLxeVVU1amnDzMMzWvmiD+HA4yDrn6Fn9 Zg/uCWkXA9CVFxQdMc3sAoYu2lgDrWA0oyiREYkTdGuoSXRYWRF7A0= 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:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=4tmAuqQg6eSzw/Vsu0TSyplZF0g=; b=p9GveB6gqm6yvbBvD3QP Q3DwhAMmhY646C72LrT5tkGsP/qFuEXgXLiF3+e0PoryRqOijBL3g3hVyY4i0QAd 53h9qVO8wG3pnqLHM5+YRB9QWTtcB4riEhNbLHHAdfYm+9GzsrcOocfNq9axODzj b2pVzwmBnlQgy+QknzHZDzU= Received: (qmail 105937 invoked by alias); 16 Jul 2018 19:38:44 -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 105921 invoked by uid 89); 16 Jul 2018 19:38:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=figured, sk:scan-ip, sk:scanip, get_identifier X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jul 2018 19:38:42 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6GJSYd6046005 for ; Mon, 16 Jul 2018 19:38:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : subject : to : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=Zz6QauccGPpERvyWE4SN5ZJoUGBiFF/qCVGG6bLJnnI=; b=Na+UGxLKB+RH/ODz9+PxPWEDsMYK9MTYBkJIyNoHk/k46yyP++xW+sutzUXDUrxUICj9 lEEbG6U/upwfIn3uTavfm9jNDlI8KcWzQS21WxmpD7CC7Q3ZdgxK2AuN7349vl0XPmDG nj3mQbqIX9rRwKULu/ak6a9pSsHE60HOKYzH90HBu0+Ay3b978uw3rwe6V1+hpMmjMqp yiCk89pxhFU+Fw24r29O1rHuwq+DygmJEX+orHbZj4xGT4+z/0bDem/mHdlUeS/XdBvL eBikgUw3BjwIiKJBzFX5InaDSbuT6DtXrBuINHCaPsPiuJnrX8sZr9QI9l2AQ8Yfn7ga 1A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2k7a3jnwvs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 16 Jul 2018 19:38:40 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w6GJcco6032613 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 16 Jul 2018 19:38:39 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6GJccMW017960 for ; Mon, 16 Jul 2018 19:38:38 GMT Received: from [10.39.236.121] (/10.39.236.121) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 16 Jul 2018 12:38:38 -0700 From: Michael Ploujnikov Openpgp: preference=signencrypt Subject: [PATCH] Make function clone name numbering independent. To: gcc-patches@gcc.gnu.org Message-ID: Date: Mon, 16 Jul 2018 15:38:36 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, This patch is a small part of the work I'm doing to make function codegen/assembly independent from one another as mentioned in: https://gcc.gnu.org/ml/gcc/2018-07/msg00210.html. It deals with clone_fn_id_num rather than object UIDs and I figured it's better to make my first submission with a smaller, simpler and self-contained patch. This changes clone_function_name_1 such that clone names are based on a per-function rather than a global counter so that the number of clones of one function doesn't affect the numbering of clone names of other functions. This should have minimal impact as the only user of the clone names that I found (https://gcc.gnu.org/ml/gcc/2013-03/msg00268.html) doesn't actually care about the specific numeric values. Thanks - Michael gcc: 2018-07-16 Michael Ploujnikov Make function clone name numbering independent. * cgraphclones.c: Replace clone_fn_id_num with clone_fn_ids. (clone_function_name_1): Use it. testsuite: 2018-07-16 Michael Ploujnikov Clone id counters should be completely independent from one another. * gcc/testsuite/gcc.dg/independent-cloneids-1.c: New test. --- gcc/cgraphclones.c | 11 ++++++-- gcc/testsuite/gcc.dg/independent-cloneids-1.c | 38 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/independent-cloneids-1.c diff --git gcc/cgraphclones.c gcc/cgraphclones.c index 69572b9..c5a40bd 100644 --- gcc/cgraphclones.c +++ gcc/cgraphclones.c @@ -528,7 +528,7 @@ cgraph_node::create_clone (tree new_decl, gcov_type gcov_count, int freq, return new_node; } -static GTY(()) unsigned int clone_fn_id_num; +static GTY(()) hash_map *clone_fn_ids; /* Return a new assembler name for a clone with SUFFIX of a decl named NAME. */ @@ -543,7 +543,14 @@ clone_function_name_1 (const char *name, const char *suffix) memcpy (prefix, name, len); strcpy (prefix + len + 1, suffix); prefix[len] = symbol_table::symbol_suffix_separator (); - ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, clone_fn_id_num++); + unsigned int *suffix_counter; + if (!clone_fn_ids) { + /* Initialize the per-function counter hash table if this is the first call */ + clone_fn_ids = hash_map::create_ggc (1000); + } + suffix_counter = &clone_fn_ids->get_or_insert(name); + ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, *suffix_counter); + *suffix_counter = *suffix_counter + 1; return get_identifier (tmp_name); } diff --git gcc/testsuite/gcc.dg/independent-cloneids-1.c gcc/testsuite/gcc.dg/independent-cloneids-1.c new file mode 100644 index 0000000..d723e20 --- /dev/null +++ gcc/testsuite/gcc.dg/independent-cloneids-1.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fipa-cp -fipa-cp-clone -fdump-ipa-cp" } */ + +extern int printf (const char *, ...); + +static int __attribute__ ((noinline)) +foo (int arg) +{ + return 7 * arg; +} + +static int __attribute__ ((noinline)) +bar (int arg) +{ + return arg * arg; +} + +int +baz (int arg) +{ + printf("%d\n", bar (3)); + printf("%d\n", bar (4)); + printf("%d\n", foo (5)); + printf("%d\n", foo (6)); + /* adding or removing the following call should not affect foo + function's clone numbering */ + printf("%d\n", bar (7)); + return foo (8); +} + +/* { dg-final { scan-ipa-dump "Function bar.constprop.0" "cp" } } */ +/* { dg-final { scan-ipa-dump "Function bar.constprop.1" "cp" } } */ +/* { dg-final { scan-ipa-dump "Function bar.constprop.3" "cp" } } */ +/* { dg-final { scan-ipa-dump "Function foo.constprop.0" "cp" } } */ +/* { dg-final { scan-ipa-dump "Function foo.constprop.1" "cp" } } */ +/* { dg-final { scan-ipa-dump "Function foo.constprop.2" "cp" } } */ +/* { dg-final { scan-ipa-dump-not "Function foo.constprop.3" "cp" } } */ +/* { dg-final { scan-ipa-dump-not "Function foo.constprop.4" "cp" } } */