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: [trans-mem] GROW and bug


Martin Schindewolf wrote:
Program received signal SIGSEGV, Segmentation fault.
0x08214ae1 in first_dom_son (dir=CDI_DOMINATORS, bb=0xb2b2412c) at ../../transactional-memory/gcc/dominance.c:1395
1395 struct et_node *son = bb->dom[dir_index]->son;

Ouch. Dominators got corrupted. I thought I'd figured that one out and fixed it. I guess I'll have to really store all the information I need and discard dominator information before I start adding back edges... Please send me the test case.
Please find it attached.

Not quite the bug I thought, but fixed now.



r~
        * trans-mem.c (expand_irrevokable): Mark all call-clobbered tags
        for renaming.
        (execute_tm_edges): Clear all_tm_regions at the end.
        (gate_tm_memopt): Disable.
        * tree-ssa-operands.c (add_all_call_clobber_ops): Handle .GLOBAL_VAR.
        Use add_virtual_operand directly and pretend to be a call site.
        (add_call_clobber_ops): Streamline .GLOBAL_VAR handling.
        (add_call_read_ops): Likewise.
        * testsuite/gcc.dg/tm/opt-1.c: New.

--- testsuite/gcc.dg/tm/opt-1.c	(revision 141600)
+++ testsuite/gcc.dg/tm/opt-1.c	(local)
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -O" } */
+
+extern void usleep (int) __attribute__((tm_pure));
+extern int rand(void) __attribute__((pure, tm_pure));
+extern int printf (const char *, ...);
+extern void *malloc (__SIZE_TYPE__) __attribute__((malloc));
+extern void xyzzy (void * (*)(void *));
+
+typedef struct
+{
+  int id;
+} parm;
+
+int gvar;
+
+void *hello(void *arg)
+{
+  parm *p=(parm *)arg;
+  int tmp = p->id;
+  int tmp3;
+  printf ("Thread reads %d.\n", tmp);
+  __tm_atomic
+    {
+      int tmp2 = gvar;
+      usleep ((int) (10.0*rand()/(10+1.0))/100);
+      gvar = tmp + tmp2;
+      tmp3 = gvar;
+    }
+  printf("tmp3 = %d\n", tmp3);
+  return 0;
+}
+
+int
+main()
+{
+  int i, n = rand();
+
+  for (i=0; i<n; i++)
+    xyzzy (hello);
+
+  return 0;
+}
--- trans-mem.c	(revision 141600)
+++ trans-mem.c	(local)
@@ -631,6 +631,7 @@ static void
 expand_irrevokable (struct tm_region *region, gimple_stmt_iterator *gsi)
 {
   gimple g;
+  tree var;
 
   tm_atomic_subcode_ior (region, GTMA_HAVE_CALL_IRREVOKABLE);
 
@@ -638,6 +639,29 @@ expand_irrevokable (struct tm_region *re
   add_stmt_to_tm_region (region, g);
 
   gsi_insert_before (gsi, g, GSI_SAME_STMT);
+
+  /* We may be inserting this for a function or asm that doesn't clobber
+     all memory state, so we can't just use mark_vops_in_stmt as below.  */
+  var = gimple_global_var (cfun);
+  if (var)
+    mark_sym_for_renaming (var);
+  else
+    {
+      bitmap_iterator bi;
+      unsigned int i;
+
+      EXECUTE_IF_SET_IN_BITMAP (gimple_call_clobbered_vars (cfun), 0, i, bi)
+	{
+	  var = referenced_var (i);
+	  mark_sym_for_renaming (var);
+	}
+
+      EXECUTE_IF_SET_IN_BITMAP (gimple_addressable_vars (cfun), 0, i, bi)
+	{
+	  var = referenced_var (i);
+	  mark_sym_for_renaming (var);
+	}
+    }
 }
 
 
@@ -1169,6 +1193,7 @@ execute_tm_edges (void)
      the SSA web in the TODO section following this pass.  */
   free_dominance_info (CDI_DOMINATORS);
   bitmap_obstack_release (&tm_obstack);
+  all_tm_regions = NULL;
 
   return 0;
 }
