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]

[LTO] fix ipa-cp


Hi,
this patch makes duplication hooks to work right, so we don't get data
out of sync while updating cgraph and revert earlier Raphael's change to
attach IPA data to DECLs rather than nodes (that breaks with virtual
clones).

Bootstrapped/regtested x86_64-linux, OK?

I get following failures, but I think they are not related to the
change.
FAIL: 18_support/nested_exception/rethrow_if_nested.cc execution test
FAIL: 20_util/make_signed/requirements/typedefs-2.cc (test for excess errors)
FAIL: 20_util/make_unsigned/requirements/typedefs-2.cc (test for excess errors)
FAIL: 21_strings/basic_string/numeric_conversions/char/stod.cc execution test
FAIL: 21_strings/basic_string/numeric_conversions/char/stof.cc execution test
FAIL: 21_strings/basic_string/numeric_conversions/char/stold.cc execution test
FAIL: 21_strings/basic_string/numeric_conversions/wchar_t/stod.cc execution test
FAIL: 21_strings/basic_string/numeric_conversions/wchar_t/stof.cc execution test
FAIL: 21_strings/basic_string/numeric_conversions/wchar_t/stold.cc execution test
FAIL: 22_locale/locale/cons/12352.cc execution test
FAIL: 22_locale/time_get/get_date/wchar_t/4.cc execution test
FAIL: 23_containers/deque/capacity/29134-2.cc execution test
FAIL: 23_containers/vector/bool/modifiers/insert/31370.cc execution test
FAIL: 23_containers/vector/cons/4.cc execution test
FAIL: 23_containers/vector/ext_pointer/modifiers/insert.cc execution test
FAIL: 27_io/basic_filebuf/overflow/char/13858.cc execution test
FAIL: 27_io/basic_filebuf/overflow/wchar_t/13858.cc execution test
FAIL: 27_io/basic_filebuf/underflow/wchar_t/9178.cc execution test
FAIL: 27_io/basic_istream/exceptions/char/9561.cc execution test
FAIL: ext/enc_filebuf/char/13189.cc execution test
FAIL: ext/enc_filebuf/wchar_t/13189.cc execution test
FAIL: ext/pb_ds/regression/hash_data_map_rand.cc execution test
FAIL: ext/pb_ds/regression/hash_no_data_map_rand.cc execution test
FAIL: ext/pb_ds/regression/priority_queue_rand.cc execution test
FAIL: ext/pb_ds/regression/tree_data_map_rand.cc execution test
FAIL: ext/pb_ds/regression/tree_no_data_map_rand.cc execution test
FAIL: ext/pb_ds/regression/trie_data_map_rand.cc execution test
FAIL: ext/pb_ds/regression/trie_no_data_map_rand.cc execution test
FAIL: tr1/5_numerical_facilities/random/ranlux3_01.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/ranlux4_01.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/subtract_with_carry_01/cons/default.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/subtract_with_carry_01/cons/gen1.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/subtract_with_carry_01/cons/seed1.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/subtract_with_carry_01/cons/seed2.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/subtract_with_carry_01/operators/equal.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/subtract_with_carry_01/operators/not_equal.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/subtract_with_carry_01/operators/serialize.cc (test for excess errors)
FAIL: tr1/5_numerical_facilities/random/subtract_with_carry_01/requirements/typedefs.cc (test for excess errors)
	* ipa-reference.c (add_new_function, remove_node_data,
	duplicate_node_data): Declare.
	(ipa_init): Initialize hooks here.
	(generate_summary): Do not initialize them here.
	* ipa-pure-const.c (get_function_state): Revert earlier Raphael's change.
	(node_duplication_hook_holder, node_removal_hook_holder,
	set_function_state): Likewise.
	(duplicate_node_data, remove_node_data): New.
	(finish_state): Remove.
	(register_hooks): New function.
	(generate_summary): Use it here instead of registering.
	(read_summary): Likewise.
	(propagate): Revert Raphael's change.
	* passes.c (init_optimization_passes): Re-enable.

	* gcc.dg/ipa/ipa.exp: Re-enable
Index: ipa-reference.c
===================================================================
*** ipa-reference.c	(revision 148311)
--- ipa-reference.c	(working copy)
*************** along with GCC; see the file COPYING3.  
*** 70,75 ****
--- 70,82 ----
  #include "langhooks.h"
  #include "lto-section-in.h"
  #include "lto-section-out.h"
+ static void add_new_function (struct cgraph_node *node,
+ 			      void *data ATTRIBUTE_UNUSED);
+ static void remove_node_data (struct cgraph_node *node,
+ 			      void *data ATTRIBUTE_UNUSED);
+ static void duplicate_node_data (struct cgraph_node *src,
+ 				 struct cgraph_node *dst,
+ 				 void *data ATTRIBUTE_UNUSED);
  
  /* The static variables defined within the compilation unit that are
     loaded or stored directly by function that owns this structure.  */ 
