public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [lto][patch] Remove nodes for extern inline function before writing to disk
@ 2008-10-09 13:41 Rafael Espindola
  2008-10-09 13:53 ` Diego Novillo
  0 siblings, 1 reply; 12+ messages in thread
From: Rafael Espindola @ 2008-10-09 13:41 UTC (permalink / raw)
  To: gcc-patches; +Cc: Diego Novillo

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

gcc normally removes the extern inline bodies after IPA. The problem
for LTO is that streaming is part of IPA.

This patch adds another pass so that we remove the bodies before streaming.

2008-10-08 Rafael Espindola  <espindola@google.com>

	* lto-cgraph.c (output_edge): Assert that the caller is not external.
	* passes.c (init_optimization_passes): Register pass_ipa_free_lang_specifics2.
	* tree-pass.h (pass_ipa_free_lang_specifics2): New.
	* tree.c (free_lang_specifics2): New.
	(pass_ipa_free_lang_specifics2): New.

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: clean2.patch --]
[-- Type: text/x-diff; name=clean2.patch, Size: 2511 bytes --]

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index 12fad49..5ebdd50 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -167,6 +167,8 @@ output_edge (struct lto_simple_output_block *ob,
   intptr_t ref;
   unsigned HOST_WIDEST_INT flags = 0;
 
+  gcc_assert (!DECL_EXTERNAL (edge->caller->decl));
+
   lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_edge);
   LTO_DEBUG_INDENT (LTO_cgraph_edge);
 
diff --git a/gcc/passes.c b/gcc/passes.c
index a39c7ab..7a9e0aa 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -572,6 +572,7 @@ init_optimization_passes (void)
     }
   NEXT_PASS (pass_ipa_increase_alignment);
   NEXT_PASS (pass_ipa_matrix_reorg);
+  NEXT_PASS (pass_ipa_free_lang_specifics2);
   NEXT_PASS (pass_ipa_cp);
   /* All regular IPA_PASSes need to be clumped together.  */
   NEXT_PASS (pass_ipa_lto_gimple_out);
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index b574b65..13e31c5 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -392,6 +392,7 @@ extern struct gimple_opt_pass pass_reset_cc_flags;
 
 /* IPA Passes */
 extern struct simple_ipa_opt_pass pass_ipa_free_lang_specifics;
+extern struct simple_ipa_opt_pass pass_ipa_free_lang_specifics2;
 extern struct simple_ipa_opt_pass pass_ipa_function_and_variable_visibility;
 extern struct simple_ipa_opt_pass pass_ipa_early_inline;
 
diff --git a/gcc/tree.c b/gcc/tree.c
index 4be455a..7a81d1b 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -4103,6 +4103,13 @@ free_lang_specifics (void)
   return 0;
 }
 
+static unsigned
+free_lang_specifics2 (void)
+{
+  /* This pass remove bodies of extern inline functions we never inlined. */
+  cgraph_remove_unreachable_nodes (false, dump_file);
+  return 0;
+}
 
 /* Gate function for free_lang_specifics.  FIXME lto.  This should be
    unconditional and not depend on whether we're producing LTO
@@ -4135,6 +4142,25 @@ struct simple_ipa_opt_pass pass_ipa_free_lang_specifics =
  }
 };
 
+struct simple_ipa_opt_pass pass_ipa_free_lang_specifics2 =
+{
+ {
+  SIMPLE_IPA_PASS,
+  NULL,					/* name */
+  gate_free_lang_specifics,		/* gate */
+  free_lang_specifics2,			/* execute */
+  NULL,					/* sub */
+  NULL,					/* next */
+  0,					/* static_pass_number */
+  0,					/* tv_id */
+  0,	                                /* properties_required */
+  0,					/* properties_provided */
+  0,					/* properties_destroyed */
+  0,					/* todo_flags_start */
+  0					/* todo_flags_finish */
+ }
+};
+
 /* Return nonzero if IDENT is a valid name for attribute ATTR,
    or zero if not.
 

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 13:41 [lto][patch] Remove nodes for extern inline function before writing to disk Rafael Espindola
@ 2008-10-09 13:53 ` Diego Novillo
  2008-10-09 14:08   ` Rafael Espindola
  0 siblings, 1 reply; 12+ messages in thread
From: Diego Novillo @ 2008-10-09 13:53 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: gcc-patches

On Thu, Oct 9, 2008 at 06:23, Rafael Espindola <espindola@google.com> wrote:

>        * lto-cgraph.c (output_edge): Assert that the caller is not external.
>        * passes.c (init_optimization_passes): Register pass_ipa_free_lang_specifics2.
>        * tree-pass.h (pass_ipa_free_lang_specifics2): New.
>        * tree.c (free_lang_specifics2): New.
>        (pass_ipa_free_lang_specifics2): New.

No need to create another pass for this.  Just call
cgraph_remove_unreachable_nodes from pass_ipa_free_lang_specifics.  OK
with that change.


Diego.

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 13:53 ` Diego Novillo
@ 2008-10-09 14:08   ` Rafael Espindola
  2008-10-09 14:18     ` Diego Novillo
  0 siblings, 1 reply; 12+ messages in thread
