From patchwork Wed Jul 17 21:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kwok Cheung Yeung X-Patchwork-Id: 1133453 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505235-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="gzRO3JBF"; dkim-atps=neutral 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 45pr6Y1ztvz9sBt for ; Thu, 18 Jul 2019 07:30:59 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; q=dns; s= default; b=W2Lhcee7zJMoB3s0Pm1sC4q5IBMfWZLY/4sVTZ+sz13OKX0SL4PkB qpdAB3sg2PH5wP+mhvNMd9Yxe2t5up715dAPZrH5SRkCKMQx8qy9WhiNXTmc0us2 0WPHgxO2jXg1+CyBcfMcje2VH97wKV8KKhqNvJUt2ONFFUqsuLC0yE= 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:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=default; bh=ciwX3yLZw+A6DsiiUlYSrzFem1M=; b=gzRO3JBFWo8tejQ3F//ZtEMOxf5L L+Rj1CCgQeD0S+kosRRytJsoK0MqOkF6xoV6XmeKheY/JOXiUwOrPQ6otma1Yu/Y V9NdfJISmw2eKIBHtjaMJJGw6fd3KSAApsMaBxX3ed2+bsgeQ7xb5W4NoKy51vrj Vr5ti6G0mZmaz04= Received: (qmail 39745 invoked by alias); 17 Jul 2019 21:30:51 -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 39667 invoked by uid 89); 17 Jul 2019 21:30:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= 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, 17 Jul 2019 21:30:43 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1hnrVZ-0002dd-Pe from Kwok_Yeung@mentor.com ; Wed, 17 Jul 2019 14:30:41 -0700 Received: from [172.30.64.32] (137.202.0.90) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 17 Jul 2019 22:30:37 +0100 Subject: [PATCH 09/10, OpenACC] Avoid introducing 'create' mapping clauses for loop index variables in kernels regions From: Kwok Cheung Yeung To: , Jakub Jelinek CC: Thomas Schwinge , Julian Brown References: <5e191259-d5d5-34ce-7fd5-fc8d2e6d982e@codesourcery.com> Message-ID: <846179c6-abad-fbdb-b44a-a05b7b1eb9be@codesourcery.com> Date: Wed, 17 Jul 2019 22:30:33 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <5e191259-d5d5-34ce-7fd5-fc8d2e6d982e@codesourcery.com> This patch avoids adding CREATE mapping clauses for loop index variables. It also sets TREE_ADDRESSABLE on newly mapped declarations, which fixes an ICE that sometimes appears due to an assert firing in omp-low.c. 2019-07-16 Julian Brown gcc/ * omp-oacc-kernels.c (find_omp_for_index_vars_1, find_omp_for_index_vars): New functions. (maybe_build_inner_data_region): Add IDX_VARS argument. Don't add CREATE mapping clauses for loop index variables. Set TREE_ADDRESSABLE flag on newly-mapped declarations as a side effect. (decompose_kernels_region_body): Call find_omp_for_index_vars. Don't create PRESENT clause for loop index variables. Pass index variable set to maybe_build_inner_data_region. --- gcc/omp-oacc-kernels.c | 58 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 7 deletions(-) clauses for them and add these clauses to the list of clauses to be @@ -1163,7 +1205,9 @@ decompose_kernels_region_body (gimple *kernels_region, tree kernels_clauses) tree present_clauses = kernels_clauses; for (tree var = inner_bind_vars; var; var = TREE_CHAIN (var)) { - if (!DECL_ARTIFICIAL (var) && TREE_CODE (var) != CONST_DECL) + if (!DECL_ARTIFICIAL (var) + && TREE_CODE (var) != CONST_DECL + && !idx_vars.contains (var)) { tree present_clause = build_omp_clause (loc, OMP_CLAUSE_MAP); OMP_CLAUSE_SET_MAP_KIND (present_clause, GOMP_MAP_FORCE_PRESENT); @@ -1342,7 +1386,7 @@ decompose_kernels_region_body (gimple *kernels_region, tree kernels_clauses) /* If we found variables declared in nested scopes, build a data region to map them to the device. */ body = maybe_build_inner_data_region (loc, body, inner_bind_vars, - inner_cleanup); + inner_cleanup, &idx_vars); return body; } diff --git a/gcc/omp-oacc-kernels.c b/gcc/omp-oacc-kernels.c index d65e6c6..2091385 100644 --- a/gcc/omp-oacc-kernels.c +++ b/gcc/omp-oacc-kernels.c @@ -766,6 +766,43 @@ flatten_binds (gbind *bind, bool include_toplevel_vars = false) return vars; } +/* Recursively search BODY_SEQUENCE for 'for' loops, and record their loop + indices in IDX_VARS. */ + +static void +find_omp_for_index_vars_1 (gimple_seq body_sequence, hash_set *idx_vars) +{ + gimple_stmt_iterator gsi; + + for (gsi = gsi_start (body_sequence); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + gimple *for_stmt = top_level_omp_for_in_stmt (stmt); + + if (for_stmt) + { + tree idx = gimple_omp_for_index (for_stmt, 0); + idx_vars->add (idx); + find_omp_for_index_vars_1 (gimple_omp_body (for_stmt), idx_vars); + } + else if (gimple_code (stmt) == GIMPLE_BIND) + find_omp_for_index_vars_1 (gimple_bind_body (as_a (stmt)), + idx_vars); + } +} + +/* Find all loop index variables in a bind. */ + +static hash_set +find_omp_for_index_vars (gbind *bind) +{ + hash_set idx_vars; + + find_omp_for_index_vars_1 (gimple_bind_body (bind), &idx_vars); + + return idx_vars; +} + /* Helper function for places where we construct data regions. Wraps the BODY inside a try-finally construct at LOC that calls __builtin_GOACC_data_end in its cleanup block. Returns this try statement. */ @@ -784,13 +821,15 @@ make_data_region_try_statement (location_t loc, gimple *body) /* If INNER_BIND_VARS holds variables, build an OpenACC data region with location LOC containing BODY and having "create(var)" clauses for each - variable. If INNER_CLEANUP is present, add a try-finally statement with - this cleanup code in the finally block. Return the new data region, or - the original BODY if no data region was needed. */ + variable (such variables are also made addressable as a side effect). If + INNER_CLEANUP is present, add a try-finally statement with this cleanup + code in the finally block. Return the new data region, or the original + BODY if no data region was needed. */ static gimple * maybe_build_inner_data_region (location_t loc, gimple *body, - tree inner_bind_vars, gimple *inner_cleanup) + tree inner_bind_vars, gimple *inner_cleanup, + hash_set *idx_vars) { /* Build data "create(var)" clauses for these local variables. Below we will add these to a data region enclosing the entire body @@ -817,7 +856,7 @@ maybe_build_inner_data_region (location_t loc, gimple *body, else inner_bind_vars = next; } - else + else if (!idx_vars->contains (v)) { /* Otherwise, build the map clause. */ tree new_clause = build_omp_clause (loc, OMP_CLAUSE_MAP); @@ -825,6 +864,7 @@ maybe_build_inner_data_region (location_t loc, gimple *body, OMP_CLAUSE_DECL (new_clause) = v; OMP_CLAUSE_SIZE (new_clause) = DECL_SIZE_UNIT (v); OMP_CLAUSE_CHAIN (new_clause) = inner_data_clauses; + TREE_ADDRESSABLE (v) = 1; inner_data_clauses = new_clause; prev_mapped_var = v; @@ -1156,6 +1196,8 @@ decompose_kernels_region_body (gimple *kernels_region, tree kernels_clauses) tree inner_bind_vars = flatten_binds (kernels_bind); gimple_seq body_sequence = gimple_bind_body (kernels_bind); + hash_set idx_vars = find_omp_for_index_vars (kernels_bind); + /* All these inner variables will get allocated on the device (below, by calling maybe_build_inner_data_region). Here we create "present"