public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][Middle-end][Version 3]Add a new option to control inlining only on static functions
@ 2018-09-18 18:58 Qing Zhao
  2018-09-18 23:18 ` Martin Sebor
  0 siblings, 1 reply; 124+ messages in thread
From: Qing Zhao @ 2018-09-18 18:58 UTC (permalink / raw)
  To: gcc Patches
  Cc: jeff Law, Richard Guenther, Jakub Jelinek, Alexander Monakov,
	andrew Pinski

[-- Attachment #1: Type: text/plain, Size: 1112 bytes --]

Hi,

this is the 3rd version of the patch, the major change is to address Andrew’s 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  <qing.zhao@oracle.com>
+
+	* 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. 

gcc/testsuite/ChangeLog

+2018-09-18  Qing Zhao  <qing.zhao@oracle.com>
+
+	* gcc.dg/inline_only_static.c: New test.
+


[-- Attachment #2: New-inline-only-static.patch --]
[-- Type: application/octet-stream, Size: 4004 bytes --]

---
 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

^ permalink raw reply	[flat|nested] 124+ messages in thread

end of thread, other threads:[~2019-04-11  7:58 UTC | newest]

Thread overview: 124+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-18 18:58 [PATCH][Middle-end][Version 3]Add a new option to control inlining only on static functions Qing Zhao
2018-09-18 23:18 ` Martin Sebor
2018-09-19 15:07   ` Qing Zhao
2018-09-21 15:19     ` [PATCH][Middle-end][Version 4]Add " Qing Zhao
2018-09-26  1:01       ` PING: " Qing Zhao
2018-09-26 11:20       ` Alexander Monakov
2018-09-26 12:49         ` Paolo Carlini
2018-09-26 14:43         ` Qing Zhao
2018-09-26 15:18           ` Alexander Monakov
2018-09-26 23:07             ` Qing Zhao
2018-09-26 23:54               ` Alexander Monakov
2018-09-27  5:16                 ` Qing Zhao
2018-09-27  7:46                   ` Richard Biener
2018-09-27 16:30                     ` Qing Zhao
2018-09-27  8:55                   ` Alexander Monakov
2018-09-27  8:58                 ` Jan Hubicka
2018-09-27 11:12                   ` Richard Biener
2018-09-26 13:24       ` Jason Merrill
2018-09-26 13:31         ` Richard Biener
2018-09-26 13:40           ` Jason Merrill
2018-09-26 14:46             ` Jeff Law
2018-09-26 14:58               ` Jason Merrill
2018-09-26 15:10                 ` Jan Hubicka
2018-09-26 17:12                   ` Qing Zhao
2018-09-26 17:22                     ` Jan Hubicka
2018-09-26 21:36                       ` Qing Zhao
2018-09-27  9:47                         ` Jan Hubicka
2018-09-27 12:29                           ` GCC options for kernel live-patching (Was: Add a new option to control inlining only on static functions) Martin Jambor
2018-09-27 16:40                             ` Qing Zhao
2018-10-01 17:14                             ` Qing Zhao
2018-10-02  8:38                               ` Martin Jambor
2018-10-02 14:00                                 ` Qing Zhao
2018-10-02 14:11                                   ` Martin Liška
2018-10-02 14:55                                     ` Qing Zhao
2018-10-02 14:59                                       ` Martin Liška
2018-10-02 15:24                                         ` Qing Zhao
2018-10-02 17:16                                           ` Martin Liška
2018-10-02 18:34                                             ` Richard Biener
2018-10-02 21:25                                               ` Qing Zhao
2018-10-03  9:05                                                 ` Martin Liška
2018-10-03 10:53                                                 ` Martin Jambor
2018-10-03 16:11                                                   ` Qing Zhao
2018-10-04 13:20                                                     ` Richard Biener
2018-10-18 19:36                                                       ` [RFC] GCC support for live-patching Qing Zhao
2018-10-19  8:53                                                         ` Bernhard Reutner-Fischer
2018-10-19 18:33                                                           ` Qing Zhao
2018-10-24 21:16                                                             ` Alexandre Oliva
2018-10-19 14:25                                                         ` Andi Kleen
2018-10-19 18:33                                                           ` Qing Zhao
2018-10-20  6:47                                                             ` Andi Kleen
2018-10-22 13:07                                                         ` Martin Jambor
2018-10-22 17:59                                                           ` Qing Zhao
2018-10-22 15:36                                                         ` Miroslav Benes
2018-10-22 21:01                                                           ` Qing Zhao
2018-10-23  9:37                                                             ` Miroslav Benes
2018-10-23 19:54                                                               ` Qing Zhao
2018-10-24 13:17                                                                 ` Miroslav Benes
2018-10-23 13:37                                                             ` Nicolai Stange
2018-10-23 20:34                                                               ` Qing Zhao
2018-10-23 21:18                                                                 ` Nicolai Stange
2018-10-24 17:19                                                                 ` Qing Zhao
2018-10-31 22:04                                                         ` [RFC] [2nd version] " Qing Zhao
2018-10-31 22:08                                                         ` [RFC] " Qing Zhao
2018-10-03  9:23                                             ` GCC options for kernel live-patching (Was: Add a new option to control inlining only on static functions) Jan Hubicka
2018-10-03 11:27                                               ` Martin Liška
2018-10-22 10:49                                                 ` Martin Liška
     [not found]                                                   ` <20181105095135.j3mnzox6rkktkoto@kam.mff.cuni.cz>
2018-11-05 22:26                                                     ` Qing Zhao
2018-11-07 14:22                                                     ` Martin Liška
2018-11-07 14:27                                                       ` Jan Hubicka
2018-11-07 14:44                                                         ` Martin Liška
2018-11-08 14:59                                                       ` Jan Hubicka
2018-11-09 15:33                                                         ` [PATCH][RFC] Come up with -flive-patching master option Martin Liška
2018-11-09 17:43                                                           ` Qing Zhao
2018-11-10  8:51                                                             ` Martin Liška
2018-11-12  2:28                                                               ` Qing Zhao
2018-11-12  8:53                                                                 ` Martin Liška
2018-11-12 22:29                                                                   ` Qing Zhao
2018-11-13 17:49                                                                     ` Qing Zhao
2018-11-13 19:18                                                                       ` Miroslav Benes
2018-11-13 21:16                                                                         ` Qing Zhao
2018-11-14 15:03                                                                           ` Martin Liška
2018-11-14 17:54                                                                             ` Qing Zhao
2018-11-15  8:41                                                                               ` Martin Liška
2018-11-15 15:41                                                                                 ` Qing Zhao
2018-11-16  1:36                                                                                   ` [PATCH]Come " Qing Zhao
2018-11-16 15:26                                                                                     ` Martin Liška
2018-11-16 15:51                                                                                       ` Jan Hubicka
2018-11-16 16:25                                                                                         ` Qing Zhao
2018-11-16 16:05                                                                                       ` Qing Zhao
2018-11-19  8:12                                                                                         ` Martin Liška
     [not found]                                                                                           ` <F78B52B9-9F9A-4FA0-91BF-A33307D87AA8@oracle.c! ! om>
