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]

[trans-mem] fix clone edge frequencies


Hi guys!

During the TM IPA pass, we create clones with
cgraph_copy_node_for_versioning().  However, this calls
cgraph_clone_edge() on all callee edges and actually changes the edge
frequencies incorrectly.  This causes verify_cgraph_node() to fail:

b.c:10:1: error: caller edge frequency 151 does not match BB freqency 389
TMreleaseNode/3(-1) @0x7ffff7a9a888 availability:not_available reachable
  called by: TMrbtree_insert/2 (0.15 per call) 
  calls: 

I actually don't understand the frequency business at all, especially
why cgraph_clone_edge() changes them so.  Am I suppose to fix the
frequencies upon return to cgraph_copy_node_for_versioning() (see patch
below), or am I papering over the problem?

Thanks.

	* trans-mem.c (ipa_tm_create_version): Fix frequencies.

Index: testsuite/c-c++-common/tm/freq.c
===================================================================
--- testsuite/c-c++-common/tm/freq.c	(revision 0)
+++ testsuite/c-c++-common/tm/freq.c	(revision 0)
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -O" } */
+
+extern __attribute__((transaction_safe)) void TMreleaseNode ();
+
+int global;
+
+__attribute__((transaction_safe))
+TMrbtree_insert ()
+{
+  if (global)
+    TMreleaseNode();
+}
Index: trans-mem.c
===================================================================
--- trans-mem.c	(revision 158043)
+++ trans-mem.c	(working copy)
@@ -3752,6 +3752,16 @@ ipa_tm_create_version (struct cgraph_nod
   new_node = cgraph_copy_node_for_versioning (old_node, new_decl, NULL);
   get_cg_data (old_node)->clone = new_node;
 
+  /* Fix callee frequencies after cgraph_copy_node_for_versioning.  */
+  if (new_node->callees)
+    {
+      struct cgraph_edge *e;
+      for (e = new_node->callees; e; e = e->next_callee)
+	e->frequency =
+	  compute_call_stmt_bb_frequency (e->caller->decl,
+					  gimple_bb (e->call_stmt));
+    }
+
   if (!DECL_EXTERNAL (old_decl))
     tree_function_versioning (old_decl, new_decl, NULL, false, NULL);
 


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