public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400)
@ 2011-06-24 14:58 Jakub Jelinek
  2011-06-24 19:49 ` Joseph S. Myers
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jakub Jelinek @ 2011-06-24 14:58 UTC (permalink / raw)
  To: Jason Merrill, Joseph S. Myers; +Cc: gcc-patches

Hi!

On the huge testcase in the PR we ICE, because GC needs too deep recursion.
I've noticed that part of the problem is deep recursion through
TYPE_NEXT_VARIANT pointers.
As TREE_CHAIN on types is TYPE_STUB_DECL, therefore should point
to a different kind of tree and thus isn't really a pointer through
which long chain of trees are linked together, I think we should
use TYPE_NEXT_VARIANT as such chain instead.
In fact, the C FE already uses it, just for INTEGER_TYPEs only.
This patch changes both C and C++ FEs to use it for all types.

The patch fixes the testcase (while without the patch it needs
roughly 35MB of stack, with the patch 5.25MB is enough) and has been
bootstrapped/regtested on x86_64-linux and i686-linux.  Ok for trunk?

2011-06-24  Jakub Jelinek  <jakub@redhat.com>

	PR c++/46400
	* cp-tree.h (union lang_tree_node): Use TYPE_NEXT_VARIANT
	instead of TYPE_CHAIN for chain_next for types.

	* c-decl.c (union lang_tree_node): Use TYPE_NEXT_VARIANT
	instead of TYPE_CHAIN for chain_next for types.

--- gcc/cp/cp-tree.h.jj	2011-06-21 16:45:52.000000000 +0200
+++ gcc/cp/cp-tree.h	2011-06-24 12:07:42.000000000 +0200
@@ -729,7 +729,7 @@ enum cp_tree_node_structure_enum {
 
 /* The resulting tree type.  */
 union GTY((desc ("cp_tree_node_structure (&%h)"),
-       chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL"))) lang_tree_node {
+       chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_TYPE_COMMON) ? ((union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic)) : CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL"))) lang_tree_node {
   union tree_node GTY ((tag ("TS_CP_GENERIC"),
 			desc ("tree_node_structure (&%h)"))) generic;
   struct template_parm_index_s GTY ((tag ("TS_CP_TPI"))) tpi;
--- gcc/c-decl.c.jj	2011-06-17 11:02:19.000000000 +0200
+++ gcc/c-decl.c	2011-06-24 12:13:35.000000000 +0200
@@ -238,7 +238,7 @@ extern char C_SIZEOF_STRUCT_LANG_IDENTIF
 /* The resulting tree type.  */
 
 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
-       chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))  lang_tree_node
+       chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_TYPE_COMMON) ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))  lang_tree_node
  {
   union tree_node GTY ((tag ("0"),
 			desc ("tree_node_structure (&%h)")))

	Jakub

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

* Re: [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400)
  2011-06-24 14:58 [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400) Jakub Jelinek
@ 2011-06-24 19:49 ` Joseph S. Myers
  2011-06-24 23:13 ` Jason Merrill
  2011-06-24 23:15 ` Richard Henderson
  2 siblings, 0 replies; 6+ messages in thread
From: Joseph S. Myers @ 2011-06-24 19:49 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jason Merrill, gcc-patches

On Fri, 24 Jun 2011, Jakub Jelinek wrote:

> 	* c-decl.c (union lang_tree_node): Use TYPE_NEXT_VARIANT
> 	instead of TYPE_CHAIN for chain_next for types.

The C changes are OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400)
  2011-06-24 14:58 [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400) Jakub Jelinek
  2011-06-24 19:49 ` Joseph S. Myers
@ 2011-06-24 23:13 ` Jason Merrill
  2011-06-24 23:15 ` Richard Henderson
  2 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2011-06-24 23:13 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Joseph S. Myers, gcc-patches

OK.

Jason

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

* Re: [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400)
  2011-06-24 14:58 [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400) Jakub Jelinek
  2011-06-24 19:49 ` Joseph S. Myers
  2011-06-24 23:13 ` Jason Merrill
@ 2011-06-24 23:15 ` Richard Henderson
  2011-06-27 16:50   ` Jakub Jelinek
  2 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2011-06-24 23:15 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jason Merrill, Joseph S. Myers, gcc-patches

On 06/24/2011 07:43 AM, Jakub Jelinek wrote:
> +       chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_TYPE_COMMON) ? ((union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic)) : CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL"))) lang_tree_node {

Is it possible to break this out into an inline (or, i suppose, out of line)
function?  This is getting fairly unreadable...


r~

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

* Re: [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400)
  2011-06-24 23:15 ` Richard Henderson
