This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch to decl2.c


On Fri, Sep 05, 2003 at 09:34:13AM -0700, Mark Mitchell wrote:
> 	* decl2.c (mark_used): Use ggc_push_context/ggc_pop_context.
> 	* tree.c (cp_cannot_inline_tree_fn): Likewise.
> 
> I objected to the idea of this patch, and Richard's patch to optimize.c
> was supposed to handle this problem, if I understand correctly.

No, Geoff's fixes a different problem from mine.  

It also, unfortunately, is causing the opt/inline4 failure
you sent mail about last night.  The problem here is that
we only support HOST_BITS_PER_LONG nesting levels (to make
various parts of gc faster).  Whereas the test case requires
at least 250 levels of template instantiation.

I've been trying for the last two days to un-nest these
function compilations, so that instantiate_decl just queues
the new function and we compile it on the next round of
toplevel queue processing.  I havn't gotten that to work yet.
Seemingly unrelated changes cause the parser to go haywire,
and tracking the problems down one by one is tedious.

In the meantime, I think the following may work.  I'm just 
now starting a gcac bootstrap, so I don't expect results 
until after I've quit for the day.


r~



Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.442
diff -u -p -r1.442 c-decl.c
--- c-decl.c	4 Sep 2003 03:17:45 -0000	1.442
+++ c-decl.c	5 Sep 2003 17:59:56 -0000
@@ -6176,7 +6176,7 @@ c_expand_body_1 (tree fndecl, int nested
       expand_pending_sizes (DECL_LANG_SPECIFIC (fndecl)->pending_sizes);
     }
 
-  tree_rest_of_compilation (fndecl);
+  tree_rest_of_compilation (fndecl, nested_p);
 
   /* With just -Wextra, complain only if function returns both with
      and without a value.  */
Index: toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.113
diff -u -p -r1.113 toplev.h
--- toplev.h	29 Aug 2003 23:21:11 -0000	1.113
+++ toplev.h	5 Sep 2003 17:59:57 -0000
@@ -66,7 +66,7 @@ extern void inform (const char *, ...) A
 extern void rest_of_decl_compilation (tree, const char *, int, int);
 extern void rest_of_type_compilation (tree, int);
 extern void rest_of_compilation (tree);
-extern void tree_rest_of_compilation (tree);
+extern void tree_rest_of_compilation (tree, bool);
 
 extern void announce_function (tree);
 
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.1
diff -u -p -r2.1 tree-optimize.c
--- tree-optimize.c	29 Aug 2003 23:21:11 -0000	2.1
+++ tree-optimize.c	5 Sep 2003 17:59:57 -0000
@@ -93,18 +93,14 @@ clear_decl_rtl (tree *tp, int *walk_subt
    compilation for FNDECL.  */
 
 void
-tree_rest_of_compilation (tree fndecl)
+tree_rest_of_compilation (tree fndecl, bool nested_p)
 {
-  static int nesting = -1;
-
   timevar_push (TV_EXPAND);
 
-  ++nesting;
-
   if (flag_unit_at_a_time && !cgraph_global_info_ready)
     abort ();
 
-  if (nesting > 0)
+  if (nested_p)
     /* Squirrel away our current state.  */
     push_function_context ();
 
@@ -162,7 +158,7 @@ tree_rest_of_compilation (tree fndecl)
 
   /* If this is a nested function, protect the local variables in the stack
      above us from being collected while we're compiling this function.  */
-  if (nesting > 0)
+  if (nested_p)
     ggc_push_context ();
 
   /* There's no need to defer outputting this function any more; we
@@ -173,7 +169,7 @@ tree_rest_of_compilation (tree fndecl)
   rest_of_compilation (fndecl);
 
   /* Undo the GC context switch.  */
-  if (nesting > 0)
+  if (nested_p)
     ggc_pop_context ();
 
   /* If requested, warn about function definitions where the function will
@@ -227,7 +223,7 @@ tree_rest_of_compilation (tree fndecl)
 				clear_decl_rtl,
 				fndecl);
 
-  if (DECL_SAVED_INSNS (fndecl) == 0 && ! nesting && ! flag_inline_trees)
+  if (DECL_SAVED_INSNS (fndecl) == 0 && !nested_p && !flag_inline_trees)
     {
       /* Stop pointing to the local nodes about to be freed.
 	 But DECL_INITIAL must remain nonzero so we know this
@@ -240,11 +236,9 @@ tree_rest_of_compilation (tree fndecl)
       DECL_ARGUMENTS (fndecl) = 0;
     }
 
-  if (nesting > 0)
+  if (nested_p)
     /* Return to the enclosing function.  */
     pop_function_context ();
-
-  --nesting;
 
   timevar_pop (TV_EXPAND);
 }
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.667
diff -u -p -r1.667 decl2.c
--- cp/decl2.c	5 Sep 2003 08:24:19 -0000	1.667
+++ cp/decl2.c	5 Sep 2003 18:00:00 -0000
@@ -4226,10 +4226,7 @@ mark_used (tree decl)
 		  information.  */
 	       || cp_function_chain->can_throw);
 
