From patchwork Wed Nov 12 13:16:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 409972 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 11C431400AB for ; Thu, 13 Nov 2014 00:16:44 +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=DHX2Afc/GXiBx6XZV 92Ofq3jjkMZugOK6BUJBlXGPwN86ReFac+Fkt87VoQi+MX85sCfFw1Y1siKGPHtE BuqM+lqiJh3W7a9ewEOeD2O86gJOXgVLSAkLsut5u8SWKi4VGPpj5snkTOhJ6IPj W03gYLibMqE0D2D2e0R2Eu0ywQ= 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=aSQpKgaj8txVEn18frKmsHa 3h5Q=; b=X6s+814WlrEI5AiGiBf8WOKcPLVA9CVRj0tRL67V4SP2hlXrY/9Kg2M qX2/wZUxPp0U3GKTVTJp/F2sDcjdCJ1L3/kbt/cHrzJ/GS72fg6J9A1h5xUxWS2n 8DOfkUmJ4qfhEGkg06WiByWns3HjDJ0PaZG36TLqf55ClC4Z+Bwk= Received: (qmail 29955 invoked by alias); 12 Nov 2014 13:16:36 -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 29834 invoked by uid 89); 12 Nov 2014 13:16:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 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; Wed, 12 Nov 2014 13:16:33 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1XoXme-0004Ov-IN from Tom_deVries@mentor.com ; Wed, 12 Nov 2014 05:16:29 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.181.6; Wed, 12 Nov 2014 13:16:27 +0000 Message-ID: <54635DA8.6030603@mentor.com> Date: Wed, 12 Nov 2014 14:16:24 +0100 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Richard Biener CC: Jakub Jelinek , GCC Patches , Thomas Schwinge , Bernd Schmidt Subject: Run pass_expand_omp_ssa after pass_paralellize_loops References: <53E24570.1010200@mentor.com> <53F1EEB7.1090509@mentor.com> <540ED665.3010003@mentor.com> <54185877.6020902@mentor.com> <542AB218.5060502@mentor.com> In-Reply-To: <542AB218.5060502@mentor.com> [ moved from gcc@ to gcc-patches@ ] [ subject was: Re: [gomp4] openacc kernels directive support ] On 30-09-14 15:37, Tom de Vries wrote: >> I would be happily accepting splitting the current autopar pass >> that way, that is, do >> >> NEXT_PASS (pass_parallelize_loops) >> PUSH_INSERT_PASSES_WITHIN (pass_parallelize_loops) >> NEXT_PASS (pass_expand_omp) >> POP_INSERT_PASSES () >> >> and make the analysis code handle lowered OMP form. >> > > To explore that, I created a tentative patch on top of the gomp-4_0-branch, > which allows a non-bootstrap build and a gcc dg.exp run, so at least a couple of > parloops test-cases. I can put this through bootstrap and reg-test if you > confirm this patch is what you want. > > I'm not sure though OACC and autopar can share the actual function split-off. > autopar is run rather late, later than the lto-stream point, while we need the > split-off done before that for oacc. I'm also not sure what the point would be > to have lowered OMP form in all those passes in between, I'd think you want to > omp-expand it asap. Richard, This patch implements your proposal. It uses pass_expand_omp after pass_parallelize_loops to expand the omp constructs inserted by pass_parallelize_loops. Note: the patch doesn't remove omp_expand_local, since I'm still using that in my oacc kernels directive patch series. Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom 2014-11-12 Tom de Vries * function.h (struct function): Add omp_expand_needed field. * omp-low.c (pass_data pass_data_expand_omp_ssa): New pass_data. (class pass_expand_omp_ssa): New pass. (make_pass_expand_omp_ssa): New function. * passes.def (pass_parallelize_loops): Use PUSH_INSERT_PASSES_WITHIN instead of NEXT_PASS. (pass_expand_omp_ssa): Add after pass_parallelize_loops. * tree-parloops.c (gen_parallel_loop): Remove call to omp_expand_local. (pass_parallelize_loops::execute): Don't do cleanups TODO_cleanup_cfg and TODO_rebuild_alias yet. Add TODO_update_ssa. Set cfun->omp_expand_needed. * tree-pass.h (make_pass_expand_omp_ssa): Declare. --- gcc/function.h | 3 +++ gcc/omp-low.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gcc/passes.def | 3 +++ gcc/tree-parloops.c | 18 +++++++----------- gcc/tree-pass.h | 1 + 5 files changed, 56 insertions(+), 11 deletions(-) diff --git a/gcc/function.h b/gcc/function.h index 3a6305c..1afce69 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -667,6 +667,9 @@ struct GTY(()) function { /* Set when the tail call has been identified. */ unsigned int tail_call_marked : 1; + + /* Set when an omp_expand is needed. */ + unsigned int omp_expand_needed : 1; }; /* Add the decl D to the local_decls list of FUN. */ diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 5210de1..b748ee1 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -8832,6 +8832,48 @@ make_pass_expand_omp (gcc::context *ctxt) { return new pass_expand_omp (ctxt); } + +namespace { + +const pass_data pass_data_expand_omp_ssa = +{ + GIMPLE_PASS, /* type */ + "ompexpssa", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_NONE, /* tv_id */ + PROP_cfg | PROP_ssa, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + TODO_cleanup_cfg | TODO_rebuild_alias, /* todo_flags_finish */ +}; + +class pass_expand_omp_ssa : public gimple_opt_pass +{ +public: + pass_expand_omp_ssa (gcc::context *ctxt) + : gimple_opt_pass (pass_data_expand_omp_ssa, ctxt) + {} + + /* opt_pass methods: */ + virtual bool gate (function *) { return (bool)cfun->omp_expand_needed; } + + virtual unsigned int execute (function *) + { + unsigned res = execute_expand_omp (); + cfun->omp_expand_needed = 0; + return res; + } + +}; // class pass_expand_omp_ssa + +} // anon namespace + +gimple_opt_pass * +make_pass_expand_omp_ssa (gcc::context *ctxt) +{ + return new pass_expand_omp_ssa (ctxt); +} /* Routines to lower OpenMP directives into OMP-GIMPLE. */ diff --git a/gcc/passes.def b/gcc/passes.def index 2305d67..dd91718 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -241,6 +241,9 @@ along with GCC; see the file COPYING3. If not see POP_INSERT_PASSES () NEXT_PASS (pass_iv_canon); NEXT_PASS (pass_parallelize_loops); + PUSH_INSERT_PASSES_WITHIN (pass_parallelize_loops) + NEXT_PASS (pass_expand_omp_ssa); + POP_INSERT_PASSES () NEXT_PASS (pass_if_conversion); /* pass_vectorize must immediately follow pass_if_conversion. Please do not add any other passes in between. */ diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c index 09b3f16..c5e3041 100644 --- a/gcc/tree-parloops.c +++ b/gcc/tree-parloops.c @@ -1753,7 +1753,6 @@ gen_parallel_loop (struct loop *loop, tree many_iterations_cond, type, nit; tree arg_struct, new_arg_struct; gimple_seq stmts; - basic_block parallel_head; edge entry, exit; struct clsn_data clsn_data; unsigned prob; @@ -1891,8 +1890,8 @@ gen_parallel_loop (struct loop *loop, cond_stmt = last_stmt (loop->header); if (cond_stmt) loc = gimple_location (cond_stmt); - parallel_head = create_parallel_loop (loop, create_loop_fn (loc), arg_struct, - new_arg_struct, n_threads, loc); + create_parallel_loop (loop, create_loop_fn (loc), arg_struct, + new_arg_struct, n_threads, loc); if (reduction_list->elements () > 0) create_call_for_reduction (loop, reduction_list, &clsn_data); @@ -1906,13 +1905,6 @@ gen_parallel_loop (struct loop *loop, removed statements. */ FOR_EACH_LOOP (loop, 0) free_numbers_of_iterations_estimates_loop (loop); - - /* Expand the parallel constructs. We do it directly here instead of running - a separate expand_omp pass, since it is more efficient, and less likely to - cause troubles with further analyses not being able to deal with the - OMP trees. */ - - omp_expand_local (parallel_head); } /* Returns true when LOOP contains vector phi nodes. */ @@ -2284,7 +2276,11 @@ pass_parallelize_loops::execute (function *fun) return 0; if (parallelize_loops ()) - return TODO_cleanup_cfg | TODO_rebuild_alias; + { + fun->omp_expand_needed = 1; + return TODO_update_ssa; + } + return 0; } diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index a3efdd8..d68979f 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -399,6 +399,7 @@ extern gimple_opt_pass *make_pass_lower_vector_ssa (gcc::context *ctxt); extern gimple_opt_pass *make_pass_lower_omp (gcc::context *ctxt); extern gimple_opt_pass *make_pass_diagnose_omp_blocks (gcc::context *ctxt); extern gimple_opt_pass *make_pass_expand_omp (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_expand_omp_ssa (gcc::context *ctxt); extern gimple_opt_pass *make_pass_object_sizes (gcc::context *ctxt); extern gimple_opt_pass *make_pass_strlen (gcc::context *ctxt); extern gimple_opt_pass *make_pass_fold_builtins (gcc::context *ctxt); -- 1.9.1