This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Discard unreachable nested functions at -O0
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 31 May 2010 12:26:42 +0200
- Subject: [patch] Discard unreachable nested functions at -O0
Hi,
in Ada the front-end generates a lot of nested functions for generic packages
or composite types and we want them to be discarded if unreachable even at -O0
to speed things up and save memory.
Some years ago I submitted a patch to that effect:
http://gcc.gnu.org/ml/gcc-patches/2006-03/msg01201.html
but it was rejected by RTH on technical grounds (we use it internally though).
I'm submitting a revised version, which is trivial since the compiler now
works in unit-at-a-time mode. And it's worth noting that this is actually
supposed to be already implemented, see cgraph_decide_is_function_needed:
When not optimizing, also output the static functions. (see
PR24561), but don't do so for always_inline functions, functions
declared inline and nested functions. These was optimized out
in the original implementation and it is unclear whether we want
to change the behavior here. */
Tested on x86_64-suse-linux, OK for mainline?
2010-05-31 Eric Botcazou <ebotcazou@adacore.com>
* cgraphunit.c (cgraph_decide_is_function_needed): Really return false
for nested functions in non-optimized compilation.
2010-05-31 Eric Botcazou <ebotcazou@adacore.com>
* gcc.dg/nested-func-7.c: New test.
* gnat.dg/frame_overflow.adb: Adjust directives.
--
Eric Botcazou
Index: cgraphunit.c
===================================================================
--- cgraphunit.c (revision 159937)
+++ cgraphunit.c (working copy)
@@ -352,13 +352,15 @@ cgraph_decide_is_function_needed (struct
When not optimizing, also output the static functions. (see
PR24561), but don't do so for always_inline functions, functions
- declared inline and nested functions. These was optimized out
+ 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 (((TREE_PUBLIC (decl)
- || (!optimize && !node->local.disregard_inline_limits
+ || (!optimize
+ && !node->local.disregard_inline_limits
&& !DECL_DECLARED_INLINE_P (decl)
- && !node->origin))
+ && !(DECL_CONTEXT (decl)
+ && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)))
&& !flag_whole_program
&& !flag_lto
&& !flag_whopr)
Index: testsuite/gnat.dg/frame_overflow.adb
===================================================================
--- testsuite/gnat.dg/frame_overflow.adb (revision 159937)
+++ testsuite/gnat.dg/frame_overflow.adb (working copy)
@@ -1,5 +1,4 @@
-- { dg-do compile }
--- { dg-xfail-if "missing late warning" { *-*-* } { "-flto" } { "" } }
with System;
@@ -11,8 +10,8 @@ procedure frame_overflow is
type Bitmap_T is record
Bits : Bitmap_Array_T := (others => False);
end record;
-
- function -- { dg-error "too large" }
+
+ function
Set_In (Bitmap : Bitmap_T; Bitpos : Bitpos_Range_T) return Bitmap_T
is
Result: Bitmap_T := Bitmap; -- { dg-error "Storage_Error" }
/* { dg-do compile } */
/* { dg-options "-fdump-tree-optimized" } */
void foo (void)
{
int a;
void bar (void)
{
a = 1;
}
}
/* { dg-final { scan-tree-dump-not "bar" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */