Make ipa-reference/ipa-type-escape happy about new functions

Jan Hubicka jh@suse.cz
Thu Aug 21 16:36:00 GMT 2008


Hi,
this patch makes ipa-reference and ipa-pure-const happy about clones newly
introduced by ipcp.  The way I updated ipa-pure-const is bit crude; we should
use VECtor here.  I will do that as followup, first I really would like to see
ipcp working well.

Bootstrapped/regtested i686-linux with the IPCP changes, will commit it after
testing separately.

Honza

	* cgraph.c (first_cgraph_function_insertion_hook): New variable.
	(cgraph_add_function_insertion_hook, cgraph_remove_function_insertion_hook,
	cgraph_call_function_insertion_hooks): New functions.
	* cgraph.h (cgraph_add_function_insertion_hook, cgraph_remove_function_insertion_hook,
	cgraph_call_function_insertion_hooks): Declare.
	* ipa-reference.c (function_insertion_hook_holder): New variable.
	(check_operand, look_for_address_of): When checking late, do not care
	about module bitmaps.
	(add_new_function): New function.
	(generate_summary): Register hooks; zero module bitmaps.
	(propagate): Unregister hooks.
	* ipa-pure-const.c (function_insertion_hook_holder): New variable.
	(add_new_function): New function.
	(generate_summary): Register hook.
	(propagate): Remove hook.
Index: cgraph.c
===================================================================
*** cgraph.c	(revision 139384)
--- cgraph.c	(working copy)
*************** struct cgraph_node_hook_list *first_cgra
*** 173,178 ****
--- 173,180 ----
  struct cgraph_2edge_hook_list *first_cgraph_edge_duplicated_hook;
  /* List of hooks triggered when a node is duplicated.  */
  struct cgraph_2node_hook_list *first_cgraph_node_duplicated_hook;
+ /* List of hooks triggered when an function is inserted.  */
+ struct cgraph_node_hook_list *first_cgraph_function_insertion_hook;
  
  
  /* Register HOOK to be called with DATA on each removed edge.  */
*************** cgraph_call_node_removal_hooks (struct c
*** 255,260 ****
--- 257,302 ----
    }
  }
  
+ /* Register HOOK to be called with DATA on each removed node.  */
+ struct cgraph_node_hook_list *
+ cgraph_add_function_insertion_hook (cgraph_node_hook hook, void *data)
+ {
+   struct cgraph_node_hook_list *entry;
+   struct cgraph_node_hook_list **ptr = &first_cgraph_function_insertion_hook;
+ 
+   entry = (struct cgraph_node_hook_list *) xmalloc (sizeof (*entry));
+   entry->hook = hook;
+   entry->data = data;
+   entry->next = NULL;
+   while (*ptr)
+     ptr = &(*ptr)->next;
+   *ptr = entry;
+   return entry;
+ }
+ 
+ /* Remove ENTRY from the list of hooks called on removing nodes.  */
+ void
+ cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *entry)
+ {
+   struct cgraph_node_hook_list **ptr = &first_cgraph_function_insertion_hook;
+ 
+   while (*ptr != entry)
+     ptr = &(*ptr)->next;
+   *ptr = entry->next;
+ }
+ 
+ /* Call all node removal hooks.  */
+ void
+ cgraph_call_function_insertion_hooks (struct cgraph_node *node)
+ {
+   struct cgraph_node_hook_list *entry = first_cgraph_function_insertion_hook;
+   while (entry)
+   {
+     entry->hook (node, entry->data);
+     entry = entry->next;
+   }
+ }
+ 
  /* Register HOOK to be called with DATA on each duplicated edge.  */
  struct cgraph_2edge_hook_list *
  cgraph_add_edge_duplication_hook (cgraph_2edge_hook hook, void *data)
Index: cgraph.h
===================================================================
*** cgraph.h	(revision 139384)
--- cgraph.h	(working copy)
*************** void cgraph_remove_edge_removal_hook (st
*** 372,377 ****
--- 372,381 ----
  struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
  							    void *);
  void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
+ struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
+ 							          void *);
+ void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
+ void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
  struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
  void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
  struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
Index: ipa-reference.c
===================================================================
*** ipa-reference.c	(revision 139384)
--- ipa-reference.c	(working copy)
*************** static struct pointer_set_t *visited_nod
*** 95,100 ****
--- 95,103 ----
  
  static bitmap_obstack ipa_obstack;
  