@ 2011-06-27 16:50   ` Jakub Jelinek
  2011-06-27 16:59     ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2011-06-27 16:50 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Jason Merrill, Joseph S. Myers, gcc-patches

On Fri, Jun 24, 2011 at 03:21:07PM -0700, Richard Henderson wrote:
> On 06/24/2011 07:43 AM, Jakub Jelinek wrote:
> > +       chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_TYPE_COMMON) ? ((union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic)) : CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL"))) lang_tree_node {
> 
> Is it possible to break this out into an inline (or, i suppose, out of line)
> function?  This is getting fairly unreadable...

Like this?  Bootstrapped/regtested on x86_64-linux and i686-linux.

2011-06-27  Jakub Jelinek  <jakub@redhat.com>

	* c-common.h (c_tree_chain_next): New static inline function.

	* c-decl.c (union lang_tree_node): Use it in chain_next expression.

	* cp-tree.h (union lang_tree_node): Use it in chain_next expression.

--- gcc/c-family/c-common.h.jj	2011-05-31 08:02:51.000000000 +0200
+++ gcc/c-family/c-common.h	2011-06-27 15:58:21.000000000 +0200
@@ -1016,4 +1016,19 @@ extern bool c_omp_sharing_predetermined 
 extern tree c_omp_remap_decl (tree, bool);
 extern void record_types_used_by_current_var_decl (tree);
 
+/* Return next tree in the chain for chain_next walking of tree nodes.  */
+static inline tree
+c_tree_chain_next (tree t)
+{
+  /* TREE_CHAIN of a type is TYPE_STUB_DECL, which is different
+     kind of object, never a long chain of nodes.  Prefer
+     TYPE_NEXT_VARIANT for types.  */
+  if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_TYPE_COMMON))
+    return TYPE_NEXT_VARIANT (t);
+  /* Otherwise, if there is TREE_CHAIN, return it.  */
+  if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_COMMON))
+    return TREE_CHAIN (t);
+  return NULL;
+}
+
 #endif /* ! GCC_C_COMMON_H */
--- gcc/c-decl.c.jj	2011-06-26 09:55:31.000000000 +0200
+++ gcc/c-decl.c	2011-06-27 16:00:18.000000000 +0200
@@ -238,7 +238,7 @@ extern char C_SIZEOF_STRUCT_LANG_IDENTIF
 /* The resulting tree type.  */
 
 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
-       chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_TYPE_COMMON) ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))  lang_tree_node
+       chain_next ("(union lang_tree_node *) c_tree_chain_next (&%h.generic)"))) lang_tree_node
  {
   union tree_node GTY ((tag ("0"),
 			desc ("tree_node_structure (&%h)")))
--- gcc/cp/cp-tree.h.jj	2011-06-26 09:55:24.000000000 +0200
+++ gcc/cp/cp-tree.h	2011-06-27 16:01:09.000000000 +0200
@@ -729,7 +729,7 @@ enum cp_tree_node_structure_enum {
 
 /* The resulting tree type.  */
 union GTY((desc ("cp_tree_node_structure (&%h)"),
-       chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_TYPE_COMMON) ? ((union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic)) : CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL"))) lang_tree_node {
+       chain_next ("(union lang_tree_node *) c_tree_chain_next (&%h.generic)"))) lang_tree_node {
   union tree_node GTY ((tag ("TS_CP_GENERIC"),
 			desc ("tree_node_structure (&%h)"))) generic;
   struct template_parm_index_s GTY ((tag ("TS_CP_TPI"))) tpi;


	Jakub

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

* Re: [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400)
  2011-06-27 16:50   ` Jakub Jelinek
@ 2011-06-27 16:59     ` Richard Henderson
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2011-06-27 16:59 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jason Merrill, Joseph S. Myers, gcc-patches

On 06/27/2011 09:42 AM, Jakub Jelinek wrote:
> 2011-06-27  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* c-common.h (c_tree_chain_next): New static inline function.
> 
> 	* c-decl.c (union lang_tree_node): Use it in chain_next expression.
> 
> 	* cp-tree.h (union lang_tree_node): Use it in chain_next expression.

Ok.  Thanks.

r~

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

end of thread, other threads:[~2011-06-27 16:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-24 14:58 [PATCH] Use TYPE_NEXT_VARIANT instead of TREE_CHAIN as chain_next for types during GC (PR c++/46400) Jakub Jelinek
2011-06-24 19:49 ` Joseph S. Myers
2011-06-24 23:13 ` Jason Merrill
2011-06-24 23:15 ` Richard Henderson
2011-06-27 16:50   ` Jakub Jelinek
2011-06-27 16:59     ` Richard Henderson

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