This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] GGC friendly function save/restore
> > On Fri, Nov 28, 2003 at 11:18:16PM +0100, Jan Hubicka wrote:
> > > /* Nonzero if the rtl inliner has saved the function for inlining. */
> > > unsigned int saved_for_inline : 1;
> > > +
> > > + /* Saved tree and arguments during tree optimization. Used later for
> > > + inlining */
> > > + tree GTY(()) saved_tree;
> > > + tree GTY(()) saved_args;
> >
> > Not ok.
> >
> > (1) No need for GTY markings on individual fields.
> > (2) You didn't put these at the correct place. Read the comments.
> I see.
> >
> > > + if (cfun->saved_tree)
> > > + {
> > > + /* We might need the body of this function so that we can expand
> > > + it inline somewhere else. */
> > > + DECL_SAVED_TREE (fndecl) = cfun->saved_tree;
> > > + DECL_ARGUMENTS (fndecl) = cfun->saved_args;
> > > + }
> > > + cfun = 0;
> >
> > (3) What do you think this is doing?
> > cfun == DECL_SAVED_INSNS (current_function_decl), so this is still
> > reachable. You definitely beed to zap saved_tree/saved_args here.
> > Which also means that the zapping of saved_tree earlier should have
> > been useless.
>
> DECL_SAVED_INSNS is zapped at the end of rest_of_compilation. Perhaps I
> should move that bit to line just bellow cfun = 0 to make this more
> readable. Or am I missing your point?
OK, here is updated patch. I am still testing it, but I would like to
ask about your comment before burning another 10 hours of machine
time... (all my testing machines are somewhat overloaded by strickier
checking)
2003-11-28 Jan Hubicka <jh@suse.cz>
* function.h (struct function): Add saved_tree/saved_args.
* toplev.c (rest_of_compilation): Move code to clear cfun and
DECL_SAVED_INSNS and call to ggc_collect to ...
* tree-optimize.c (tree_rest_of_compilation): ... this function. Use
cfun to save/restore function body.
Index: function.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.h,v
retrieving revision 1.83.2.18
diff -c -3 -p -r1.83.2.18 function.h
*** function.h 15 Nov 2003 19:44:36 -0000 1.83.2.18
--- function.h 28 Nov 2003 23:13:09 -0000
*************** struct function GTY(())
*** 181,186 ****
--- 181,193 ----
struct emit_status *emit;
struct varasm_status *varasm;
+ /* For tree-optimize.c. */
+
+ /* Saved tree and arguments during tree optimization. Used later for
+ inlining */
+ tree saved_tree;
+ tree saved_args;
+
/* For function.c. */
/* Name of this function. */
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.654.2.80
diff -c -3 -p -r1.654.2.80 toplev.c
*** toplev.c 25 Nov 2003 02:09:53 -0000 1.654.2.80
--- toplev.c 28 Nov 2003 23:13:09 -0000
*************** rest_of_compilation (tree decl)
*** 3685,3698 ****
/* We're done with this function. Free up memory if we can. */
free_after_parsing (cfun);
- if (! DECL_DEFER_OUTPUT (decl))
- {
- free_after_compilation (cfun);
- DECL_SAVED_INSNS (decl) = 0;
- }
- cfun = 0;
-
- ggc_collect ();
timevar_pop (TV_REST_OF_COMPILATION);
}
--- 3685,3690 ----
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 1.1.4.79
diff -c -3 -p -r1.1.4.79 tree-optimize.c
*** tree-optimize.c 25 Nov 2003 14:18:43 -0000 1.1.4.79
--- tree-optimize.c 28 Nov 2003 23:13:10 -0000
*************** void
*** 266,272 ****
tree_rest_of_compilation (tree fndecl, bool nested_p)
{
location_t saved_loc;
! tree saved_tree = NULL, saved_args = NULL, chain;
timevar_push (TV_EXPAND);
--- 266,272 ----
tree_rest_of_compilation (tree fndecl, bool nested_p)
{
location_t saved_loc;
! tree chain;
timevar_push (TV_EXPAND);
*************** tree_rest_of_compilation (tree fndecl, b
*** 293,303 ****
it inline somewhere else. This means not lowering some constructs
such as exception handling. */
if (DECL_INLINE (fndecl) && flag_inline_trees)
! {
! saved_tree = save_body (fndecl, &saved_args);
! /* ??? We're saving this value here on the stack. Don't gc it. */
! nested_p = true;
! }
/* Mudflap-instrument any relevant declarations. */
if (flag_mudflap)
--- 293,299 ----
it inline somewhere else. This means not lowering some constructs
such as exception handling. */
if (DECL_INLINE (fndecl) && flag_inline_trees)
! cfun->saved_tree = save_body (fndecl, &cfun->saved_args);
/* Mudflap-instrument any relevant declarations. */
if (flag_mudflap)
*************** tree_rest_of_compilation (tree fndecl, b
*** 404,409 ****
--- 400,415 ----
if (nested_p)
ggc_pop_context ();
+ /* Restore original body if still needed. */
+ if (cfun->saved_tree)
+ {
+ DECL_SAVED_TREE (fndecl) = cfun->saved_tree;
+ DECL_ARGUMENTS (fndecl) = cfun->saved_args;
+ }
+ cfun = 0;
+ DECL_SAVED_INSNS (fndecl) = 0;
+ ggc_collect ();
+
/* If requested, warn about function definitions where the function will
return a value (usually of some struct or union type) which itself will
take up a lot of stack space. */
*************** tree_rest_of_compilation (tree fndecl, b
*** 430,442 ****
/* ??? Looks like some of this could be combined. */
- if (DECL_INLINE (fndecl) && flag_inline_trees)
- {
- /* We might need the body of this function so that we can expand
- it inline somewhere else. */
- DECL_SAVED_TREE (fndecl) = saved_tree;
- DECL_ARGUMENTS (fndecl) = saved_args;
- }
/* If possible, obliterate the body of the function so that it can
be garbage collected. */
--- 436,441 ----