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] implement PR_READONLY


This runtime hint should be turned on when we're sure the transaction
performs no memory writes.  Since rth said not to worry about IPA for
clues, the following patch just assumes that any calls within a
transaction perform a write, unless the call is a const/pure.

I have doned this by being more aggressive in setting GTMA_HAVE_STORE in
expand_call_tm.

OK for branch?

	* gimple-pretty-print.c (dump_gimple_call): Handle PR_READONLY.
	* trans-mem.c (expand_transaction): Set PR_READONLY.
	(expand_call_tm): Set GTMA_HAVE_STORE more aggressively.
	* trans-mem.h (PR_READONLY): New.

Index: testsuite/gcc.dg/tm/20091221.c
===================================================================
--- testsuite/gcc.dg/tm/20091221.c	(revision 0)
+++ testsuite/gcc.dg/tm/20091221.c	(revision 0)
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -fdump-tree-tmedge" } */
+
+int i;
+extern void virgin () __attribute__((transaction_pure));
+
+foo()
+{
+	__transaction {
+	    virgin(i);
+	}
+}
+
+/* { dg-final { scan-tree-dump-times "readOnly" 1 "tmedge" } } */
+/* { dg-final { cleanup-tree-dump "tmedge" } } */
Index: gimple-pretty-print.c
===================================================================
--- gimple-pretty-print.c	(revision 154874)
+++ gimple-pretty-print.c	(working copy)
@@ -585,6 +585,8 @@ dump_gimple_call (pretty_printer *buffer
 	pp_string (buffer, "exceptionBlock ");
       if (props & PR_HASELSE)
 	pp_string (buffer, "hasElse ");
+      if (props & PR_READONLY)
+	pp_string (buffer, "readOnly ");
 
       pp_string (buffer, "]");
     }
Index: trans-mem.c
===================================================================
--- trans-mem.c	(revision 155169)
+++ trans-mem.c	(working copy)
@@ -1963,11 +1963,20 @@ expand_call_tm (struct tm_region *region
   tree lhs = gimple_call_lhs (stmt);
   tree fn_decl;
   struct cgraph_node *node;
+  bool retval = false;
 
   if (is_tm_pure_call (stmt))
     return false;
 
   fn_decl = gimple_call_fndecl (stmt);
+  if (fn_decl)
+    retval = is_tm_ending_fndecl (fn_decl);
+  if (!retval)
+    {
+      /* Assume all non-const/pure calls write to memory, except
+	 transaction ending builtins.  */
+      transaction_subcode_ior (region, GTMA_HAVE_STORE);
+    }
 
   /* For indirect calls, we already generated a call into the runtime.  */
   if (!fn_decl)
@@ -1994,10 +2003,10 @@ expand_call_tm (struct tm_region *region
       return true;
     }
 
-  if (lhs && requires_barrier (region->entry_block, lhs, stmt))
-    transaction_subcode_ior (region, GTMA_HAVE_STORE);
+  if (lhs)
+    (void) requires_barrier (region->entry_block, lhs, stmt);
 
-  return is_tm_ending_fndecl (fn_decl);
+  return retval;
 }
 
 
@@ -2217,6 +2226,8 @@ expand_transaction (struct tm_region *re
     flags |= PR_HASNOIRREVOCABLE;
   if ((subcode & GTMA_HAVE_ABORT) == 0)
     flags |= PR_HASNOABORT;
+  if ((subcode & GTMA_HAVE_STORE) == 0)
+    flags |= PR_READONLY;
   t2 = build_int_cst (TREE_TYPE (status), flags);
   g = gimple_build_call (tm_start, 1, t2);
   gimple_call_set_lhs (g, status);
Index: trans-mem.h
===================================================================
--- trans-mem.h	(revision 154874)
+++ trans-mem.h	(working copy)
@@ -32,3 +32,4 @@
 #define PR_PREFERUNINSTRUMENTED	0x0800
 #define PR_EXCEPTIONBLOCK	0x1000
 #define PR_HASELSE		0x2000
+#define PR_READONLY		0x4000


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