From patchwork Fri Sep 11 10:55:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 516680 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 BF3D6140789 for ; Fri, 11 Sep 2015 20:55:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=o/C7FMp8; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=IMnGRTYF6BAs+FcHyOpnWbP1ringbffhHS4TeWScrIvpk/bpaB IyDz/Yu5z/zKb1C3VusiUx2gJkEr1d6sZr/rq0deOVOWsPATwJwQdVvMAphb+J4B DTLd2fL7ZyTBZWJ0nkat5U9t9Cs8zpudo9wJ9RZUAX94/seAb82/RnGbo= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=QI2I6N0HjXr0cpsl3cGe5f6jxhc=; b=o/C7FMp8pf5VQClnpcno hsMO1x6SMjbdyccJoYNV660tvCB+SSy+YHgDXsQCogk23i9D0e/vSzMtuWcdl1Hk ku55d2F+jD1q61qp+LGlc03p9HB8vWE7wPtd9ljueHZj7EpVAiDXhcyW+sq182xh CQDn/yDdSggUkkfUOTRconM= Received: (qmail 44487 invoked by alias); 11 Sep 2015 10:55:48 -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 44477 invoked by uid 89); 11 Sep 2015 10:55:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_20, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 11 Sep 2015 10:55:45 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60774) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ZaLza-0001bM-TW for gcc-patches@gnu.org; Fri, 11 Sep 2015 06:55:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZaLzV-0002pm-F3 for gcc-patches@gnu.org; Fri, 11 Sep 2015 06:55:42 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:54913) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaLzV-0002oO-3d for gcc-patches@gnu.org; Fri, 11 Sep 2015 06:55:37 -0400 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 1ZaLzS-0001FC-EW from Tom_deVries@mentor.com ; Fri, 11 Sep 2015 03:55:34 -0700 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.224.2; Fri, 11 Sep 2015 11:55:27 +0100 To: Jakub Jelinek , Richard Biener CC: "gcc-patches@gnu.org" From: Tom de Vries Subject: [PATCH][PR67476] Add param parloops-schedule Message-ID: <55F2B304.7060604@mentor.com> Date: Fri, 11 Sep 2015 12:55:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 Hi, this patch adds a param parloops-schedule=<0-4>, which sets the omp schedule for loops paralellized by parloops. The <0-4> maps onto . Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom Add param parloops-schedule 2015-09-10 Tom de Vries PR tree-optimization/67476 * doc/invoke.texi (@item parloops-schedule): New item. * omp-low.c (expand_omp_for_generic): Handle simple latch. Add missing phis. Handle original loop. * params.def (PARAM_PARLOOPS_SCHEDULE): New DEFPARAM. * tree-parloops.c (create_parallel_loop): Handle PARAM_PARLOOPS_SCHEDULE. * testsuite/libgomp.c/autopar-3.c: New test. * testsuite/libgomp.c/autopar-4.c: New test. * testsuite/libgomp.c/autopar-5.c: New test. * testsuite/libgomp.c/autopar-6.c: New test. * testsuite/libgomp.c/autopar-7.c: New test. * testsuite/libgomp.c/autopar-8.c: New test. --- gcc/doc/invoke.texi | 4 +++ gcc/omp-low.c | 57 +++++++++++++++++++++++++++++++-- gcc/params.def | 6 ++++ gcc/tree-parloops.c | 24 +++++++++++++- libgomp/testsuite/libgomp.c/autopar-3.c | 4 +++ libgomp/testsuite/libgomp.c/autopar-4.c | 4 +++ libgomp/testsuite/libgomp.c/autopar-5.c | 4 +++ libgomp/testsuite/libgomp.c/autopar-6.c | 4 +++ libgomp/testsuite/libgomp.c/autopar-7.c | 4 +++ libgomp/testsuite/libgomp.c/autopar-8.c | 4 +++ 10 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 libgomp/testsuite/libgomp.c/autopar-3.c create mode 100644 libgomp/testsuite/libgomp.c/autopar-4.c create mode 100644 libgomp/testsuite/libgomp.c/autopar-5.c create mode 100644 libgomp/testsuite/libgomp.c/autopar-6.c create mode 100644 libgomp/testsuite/libgomp.c/autopar-7.c create mode 100644 libgomp/testsuite/libgomp.c/autopar-8.c diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 76e5e29..f3b67a8 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -11005,6 +11005,10 @@ automaton. The default is 50. Chunk size of omp schedule for loops parallelized by parloops. The default is 0. +@item parloops-schedule +Schedule type of omp schedule for loops parallelized by parloops (0:static, +1:dynamic, 2:guided, 3:auto, 4:runtime). The default is 0. + @end table @end table diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 88a5149..4f0498b 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -239,6 +239,7 @@ static vec taskreg_contexts; static void scan_omp (gimple_seq *, omp_context *); static tree scan_omp_1_op (tree *, int *, void *); +static gphi *find_phi_with_arg_on_edge (tree, edge); #define WALK_SUBSTMTS \ case GIMPLE_BIND: \ @@ -6155,7 +6156,9 @@ expand_omp_for_generic (struct omp_region *region, if (!broken_loop) { l2_bb = create_empty_bb (cont_bb); - gcc_assert (BRANCH_EDGE (cont_bb)->dest == l1_bb); + gcc_assert (BRANCH_EDGE (cont_bb)->dest == l1_bb + || (single_succ_edge (BRANCH_EDGE (cont_bb)->dest)->dest + == l1_bb)); gcc_assert (EDGE_COUNT (cont_bb->succs) == 2); } else @@ -6429,8 +6432,12 @@ expand_omp_for_generic (struct omp_region *region, remove_edge (e); make_edge (cont_bb, l2_bb, EDGE_FALSE_VALUE); - add_bb_to_loop (l2_bb, cont_bb->loop_father); e = find_edge (cont_bb, l1_bb); + if (e == NULL) + { + e = BRANCH_EDGE (cont_bb); + gcc_assert (single_succ (e->dest) == l1_bb); + } if (gimple_omp_for_combined_p (fd->for_stmt)) { remove_edge (e); @@ -6454,7 +6461,45 @@ expand_omp_for_generic (struct omp_region *region, e->flags = EDGE_FALLTHRU; } make_edge (l2_bb, l0_bb, EDGE_TRUE_VALUE); + } + + + if (gimple_in_ssa_p (cfun)) + { + gphi_iterator psi; + + for (psi = gsi_start_phis (l3_bb); !gsi_end_p (psi); gsi_next (&psi)) + { + source_location locus; + gphi *nphi; + gphi *exit_phi = psi.phi (); + + edge l2_to_l3 = find_edge (l2_bb, l3_bb); + tree exit_res = PHI_ARG_DEF_FROM_EDGE (exit_phi, l2_to_l3); + basic_block latch = BRANCH_EDGE (cont_bb)->dest; + edge latch_to_l1 = find_edge (latch, l1_bb); + gphi *inner_phi = find_phi_with_arg_on_edge (exit_res, latch_to_l1); + + tree t = gimple_phi_result (exit_phi); + tree new_res = copy_ssa_name (t, NULL); + nphi = create_phi_node (new_res, l0_bb); + + edge l0_to_l1 = find_edge (l0_bb, l1_bb); + t = PHI_ARG_DEF_FROM_EDGE (inner_phi, l0_to_l1); + locus = gimple_phi_arg_location_from_edge (inner_phi, l0_to_l1); + edge entry_to_l0 = find_edge (entry_bb, l0_bb); + add_phi_arg (nphi, t, entry_to_l0, locus); + + edge l2_to_l0 = find_edge (l2_bb, l0_bb); + add_phi_arg (nphi, exit_res, l2_to_l0, UNKNOWN_LOCATION); + + add_phi_arg (inner_phi, new_res, l0_to_l1, UNKNOWN_LOCATION); + }; + } + + if (!broken_loop) + { set_immediate_dominator (CDI_DOMINATORS, l2_bb, recompute_dominator (CDI_DOMINATORS, l2_bb)); set_immediate_dominator (CDI_DOMINATORS, l3_bb, @@ -6464,14 +6509,20 @@ expand_omp_for_generic (struct omp_region *region, set_immediate_dominator (CDI_DOMINATORS, l1_bb, recompute_dominator (CDI_DOMINATORS, l1_bb)); + struct loop *loop = l1_bb->loop_father; + add_bb_to_loop (l2_bb, entry_bb->loop_father); + struct loop *outer_loop = alloc_loop (); outer_loop->header = l0_bb; outer_loop->latch = l2_bb; add_loop (outer_loop, l0_bb->loop_father); + if (loop != entry_bb->loop_father) + return; + if (!gimple_omp_for_combined_p (fd->for_stmt)) { - struct loop *loop = alloc_loop (); + loop = alloc_loop (); loop->header = l1_bb; /* The loop may have multiple latches. */ add_loop (loop, outer_loop); diff --git a/gcc/params.def b/gcc/params.def index 34e2025..7180d44 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -1145,6 +1145,12 @@ DEFPARAM (PARAM_PARLOOPS_CHUNK_SIZE, "parloops-chunk-size", "Chunk size of omp schedule for loops parallelized by parloops", 0, 0, 0) + +DEFPARAM (PARAM_PARLOOPS_SCHEDULE, + "parloops-schedule", + "Schedule type of omp schedule for loops parallelized by parloops " + "(0:static, 1:dynamic, 2:guided, 3:auto, 4:runtime)", + 0, 0, 4) /* Local variables: diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c index c164121..a9c9c44 100644 --- a/gcc/tree-parloops.c +++ b/gcc/tree-parloops.c @@ -2092,8 +2092,30 @@ create_parallel_loop (struct loop *loop, tree loop_fn, tree data, gimple_cond_set_lhs (cond_stmt, cvar_base); type = TREE_TYPE (cvar); t = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); - OMP_CLAUSE_SCHEDULE_KIND (t) = OMP_CLAUSE_SCHEDULE_STATIC; int chunk_size = PARAM_VALUE (PARAM_PARLOOPS_CHUNK_SIZE); + int schedule_type = PARAM_VALUE (PARAM_PARLOOPS_SCHEDULE); + switch (schedule_type) + { + case 0: + OMP_CLAUSE_SCHEDULE_KIND (t) = OMP_CLAUSE_SCHEDULE_STATIC; + break; + case 1: + OMP_CLAUSE_SCHEDULE_KIND (t) = OMP_CLAUSE_SCHEDULE_DYNAMIC; + break; + case 2: + OMP_CLAUSE_SCHEDULE_KIND (t) = OMP_CLAUSE_SCHEDULE_GUIDED; + break; + case 3: + OMP_CLAUSE_SCHEDULE_KIND (t) = OMP_CLAUSE_SCHEDULE_AUTO; + chunk_size = 0; + break; + case 4: + OMP_CLAUSE_SCHEDULE_KIND (t) = OMP_CLAUSE_SCHEDULE_RUNTIME; + chunk_size = 0; + break; + default: + gcc_unreachable (); + } if (chunk_size != 0) OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (t) = build_int_cst (integer_type_node, chunk_size); diff --git a/libgomp/testsuite/libgomp.c/autopar-3.c b/libgomp/testsuite/libgomp.c/autopar-3.c new file mode 100644 index 0000000..0bf30ac --- /dev/null +++ b/libgomp/testsuite/libgomp.c/autopar-3.c @@ -0,0 +1,4 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-parallelize-loops=4 -ffast-math --param parloops-schedule=1" } */ + +#include "autopar-1.c" diff --git a/libgomp/testsuite/libgomp.c/autopar-4.c b/libgomp/testsuite/libgomp.c/autopar-4.c new file mode 100644 index 0000000..1846acc --- /dev/null +++ b/libgomp/testsuite/libgomp.c/autopar-4.c @@ -0,0 +1,4 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-parallelize-loops=4 -ffast-math --param parloops-schedule=1 --param parloops-chunk-size=100" } */ + +#include "autopar-1.c" diff --git a/libgomp/testsuite/libgomp.c/autopar-5.c b/libgomp/testsuite/libgomp.c/autopar-5.c new file mode 100644 index 0000000..5fedf08 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/autopar-5.c @@ -0,0 +1,4 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-parallelize-loops=4 -ffast-math --param parloops-schedule=2" } */ + +#include "autopar-1.c" diff --git a/libgomp/testsuite/libgomp.c/autopar-6.c b/libgomp/testsuite/libgomp.c/autopar-6.c new file mode 100644 index 0000000..b45aa1c --- /dev/null +++ b/libgomp/testsuite/libgomp.c/autopar-6.c @@ -0,0 +1,4 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-parallelize-loops=4 -ffast-math --param parloops-schedule=2 --param parloops-chunk-size=100" } */ + +#include "autopar-1.c" diff --git a/libgomp/testsuite/libgomp.c/autopar-7.c b/libgomp/testsuite/libgomp.c/autopar-7.c new file mode 100644 index 0000000..7ca7c3f --- /dev/null +++ b/libgomp/testsuite/libgomp.c/autopar-7.c @@ -0,0 +1,4 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-parallelize-loops=4 -ffast-math --param parloops-schedule=3" } */ + +#include "autopar-1.c" diff --git a/libgomp/testsuite/libgomp.c/autopar-8.c b/libgomp/testsuite/libgomp.c/autopar-8.c new file mode 100644 index 0000000..80afb36 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/autopar-8.c @@ -0,0 +1,4 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-parallelize-loops=4 -ffast-math --param parloops-schedule=4" } */ + +#include "autopar-1.c" -- 1.9.1