From patchwork Fri Nov 14 01:13:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 410659 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EA1841400D5 for ; Fri, 14 Nov 2014 12:15:11 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=qjSBk2Cqe2NXkUBO9 eM63VQk5FGVG05SuN2A5sp8FjxANHHjQMZ8MvugZmiqPcPXqHaamY7aD7AqBNrQQ BRD5i23Kj74v5PYNlQxdap2kW3isIF3uKsZanLAIU/GinAS3JdSkZI7iUg1+cucq pUY9Ejs+Al6x85FCKqhz4N62wY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=oljPpH9vCL/KxDb4mCKZA2H Yh+M=; b=K/4JOlgvjeNI1wb7QCWs7pnDPDoJQAXepzVcaEF9P5Dk4cZVxM0ayBJ pUX5vGHtF8aIm/yQ02b72oXcVEIHr3AgdOaVVcs0EoTnFKskcEiL89Agtxt3FHB1 pn8lREnk2fi+7YAUA4rXQVhi1lQaDJb2E+U+7y/xhlfn4JlsMj58= Received: (qmail 646 invoked by alias); 14 Nov 2014 01:14:07 -0000 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 Received: (qmail 564 invoked by uid 89); 14 Nov 2014 01:14:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Nov 2014 01:14:04 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1Xp5Sa-0003PG-3p from Cesar_Philippidis@mentor.com ; Thu, 13 Nov 2014 17:14:00 -0800 Received: from [127.0.0.1] (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.181.6; Thu, 13 Nov 2014 17:13:59 -0800 Message-ID: <54655755.1080509@mentor.com> Date: Thu, 13 Nov 2014 17:13:57 -0800 From: Cesar Philippidis User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Jakub Jelinek CC: Thomas Schwinge , Subject: Re: OpenACC middle end changes References: <20141113180949.GX5026@tucnak.redhat.com> <54650093.1070109@mentor.com> <20141113190906.GY5026@tucnak.redhat.com> In-Reply-To: <20141113190906.GY5026@tucnak.redhat.com> On 11/13/2014 11:09 AM, Jakub Jelinek wrote: > On Thu, Nov 13, 2014 at 11:03:47AM -0800, Cesar Philippidis wrote: >>>> @@ -233,6 +242,90 @@ static tree scan_omp_1_op (tree *, int *, void *); >>>> *handled_ops_p = false; \ >>>> break; >>>> >>>> +/* Helper function to get the reduction array name */ >>>> +static const char * >>>> +omp_get_id (tree node) >>> >>> Be more specific in the function name what it is for? >> >> It's the name of the array containing the partial reductions for >> original reduction variable. >> >>>> +{ >>>> + const char *id = IDENTIFIER_POINTER (DECL_NAME (node)); >>>> + int len = strlen ("omp$") + strlen (id); >>>> + char *temp_name = (char *)alloca (len+1); >>>> + snprintf (temp_name, len+1, "gfc$%s", id); >>> >>> gfc$ ? >> >> It's just a semi-random prefix I used to make the partial reduction >> array identifier unique to aid with debugging. I was working on the >> fortran front end at the time. Maybe s/gfc/oacc/? > > Yeah, something (and please use the same string in the strlen and sprintf. > If the symbol is emitted into assembly, you need to check for > NO_DOLLARS_IN_LABELS and similar. Oh, and please use spaces around +. > And name the function so that it is clear what is it for. The attached patch cleanup the various reduction functions and their usages. Thomas, I've applied this to gomp-4_0-branch. Cesar 2014-11-13 Cesar Philippidis gcc/ * omp-low.c (omp_get_id): Rename to... (oacc_get_reduction_array_id): ... this. (lookup_oacc_reduction): ... this. (lookup_reduction): Rename to... (maybe_lookup_reduction): Rename to... (maybe_lookup_oacc_reduction): ... this. (scan_sharing_clauses): Update calls to renamed fns. (lower_reduction_var_helper): Rename to... (oacc_lower_reduction_var_helper): ... this. (lower_reduction_clauses): Rename to... (oacc_lower_reduction_clauses): ... this. (omp_gimple_assign_with_ops): Rename to... (oacc_gimple_assign_with_ops): ... this. (initialize_reduction_data): Rename to ... (oacc_initialize_reduction_data): ... this. (finalize_reduction_data): Rename to... (oacc_finalize_reduction_data): ... this. (process_reduction_data): Rename to... (oacc_process_reduction_data): ... this. (lower_omp_target): Update calls to renamed fns. diff --git a/gcc/omp-low.c b/gcc/omp-low.c index e511846..da9c5a5 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -242,15 +242,16 @@ static tree scan_omp_1_op (tree *, int *, void *); *handled_ops_p = false; \ break; -/* Helper function to get the reduction array name */ +/* Helper function to get the name of the array containing the partial + reductions for OpenACC reductions. */ static const char * -omp_get_id (tree node) +oacc_get_reduction_array_id (tree node) { const char *id = IDENTIFIER_POINTER (DECL_NAME (node)); - int len = strlen ("omp$") + strlen (id); - char *temp_name = (char *)alloca (len+1); - snprintf (temp_name, len+1, "gfc$%s", id); - return IDENTIFIER_POINTER(get_identifier (temp_name)); + int len = strlen ("OACC") + strlen (id); + char *temp_name = XALLOCAVEC (char, len + 1); + snprintf (temp_name, len+1, "OACC%s", id); + return IDENTIFIER_POINTER (get_identifier (temp_name)); } /* Determine the number of threads OpenACC threads used to determine the @@ -983,7 +984,7 @@ maybe_lookup_field (tree var, omp_context *ctx) } static inline tree -lookup_reduction (const char *id, omp_context *ctx) +lookup_oacc_reduction (const char *id, omp_context *ctx) { gcc_assert (is_gimple_omp_oacc_specifically (ctx->stmt)); @@ -993,7 +994,7 @@ lookup_reduction (const char *id, omp_context *ctx) } static inline tree -maybe_lookup_reduction (tree var, omp_context *ctx) +maybe_lookup_oacc_reduction (tree var, omp_context *ctx) { splay_tree_node n = NULL; if (ctx->reduction_map) @@ -1759,14 +1760,15 @@ scan_sharing_clauses (tree clauses, omp_context *ctx) tree var = OMP_CLAUSE_DECL (c); tree type = get_base_type (var); tree ptype = build_pointer_type (type); - tree array = create_tmp_var (ptype, omp_get_id (var)); + tree array = create_tmp_var (ptype, + oacc_get_reduction_array_id (var)); omp_context *c = (ctx->field_map ? ctx : ctx->outer); install_var_field (array, true, 3, c); install_var_local (array, c); /* Insert it into the current context. */ - splay_tree_insert (ctx->reduction_map, - (splay_tree_key) omp_get_id(var), + splay_tree_insert (ctx->reduction_map, (splay_tree_key) + oacc_get_reduction_array_id (var), (splay_tree_value) array); splay_tree_insert (ctx->reduction_map, (splay_tree_key) array, @@ -4419,8 +4421,8 @@ lower_lastprivate_clauses (tree clauses, tree predicate, gimple_seq *stmt_list, } static void -lower_reduction_var_helper (gimple_seq *stmt_seqp, omp_context *ctx, tree tid, - tree var, tree new_var) +oacc_lower_reduction_var_helper (gimple_seq *stmt_seqp, omp_context *ctx, + tree tid, tree var, tree new_var) { /* The atomic add at the end of the sum creates unnecessary write contention on accelerators. To work around this, @@ -4438,7 +4440,7 @@ lower_reduction_var_helper (gimple_seq *stmt_seqp, omp_context *ctx, tree tid, tree ptype = build_pointer_type (type); - t = lookup_reduction (omp_get_id (var), ctx); + t = lookup_oacc_reduction (oacc_get_reduction_array_id (var), ctx); t = build_receiver_ref (t, false, ctx->outer); array = create_tmp_var (ptype, NULL); @@ -4549,7 +4551,8 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx) } else { - lower_reduction_var_helper (stmt_seqp, ctx, tid, var, new_var); + oacc_lower_reduction_var_helper (stmt_seqp, ctx, tid, var, + new_var); return; } } @@ -4573,7 +4576,8 @@ lower_reduction_clauses (tree clauses, gimple_seq *stmt_seqp, omp_context *ctx) { if (is_gimple_omp_oacc_specifically (ctx->stmt)) { - lower_reduction_var_helper (stmt_seqp, ctx, tid, var, new_var); + oacc_lower_reduction_var_helper (stmt_seqp, ctx, tid, var, + new_var); } else { @@ -9534,7 +9538,8 @@ make_pass_expand_omp (gcc::context *ctxt) /* Helper function to preform, potentially COMPLEX_TYPE, operation and convert it to gimple. */ static void -omp_gimple_assign_with_ops (tree_code op, tree dest, tree src, gimple_seq *seq) +oacc_gimple_assign_with_ops (tree_code op, tree dest, tree src, + gimple_seq *seq) { gimple stmt; @@ -9618,8 +9623,8 @@ omp_gimple_assign_with_ops (tree_code op, tree dest, tree src, gimple_seq *seq) vector_length threads in total. */ static void -initialize_reduction_data (tree clauses, tree nthreads, gimple_seq *stmt_seqp, - omp_context *ctx) +oacc_initialize_reduction_data (tree clauses, tree nthreads, + gimple_seq *stmt_seqp, omp_context *ctx) { gcc_assert (is_gimple_omp_oacc_specifically (ctx->stmt)); @@ -9655,7 +9660,8 @@ initialize_reduction_data (tree clauses, tree nthreads, gimple_seq *stmt_seqp, tree var = OMP_CLAUSE_DECL (c); tree type = get_base_type (var); - tree array = lookup_reduction (omp_get_id (var), ctx); + tree array = lookup_oacc_reduction (oacc_get_reduction_array_id (var), + ctx); tree size, call; /* Calculate size of the reduction array. */ @@ -9702,8 +9708,8 @@ initialize_reduction_data (tree clauses, tree nthreads, gimple_seq *stmt_seqp, on the accelerator. */ static void -finalize_reduction_data (tree clauses, tree nthreads, gimple_seq *stmt_seqp, - omp_context *ctx) +oacc_finalize_reduction_data (tree clauses, tree nthreads, + gimple_seq *stmt_seqp, omp_context *ctx) { gcc_assert (is_gimple_omp_oacc_specifically (ctx->stmt)); @@ -9756,7 +9762,8 @@ finalize_reduction_data (tree clauses, tree nthreads, gimple_seq *stmt_seqp, /* Set up reduction variable var. */ var = OMP_CLAUSE_DECL (c); type = get_base_type (var); - array = lookup_reduction (omp_get_id (OMP_CLAUSE_DECL (c)), ctx); + array = lookup_oacc_reduction (oacc_get_reduction_array_id + (OMP_CLAUSE_DECL (c)), ctx); /* Calculate the array offset. */ tree offset = create_tmp_var (sizetype, NULL); @@ -9793,8 +9800,8 @@ finalize_reduction_data (tree clauses, tree nthreads, gimple_seq *stmt_seqp, break; default: /* The lhs isn't a gimple_reg when var is COMPLEX_TYPE. */ - omp_gimple_assign_with_ops (OMP_CLAUSE_REDUCTION_CODE (c), - t, mem, stmt_seqp); + oacc_gimple_assign_with_ops (OMP_CLAUSE_REDUCTION_CODE (c), + t, mem, stmt_seqp); } t = fold_build1 (NOP_EXPR, TREE_TYPE (var), t); @@ -9818,7 +9825,7 @@ finalize_reduction_data (tree clauses, tree nthreads, gimple_seq *stmt_seqp, scan that for reductions. */ static void -process_reduction_data (gimple_seq *body, gimple_seq *in_stmt_seqp, +oacc_process_reduction_data (gimple_seq *body, gimple_seq *in_stmt_seqp, gimple_seq *out_stmt_seqp, omp_context *ctx) { gcc_assert (is_gimple_omp_oacc_specifically (ctx->stmt)); @@ -9920,8 +9927,9 @@ process_reduction_data (gimple_seq *body, gimple_seq *in_stmt_seqp, in_stmt_seqp); gimple_seq_add_stmt (in_stmt_seqp, gimple_build_label (exit)); - initialize_reduction_data (clauses, nthreads, in_stmt_seqp, ctx); - finalize_reduction_data (clauses, nthreads, out_stmt_seqp, ctx); + oacc_initialize_reduction_data (clauses, nthreads, in_stmt_seqp, + ctx); + oacc_finalize_reduction_data (clauses, nthreads, out_stmt_seqp, ctx); break; default: // Scan for other directives which support reduction here. @@ -11198,7 +11206,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) { case GIMPLE_OACC_KERNELS: case GIMPLE_OACC_PARALLEL: - process_reduction_data (&tgt_body, &irlist, &orlist, ctx); + oacc_process_reduction_data (&tgt_body, &irlist, &orlist, ctx); break; default: break; @@ -11399,7 +11407,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) || (OMP_CLAUSE_MAP_KIND (c) != OMP_CLAUSE_MAP_FORCE_DEVICEPTR) || TREE_CODE (TREE_TYPE (ovar)) != ARRAY_TYPE); - if (maybe_lookup_reduction (var, ctx)) + if (maybe_lookup_oacc_reduction (var, ctx)) { gcc_assert (gimple_code (stmt) == GIMPLE_OACC_KERNELS || gimple_code (stmt) == GIMPLE_OACC_PARALLEL);