-      /* Our caller is likely to have lots of data on the stack.  */
-      ggc_push_context ();
       instantiate_decl (decl, defer);
-      ggc_pop_context ();
     }
 }
 
Index: cp/optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/optimize.c,v
retrieving revision 1.96
diff -u -p -r1.96 optimize.c
--- cp/optimize.c	3 Sep 2003 21:38:26 -0000	1.96
+++ cp/optimize.c	5 Sep 2003 18:00:00 -0000
@@ -56,31 +56,7 @@ optimize_function (tree fn)
          and (d) TARGET_ASM_OUTPUT_MI_THUNK is there to DTRT anyway.  */
       && !DECL_THUNK_P (fn))
     {
-      /* ??? Work around GC problem.  Call stack is
-
-	 -> instantiate_decl
-	 -> expand_or_defer_fn
-	 -> maybe_clone_body
-	 -> expand_body
-	 -> tree_rest_of_compilation
-
-	 which of course collects.  This used to be protected by the
-	 "regular" nested call ggc_push_context that now lives in 
-	 tree_rest_of_compilation.
-
-	 Two good fixes:
-	 (1) Do inlining in tree_rest_of_compilation.  This is good
-	     in that this common optimization happens in common code.
-	 (2) Don't nest compilation of functions.  Instead queue the
-	     new function to cgraph, and let it get picked up in the
-	     next round of "emit everything that needs emitting".
-
-	 For the nonce, just protect things here.  */
-
-      ggc_push_context ();
       optimize_inline_calls (fn);
-      ggc_pop_context ();
-
       dump_function (TDI_inlined, fn);
     }
   
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.774
diff -u -p -r1.774 pt.c
--- cp/pt.c	5 Sep 2003 08:38:42 -0000	1.774
+++ cp/pt.c	5 Sep 2003 18:00:16 -0000
@@ -5100,6 +5100,12 @@ instantiate_class_template (tree type)
      it now.  */
   push_deferring_access_checks (dk_no_deferred);
 
+  /* Our caller does not expect us to gc collect.  If we do nothing,
+     this may happen in the path in which we compile this new 
+     function.  Make sure tree_rest_of_compilation creates a new
+     gc context.  */
+  function_depth++;
+
   maybe_push_to_top_level (uses_template_parms (type));
 
   if (t)
@@ -5427,6 +5433,7 @@ instantiate_class_template (tree type)
   pop_from_top_level ();
   pop_deferring_access_checks ();
   pop_tinst_level ();
+  function_depth--;
 
   if (TYPE_CONTAINS_VPTR_P (type))
     keyed_classes = tree_cons (NULL_TREE, type, keyed_classes);
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.356
diff -u -p -r1.356 semantics.c
--- cp/semantics.c	5 Sep 2003 08:38:42 -0000	1.356
+++ cp/semantics.c	5 Sep 2003 18:00:19 -0000
@@ -2868,7 +2868,7 @@ expand_body (tree fn)
   optimize_function (fn);
   timevar_pop (TV_INTEGRATION);
 
-  tree_rest_of_compilation (fn);
+  tree_rest_of_compilation (fn, function_depth > 1);
 
   current_function_decl = saved_function;
   input_location = saved_loc;
Index: cp/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.345
diff -u -p -r1.345 tree.c
--- cp/tree.c	5 Sep 2003 08:24:21 -0000	1.345
+++ cp/tree.c	5 Sep 2003 18:00:21 -0000
@@ -2026,14 +2026,7 @@ cp_cannot_inline_tree_fn (tree* fnp)
 			(template_for_substitution (fn))))
 	return 1;
 
-      /* Our caller does not expect us to call ggc_collect, but
-	 instantiate_decl can call rest_of_compilation so we must
-	 protect our caller.  */
-      ggc_push_context();
-      
       fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0);
-
-      ggc_pop_context();
 
       if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
 	return 1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]