From patchwork Mon Oct 12 15:09:19 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: 529170 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 727291402A8 for ; Tue, 13 Oct 2015 02:10:29 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=FX/aqsxr; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=QglPrCm1PgK3Fln6D hIZs9zV8MqqDDrDBzlZROY/CD8vDLa1VwV3XcwFrETNPF95Cm1YH+jFmJAvykgp3 sGgl+jwl7SQRmIhLyYDWMoGYYAsO3Ku1uv6yyx39rRM6gV9gTsG72ZVkMbhdL1Nd cT2PJ0zkEuN7l0U6rGEf1719A4= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=c5gwD5L8sRtHXM8v6CyCKa/ mCSs=; b=FX/aqsxrkUH6j++7PjMeWJXNqj7PjnS6LG64I6lBXblt1zOS7xBwNyn YWkF6K2MlWlgQ8imxlDQ4DH+ihCgxi1BmVRyLiI/675hgQs87zUDBvPu6FwcUatg nG8mVRsnwI9N42j8R2iIKZjPYiZiVCR+gariOnzJyahYXY5C6jWo= Received: (qmail 54395 invoked by alias); 12 Oct 2015 15:10:18 -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 54384 invoked by uid 89); 12 Oct 2015 15:10:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, 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; Mon, 12 Oct 2015 15:10:16 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54530) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1Zlejt-00075r-T3 for gcc-patches@gnu.org; Mon, 12 Oct 2015 11:10:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zlejn-0002Av-Ok for gcc-patches@gnu.org; Mon, 12 Oct 2015 11:10:13 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:64571) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zlejn-0002AU-H6 for gcc-patches@gnu.org; Mon, 12 Oct 2015 11:10:07 -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 1Zlejm-00008F-Md from Tom_deVries@mentor.com ; Mon, 12 Oct 2015 08:10:07 -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; Mon, 12 Oct 2015 16:10:05 +0100 Subject: [committed. gomp4, 5/6] Add oacc kernels related infra functions To: "gcc-patches@gnu.org" References: <561BC874.2020908@mentor.com> CC: Jakub Jelinek From: Tom de Vries Message-ID: <561BCD1F.90108@mentor.com> Date: Mon, 12 Oct 2015 17:09:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <561BC874.2020908@mentor.com> X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 On 12/10/15 16:49, Tom de Vries wrote: > Hi, > > I've committed the following patch series to the gomp-4_0-branch. > > 1 Add pass_dominator::jump_threading_p () > 2 Add dom_walker::walk_until > 3 Add pass_dominator::sese_mode_p () > 4 Add skip_stmt parm to pass_dominator::get_sese () > 5 Add oacc kernels related infra functions > 6 Add pass_dominator_oacc_kernels > > The patch series adds a pass pass_dominator_oacc_kernels, which does the > pass_dominator optimizations (with the exception of jump threading) on > each oacc kernels region rather than on the whole function. > > Bootstrapped and reg-tested on x86_64. > > I'll post the patches individually, in reply to this email. This patch adds three new oacc kernels region related infrastructure functions: extern tree get_omp_data_i (basic_block); extern bool oacc_kernels_region_entry_p (basic_block, gomp_target **); extern basic_block get_oacc_kernels_region_exit (basic_block); Thanks, - Tom Add oacc kernels related infra functions 2015-10-12 Tom de Vries * omp-low.c (get_oacc_kernels_region_exit, get_omp_data_i): New function. (oacc_kernels_region_entry_p): New function. Factor out of ... (gimple_stmt_omp_data_i_init_p): ... here. * omp-low.h (get_oacc_kernels_region_exit, oacc_kernels_region_entry_p) (get_omp_data_i): Declare. --- gcc/omp-low.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ gcc/omp-low.h | 3 ++ 2 files changed, 96 insertions(+), 9 deletions(-) diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 2b2c3a7..2289486 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -9981,6 +9981,53 @@ loop_get_oacc_kernels_region_entry (struct loop *loop) } } +/* Return the oacc kernels region exit corresponding to REGION_ENTRY. */ + +basic_block +get_oacc_kernels_region_exit (basic_block region_entry) +{ + gcc_checking_assert (oacc_kernels_region_entry_p (region_entry, NULL)); + + bitmap to_visit = BITMAP_ALLOC (NULL); + bitmap visited = BITMAP_ALLOC (NULL); + bitmap_clear (to_visit); + bitmap_clear (visited); + + bitmap_set_bit (to_visit, region_entry->index); + + basic_block bb; + while (true) + { + if (bitmap_empty_p (to_visit)) + { + bb = NULL; + break; + } + + unsigned int index = bitmap_first_set_bit (to_visit); + bitmap_clear_bit (to_visit, index); + bitmap_set_bit (visited, index); + bb = BASIC_BLOCK_FOR_FN (cfun, index); + + gimple *last = last_stmt (bb); + if (last != NULL + && gimple_code (last) == GIMPLE_OMP_RETURN) + break; + + edge_iterator ei; + for (ei = ei_start (bb->succs); !ei_end_p (ei); ei_next (&ei)) + { + edge e = ei_edge (ei); + unsigned int dest_index = e->dest->index; + if (!bitmap_bit_p (visited, dest_index)) + bitmap_set_bit (to_visit, dest_index); + } + } + + BITMAP_FREE (to_visit); + return bb; +} + /* Encode an oacc launch argument. This matches the GOMP_LAUNCH_PACK macro on gomp-constants.h. We do not check for overflow. */ @@ -15154,6 +15201,31 @@ omp_finish_file (void) } } +/* Return true if BB is an oacc kernels region entry. If DIRECTIVE is non-null, + return the corresponding kernels directive in *DIRECTIVE. */ + +bool +oacc_kernels_region_entry_p (basic_block bb, gomp_target **directive) +{ + /* Check that the last statement in the preceding bb is an oacc kernels + stmt. */ + if (!single_pred_p (bb)) + return false; + gimple *last = last_stmt (single_pred (bb)); + if (last == NULL + || gimple_code (last) != GIMPLE_OMP_TARGET) + return false; + gomp_target *kernels = as_a (last); + + bool res = (gimple_omp_target_kind (kernels) + == GF_OMP_TARGET_KIND_OACC_KERNELS); + + if (res && directive) + *directive = kernels; + + return res; +} + /* Return true if STMT is copy assignment .omp_data_i = &.omp_data_arr. */ bool @@ -15171,15 +15243,8 @@ gimple_stmt_omp_data_i_init_p (gimple *stmt) /* Check that the last statement in the preceding bb is an oacc kernels stmt. */ basic_block bb = gimple_bb (stmt); - if (!single_pred_p (bb)) - return false; - gimple *last = last_stmt (single_pred (bb)); - if (last == NULL - || gimple_code (last) != GIMPLE_OMP_TARGET) - return false; - gomp_target *kernels = as_a (last); - if (gimple_omp_target_kind (kernels) - != GF_OMP_TARGET_KIND_OACC_KERNELS) + gomp_target *kernels; + if (!oacc_kernels_region_entry_p (bb, &kernels)) return false; /* Get omp_data_arr from the oacc kernels stmt. */ @@ -15190,6 +15255,25 @@ gimple_stmt_omp_data_i_init_p (gimple *stmt) return operand_equal_p (obj, omp_data_arr, 0); } + +/* Return omp_data_i corresponding to the assignment + .omp_data_i = &.omp_data_arr in oacc kernels region entry REGION_ENTRY. */ + +tree +get_omp_data_i (basic_block region_entry) +{ + if (!single_succ_p (region_entry)) + return NULL_TREE; + basic_block bb = single_succ (region_entry); + gimple_stmt_iterator gsi = gsi_start_bb (bb); + if (gsi_end_p (gsi)) + return NULL_TREE; + gimple *stmt = gsi_stmt (gsi); + if (!gimple_stmt_omp_data_i_init_p (stmt)) + return NULL_TREE; + return gimple_assign_lhs (stmt); +} + namespace { const pass_data pass_data_late_lower_omp = diff --git a/gcc/omp-low.h b/gcc/omp-low.h index febcbd7..62a7d4a 100644 --- a/gcc/omp-low.h +++ b/gcc/omp-low.h @@ -30,6 +30,9 @@ extern tree omp_reduction_init (tree, tree); extern bool make_gimple_omp_edges (basic_block, struct omp_region **, int *); extern void omp_finish_file (void); extern bool gimple_stmt_omp_data_i_init_p (gimple *); +extern tree get_omp_data_i (basic_block); +extern bool oacc_kernels_region_entry_p (basic_block, gomp_target **); +extern basic_block get_oacc_kernels_region_exit (basic_block); extern basic_block loop_get_oacc_kernels_region_entry (struct loop *); extern void replace_oacc_fn_attrib (tree, tree); extern tree build_oacc_routine_dims (tree); -- 1.9.1