Free ipcp transformation summaries for inline clones
diff mbox series

Message ID 20191110175605.lwka7mluob3rkkvc@kam.mff.cuni.cz
State New
Headers show
Series
  • Free ipcp transformation summaries for inline clones
Related show

Commit Message

Jan Hubicka Nov. 10, 2019, 5:56 p.m. UTC
Hi,
this patch implements freeing of transformation summaries for inline
clones. It also cleans up how they are duplicated (via its own duplicate
method rather then being budndled to duplication of indirect call infos)
and adds destructor so we release the memory of vectors.

I also noticed that agg replacements was not copied before, so I
implemnted it.

Bootstrapped/regtested x86_64-linux, comitted.

	* ipa-prop.c (ipa_propagate_indirect_call_infos): Remove ipcp
	summary.
	(ipcp_transformation_t::duplicate): Break out from ...
	(ipa_node_params_t::duplicate): ... here; add copying of agg
	replacements.
	* ipa-prop.h (ipcp_transformation): Add constructor and destructor.
	(ipcp_transformation_t): Add duplicate.

Patch
diff mbox series

Index: ipa-prop.c
===================================================================
--- ipa-prop.c	(revision 278020)
+++ ipa-prop.c	(working copy)
@@ -3746,6 +3746,8 @@  ipa_propagate_indirect_call_infos (struc
       if (ok)
         ipa_edge_args_sum->remove (cs);
     }
+  if (ipcp_transformation_sum)
+    ipcp_transformation_sum->remove (cs->callee);
 
   return changed;
 }
@@ -3986,27 +3988,28 @@  ipa_node_params_t::duplicate(cgraph_node
 	}
       ipa_set_node_agg_value_chain (dst, new_av);
     }
+}
 
-  ipcp_transformation *src_trans = ipcp_get_transformation_summary (src);
+/* Duplication of ipcp transformation summaries.  */
 
-  if (src_trans)
+void
+ipcp_transformation_t::duplicate(cgraph_node *, cgraph_node *dst,
+			         ipcp_transformation *src_trans,
+			         ipcp_transformation *dst_trans)
+{
+  /* Avoid redundant work of duplicating vectors we will never use.  */
+  if (dst->inlined_to)
+    return;
+  dst_trans->bits = vec_safe_copy (src_trans->bits);
+  dst_trans->m_vr = vec_safe_copy (src_trans->m_vr);
+  ipa_agg_replacement_value *agg = src_trans->agg_values,
+			    **aggptr = &dst_trans->agg_values;
+  while (agg)
     {
-      ipcp_transformation_initialize ();
-      src_trans = ipcp_transformation_sum->get_create (src);
-      ipcp_transformation *dst_trans
-	= ipcp_transformation_sum->get_create (dst);
-
-      dst_trans->bits = vec_safe_copy (src_trans->bits);
-
-      const vec<ipa_vr, va_gc> *src_vr = src_trans->m_vr;
-      vec<ipa_vr, va_gc> *&dst_vr
-	= ipcp_get_transformation_summary (dst)->m_vr;
-      if (vec_safe_length (src_trans->m_vr) > 0)
-	{
-	  vec_safe_reserve_exact (dst_vr, src_vr->length ());
-	  for (unsigned i = 0; i < src_vr->length (); ++i)
-	    dst_vr->quick_push ((*src_vr)[i]);
-	}
+      *aggptr = ggc_alloc<ipa_agg_replacement_value> ();
+      **aggptr = *agg;
+      agg = agg->next;
+      aggptr = &(*aggptr)->next;
     }
 }
 
Index: ipa-prop.h
===================================================================
--- ipa-prop.h	(revision 278020)
+++ ipa-prop.h	(working copy)
@@ -639,6 +639,25 @@  struct GTY(()) ipcp_transformation
   vec<ipa_bits *, va_gc> *bits;
   /* Value range information.  */
   vec<ipa_vr, va_gc> *m_vr;
+
+  /* Default constructor.  */
+  ipcp_transformation ()
+  : agg_values (NULL), bits (NULL), m_vr (NULL)
+  { }
+
+  /* Default destructor.  */
+  ~ipcp_transformation ()
+  {
+    ipa_agg_replacement_value *agg = agg_values;
+    while (agg)
+      {
+	ipa_agg_replacement_value *next = agg->next;
+	ggc_free (agg);
+	agg = next;
+      }
+    vec_free (bits);
+    vec_free (m_vr);
+  }
 };
 
 void ipa_set_node_agg_value_chain (struct cgraph_node *node,
@@ -759,6 +778,11 @@  public:
       ipcp_transformation_t (symtab, true);
     return summary;
   }
+  /* Hook that is called by summary when a node is duplicated.  */
+  virtual void duplicate (cgraph_node *node,
+			  cgraph_node *node2,
+			  ipcp_transformation *data,
+			  ipcp_transformation *data2);
 };
 
 /* Function summary where the IPA CP transformations are actually stored.  */