From patchwork Fri Jun 18 15:26:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 56202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id F3AFDB7D4F for ; Sat, 19 Jun 2010 01:26:20 +1000 (EST) Received: (qmail 11692 invoked by alias); 18 Jun 2010 15:26:16 -0000 Received: (qmail 11683 invoked by uid 22791); 18 Jun 2010 15:26:14 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Jun 2010 15:26:09 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5IFQ4uT028294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 18 Jun 2010 11:26:05 -0400 Received: from redhat.com (vpn-11-107.rdu.redhat.com [10.11.11.107]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5IFQ0og029624 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 18 Jun 2010 11:26:03 -0400 Date: Fri, 18 Jun 2010 11:26:00 -0400 From: Aldy Hernandez To: Patrick Marlier Cc: Richard Henderson , FELBER Pascal , Javier Arias , gcc-patches@gcc.gnu.org Subject: Re: [trans-mem] issue with openmp Message-ID: <20100618152559.GA7343@redhat.com> References: <4C04C24A.4080103@unine.ch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4C04C24A.4080103@unine.ch> User-Agent: Mutt/1.5.20 (2009-08-17) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. 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)