2018-11-19 15:53                                                                                           ` Qing Zhao
2018-11-20 12:10                                                                                             ` Martin Liška
2018-11-20 15:32                                                                                               ` [PATCH][Version 3]Come " Qing Zhao
2018-11-26 15:54                                                                                                 ` PING: " Qing Zhao
2018-11-30 17:04                                                                                                   ` [wwwdocs] [PATCH]introduce new -flive-patching master option into gcc9 Qing Zhao
2018-11-30 18:29                                                                                                     ` Jeff Law
2018-11-30 20:44                                                                                                       ` Qing Zhao
2018-11-28 15:52                                                                                                 ` [PATCH][Version 3]Come up with -flive-patching master option Jan Hubicka
2018-11-28 20:25                                                                                                   ` Qing Zhao
2018-11-29 16:16                                                                                                     ` Qing Zhao
2018-12-05 23:16                                                                                                     ` Question on Disable no throw for " Qing Zhao
2019-01-02 11:47                                                                                                       ` Martin Liška
2019-01-09 11:28                                                                                                         ` Martin Liška
2018-12-07 13:07                                                                                                     ` [PATCH][Version 3]Come up with " Rainer Orth
2018-12-07 15:14                                                                                                       ` Qing Zhao
2019-04-10 14:46                                                                                                 ` Jonathan Wakely
2019-04-10 19:24                                                                                                   ` Qing Zhao
2019-04-10 20:01                                                                                                     ` Jonathan Wakely
2019-04-11  8:11                                                                                                       ` Richard Biener
2018-11-14 22:05                                                                           ` [PATCH][RFC] Come " Miroslav Benes
     [not found]                                                               ` <20181110170343.g3k7j7rlydid3ahr@kam.mff.cuni.cz>
2018-11-12  9:29                                                                 ` Martin Liška
2018-11-09 18:38                                                           ` Bernhard Reutner-Fischer
2018-11-10  8:48                                                           ` Martin Liška
2018-10-03 12:18                                               ` GCC options for kernel live-patching (Was: Add a new option to control inlining only on static functions) Martin Jambor
2018-10-03 16:00                                               ` Qing Zhao
2018-10-23 12:34                             ` Performance impact of disabling non-clone IPA optimizations for the Linux kernel (was: "GCC options for kernel live-patching") Nicolai Stange
2018-10-24 14:30                               ` Jiri Kosina
2018-10-24 14:44                                 ` Miroslav Benes
2018-09-27 16:32                           ` [PATCH][Middle-end][Version 4]Add a new option to control inlining only on static functions Qing Zhao
2018-09-26 22:42                       ` Qing Zhao
2018-09-26 16:02               ` Qing Zhao
2018-09-26 15:52           ` Qing Zhao
2018-09-26 16:02             ` Jan Hubicka
2018-09-26 18:51               ` Qing Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).