*************** ipa_init (void) 
*** 593,598 ****
--- 600,612 ----
       since all we would be interested in are the addressof
       operations.  */
    visited_nodes = pointer_set_create ();
+ 
+   function_insertion_hook_holder =
+       cgraph_add_function_insertion_hook (&add_new_function, NULL);
+   node_removal_hook_holder =
+       cgraph_add_node_removal_hook (&remove_node_data, NULL);
+   node_duplication_hook_holder =
+       cgraph_add_node_duplication_hook (&duplicate_node_data, NULL);
  }
  
  /* Check out the rhs of a static or global initialization VNODE to see
*************** generate_summary (void)
*** 846,857 ****
    bitmap module_statics_readonly;
    bitmap bm_temp;
    
-   function_insertion_hook_holder =
-       cgraph_add_function_insertion_hook (&add_new_function, NULL);
-   node_removal_hook_holder =
-       cgraph_add_node_removal_hook (&remove_node_data, NULL);
-   node_duplication_hook_holder =
-       cgraph_add_node_duplication_hook (&duplicate_node_data, NULL);
    ipa_init ();
    module_statics_readonly = BITMAP_ALLOC (&local_info_obstack);
    bm_temp = BITMAP_ALLOC (&local_info_obstack);
--- 860,865 ----
Index: testsuite/gcc.dg/ipa/ipa.exp
===================================================================
*** testsuite/gcc.dg/ipa/ipa.exp	(revision 148311)
--- testsuite/gcc.dg/ipa/ipa.exp	(working copy)
***************
*** 16,24 ****
  
  # GCC testsuite that uses the `dg.exp' driver.
  
- # FIXME lto.  Disable for now until clones are handled properly.
- return
- 
  # Load support procs.
  load_lib gcc-dg.exp
  
--- 16,21 ----
Index: ipa-pure-const.c
===================================================================
*** ipa-pure-const.c	(revision 148311)
--- ipa-pure-const.c	(working copy)
*************** static VEC (funct_state, heap) *funct_st
*** 101,121 ****
  
  /* Holders of ipa cgraph hooks: */
  static struct cgraph_node_hook_list *function_insertion_hook_holder;
  
! /* Return the function state from NODE.  */
  
  static inline funct_state
  get_function_state (struct cgraph_node *node)
  {
-   tree decl = node->decl;
-   unsigned int uid;
-   gcc_assert (decl);
-   uid = DECL_UID (decl);
- 
    if (!funct_state_vec
!       || VEC_length (funct_state, funct_state_vec) <= uid)
      return NULL;
!   return VEC_index (funct_state, funct_state_vec, uid);
  }
  
  /* Set the function state S for NODE.  */
--- 101,127 ----
  
  /* Holders of ipa cgraph hooks: */
  static struct cgraph_node_hook_list *function_insertion_hook_holder;
+ static struct cgraph_2node_hook_list *node_duplication_hook_holder;
+ static struct cgraph_node_hook_list *node_removal_hook_holder;
  
! /* Init the function state.  */
! 
! static void
! finish_state (void)
! {
!   free (funct_state_vec);
! }
! 
! 
! /* Return the function state from NODE.  */ 
  
  static inline funct_state
  get_function_state (struct cgraph_node *node)
  {
    if (!funct_state_vec
!       || VEC_length (funct_state, funct_state_vec) <= (unsigned int)node->uid)
      return NULL;
!   return VEC_index (funct_state, funct_state_vec, node->uid);
  }
  
  /* Set the function state S for NODE.  */
