public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [LTO] PATCH: Fix for ICE vector VEC(cgraph_node_ptr,base) index domain error
@ 2008-10-23 13:26 Simon Baldwin
  2008-10-23 13:29 ` Diego Novillo
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Baldwin @ 2008-10-23 13:26 UTC (permalink / raw)
  To: gcc-patches

Callgraph nodes are not necessarily written out in such an order that an
inlined function can always locate the function that inlines it.  Sometimes,
the function that inlines it has not yet been read.

This patch addresses that by deferring node lookup by reference until all of
the callgraph nodes have been read, and fixes the following:

  extern inline void __attribute__((__always_inline__)) func(void) { }
  void f(void) { func(); }

  $ gcc -c -fwhopr -o f.o f.c
  $ gcc -shared -fwhopr -o f.so f.o
  lto1: internal compiler error: vector VEC(cgraph_node_ptr,base) index
  domain error, in input_node at lto/lto-lang.c:1216


gcc/lto/ChangeLog
2008-10-22  Simon Baldwin  <simonb@google.com>

	* lto-lang.c: (input_node): Save the node reference, rather than the
	node pointer, in node->inlined_to.
	(fixup_cgraph_nodes): New function, convert node references into
	node pointers.
	(input_cgraph_1): Call fixup_cgraph_nodes.


Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c	(revision 141263)
+++ gcc/lto/lto-lang.c	(working copy)
@@ -1212,10 +1212,10 @@ input_node (struct lto_file_decl_data* f
 	  node->global.estimated_stack_size = estimated_stack_size;
 	  node->global.stack_frame_offset = stack_frame_offset;
 	  node->global.insns = insns;
-	  if (ref != LCC_NOT_FOUND)
-	    node->global.inlined_to = VEC_index (cgraph_node_ptr, nodes, ref);
-	  else
-	    node->global.inlined_to = NULL;
+
+          /* Store a reference for now, and fix up later to be a pointer.  */
+          node->global.inlined_to = (graph_node_ptr) ref;
+
 	  node->global.estimated_growth = estimated_growth;
 	  node->global.inlined = inlined;
 	}
@@ -1270,6 +1270,26 @@ input_edge (struct lto_input_block *ib, 
   edge->indirect_call = lto_get_flag (&flags);
 }
 
+/* Callgraph node inlined_to fields are currently references; here is where
+   we convert them into node pointers.  */
+
+static void
+fixup_cgraph_nodes (VEC(cgraph_node_ptr, heap) *nodes)
+{
+  int i;
+
+  for (i = 0; VEC_iterate (cgraph_node_ptr, nodes, i, node); i++)
+    {
+      const int ref = (int) node->global.inlined_to;
+
+      if (ref != LCC_NOT_FOUND)
+        node->global.inlined_to = VEC_index (cgraph_node_ptr, nodes, ref);
+      else
+        node->global.inlined_to = NULL;
+    }
+
+}
+
 /* Input a cgraph from IB using the info in FILE_DATA.  */
 
 static void
@@ -1286,7 +1306,7 @@ input_cgraph_1 (struct lto_file_decl_dat
       LTO_DEBUG_INDENT (tag);
 
       if (tag == LTO_cgraph_edge)
-	  input_edge (ib, nodes);
+        input_edge (ib, nodes);
       else 
 	{
 	  node = input_node (file_data, ib, tag, nodes);
@@ -1297,6 +1317,7 @@ input_cgraph_1 (struct lto_file_decl_dat
       tag = lto_input_uleb128 (ib);
     }
 
+  fixup_cgraph_nodes (nodes);
   VEC_free (cgraph_node_ptr, heap, nodes);
 }
 

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

* Re: [LTO] PATCH: Fix for ICE vector VEC(cgraph_node_ptr,base) index domain error
  2008-10-23 13:26 [LTO] PATCH: Fix for ICE vector VEC(cgraph_node_ptr,base) index domain error Simon Baldwin
@ 2008-10-23 13:29 ` Diego Novillo
  2008-10-23 15:56   ` Simon Baldwin
  0 siblings, 1 reply; 4+ messages in thread
From: Diego Novillo @ 2008-10-23 13:29 UTC (permalink / raw)
  To: Simon Baldwin; +Cc: gcc-patches

On Thu, Oct 23, 2008 at 05:38, Simon Baldwin <simonb@google.com> wrote:

> 2008-10-22  Simon Baldwin  <simonb@google.com>
>
>        * lto-lang.c: (input_node): Save the node reference, rather than the
>        node pointer, in node->inlined_to.
>        (fixup_cgraph_nodes): New function, convert node references into
>        node pointers.
>        (input_cgraph_1): Call fixup_cgraph_nodes.

OK.

I've added this to the list of multi-file test cases in the wiki
(http://gcc.gnu.org/wiki/whopr).


Diego.

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

* Re: [LTO] PATCH: Fix for ICE vector VEC(cgraph_node_ptr,base) index  domain error
  2008-10-23 13:29 ` Diego Novillo
@ 2008-10-23 15:56   ` Simon Baldwin
  2008-10-23 16:35     ` Diego Novillo
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Baldwin @ 2008-10-23 15:56 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

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