@@ -1204,7 +1229,7 @@ execute_tm_memopt (void)
 static bool
 gate_tm_memopt (void)
 {
-  return optimize > 0;
+  return 0 && optimize > 0;
 }
 
 struct gimple_opt_pass pass_tm_memopt =
--- tree-ssa-operands.c	(revision 141600)
+++ tree-ssa-operands.c	(local)
@@ -1635,27 +1635,43 @@ get_tmr_operands (gimple stmt, tree expr
 }
 
 
-/* Clobber everything in memory.  Used when memory barriers are seen.  */
+/* Clobber everything in memory.  Used when memory barriers are seen.
+   Note that we set IS_CALL_SITE to true for add_virtual_operand, even
+   if this isn't actually a call, but an ASM or TM_ATOMIC.  This is
+   done because some vdefs are pruned for non-calls, and we don't want
+   that; we want ALL clobbers for the memory barrier.  */
 
 static void
 add_all_call_clobber_ops (gimple stmt)
 {
   unsigned i;
   bitmap_iterator bi;
+  tree global_var;
 
   /* Mark the statement as having memory operands.  */
   gimple_set_references_memory (stmt, true);
 
+  /* If we created .GLOBAL_VAR earlier, just use it.  */
+  global_var = gimple_global_var (cfun);
+  if (global_var)
+    {
+      add_virtual_operand (global_var, stmt, opf_def | opf_implicit,
+			   NULL, 0, -1, true);
+      return;
+    }
+
   EXECUTE_IF_SET_IN_BITMAP (gimple_call_clobbered_vars (cfun), 0, i, bi)
     {
       tree var = referenced_var (i);
-      add_stmt_operand (&var, stmt, opf_def | opf_implicit);
+      add_virtual_operand (var, stmt, opf_def | opf_implicit,
+			   NULL_TREE, 0, -1, true);
     }
 
   EXECUTE_IF_SET_IN_BITMAP (gimple_addressable_vars (cfun), 0, i, bi)
     {
       tree var = referenced_var (i);
-      add_stmt_operand (&var, stmt, opf_def | opf_implicit);
+      add_virtual_operand (var, stmt, opf_def | opf_implicit,
+			   NULL_TREE, 0, -1, true);
     }
 }
 
@@ -1668,14 +1684,15 @@ add_call_clobber_ops (gimple stmt, tree 
   unsigned u;
   bitmap_iterator bi;
   bitmap not_read_b, not_written_b;
+  tree global_var;
 
   gcc_assert (!(gimple_call_flags (stmt) & (ECF_PURE | ECF_CONST)));
 
   /* If we created .GLOBAL_VAR earlier, just use it.  */
-  if (gimple_global_var (cfun))
+  global_var = gimple_global_var (cfun);
+  if (global_var)
     {
-      tree var = gimple_global_var (cfun);
-      add_virtual_operand (var, stmt, opf_def, NULL, 0, -1, true);
+      add_virtual_operand (global_var, stmt, opf_def, NULL, 0, -1, true);
       return;
     }
 
@@ -1734,6 +1751,7 @@ add_call_read_ops (gimple stmt, tree cal
   unsigned u;
   bitmap_iterator bi;
   bitmap not_read_b;
+  tree global_var;
 
   /* Const functions do not reference memory.  */
   if (gimple_call_flags (stmt) & ECF_CONST)
@@ -1770,10 +1788,10 @@ add_call_read_ops (gimple stmt, tree cal
   /* Add a VUSE for .GLOBAL_VAR if it has been created.  See
      add_referenced_var for the heuristic used to decide whether to
      create .GLOBAL_VAR.  */
-  if (gimple_global_var (cfun))
+  global_var = gimple_global_var (cfun);
+  if (global_var)
     {
-      tree var = gimple_global_var (cfun);
-      add_virtual_operand (var, stmt, opf_use, NULL, 0, -1, true);
+      add_virtual_operand (global_var, stmt, opf_use, NULL, 0, -1, true);
       return;
     }
 

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