From: Rafael Espindola @ 2008-10-09 14:08 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

> No need to create another pass for this.  Just call
> cgraph_remove_unreachable_nodes from pass_ipa_free_lang_specifics.  OK
> with that change.

pass_ipa_free_lang_specifics runs too early. If we remove the bodies
there, programs that have extern inline functions and assume they are
inlined will fail. We actually test for that on the testsuite (forgot
the test number).


> Diego.
>

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 14:18     ` Diego Novillo
@ 2008-10-09 14:18       ` Rafael Espindola
  2008-10-09 14:30         ` Diego Novillo
  2008-10-09 14:31         ` Paolo Bonzini
  0 siblings, 2 replies; 12+ messages in thread
From: Rafael Espindola @ 2008-10-09 14:18 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

> Oh, right.  In that case, just add TODO_remove_functions to
> todo_flags_start in pass_ipa_lto_gimple_out.  That should remove the
> unreachable nodes just before we emit gimple.

That would call

cgraph_remove_unreachable_nodes (true, dump_file);

What we need is

cgraph_remove_unreachable_nodes (false, dump_file);

> Diego.
>

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 14:08   ` Rafael Espindola
@ 2008-10-09 14:18     ` Diego Novillo
  2008-10-09 14:18       ` Rafael Espindola
  0 siblings, 1 reply; 12+ messages in thread
From: Diego Novillo @ 2008-10-09 14:18 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: gcc-patches

On Thu, Oct 9, 2008 at 06:52, Rafael Espindola <espindola@google.com> wrote:

> pass_ipa_free_lang_specifics runs too early. If we remove the bodies
> there, programs that have extern inline functions and assume they are
> inlined will fail. We actually test for that on the testsuite (forgot
> the test number).

Oh, right.  In that case, just add TODO_remove_functions to
todo_flags_start in pass_ipa_lto_gimple_out.  That should remove the
unreachable nodes just before we emit gimple.


Diego.

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 14:18       ` Rafael Espindola
@ 2008-10-09 14:30         ` Diego Novillo
  2008-10-09 14:37           ` Rafael Espindola
  2008-10-09 14:31         ` Paolo Bonzini
  1 sibling, 1 reply; 12+ messages in thread
From: Diego Novillo @ 2008-10-09 14:30 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: gcc-patches

On Thu, Oct 9, 2008 at 07:07, Rafael Espindola <espindola@google.com> wrote:

> What we need is
>
> cgraph_remove_unreachable_nodes (false, dump_file);

OK, let's just call it from lto_output() directly, then.  It doesn't
make sense to introduce a new pass just to call this function.


Diego.

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

* Re: [lto][patch] Remove nodes for extern inline function before writing  to disk
  2008-10-09 14:18       ` Rafael Espindola
  2008-10-09 14:30         ` Diego Novillo
@ 2008-10-09 14:31         ` Paolo Bonzini
  1 sibling, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2008-10-09 14:31 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: Diego Novillo, gcc-patches

Rafael Espindola wrote:
>> Oh, right.  In that case, just add TODO_remove_functions to
>> todo_flags_start in pass_ipa_lto_gimple_out.  That should remove the
>> unreachable nodes just before we emit gimple.
> 
> That would call
> 
> cgraph_remove_unreachable_nodes (true, dump_file);
> 
> What we need is
> 
> cgraph_remove_unreachable_nodes (false, dump_file);

Then I guess you can add that at the beginning of
pass_ipa_lto_gimple_out's function.  But if not, please rename
pass_free_lang_specifics2 anyway (just so that I have something sensible
to say :-)

Paolo

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 14:30         ` Diego Novillo
@ 2008-10-09 14:37           ` Rafael Espindola
  2008-10-09 14:50             ` Diego Novillo
  0 siblings, 1 reply; 12+ messages in thread
From: Rafael Espindola @ 2008-10-09 14:37 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

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

> OK, let's just call it from lto_output() directly, then.  It doesn't
> make sense to introduce a new pass just to call this function.

I am testing the attached patch.

2008-10-09 Rafael Espindola  <espindola@google.com>

	* lto-cgraph.c (output_edge): Assert that the caller is not external.
	* lto-function-out.c (lto_output): Call cgraph_remove_unreachable_nodes.

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: clean3.patch --]
[-- Type: text/x-diff; name=clean3.patch, Size: 887 bytes --]

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index 12fad49..5ebdd50 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -167,6 +167,8 @@ output_edge (struct lto_simple_output_block *ob,
   intptr_t ref;
   unsigned HOST_WIDEST_INT flags = 0;
 
+  gcc_assert (!DECL_EXTERNAL (edge->caller->decl));
+
   lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_edge);
   LTO_DEBUG_INDENT (LTO_cgraph_edge);
 
diff --git a/gcc/lto-function-out.c b/gcc/lto-function-out.c
index 90dedad..17621f2 100644
--- a/gcc/lto-function-out.c
+++ b/gcc/lto-function-out.c
@@ -2379,6 +2379,9 @@ lto_output (cgraph_node_set set)
   struct lto_out_decl_state *decl_state;
   cgraph_node_set_iterator csi;
 
+  /* Remove bodies of extern inline functions we never inlined. */
+  cgraph_remove_unreachable_nodes (false, dump_file);
+
   bitmap_obstack_initialize (NULL);
   lto_static_init_local ();
 

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 14:37           ` Rafael Espindola
@ 2008-10-09 14:50             ` Diego Novillo
  2008-10-09 15:55               ` Rafael Espindola
  0 siblings, 1 reply; 12+ messages in thread
