From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108769 invoked by alias); 18 Sep 2018 18:58:18 -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 108749 invoked by uid 89); 18 Sep 2018 18:58:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy=H*c:HHHHHHHH, H*c:HHHH X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Sep 2018 18:58:16 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w8IIsRbD176963; Tue, 18 Sep 2018 18:58:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : content-type : mime-version : subject : message-id : date : cc : to; s=corp-2018-07-02; bh=smuU7KJwej4UcA5XUDKnpkK0exafhuF8dQENwUPNQLY=; b=41va4hnakK/9sz2ITukhmfODyNXqEhU4g8LJF5af2ebARDekxESXFShIDXze67SnZBol UHTI8nkQOoPwlCAT/wfKxXPLvZ4Me5FC86JgKvrC0MnglZAYz2XW/JRYNbC1v7Zfh8LY hBJ5787oA/CM3nnv7/uGJPpzq4iO43F5cI/tfK1FgmMq2JmS7TWxjZnHQUV+6/uDaL5T KQt1SLvCPG4ORJBU0P53uK8VjD0xPMMXwVexzA5/CADXfUSaUwF2zh/EMBn4+VSrczeE 0MOwW/vuyLmlipBPS1rWt8xW4VrQ96Ic9QX6iCJirkiwyMvQtKP0vFkFzA7wSL2mAYku 7A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2mgsgtpjbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Sep 2018 18:58:14 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w8IIwE0k014827 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Sep 2018 18:58:14 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w8IIwDEx024982; Tue, 18 Sep 2018 18:58:13 GMT Received: from dhcp-10-159-232-95.vpn.oracle.com (/10.159.232.95) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 18 Sep 2018 11:58:13 -0700 From: Qing Zhao Content-Type: multipart/mixed; boundary="Apple-Mail=_4E8A91B5-067F-4AFE-92F3-337B6AD37171" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH][Middle-end][Version 3]Add a new option to control inlining only on static functions Message-Id: Date: Tue, 18 Sep 2018 18:58:00 -0000 Cc: jeff Law , Richard Guenther , Jakub Jelinek , Alexander Monakov , andrew Pinski To: gcc Patches X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg01019.txt.bz2 --Apple-Mail=_4E8A91B5-067F-4AFE-92F3-337B6AD37171 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Content-length: 1083 Hi, this is the 3rd version of the patch, the major change is to address Andrew= =E2=80=99s concern on the documentation part. I updated the documentation of this option as following: '-finline-only-static' By default, GCC inlines functions without considering whether they are static or not. This flag guides inliner to only inline static functions. This option has any effect only when inlining itself is turned on by the -finline-functions or -finline-small-fiunctions. Off by default. all other changes keep the same as version 2. please take a look again. and let me know any comment and suggestion. thanks. Qing gcc/ChangeLog +2018-09-18 Qing Zhao + + * cif-code.def (FUNCTION_EXTERN): New CIFCODE. + * common.opt (-finline-only-static): New option. + * doc/invoke.texi: Document -finline-only-static. + * ipa-inline.c (can_inline_edge_p): Control inlining based on + function's visibility.=20 gcc/testsuite/ChangeLog +2018-09-18 Qing Zhao + + * gcc.dg/inline_only_static.c: New test. + --Apple-Mail=_4E8A91B5-067F-4AFE-92F3-337B6AD37171 Content-Disposition: attachment; filename=New-inline-only-static.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="New-inline-only-static.patch" Content-Transfer-Encoding: 7bit Content-length: 4004 --- gcc/cif-code.def | 6 ++++++ gcc/common.opt | 4 ++++ gcc/doc/invoke.texi | 12 +++++++++++- gcc/ipa-inline.c | 6 ++++++ gcc/testsuite/gcc.dg/inline_only_static.c | 22 ++++++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/inline_only_static.c diff --git a/gcc/cif-code.def b/gcc/cif-code.def index 19a7621..64b2b1a 100644 --- a/gcc/cif-code.def +++ b/gcc/cif-code.def @@ -132,6 +132,12 @@ DEFCIFCODE(USES_COMDAT_LOCAL, CIF_FINAL_ERROR, DEFCIFCODE(ATTRIBUTE_MISMATCH, CIF_FINAL_ERROR, N_("function attribute mismatch")) +/* We can't inline because the user requests only inlining static function + but the function is external visible. */ +DEFCIFCODE(FUNCTION_EXTERN, CIF_FINAL_ERROR, + N_("function is external visible when the user requests only" + " inlining static")) + /* We proved that the call is unreachable. */ DEFCIFCODE(UNREACHABLE, CIF_FINAL_ERROR, N_("unreachable")) diff --git a/gcc/common.opt b/gcc/common.opt index ef6a630..9c66a56 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1633,6 +1633,10 @@ finline-atomics Common Report Var(flag_inline_atomics) Init(1) Optimization Inline __atomic operations when a lock free instruction sequence is available. +finline-only-static +Common RejectNegative Var(flag_inline_only_static) Init(0) +Inline functions only when they are declared \"static\". + fcf-protection Common RejectNegative Alias(fcf-protection=,full) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index ec12711..b6b0db5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -407,7 +407,8 @@ Objective-C and Objective-C++ Dialects}. -fgcse-sm -fhoist-adjacent-loads -fif-conversion @gol -fif-conversion2 -findirect-inlining @gol -finline-functions -finline-functions-called-once -finline-limit=@var{n} @gol --finline-small-functions -fipa-cp -fipa-cp-clone @gol +-finline-only-static @gol +-finline-small-functions -fipa-cp -fipa-cp-clone @gol -fipa-bit-cp -fipa-vrp @gol -fipa-pta -fipa-profile -fipa-pure-const -fipa-reference -fipa-icf @gol -fira-algorithm=@var{algorithm} @gol @@ -8066,6 +8067,15 @@ having large chains of nested wrapper functions. Enabled by default. +@item -finline-only-static +@opindex finline-only-static +By default, GCC inlines functions without considering whether they are static +or not. This flag guides inliner to only inline static functions. +This option has any effect only when inlining itself is turned on by the +-finline-functions or -finline-small-fiunctions. + +Off by default. + @item -fipa-sra @opindex fipa-sra Perform interprocedural scalar replacement of aggregates, removal of diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c index 0257885..f432243 100644 --- a/gcc/ipa-inline.c +++ b/gcc/ipa-inline.c @@ -376,6 +376,12 @@ can_inline_edge_p (struct cgraph_edge *e, bool report, e->inline_failed = CIF_ATTRIBUTE_MISMATCH; inlinable = false; } + else if (callee->externally_visible + && flag_inline_only_static) + { + e->inline_failed = CIF_FUNCTION_EXTERN; + inlinable = false; + } if (!inlinable && report) report_inline_failed_reason (e); return inlinable; diff --git a/gcc/testsuite/gcc.dg/inline_only_static.c b/gcc/testsuite/gcc.dg/inline_only_static.c new file mode 100644 index 0000000..70fd36c --- /dev/null +++ b/gcc/testsuite/gcc.dg/inline_only_static.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -finline-only-static -fdump-tree-einline" } */ + +extern int sum, n, m; + +int foo (int a) +{ + return a + n; +} + +static int bar (int b) +{ + return b * m; +} + +int main() +{ + sum = foo (m) + bar (n); + return 0; +} + +/* { dg-final { scan-tree-dump "not inlinable: main/2 -> foo/0, function is external visible when the user requests only inlining static" "einline" } } */ -- 1.9.1 --Apple-Mail=_4E8A91B5-067F-4AFE-92F3-337B6AD37171--