From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1729) id CEEE93AA7C84; Thu, 13 May 2021 16:10:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEEE93AA7C84 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Kwok Yeung To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-11] Avoid introducing 'create' mapping clauses for loop index variables in kernels regions X-Act-Checkin: gcc X-Git-Author: Julian Brown X-Git-Refname: refs/heads/devel/omp/gcc-11 X-Git-Oldrev: 526068fc0de093be52c376bfc1b7172bb9edf726 X-Git-Newrev: dd55d4aa80ffc6a421927d8dfff078e6a908edc0 Message-Id: <20210513161037.CEEE93AA7C84@sourceware.org> Date: Thu, 13 May 2021 16:10:37 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 May 2021 16:10:37 -0000 https://gcc.gnu.org/g:dd55d4aa80ffc6a421927d8dfff078e6a908edc0 commit dd55d4aa80ffc6a421927d8dfff078e6a908edc0 Author: Julian Brown Date: Thu May 16 05:45:35 2019 -0700 Avoid introducing 'create' mapping clauses for loop index variables in kernels regions gcc/ * omp-oacc-kernels-decompose.cc (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. Diff: --- gcc/ChangeLog.omp | 11 ++++++++ gcc/omp-oacc-kernels-decompose.cc | 58 ++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index b1bece2fe28..7a3d381b055 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,14 @@ +2019-05-16 Julian Brown + + * omp-oacc-kernels-decompose.cc (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. + 2019-01-23 Thomas Schwinge * params.opt (openacc_kernels): Default to decompose. diff --git a/gcc/omp-oacc-kernels-decompose.cc b/gcc/omp-oacc-kernels-decompose.cc index 4ba5758a906..14b5a8ec342 100644 --- a/gcc/omp-oacc-kernels-decompose.cc +++ b/gcc/omp-oacc-kernels-decompose.cc @@ -775,6 +775,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. */ @@ -793,13 +830,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) { /* Is this an instantiation of a template? (In this case, we don't care what the generic decl is - just whether the function decl has one.) */ @@ -831,7 +870,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); @@ -839,6 +878,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; @@ -1170,6 +1210,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' clauses for them and add these clauses to the list of clauses to be @@ -1177,7 +1219,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); @@ -1356,7 +1400,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; }