aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.cc
diff options
context:
space:
mode:
authorChung-Lin Tang <cltang@baylibre.com>2025-05-02 00:27:53 +0000
committerSandra Loosemore <sloosemore@baylibre.com>2025-05-15 20:25:51 +0000
commit5fd60a678116773e99d5fd2d64a118f837e5d6f0 (patch)
tree2821bef94bfb75dceeec8369d9227e3ba0fe1b9a /gcc/c/c-parser.cc
parent3dfe9733eabd74f21999dde36166bdedc5d06b1c (diff)
downloadgcc-5fd60a678116773e99d5fd2d64a118f837e5d6f0.zip
gcc-5fd60a678116773e99d5fd2d64a118f837e5d6f0.tar.gz
gcc-5fd60a678116773e99d5fd2d64a118f837e5d6f0.tar.bz2
OpenACC 2.7: Implement reductions for arrays and records
This patch is a merge of: https://gcc.gnu.org/pipermail/gcc-patches/2025-February/675222.html This patch implements reductions for arrays, array sections, and struct/record types as according to the OpenACC 2.7 specification. 2025-02-23 Chung-Lin Tang <cltang@baylibre.com> gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_variable_list): Adjust parsing of opening square bracket. (c_parser_omp_clause_reduction): Adjustments for OpenACC-specific cases. * c-typeck.cc (c_oacc_reduction_defined_type_p): New function. (c_oacc_reduction_code_name): Likewise. (c_finish_omp_clauses): Handle OpenACC cases using new functions. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_var_list_no_open): Adjust parsing of opening square bracket. (cp_parser_omp_clause_reduction): Adjustments for OpenACC-specific cases. * semantics.cc (cp_oacc_reduction_defined_type_p): New function. (cp_oacc_reduction_code_name): Likewise. (finish_omp_reduction_clause): Handle OpenACC cases using new functions. gcc/fortran/ChangeLog: * openmp.cc (oacc_reduction_defined_type_p): New function. (resolve_omp_clauses): Adjust OpenACC array reduction error case. Adjust OMP_LIST_REDUCTION case. Use oacc_reduction_defined_type_p for OpenACC. * trans-openmp.cc (gfc_trans_omp_array_reduction_or_udr): Add 'stmtblock_t *block', and 'bool openacc' parameters. Add array and array section handling for openacc case. Adjust part of function to be !openacc only. (gfc_trans_omp_reduction_list): Add 'stmtblock_t *block', and 'bool openacc' parameters, pass to calls to gfc_trans_omp_array_reduction_or_udr. (gfc_trans_omp_array_section): Adjust setting of OMP_CLAUSE_SIZE to only OMP_CLAUSE_MAP clauses. Adjust calculations of decls and bias to use temporary variables instead of tree expression inside clauses. (gfc_trans_omp_clauses): Add 'block' and 'openacc' arguments to calls to gfc_trans_omp_reduction_list. (gfc_trans_omp_do): Pass 'op == EXEC_OACC_LOOP' as 'bool openacc' parameter in call to gfc_trans_omp_clauses. gcc/ChangeLog: * config/gcn/gcn-tree.cc (#include "omp-offload.h"): Add include. (#include "memmodel.h"): Add include. (gcn_array_reduction_buffers): New vec<tree> for holding DECLs for reduction buffer pointer variables. (gcn_lockfull_update): Add pointer type fold_converts. (gcn_reduction_update): Additions for handling ARRAY_TYPE, pointer to ARRAY_TYPE, and RECORD_TYPE reductions. (gcn_goacc_get_worker_red_decl): Adjust parameters to handle non-constant offset case. (gcn_goacc_get_worker_array_reduction_buffer): New function. (gcn_create_if_else_seq): New function. (gcn_create_do_while_loop_seq): New function. (gcn_goacc_reduction_setup): Adjustments to handle arrays and records. (gcn_goacc_reduction_init): Likewise. (gcn_goacc_reduction_fini): Likewise. (gcn_goacc_reduction_teardown): Likewise. * config/nvptx/nvptx.cc (nvptx_gen_shuffle): Properly generate V2SI shuffle using vec_extract op. (nvptx_expand_shared_addr): Adjustments to handle non-constant size. (nvptx_get_shared_red_addr): Adjust type/alignment calculations to use TYPE_SIZE/ALIGN_UNIT instead of machine mode based. (nvptx_get_shared_red_addr): New function with array_max_idx parameter. (nvptx_reduction_update): Additions for handling ARRAY_TYPE, pointer to ARRA_TYPE, and RECORD_TYPE reductions. (nvptx_goacc_reduction_setup): Likewise. (nvptx_goacc_reduction_init): Likewise. (nvptx_goacc_reduction_fini): Likewise. (nvptx_goacc_reduction_teardown): Likewise. * gimplify.cc (gimplify_scan_omp_clauses): Gimplify inside COMPONENT_REF and convert codes for OMP_CLAUSE_REDUCTION cases. Add DECL_P check for do_add/do_add_decl goto case. (gimplify_adjust_omp_clauses): Avoid GOMP_MAP_POINTER OMP_CLAUSE_SIZE handling for OpenACC kernels. Call omp_add_variable for ARRAY_REF index. Peel away array MEM_REF for decl lookup. * omp-low.cc (struct omp_context): Add 'hash_map<tree, tree> *block_vars_map' field. (omp_copy_decl_2): Create/lookup using ctx->block_vars_map first. Add new copy into ctx->block_vars_map. (install_var_field): Add 'bool field_may_exist = false' parameter. Adjust lookup assertions. (delete_omp_context): Add delete of ctx->block_vars_map. (scan_sharing_clauses): Adjust calls to install_var_field. Adjust ARRAY_REF pointer type building to use decl type, rather than generic ptr_type_node. For ARRAY_REFs on offloaded constructs, also add base expression as field lookup key. (omp_reduction_init_op): Add ARRAY_TYPE and RECORD_TYPE init op construction. (oacc_array_reduction_bias): New function. (lower_oacc_reductions): Add array reduction handling code. Arrays use a different mode of IFN parameters, using additional 'array_addr' and 'array_max_idx' arguments. The LHS var is a simple integer for dependency ordering. (lower_omp_target): Adjust 'offload' condition for GOMP_MAP_POINTER case. Generate BUILT_IN_ALLOCA_WITH_ALIGN to create private copy for reductions of non-constant size types. * omp-oacc-neuter-broadcast.cc (worker_single_copy): Add 'hash_set<tree> *array_reduction_base_vars' parameter. Avoid propagation for SSA_NAMEs used for array reduction accesses. (neuter_worker_single): Add 'hash_set<tree> *array_reduction_base_vars' parameter. Adjust recursive calls to self and worker_single_copy. (oacc_do_neutering): Add 'hash_set<tree> *array_reduction_base_vars' parameter. Adjust call to neuter_worker_single. (execute_omp_oacc_neuter_broadcast): Add local 'hash_set<tree> array_reduction_base_vars' declaration. Collect MEM_REF base-pointer SSA_NAMEs of arrays into array_reduction_base_vars. Add '&array_reduction_base_vars' argument to call of oacc_do_neutering. * omp-offload.cc (#include "cfghooks.h"): Add include. (oacc_build_array_copy): New function. (oacc_build_array_copy_loop): New function. (oacc_build_indexed_ssa_loop): New function. (default_goacc_reduction): Adjustments to handle arrays. * omp-offload.h (oacc_build_array_copy): New declaration. (oacc_build_array_copy_loop): New declaration. (oacc_build_indexed_ssa_loop): New declaration. * tree-loop-distribution.cc (generate_memset_builtin): Under OpenACC, when last stmt of pre-header block is a UNIQUE(OACC_FORK) internal-fn, split a new basic block to serve as place of insertion, otherwise may fail later checking because UNIQUE(OACC_FORK) counts as control flow stmt. (generate_memcpy_builtin): Likewise. gcc/testsuite/ChangeLog: * c-c++-common/goacc/readonly-2.c: Adjust test. * c-c++-common/goacc/reduction-9.c: Adjust test. * c-c++-common/goacc/reduction-11.c: New test. * c-c++-common/goacc/reduction-12.c: New test. * c-c++-common/goacc/reduction-13.c: New test. * c-c++-common/goacc/reduction-14.c: New test. * c-c++-common/goacc/reduction-15.c: New test. * c-c++-common/goacc/reduction-16.c: New test. * g++.dg/goacc/reductions-1.C: Adjust test. * gfortran.dg/goacc/array-reduction.f90: Adjust test. * gfortran.dg/goacc/enter-exit-data-2.f90: Adjust test. * gfortran.dg/goacc/finalize-1.f: Adjust test. * gfortran.dg/goacc/kernels-decompose-1.f95: Adjust test. * gfortran.dg/goacc/pr70828.f90: Adjust test. * gfortran.dg/goacc/reduction.f95: Adjust test. * gfortran.dg/gomp/target-enter-exit-data.f90: Adjust test. libgomp/ChangeLog: * testsuite/libgomp.oacc-c-c++-common/reduction.h (check_reduction_array_xx): New macro. (operator_apply): Likewise. (check_reduction_array_op): Likewise. (check_reduction_arraysec_op): Likewise. (function_apply): Likewise. (check_reduction_array_macro): Likewise. (check_reduction_arraysec_macro): Likewise. (check_reduction_xxx_xx_all): Likewise. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-2.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-3.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-4.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-arrays-5.c: New test. * testsuite/libgomp.oacc-c-c++-common/reduction-structs-1.c: New test. * testsuite/libgomp.oacc-fortran/reduction-10.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-11.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-12.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-13.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-14.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-15.f90: New test. * testsuite/libgomp.oacc-fortran/reduction-16.f90: New test.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r--gcc/c/c-parser.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 6d607e9..fbaa917 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -16945,8 +16945,7 @@ c_parser_omp_variable_list (c_parser *parser,
case OMP_CLAUSE_HAS_DEVICE_ADDR:
array_section_p = false;
dims.truncate (0);
- while ((ort != C_ORT_ACC || kind != OMP_CLAUSE_REDUCTION)
- && c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
+ while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE))
{
location_t loc = UNKNOWN_LOCATION;
tree low_bound = NULL_TREE, length = NULL_TREE;
@@ -18867,13 +18866,21 @@ c_parser_omp_clause_reduction (c_parser *parser, enum omp_clause_code kind,
code = MAX_EXPR;
break;
}
+ if (ort == C_ORT_ACC)
+ goto name_error;
reduc_id = c_parser_peek_token (parser)->value;
break;
}
default:
- c_parser_error (parser,
- "expected %<+%>, %<*%>, %<-%>, %<&%>, "
- "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
+ name_error:
+ if (ort == C_ORT_OMP)
+ c_parser_error (parser,
+ "expected %<+%>, %<*%>, %<-%>, %<&%>, "
+ "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
+ else
+ c_parser_error (parser,
+ "expected %<+%>, %<*%>, %<-%>, %<&%>, "
+ "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0);
return list;
}
@@ -18887,6 +18894,11 @@ c_parser_omp_clause_reduction (c_parser *parser, enum omp_clause_code kind,
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
{
+ OMP_CLAUSE_REDUCTION_CODE (c) = code;
+ /* OpenACC does not require anything below. */
+ if (ort == C_ORT_ACC)
+ continue;
+
tree d = OMP_CLAUSE_DECL (c), type;
if (TREE_CODE (d) != OMP_ARRAY_SECTION)
type = TREE_TYPE (d);
@@ -18910,7 +18922,6 @@ c_parser_omp_clause_reduction (c_parser *parser, enum omp_clause_code kind,
}
while (TREE_CODE (type) == ARRAY_TYPE)
type = TREE_TYPE (type);
- OMP_CLAUSE_REDUCTION_CODE (c) = code;
if (task)
OMP_CLAUSE_REDUCTION_TASK (c) = 1;
else if (inscan)