diff mbox

PR middle-end/68002: introduce -fkeep-static-functions

Message ID 908103EDB4893A42920B21D3568BFD9339EE9EE3@MBX13.d.ethz.ch
State New
Headers show

Commit Message

VandeVondele Joost Oct. 17, 2015, 3:17 p.m. UTC
In some cases (e.g. coverage testing) it is useful to emit code for static functions even if they are never used, which currently is not possible at -O1 and above. The following patch introduces a flag for this, which basically triggers the same code that keeps those functions alive at -O0. Thanks to Marc Glisse for replying at gcc-help and for suggesting where to look.

Bootstrapped and regtested on x86_64-unknown-linux-gnu

OK for trunk ?

Joost
gcc/ChangeLog:

2015-10-17  Joost VandeVondele  <vondele@gnu.gcc.org>

        PR middle-end/68002
	* common.opt (fkeep-static-functions): New option.
	* doc/invoke.texi: Document it.
	* cgraphunit.c (cgraph_node::finalize_function): Use it.

gcc/testsuite/ChangeLog:

2015-10-17  Joost VandeVondele  <vondele@gnu.gcc.org>

        PR middle-end/68002
	* gcc.dg/PR68002.c: New test.

Comments

Richard Biener Oct. 19, 2015, 9:18 a.m. UTC | #1
On Sat, Oct 17, 2015 at 5:17 PM, VandeVondele  Joost
<joost.vandevondele@mat.ethz.ch> wrote:
> In some cases (e.g. coverage testing) it is useful to emit code for static functions even if they are never used, which currently is not possible at -O1 and above. The following patch introduces a flag for this, which basically triggers the same code that keeps those functions alive at -O0. Thanks to Marc Glisse for replying at gcc-help and for suggesting where to look.
>
> Bootstrapped and regtested on x86_64-unknown-linux-gnu
>
> OK for trunk ?

Ok.

Thanks,
Richard.

> Joost
diff mbox

Patch

Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 228932)
+++ gcc/doc/invoke.texi	(working copy)
@@ -410,8 +410,8 @@  Objective-C and Objective-C++ Dialects}.
 -fira-loop-pressure -fno-ira-share-save-slots @gol
 -fno-ira-share-spill-slots -fira-verbose=@var{n} @gol
 -fisolate-erroneous-paths-dereference -fisolate-erroneous-paths-attribute @gol
--fivopts -fkeep-inline-functions -fkeep-static-consts @gol
--flive-range-shrinkage @gol
+-fivopts -fkeep-inline-functions -fkeep-static-functions @gol
+-fkeep-static-consts -flive-range-shrinkage @gol
 -floop-block -floop-interchange -floop-strip-mine @gol
 -floop-unroll-and-jam -floop-nest-optimize @gol
 -floop-parallelize-all -flra-remat -flto -flto-compression-level @gol
@@ -8013,6 +8013,11 @@  of its callers.  This switch does not af
 @code{extern inline} extension in GNU C90@.  In C++, emit any and all
 inline functions into the object file.
 
+@item -fkeep-static-functions
+@optindex fkeep-static-functions
+Emit @code{static} functions into the object file, even if the function
+is never used.
+
 @item -fkeep-static-consts
 @opindex fkeep-static-consts
 Emit variables declared @code{static const} when optimization isn't turned
Index: gcc/cgraphunit.c
===================================================================
--- gcc/cgraphunit.c	(revision 228932)
+++ gcc/cgraphunit.c	(working copy)
@@ -451,7 +451,7 @@  cgraph_node::finalize_function (tree dec
      declared inline and nested functions.  These were optimized out
      in the original implementation and it is unclear whether we want
      to change the behavior here.  */
-  if ((!opt_for_fn (decl, optimize)
+  if (((!opt_for_fn (decl, optimize) || flag_keep_static_functions)
        && !node->cpp_implicit_alias
        && !DECL_DISREGARD_INLINE_LIMITS (decl)
        && !DECL_DECLARED_INLINE_P (decl)
Index: gcc/testsuite/gcc.dg/PR68002.c
===================================================================
--- gcc/testsuite/gcc.dg/PR68002.c	(revision 0)
+++ gcc/testsuite/gcc.dg/PR68002.c	(revision 0)
@@ -0,0 +1,7 @@ 
+/* Ensure static functions can be kept.  */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fkeep-static-functions" } */
+
+static void bar () { }
+
+/* { dg-final { scan-assembler "bar" } } */
Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 228932)
+++ gcc/common.opt	(working copy)
@@ -1589,6 +1589,10 @@  fkeep-inline-functions
 Common Report Var(flag_keep_inline_functions)
 Generate code for functions even if they are fully inlined
 
+fkeep-static-functions
+Common Report Var(flag_keep_static_functions)
+Generate code for static functions even if they are never called 
+
 fkeep-static-consts
 Common Report Var(flag_keep_static_consts) Init(1)
 Emit static const variables even if they are not used