diff mbox

[trans-mem] issue with openmp

Message ID 20100618152559.GA7343@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez June 18, 2010, 3:26 p.m. UTC
The problem here is that gimplify_transaction() places the temporaries
that were generated for a transaction in cfun->local_decls, but
omp_copy_decl() will only look in the enclosing contexts, not in
cfun->local_decls.

rth suggested we make a better attempt at putting temporaries into the
proper context so OMP can figure out how to pull pieces out to make a
new function.

The patch below wraps the transaction bodies into a BIND_EXPR, which
gimplify_transaction() can later use for its temporaries, thus allowing
the OMP code to find a proper context.

OK for branch?

	* c-typeck.c (c_finish_transaction): Same.
	* cp/semantics.c (finish_transaction_stmt): Wrap transaction body
	in a BIND_EXPR.
diff mbox

Patch

Index: testsuite/c-c++-common/tm/omp.c
===================================================================
--- testsuite/c-c++-common/tm/omp.c	(revision 0)
+++ testsuite/c-c++-common/tm/omp.c	(revision 0)
@@ -0,0 +1,22 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -fopenmp" } */
+
+__attribute__ ((transaction_pure))
+unsigned long rdtsc();
+
+typedef struct ENTER_EXIT_TIMES
+{
+  unsigned long enter;
+} times_t;
+
+void ParClassify()
+{
+  void * Parent;
+#pragma omp parallel private(Parent)
+  {
+    times_t inside;
+    __transaction [[atomic]] {
+       inside.enter = rdtsc();
+    }
+  }
+}
Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 160538)
+++ cp/semantics.c	(working copy)
@@ -4683,7 +4683,18 @@  begin_transaction_stmt (location_t loc, 
 void
 finish_transaction_stmt (tree stmt, tree compound_stmt, int flags)
 {
-  TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
+  tree body = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
+
+  /* Wrap the transaction body in a BIND_EXPR so we have a context
+     where to put decls for OpenMP.  */
+  if (TREE_CODE (body) != BIND_EXPR)
+    {
+      body = build3 (BIND_EXPR, void_type_node, NULL, body, NULL);
+      TREE_SIDE_EFFECTS (body) = 1;
+      SET_EXPR_LOCATION (body, EXPR_LOCATION (stmt));
+    }
+
+  TRANSACTION_EXPR_BODY (stmt) = body;
   TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
   TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
 
Index: c-typeck.c
===================================================================
--- c-typeck.c	(revision 160538)
+++ c-typeck.c	(working copy)
@@ -10281,9 +10281,20 @@  c_finish_omp_clauses (tree clauses)
 /* Create a transaction node.  */
 
 tree
-c_finish_transaction (location_t loc, tree block, int flags)
+c_finish_transaction (location_t loc, tree body, int flags)
 {
-  tree stmt = build_stmt (loc, TRANSACTION_EXPR, block);
+  tree stmt;
+
+  /* Wrap the transaction body in a BIND_EXPR so we have a context
+     where to put decls for OpenMP.  */
+  if (TREE_CODE (body) != BIND_EXPR)
+    {
+      body = build3 (BIND_EXPR, void_type_node, NULL, body, NULL);
+      TREE_SIDE_EFFECTS (body) = 1;
+      SET_EXPR_LOCATION (body, loc);
+    }
+
+  stmt = build_stmt (loc, TRANSACTION_EXPR, body);
   if (flags & TM_STMT_ATTR_OUTER)
     TRANSACTION_EXPR_OUTER (stmt) = 1;
   if (flags & TM_STMT_ATTR_RELAXED)