Fix ipa_fn_summary_write for offloading LTO streaming (PR ipa/92357)
diff mbox series

Message ID 20191214091132.GT10088@tucnak
State New
Headers show
Series
  • Fix ipa_fn_summary_write for offloading LTO streaming (PR ipa/92357)
Related show

Commit Message

Jakub Jelinek Dec. 14, 2019, 9:11 a.m. UTC
Hi!

As discussed on IRC and in the PR, we get an ICE during inline_read_section
in the offloading lto1, because the size of streamed out and expected to be
streamed in data doesn't match.  This happens on the testcase from the PR
where
          for (edge = cnode->callees; edge; edge = edge->next_callee)
            write_ipa_call_summary (ob, edge);
writes summaries for 2 edges and
      for (e = node->callees; e; e = e->next_callee)
        read_ipa_call_summary (&ib, e, info != NULL);
has NULL node->callees and doesn't thus stream in anything.
That is because
  for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
    {
      node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder, i));
      if (node
          && ((node->thunk.thunk_p && !node->inlined_to)
              || lto_symtab_encoder_in_partition_p (encoder, node)))
        {
          output_outgoing_cgraph_edges (node->callees, ob, encoder);
          output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
        }
    }
didn't stream the callees out, as lto_symtab_encoder_in_partition_p (encoder, node)
is false.  All the other IPA writers that write function summaries only
handle functions that pass this predicate, using the lsei_*_function_in_partition
iterators, but ipa_fn_summary_write streams all.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
regtested on x86_64-linux with nvptx-none offloading, ok for trunk?

Note, there is another issue unrelated to this that still needs fixing.

2019-12-14  Jakub Jelinek  <jakub@redhat.com>

	PR ipa/92357
	* ipa-fnsummary.c (ipa_fn_summary_write): Use
	lto_symtab_encoder_iterator with lsei_start_function_in_partition and
	lsei_next_function_in_partition instead of walking all cgraph nodes
	in encoder.


	Jakub

Comments

Richard Biener Dec. 14, 2019, 11:13 a.m. UTC | #1
On December 14, 2019 10:11:33 AM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>As discussed on IRC and in the PR, we get an ICE during
>inline_read_section
>in the offloading lto1, because the size of streamed out and expected
>to be
>streamed in data doesn't match.  This happens on the testcase from the
>PR
>where
>          for (edge = cnode->callees; edge; edge = edge->next_callee)
>            write_ipa_call_summary (ob, edge);
>writes summaries for 2 edges and
>      for (e = node->callees; e; e = e->next_callee)
>        read_ipa_call_summary (&ib, e, info != NULL);
>has NULL node->callees and doesn't thus stream in anything.
>That is because
>  for (int i = 0; i < lto_symtab_encoder_size (encoder); i++)
>    {
>node = dyn_cast <cgraph_node *> (lto_symtab_encoder_deref (encoder,
>i));
>      if (node
>          && ((node->thunk.thunk_p && !node->inlined_to)
>              || lto_symtab_encoder_in_partition_p (encoder, node)))
>        {
>          output_outgoing_cgraph_edges (node->callees, ob, encoder);
>      output_outgoing_cgraph_edges (node->indirect_calls, ob, encoder);
>        }
>    }
>didn't stream the callees out, as lto_symtab_encoder_in_partition_p
>(encoder, node)
>is false.  All the other IPA writers that write function summaries only
>handle functions that pass this predicate, using the
>lsei_*_function_in_partition
>iterators, but ipa_fn_summary_write streams all.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
>regtested on x86_64-linux with nvptx-none offloading, ok for trunk?

Ok. 

Richard. 

>Note, there is another issue unrelated to this that still needs fixing.
>
>2019-12-14  Jakub Jelinek  <jakub@redhat.com>
>
>	PR ipa/92357
>	* ipa-fnsummary.c (ipa_fn_summary_write): Use
>	lto_symtab_encoder_iterator with lsei_start_function_in_partition and
>	lsei_next_function_in_partition instead of walking all cgraph nodes
>	in encoder.
>
>--- gcc/ipa-fnsummary.c.jj	2019-12-05 14:02:20.559570378 +0100
>+++ gcc/ipa-fnsummary.c	2019-12-13 18:01:08.344828332 +0100
>@@ -4364,24 +4364,24 @@ static void
> ipa_fn_summary_write (void)
> {
>struct output_block *ob = create_output_block
>(LTO_section_ipa_fn_summary);
>+  lto_symtab_encoder_iterator lsei;
>   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
>   unsigned int count = 0;
>-  int i;
> 
>-  for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
>+  for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p
>(lsei);
>+       lsei_next_function_in_partition (&lsei))
>     {
>-      symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
>-      cgraph_node *cnode = dyn_cast <cgraph_node *> (snode);
>-      if (cnode && cnode->definition && !cnode->alias)
>+      cgraph_node *cnode = lsei_cgraph_node (lsei);
>+      if (cnode->definition && !cnode->alias)
> 	count++;
>     }
>   streamer_write_uhwi (ob, count);
> 
>-  for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
>+  for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p
>(lsei);
>+       lsei_next_function_in_partition (&lsei))
>     {
>-      symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
>-      cgraph_node *cnode = dyn_cast <cgraph_node *> (snode);
>-      if (cnode && cnode->definition && !cnode->alias)
>+      cgraph_node *cnode = lsei_cgraph_node (lsei);
>+      if (cnode->definition && !cnode->alias)
> 	{
> 	  class ipa_fn_summary *info = ipa_fn_summaries->get (cnode);
>	  class ipa_size_summary *size_info = ipa_size_summaries->get (cnode);
>
>	Jakub

Patch
diff mbox series

--- gcc/ipa-fnsummary.c.jj	2019-12-05 14:02:20.559570378 +0100
+++ gcc/ipa-fnsummary.c	2019-12-13 18:01:08.344828332 +0100
@@ -4364,24 +4364,24 @@  static void
 ipa_fn_summary_write (void)
 {
   struct output_block *ob = create_output_block (LTO_section_ipa_fn_summary);
+  lto_symtab_encoder_iterator lsei;
   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
   unsigned int count = 0;
-  int i;
 
-  for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
+  for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
+       lsei_next_function_in_partition (&lsei))
     {
-      symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
-      cgraph_node *cnode = dyn_cast <cgraph_node *> (snode);
-      if (cnode && cnode->definition && !cnode->alias)
+      cgraph_node *cnode = lsei_cgraph_node (lsei);
+      if (cnode->definition && !cnode->alias)
 	count++;
     }
   streamer_write_uhwi (ob, count);
 
-  for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
+  for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
+       lsei_next_function_in_partition (&lsei))
     {
-      symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
-      cgraph_node *cnode = dyn_cast <cgraph_node *> (snode);
-      if (cnode && cnode->definition && !cnode->alias)
+      cgraph_node *cnode = lsei_cgraph_node (lsei);
+      if (cnode->definition && !cnode->alias)
 	{
 	  class ipa_fn_summary *info = ipa_fn_summaries->get (cnode);
 	  class ipa_size_summary *size_info = ipa_size_summaries->get (cnode);