*************** get_function_state (struct cgraph_node *
*** 123,140 ****
  static inline void
  set_function_state (struct cgraph_node *node, funct_state s)
  {
-   tree decl = node->decl;
-   unsigned int uid;
-   gcc_assert (decl);
-   uid = DECL_UID (decl);
- 
    if (!funct_state_vec
!       || VEC_length (funct_state, funct_state_vec) <= uid)
!      VEC_safe_grow_cleared (funct_state, heap, funct_state_vec, uid + 1);
!   VEC_replace (funct_state, funct_state_vec, uid, s);
  }
  
- 
  /* Check to see if the use (or definition when CHECKING_WRITE is true)
     variable T is legal in a function that is either pure or const.  */
  
--- 129,140 ----
  static inline void
  set_function_state (struct cgraph_node *node, funct_state s)
  {
    if (!funct_state_vec
!       || VEC_length (funct_state, funct_state_vec) <= (unsigned int)node->uid)
!      VEC_safe_grow_cleared (funct_state, heap, funct_state_vec, node->uid + 1);
!   VEC_replace (funct_state, funct_state_vec, node->uid, s);
  }
  
  /* Check to see if the use (or definition when CHECKING_WRITE is true)
     variable T is legal in a function that is either pure or const.  */
  
*************** add_new_function (struct cgraph_node *no
*** 578,584 ****
--- 578,621 ----
    visited_nodes = NULL;
  }
  
+ /* Called when new clone is inserted to callgraph late.  */
+ 
+ static void
+ duplicate_node_data (struct cgraph_node *src, struct cgraph_node *dst,
+ 	 	     void *data ATTRIBUTE_UNUSED)
+ {
+   if (get_function_state (src))
+     {
+       funct_state l = XNEW (struct funct_state_d);
+       gcc_assert (!get_function_state (dst));
+       memcpy (l, get_function_state (src), sizeof (*l));
+       set_function_state (dst, l);
+     }
+ }
+ 
+ /* Called when new clone is inserted to callgraph late.  */
+ 
+ static void
+ remove_node_data (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
+ {
+   if (get_function_state (node))
+     {
+       free (get_function_state (node));
+       set_function_state (node, NULL);
+     }
+ }
+ 
  
+ static void
+ register_hooks (void)
+ {
+   node_removal_hook_holder =
+       cgraph_add_node_removal_hook (&remove_node_data, NULL);
+   node_duplication_hook_holder =
+       cgraph_add_node_duplication_hook (&duplicate_node_data, NULL);
+   function_insertion_hook_holder =
+       cgraph_add_function_insertion_hook (&add_new_function, NULL);
+ }
  /* Analyze each function in the cgraph to see if it is locally PURE or
     CONST.  */
  
*************** generate_summary (void)
*** 587,594 ****
  {
    struct cgraph_node *node;
  
!   function_insertion_hook_holder =
!       cgraph_add_function_insertion_hook (&add_new_function, NULL);
    /* 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
--- 624,630 ----
  {
    struct cgraph_node *node;
  
!   register_hooks ();
    /* 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
*************** read_summary (void)
*** 667,672 ****
--- 703,709 ----
    struct lto_file_decl_data * file_data;
    unsigned int j = 0;
  
+   register_hooks ();
    while ((file_data = file_data_vec[j++]))
      {
        const char *data;
*************** propagate (void)
*** 730,738 ****
    int order_pos;
    int i;
    struct ipa_dfs_info * w_info;
-   funct_state state;
  
    cgraph_remove_function_insertion_hook (function_insertion_hook_holder);
    order_pos = ipa_utils_reduced_inorder (order, true, false, NULL);
    if (dump_file)
      {
--- 767,776 ----
    int order_pos;
    int i;
    struct ipa_dfs_info * w_info;
  
    cgraph_remove_function_insertion_hook (function_insertion_hook_holder);
+   cgraph_remove_node_duplication_hook (node_duplication_hook_holder);
+   cgraph_remove_node_removal_hook (node_removal_hook_holder);
    order_pos = ipa_utils_reduced_inorder (order, true, false, NULL);
    if (dump_file)
      {
*************** propagate (void)
*** 757,763 ****
  	{
  	  struct cgraph_edge *e;
  	  funct_state w_l = get_function_state (w);
- 	  gcc_assert (w_l);
  	  if (pure_const_state < w_l->pure_const_state)
  	    pure_const_state = w_l->pure_const_state;
  
--- 795,800 ----
*************** propagate (void)
*** 929,941 ****
  	  free (node->aux);
  	  node->aux = NULL;
  	}
      }
! 
!   for (i = 0; VEC_iterate (funct_state, funct_state_vec, i, state); i++)
!     free (state);
! 
    free (order);
    VEC_free (funct_state, heap, funct_state_vec);
    return 0;
  }
  
--- 966,978 ----
  	  free (node->aux);
  	  node->aux = NULL;
  	}
+       if (cgraph_function_body_availability (node) > AVAIL_OVERWRITABLE)
+ 	free (get_function_state (node));
      }
!   
    free (order);
    VEC_free (funct_state, heap, funct_state_vec);
+   finish_state ();
    return 0;
  }
  
Index: passes.c
===================================================================
*** passes.c	(revision 148311)
--- passes.c	(working copy)
*************** init_optimization_passes (void)
*** 589,595 ****
    p = &all_regular_ipa_passes;
    /* FIXME lto: ipa-reference was modified to ignore node duplication
       hook.  This means that we ICE first time real clone is created.  */
!   /*NEXT_PASS (pass_ipa_cp);*/
    NEXT_PASS (pass_ipa_inline);
    NEXT_PASS (pass_ipa_reference);
    NEXT_PASS (pass_ipa_pure_const); 
--- 589,595 ----
    p = &all_regular_ipa_passes;
    /* FIXME lto: ipa-reference was modified to ignore node duplication
       hook.  This means that we ICE first time real clone is created.  */
!   NEXT_PASS (pass_ipa_cp);
    NEXT_PASS (pass_ipa_inline);
    NEXT_PASS (pass_ipa_reference);
    NEXT_PASS (pass_ipa_pure_const); 


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