This is the mail archive of the gcc-patches@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]

More memory reductions on PR c++/12850


Hi,
this patch reduce memory usage from 190MB to 105MB on the testcase in C++/12850
by more curefully releasing function bodies and structs functions.

Still I am somewhat puzzled - the memory consumption after parsing whole
file and releasing unnecesary things is about 60MB and then while
expanding the functions the memory is not going down as one would expect
after releasing the function bodies, instead it is rising slightly

Any ideas why?

Bootstrapped/regtested i686-pc-gnu-linux.  OK for mainline/branch?
2004-01-28  Jan Hubicka  <jh@suse.cz>
	PR c++/12850
	* cgraph.c (cgraph_remove_node): Clear out saved/insns/arguments and
	initial pointers.
	* cgraphunit.c (cgraph_finalize_function): Clear out DECL_SAVED_INSNS
	for functions that will be only inlined.
	(cgraph_mark_function_to_output): Likewise.
	(cgraph_expand_function): Sanity check that DECL_DEFER_OUTPUT is clear;
	do not clear function body.
	* tree-optimize.c (clear_decl_rtl): Use decl_function_context.
	(tree_rest_of_compilation): Reorganize the logic releasing function
	body to use callgraph datastructure.
Index: cgraph.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraph.c,v
retrieving revision 1.42
diff -c -3 -p -r1.42 cgraph.c
*** cgraph.c	19 Jan 2004 09:43:53 -0000	1.42
--- cgraph.c	28 Jan 2004 00:26:35 -0000
*************** cgraph_remove_node (struct cgraph_node *
*** 235,240 ****
--- 235,243 ----
    if (node->next)
      node->next->previous = node->previous;
    DECL_SAVED_TREE (node->decl) = NULL;
+   DECL_SAVED_INSNS (node->decl) = NULL;
+   DECL_ARGUMENTS (node->decl) = NULL;
+   DECL_INITIAL (node->decl) = error_mark_node;
    slot = 
      htab_find_slot_with_hash (cgraph_hash, DECL_ASSEMBLER_NAME (node->decl),
  			      IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME
Index: cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.48
diff -c -3 -p -r1.48 cgraphunit.c
*** cgraphunit.c	25 Jan 2004 03:52:41 -0000	1.48
--- cgraphunit.c	28 Jan 2004 00:26:35 -0000
*************** cgraph_finalize_function (tree decl, boo
*** 228,233 ****
--- 228,238 ----
    /* If we've not yet emitted decl, tell the debug info about it.  */
    if (!TREE_ASM_WRITTEN (decl))
      (*debug_hooks->deferred_inline_function) (decl);
+ 
+   /* We will never really output the function body, clear the SAVED_INSNS array
+      early then.  */
+   if (DECL_EXTERNAL (decl))
+     DECL_SAVED_INSNS (decl) = NULL;
  }
  
  /* Walk tree and record all calls.  Called via walk_tree.  */
*************** cgraph_mark_functions_to_output (void)
*** 476,481 ****
--- 481,488 ----
  	  && !TREE_ASM_WRITTEN (decl) && !node->origin
  	  && !DECL_EXTERNAL (decl))
  	node->output = 1;
+       else
+         DECL_SAVED_INSNS (decl) = NULL;
      }
  }
  
*************** cgraph_expand_function (struct cgraph_no
*** 525,533 ****
    /* Generate RTL for the body of DECL.  Nested functions are expanded
       via lang_expand_decl_stmt.  */
    (*lang_hooks.callgraph.expand_function) (decl);
  
-   if (!cgraph_function_possibly_inlined_p (decl))
-     DECL_SAVED_TREE (decl) = NULL;
    current_function_decl = NULL;
  }
  
--- 532,540 ----
    /* Generate RTL for the body of DECL.  Nested functions are expanded
       via lang_expand_decl_stmt.  */
    (*lang_hooks.callgraph.expand_function) (decl);
+   if (DECL_DEFER_OUTPUT (decl))
+     abort ();
  
    current_function_decl = NULL;
  }
  
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.8
diff -c -3 -p -r2.8 tree-optimize.c
*** tree-optimize.c	9 Nov 2003 03:06:21 -0000	2.8
--- tree-optimize.c	28 Jan 2004 21:09:59 -0000
*************** clear_decl_rtl (tree *tp, int *walk_subt
*** 65,77 ****
      {
      case VAR_DECL:
        nonstatic_p = !TREE_STATIC (t) && !DECL_EXTERNAL (t);
!       local_p = DECL_CONTEXT (t) == data;
        break;
  
      case PARM_DECL:
      case LABEL_DECL:
        nonstatic_p = true;
!       local_p = DECL_CONTEXT (t) == data;
        break;
  
      case RESULT_DECL:
--- 66,78 ----
      {
      case VAR_DECL:
        nonstatic_p = !TREE_STATIC (t) && !DECL_EXTERNAL (t);
!       local_p = decl_function_context (t) == data;
        break;
  
      case PARM_DECL:
      case LABEL_DECL:
        nonstatic_p = true;
!       local_p = decl_function_context (t) == data;
        break;
  
      case RESULT_DECL:
*************** tree_rest_of_compilation (tree fndecl, b
*** 205,222 ****
    walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl),
  				clear_decl_rtl,
  				fndecl);
! 
!   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
! 	 was an actual function definition.
! 	 For a nested function, this is done in c_pop_function_context.
! 	 If rest_of_compilation set this to 0, leave it 0.  */
!       if (DECL_INITIAL (fndecl) != 0)
! 	DECL_INITIAL (fndecl) = error_mark_node;
  
!       DECL_ARGUMENTS (fndecl) = 0;
      }
  
    input_location = saved_loc;
--- 206,227 ----
    walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl),
  				clear_decl_rtl,
  				fndecl);
!   if (!cgraph_function_possibly_inlined_p (fndecl))
      {
!       DECL_SAVED_TREE (fndecl) = NULL;
!       if (DECL_SAVED_INSNS (fndecl) == 0
! 	  && !cgraph_node (fndecl)->origin)
! 	{
! 	  /* Stop pointing to the local nodes about to be freed.
! 	     But DECL_INITIAL must remain nonzero so we know this
! 	     was an actual function definition.
! 	     For a nested function, this is done in c_pop_function_context.
! 	     If rest_of_compilation set this to 0, leave it 0.  */
! 	  if (DECL_INITIAL (fndecl) != 0)
! 	    DECL_INITIAL (fndecl) = error_mark_node;
  
! 	  DECL_ARGUMENTS (fndecl) = 0;
! 	}
      }
  
    input_location = saved_loc;


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