From patchwork Tue Jun 22 18:17:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 56559 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 24EDBB6F16 for ; Wed, 23 Jun 2010 04:18:09 +1000 (EST) Received: (qmail 24476 invoked by alias); 22 Jun 2010 18:18:08 -0000 Received: (qmail 24460 invoked by uid 22791); 22 Jun 2010 18:18:07 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, 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; Tue, 22 Jun 2010 18:18:02 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5MIHvwZ005711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 22 Jun 2010 14:17:58 -0400 Received: from redhat.com (vpn-226-181.phx2.redhat.com [10.3.226.181]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5MIHoul007026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 22 Jun 2010 14:17:56 -0400 Date: Tue, 22 Jun 2010 14:17:50 -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: <20100622181750.GA23011@redhat.com> References: <4C04C24A.4080103@unine.ch> <20100618152559.GA7343@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100618152559.GA7343@redhat.com> 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 On Fri, Jun 18, 2010 at 11:26:00AM -0400, Aldy Hernandez wrote: > 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? Meanwhile, back at the ranch... rth complains that we should do this in the gimplifier and save the front-end work. Yay, less code! OK for branch? * gimplify.c (gimplify_transaction): 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: gimplify.c =================================================================== --- gimplify.c (revision 161187) +++ gimplify.c (working copy) @@ -6385,20 +6385,27 @@ gimplify_omp_atomic (tree *expr_p, gimpl static enum gimplify_status gimplify_transaction (tree *expr_p, gimple_seq *pre_p) { - tree expr = *expr_p, temp; + tree expr = *expr_p, temp, tbody = TRANSACTION_EXPR_BODY (expr); gimple g; gimple_seq body = NULL; struct gimplify_ctx gctx; int subcode = 0; + /* Wrap the transaction body in a BIND_EXPR so we have a context + where to put decls for OpenMP. */ + if (TREE_CODE (tbody) != BIND_EXPR) + { + tree bind = build3 (BIND_EXPR, void_type_node, NULL, tbody, NULL); + TREE_SIDE_EFFECTS (bind) = 1; + SET_EXPR_LOCATION (bind, EXPR_LOCATION (tbody)); + TRANSACTION_EXPR_BODY (expr) = bind; + } + push_gimplify_context (&gctx); temp = voidify_wrapper_expr (*expr_p, NULL); g = gimplify_and_return_first (TRANSACTION_EXPR_BODY (expr), &body); - if (g && gimple_code (g) == GIMPLE_BIND) - pop_gimplify_context (g); - else - pop_gimplify_context (NULL); + pop_gimplify_context (g); g = gimple_build_transaction (body, NULL); if (TRANSACTION_EXPR_OUTER (expr))