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]

Re: [lto]: Patch to restructure file specific information.


> 
> Someone, and i assume this will be honza will have to write a layer that
> will decide which functions to have in core at any period of time, based
> on some notion of caching knowing the order of compilation.   But we are
> getting closer to being able to make all of the inlining and ipa
> decisions without any of the function bodies in memory. 
Hi,
this patch adds very basic API for it and should make enough call to get
local passes and inliner working.
Is there way to get specific body loaded in?  (I guess I will need to
wlak through the cgraph code and update code that attempts to test
presence of body: some code tests DECL_SAVED_TREE, other code asks for
CFG and rest goes for availability flag).

Honza

Index: cgraph.h
===================================================================
*** cgraph.h	(revision 132212)
--- cgraph.h	(working copy)
*************** struct cgraph_node GTY((chain_next ("%h.
*** 183,188 ****
--- 183,192 ----
    /* unique id for profiling. pid is not suitable because of different
       number of cfg nodes with -fprofile-generate and -fprofile-use */
    int pid;
+ 
+   /* How many times the node was marked used.  When set to -1 the body will
+      not be freed until cgraph_remove_node is called.  */
+   int nused;
  };
  
  struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
*************** struct cgraph_node *save_inline_function
*** 349,354 ****
--- 353,362 ----
  void record_references_in_initializer (tree);
  bool cgraph_process_new_functions (void);
  
+ void cgraph_function_body_needed (struct cgraph_node *);
+ void cgraph_function_body_not_needed (struct cgraph_node *);
+ void cgraph_function_body_modified (struct cgraph_node *);
+ 
  /* In cgraphbuild.c  */
  unsigned int rebuild_cgraph_edges (void);
  
Index: cgraphunit.c
===================================================================
*** cgraphunit.c	(revision 132212)
--- cgraphunit.c	(working copy)
*************** save_inline_function_body (struct cgraph
*** 1720,1723 ****
--- 1720,1772 ----
    return first_clone;
  }
  
+ /* Load function body if it is not in memory.
+    This is for use for passes, such as inliner, that needs different than current
+    function body in memory.  It is expected that the function body will be released
+    soon by corresponding function_body_not_needed call. 
+ 
+    Simple ref counting is available.
+    */
+ void
+ cgraph_function_body_needed (struct cgraph_node *n)
+ {
+   if (n->nused >= 0)
+     {
+ #if 0
+       if (!n->nused
+ 	  && !DECL_STRUCT_FUNCTION (node->decl)->cfg)
+ 	/* Ask LTO to load in function.  */;
+ #endif
+       n->nused++;
+     }
+ }
+ 
+ /* Body loaded via cgraph_function_body_needed can now be released again.
+    It will not be released immmediately, but on next GGC run.  */
+ void
+ cgraph_function_body_not_needed (struct cgraph_node *n)
+ {
+   if (n->nused >= 0)
+     {
+       n->nused--;
+ #if 0
+       if (!n->used)
+ 	/* enqueue body for destruction at next GGC call.  */;
+ #endif
+     }
+ }
+ 
+ /* Mark function body as modified so it stays in memory until it is removed
+    via cgraph_remove_node.  This is used by the rest of optimization queue
+    that always locks just one function body in memory.
+ 
+    To limited degree IPA passes might lock some limited portion of program
+    in memory, but it should be used only as a last resolt.  */
+ void
+ cgraph_function_body_modified (struct cgraph_node *n)
+ {
+   cgraph_function_body_needed (n);
+   n->nused = -1;
+ }
+ 
  #include "gt-cgraphunit.h"
Index: tree-inline.c
===================================================================
*** tree-inline.c	(revision 132212)
--- tree-inline.c	(working copy)
*************** expand_call_inline (basic_block bb, tree
*** 2609,2614 ****
--- 2609,2615 ----
        goto egress;
      }
    fn = cg_edge->callee->decl;
+   cgraph_function_body_needed (cg_edge->callee);
  
  #ifdef ENABLE_CHECKING
    if (cg_edge->callee->decl != id->dst_node->decl)
*************** expand_call_inline (basic_block bb, tree
*** 2788,2793 ****
--- 2789,2795 ----
       remove the cgraph node.  */
    (*debug_hooks->outlining_inline_function) (cg_edge->callee->decl);
  
+   cgraph_function_body_not_needed (cg_edge->callee);
    /* Update callgraph if needed.  */
    cgraph_remove_node (cg_edge->callee);
  
Index: passes.c
===================================================================
*** passes.c	(revision 132212)
--- passes.c	(working copy)
*************** execute_one_pass (struct tree_opt_pass *
*** 1074,1079 ****
--- 1074,1083 ----
    if (!quiet_flag && !cfun)
      fprintf (stderr, " <%s>", pass->name ? pass->name : "");
  
+   /* Local optimization passes always modify the function body now.  */
+   if (cfun)
+     cgraph_function_body_modified (cgraph_node (current_function_decl));
+ 
    if (pass->todo_flags_start & TODO_set_props)
      cfun->curr_properties = pass->properties_required;
  


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