From 752ef8f4f5ddf9a3372e6d5dc08df6aa05a60ea3 Mon Sep 17 00:00:00 2001 From: Kwok Cheung Yeung Date: Mon, 13 Jan 2025 13:08:07 +0000 Subject: openmp: Add support for using custom mappers with iterators (C, C++) gcc/c-family/ * c-omp.cc (omp_instantiate_mapper): Apply iterator to new clauses generated from mapper. gcc/c/ * c-parser.cc (c_parser_omp_clause_map): Apply iterator to push and pop mapper clauses. gcc/cp/ * parser.cc (cp_parser_omp_clause_map): Apply iterator to push and pop mapper clauses. * semantics.cc (cxx_omp_map_array_section): Allow array types for base type of array sections. libgomp/ * testsuite/libgomp.c-c++-common/mapper-iterators-1.c: New test. * testsuite/libgomp.c-c++-common/mapper-iterators-2.c: New test. * testsuite/libgomp.c-c++-common/mapper-iterators-3.c: New test. Co-authored-by: Andrew Stubbs --- gcc/c-family/c-omp.cc | 2 ++ gcc/c/c-parser.cc | 4 ++++ gcc/cp/parser.cc | 4 ++++ gcc/cp/semantics.cc | 3 ++- 4 files changed, 12 insertions(+), 1 deletion(-) (limited to 'gcc') diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc index 7d33318..a3cd1ae 100644 --- a/gcc/c-family/c-omp.cc +++ b/gcc/c-family/c-omp.cc @@ -4761,6 +4761,7 @@ omp_instantiate_mapper (location_t loc, tree *outlist, tree mapper, tree expr, tree clauses = OMP_DECLARE_MAPPER_CLAUSES (mapper); tree dummy_var = OMP_DECLARE_MAPPER_DECL (mapper); tree mapper_name = NULL_TREE; + tree iterator = *outlist ? OMP_CLAUSE_ITERATORS (*outlist) : NULL_TREE; remap_mapper_decl_info map_info; map_info.dummy_var = dummy_var; @@ -4889,6 +4890,7 @@ omp_instantiate_mapper (location_t loc, tree *outlist, tree mapper, tree expr, } else { + OMP_CLAUSE_ITERATORS (unshared) = iterator; *outlist = unshared; outlist = &OMP_CLAUSE_CHAIN (unshared); } diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 8a5b493..31ab7d0 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -20738,6 +20738,8 @@ c_parser_omp_clause_map (c_parser *parser, tree list, enum gomp_map_kind kind) tree name = build_omp_clause (input_location, OMP_CLAUSE_MAP); OMP_CLAUSE_SET_MAP_KIND (name, GOMP_MAP_PUSH_MAPPER_NAME); OMP_CLAUSE_DECL (name) = mapper_name; + if (iterators) + OMP_CLAUSE_ITERATORS (name) = iterators; OMP_CLAUSE_CHAIN (name) = nl; nl = name; @@ -20746,6 +20748,8 @@ c_parser_omp_clause_map (c_parser *parser, tree list, enum gomp_map_kind kind) name = build_omp_clause (input_location, OMP_CLAUSE_MAP); OMP_CLAUSE_SET_MAP_KIND (name, GOMP_MAP_POP_MAPPER_NAME); OMP_CLAUSE_DECL (name) = null_pointer_node; + if (iterators) + OMP_CLAUSE_ITERATORS (name) = iterators; OMP_CLAUSE_CHAIN (name) = OMP_CLAUSE_CHAIN (last_new); OMP_CLAUSE_CHAIN (last_new) = name; } diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 83e0220..f38a327 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -43344,6 +43344,8 @@ cp_parser_omp_clause_from_to (cp_parser *parser, enum omp_clause_code kind, name = build_omp_clause (input_location, OMP_CLAUSE_MAP); OMP_CLAUSE_SET_MAP_KIND (name, GOMP_MAP_POP_MAPPER_NAME); OMP_CLAUSE_DECL (name) = null_pointer_node; + if (iterators) + OMP_CLAUSE_ITERATORS (name) = iterators; OMP_CLAUSE_CHAIN (name) = OMP_CLAUSE_CHAIN (last_new); OMP_CLAUSE_CHAIN (last_new) = name; } @@ -43659,6 +43661,8 @@ cp_parser_omp_clause_map (cp_parser *parser, tree list, enum gomp_map_kind kind) tree name = build_omp_clause (input_location, OMP_CLAUSE_MAP); OMP_CLAUSE_SET_MAP_KIND (name, GOMP_MAP_PUSH_MAPPER_NAME); OMP_CLAUSE_DECL (name) = mapper_name; + if (iterators) + OMP_CLAUSE_ITERATORS (name) = iterators; OMP_CLAUSE_CHAIN (name) = nlist; nlist = name; diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index b80bf33..770872a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -6998,7 +6998,8 @@ cxx_omp_map_array_section (location_t loc, tree t) if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE) t = convert_from_reference (t); - if (TYPE_PTR_P (TREE_TYPE (t))) + if (TYPE_PTR_P (TREE_TYPE (t)) + || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) t = build_array_ref (loc, t, low); else t = error_mark_node; -- cgit v1.1