Diego Novillo wrote:
> On Thu, Oct 23, 2008 at 05:38, Simon Baldwin <simonb@google.com> wrote:
>
>   
>> 2008-10-22  Simon Baldwin  <simonb@google.com>
>>
>>        * lto-lang.c: (input_node): Save the node reference, rather than the
>>        node pointer, in node->inlined_to.
>>        (fixup_cgraph_nodes): New function, convert node references into
>>        node pointers.
>>        (input_cgraph_1): Call fixup_cgraph_nodes.
>>     
>
> OK.
>   

Thanks.  However, changes between revs 141263 and 141308 mean that I've 
had to juggle it about a fair bit since emailing.

Would you mind taking a look at the revised version, appended below -- 
broadly the same, just a little more direct.  Thanks.

-- 
Google UK Limited | Registered Office: Belgrave House, 76 Buckingham
Palace Road, London SW1W 9TQ | Registered in England Number: 3977902


[-- Attachment #2: cgraph_fixup.patch --]
[-- Type: text/x-patch, Size: 2569 bytes --]

Callgraph nodes are not necessarily written out in such an order that an
inlined function can always locate the function that inlines it.  Sometimes,
the function that inlines it has not yet been read.

This patch addresses that by deferring node lookup by reference until all of
the callgraph nodes have been read, and fixes the following:

  extern inline void __attribute__((__always_inline__)) func(void) { }
  void f(void) { func(); }

  $ gcc -c -fwhopr -o f.o f.c
  $ gcc -shared -fwhopr -o f.so f.o
  lto1: internal compiler error: vector VEC(cgraph_node_ptr,base) index
  domain error, in input_node at lto/lto-lang.c:1216


gcc/lto/ChangeLog
2008-10-23  Simon Baldwin  <simonb@google.com>

	* lto-lang.c: (input_node): Save the node reference, rather than the
	node pointer, in node->inlined_to.
	(input_cgraph_1): Convert node references into node pointers.


Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c	(revision 141320)
+++ gcc/lto/lto-lang.c	(working copy)
@@ -1185,10 +1185,10 @@ input_node (struct lto_file_decl_data* f
       node->global.estimated_stack_size = estimated_stack_size;
       node->global.stack_frame_offset = stack_frame_offset;
       node->global.insns = insns;
-      if (ref != LCC_NOT_FOUND)
-	node->global.inlined_to = VEC_index (cgraph_node_ptr, nodes, ref);
-      else
-	node->global.inlined_to = NULL;
+
+      /* Store a reference for now, and fix up later to be a pointer.  */
+      node->global.inlined_to = (cgraph_node_ptr) ref;
+
       node->global.estimated_growth = estimated_growth;
       node->global.inlined = inlined;
     }
@@ -1302,7 +1302,7 @@ input_cgraph_1 (struct lto_file_decl_dat
       LTO_DEBUG_INDENT (tag);
 
       if (tag == LTO_cgraph_edge)
-	  input_edge (ib, nodes);
+        input_edge (ib, nodes);
       else 
 	{
 	  node = input_node (file_data, ib, tag, nodes);
@@ -1315,6 +1315,20 @@ input_cgraph_1 (struct lto_file_decl_dat
       tag = lto_input_uleb128 (ib);
     }
 
+  if (flag_ltrans)
+    {
+      for (node = cgraph_nodes; node; node = node->next)
+        {
+          const int ref = (int) node->global.inlined_to;
+
+          /* Fixup inlined_to from reference to pointer.  */
+          if (ref != LCC_NOT_FOUND)
+            node->global.inlined_to = VEC_index (cgraph_node_ptr, nodes, ref);
+          else
+            node->global.inlined_to = NULL;
+        }
+    }
+
   for (node = cgraph_nodes; node; node = node->next)
     {
       tree prevailing = lto_symtab_prevailing_decl (node->decl);

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

* Re: [LTO] PATCH: Fix for ICE vector VEC(cgraph_node_ptr,base) index domain error
  2008-10-23 15:56   ` Simon Baldwin
@ 2008-10-23 16:35     ` Diego Novillo
  0 siblings, 0 replies; 4+ messages in thread
From: Diego Novillo @ 2008-10-23 16:35 UTC (permalink / raw)
  To: Simon Baldwin; +Cc: gcc-patches

On Thu, Oct 23, 2008 at 09:18, Simon Baldwin <simonb@google.com> wrote:

> Thanks.  However, changes between revs 141263 and 141308 mean that I've had
> to juggle it about a fair bit since emailing.
>
> Would you mind taking a look at the revised version, appended below --
> broadly the same, just a little more direct.  Thanks.

I actually preferred the fixup_cgraph_nodes() function, so the code
would look like

if (flag_ltrans)
  fixup_cgraph_nodes ();

But it's not terribly important.  This version is fine too.


Diego.

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

end of thread, other threads:[~2008-10-23 13:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-23 13:26 [LTO] PATCH: Fix for ICE vector VEC(cgraph_node_ptr,base) index domain error Simon Baldwin
2008-10-23 13:29 ` Diego Novillo
2008-10-23 15:56   ` Simon Baldwin
2008-10-23 16:35     ` Diego Novillo

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