From: Diego Novillo @ 2008-10-09 14:50 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: gcc-patches

On Thu, Oct 9, 2008 at 07:29, Rafael Espindola <espindola@google.com> wrote:

> 2008-10-09 Rafael Espindola  <espindola@google.com>
>
>        * lto-cgraph.c (output_edge): Assert that the caller is not external.
>        * lto-function-out.c (lto_output): Call cgraph_remove_unreachable_nodes.

OK.  Thanks.


Diego.

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 14:50             ` Diego Novillo
@ 2008-10-09 15:55               ` Rafael Espindola
  2008-10-09 16:20                 ` Diego Novillo
  0 siblings, 1 reply; 12+ messages in thread
From: Rafael Espindola @ 2008-10-09 15:55 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

> OK.  Thanks.

It  fails :-(

ipa_write_summaries_1 calls lto_output and output_cgraph with the same
set argument. lto_output cannot invalidate any nodes in the set.


>
> Diego.
>

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 15:55               ` Rafael Espindola
@ 2008-10-09 16:20                 ` Diego Novillo
  2008-10-09 17:30                   ` Rafael Espindola
  0 siblings, 1 reply; 12+ messages in thread
From: Diego Novillo @ 2008-10-09 16:20 UTC (permalink / raw)
  To: Rafael Espindola; +Cc: gcc-patches

On Thu, Oct 9, 2008 at 08:33, Rafael Espindola <espindola@google.com> wrote:
>> OK.  Thanks.
>
> It  fails :-(
>
> ipa_write_summaries_1 calls lto_output and output_cgraph with the same
> set argument. lto_output cannot invalidate any nodes in the set.

Which calls for doing this in ipa_write_summaries.  I don't see how
useful would it be for any pass to write summary information on an
extern inline function.


Diego.

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

* Re: [lto][patch] Remove nodes for extern inline function before writing to disk
  2008-10-09 16:20                 ` Diego Novillo
@ 2008-10-09 17:30                   ` Rafael Espindola
  0 siblings, 0 replies; 12+ messages in thread
From: Rafael Espindola @ 2008-10-09 17:30 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

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

> Which calls for doing this in ipa_write_summaries.  I don't see how
> useful would it be for any pass to write summary information on an
> extern inline function.

I am testing the attached patch.

2008-10-09 Rafael Espindola  <espindola@google.com>

	* lto-cgraph.c (output_edge): Assert that the caller is not external.
	* passes.c (ipa_write_summaries): Call cgraph_remove_unreachable_nodes.

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: clean3.patch --]
[-- Type: text/x-diff; name=clean3.patch, Size: 862 bytes --]

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index 12fad49..5ebdd50 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -167,6 +167,8 @@ output_edge (struct lto_simple_output_block *ob,
   intptr_t ref;
   unsigned HOST_WIDEST_INT flags = 0;
 
+  gcc_assert (!DECL_EXTERNAL (edge->caller->decl));
+
   lto_output_uleb128_stream (ob->main_stream, LTO_cgraph_edge);
   LTO_DEBUG_INDENT (LTO_cgraph_edge);
 
diff --git a/gcc/passes.c b/gcc/passes.c
index a39c7ab..aa440f7 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -1383,7 +1383,10 @@ ipa_write_summaries (void)
 {
   cgraph_node_set set;
   struct cgraph_node *node;
- 
+
+  /* Remove bodies of extern inline functions we never inlined. */
+  cgraph_remove_unreachable_nodes (false, dump_file);
+
   if (flag_generate_lto && !(errorcount || sorrycount))
     {
       lto_new_static_inline_states ();

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

end of thread, other threads:[~2008-10-09 15:55 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-09 13:41 [lto][patch] Remove nodes for extern inline function before writing to disk Rafael Espindola
2008-10-09 13:53 ` Diego Novillo
2008-10-09 14:08   ` Rafael Espindola
2008-10-09 14:18     ` Diego Novillo
2008-10-09 14:18       ` Rafael Espindola
2008-10-09 14:30         ` Diego Novillo
2008-10-09 14:37           ` Rafael Espindola
2008-10-09 14:50             ` Diego Novillo
2008-10-09 15:55               ` Rafael Espindola
2008-10-09 16:20                 ` Diego Novillo
2008-10-09 17:30                   ` Rafael Espindola
2008-10-09 14:31         ` Paolo Bonzini

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