+ /* Holders of ipa cgraph hooks: */
+ static struct cgraph_node_hook_list *function_insertion_hook_holder;
+ 
  enum initialization_status_t
  {
    UNINITIALIZED,
*************** check_operand (ipa_reference_local_vars_
*** 296,302 ****
  	    bitmap_set_bit (local->statics_written, DECL_UID (t));
  	  /* Mark the write so we can tell which statics are
  	     readonly.  */
! 	  bitmap_set_bit (module_statics_written, DECL_UID (t));
  	}
        else if (local)
  	bitmap_set_bit (local->statics_read, DECL_UID (t));
--- 299,306 ----
  	    bitmap_set_bit (local->statics_written, DECL_UID (t));
  	  /* Mark the write so we can tell which statics are
  	     readonly.  */
! 	  if (module_statics_written)
! 	    bitmap_set_bit (module_statics_written, DECL_UID (t));
  	}
        else if (local)
  	bitmap_set_bit (local->statics_read, DECL_UID (t));
*************** look_for_address_of (tree t)
*** 345,351 ****
      {
        tree x = get_base_var (t);
        if (TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == FUNCTION_DECL) 
! 	if (has_proper_scope_for_analysis (x))
  	  bitmap_set_bit (module_statics_escape, DECL_UID (x));
      }
  }
--- 349,355 ----
      {
        tree x = get_base_var (t);
        if (TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == FUNCTION_DECL) 
! 	if (has_proper_scope_for_analysis (x) && module_statics_escape)
  	  bitmap_set_bit (module_statics_escape, DECL_UID (x));
      }
  }
*************** clean_function (struct cgraph_node *fn)
*** 935,940 ****
--- 939,957 ----
    get_function_ann (fn->decl)->reference_vars_info = NULL;
  }
  
+ /* Called when new function is inserted to callgraph late.  */
+ static void
+ add_new_function (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
+ {
+   /* There are some shared nodes, in particular the initializers on
+      static declarations.  We do not need to scan them more than once
+      since all we would be interested in are the addressof
+      operations.  */
+   visited_nodes = pointer_set_create ();
+   analyze_function (node);
+   pointer_set_destroy (visited_nodes);
+   visited_nodes = NULL;
+ }
  
  /* Analyze each function in the cgraph to see which global or statics
     are read or written.  */
*************** generate_summary (void)
*** 949,954 ****
--- 966,973 ----
    bitmap module_statics_readonly;
    bitmap bm_temp;
    
+   function_insertion_hook_holder =
+       cgraph_add_function_insertion_hook (&add_new_function, NULL);
    ipa_init ();
    module_statics_readonly = BITMAP_ALLOC (&ipa_obstack);
    bm_temp = BITMAP_ALLOC (&ipa_obstack);
*************** generate_summary (void)
*** 1031,1036 ****
--- 1050,1057 ----
    
    BITMAP_FREE(module_statics_escape);
    BITMAP_FREE(module_statics_written);
+   module_statics_escape = NULL;
+   module_statics_written = NULL;
    
    if (dump_file)
      EXECUTE_IF_SET_IN_BITMAP (all_module_statics, 0, index, bi)
*************** propagate (void)
*** 1107,1112 ****
--- 1128,1134 ----
    int order_pos = ipa_utils_reduced_inorder (order, false, true);
    int i;
  
+   cgraph_remove_function_insertion_hook (function_insertion_hook_holder);
    if (dump_file) 
      dump_cgraph (dump_file);
  
Index: ipa-pure-const.c
===================================================================
*** ipa-pure-const.c	(revision 139384)
--- ipa-pure-const.c	(working copy)
*************** typedef struct funct_state_d * funct_sta
*** 96,101 ****
--- 96,103 ----
  
  static funct_state *funct_state_vec;
  
+ /* Holders of ipa cgraph hooks: */
+ static struct cgraph_node_hook_list *function_insertion_hook_holder;
  
  /* Init the function state.  */
  
*************** end:
*** 677,682 ****
--- 679,699 ----
      }
  }
  
+ /* Called when new function is inserted to callgraph late.  */
+ static void
+ add_new_function (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
+ {
+   funct_state_vec = XRESIZEVEC (funct_state, funct_state_vec, cgraph_max_uid);
+   /* There are some shared nodes, in particular the initializers on
+      static declarations.  We do not need to scan them more than once
+      since all we would be interested in are the addressof
+      operations.  */
+   visited_nodes = pointer_set_create ();
+   analyze_function (node);
+   pointer_set_destroy (visited_nodes);
+   visited_nodes = NULL;
+ }
+ 
  
  /* Analyze each function in the cgraph to see if it is locally PURE or
     CONST.  */
*************** generate_summary (void)
*** 686,691 ****
--- 703,710 ----
  {
    struct cgraph_node *node;
  
+   function_insertion_hook_holder =
+       cgraph_add_function_insertion_hook (&add_new_function, NULL);
    init_state ();
    /* There are some shared nodes, in particular the initializers on
       static declarations.  We do not need to scan them more than once
*************** propagate (void)
*** 725,730 ****
--- 744,750 ----
    int i;
    struct ipa_dfs_info * w_info;
  
+   cgraph_remove_function_insertion_hook (function_insertion_hook_holder);
    order_pos = ipa_utils_reduced_inorder (order, true, false);
    if (dump_file)
      {



More information about the Gcc-patches mailing list