aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.cc
diff options
context:
space:
mode:
authorKwok Cheung Yeung <kcyeung@baylibre.com>2024-11-27 21:51:34 +0000
committerSandra Loosemore <sloosemore@baylibre.com>2025-05-15 20:25:52 +0000
commit176d660537b2edc8007a4bed1eb936d881a46277 (patch)
treea8e59a62cfbf3e83bf734ac1ddd2b29de9c35719 /gcc/c/c-parser.cc
parent4756123b29d183da7f57533d4ef67c6361fb2a79 (diff)
downloadgcc-176d660537b2edc8007a4bed1eb936d881a46277.zip
gcc-176d660537b2edc8007a4bed1eb936d881a46277.tar.gz
gcc-176d660537b2edc8007a4bed1eb936d881a46277.tar.bz2
openmp: Add support for iterators in 'target update' clauses (C/C++)
This adds support for iterators in 'to' and 'from' clauses in the 'target update' OpenMP directive. gcc/c/ * c-parser.cc (c_parser_omp_clause_from_to): Parse 'iterator' modifier. * c-typeck.cc (c_finish_omp_clauses): Finish iterators for to/from clauses. gcc/cp/ * parser.cc (cp_parser_omp_clause_from_to): Parse 'iterator' modifier. * semantics.cc (finish_omp_clauses): Finish iterators for to/from clauses. gcc/ * gimplify.cc (gimplify_scan_omp_clauses): Add argument for iterator loop sequence. Gimplify the clause decl and size into the iterator loop if iterators are used. (gimplify_omp_workshare): Add argument for iterator loops sequence in call to gimplify_scan_omp_clauses. (gimplify_omp_target_update): Call remove_unused_omp_iterator_vars and build_omp_iterators_loops. Add loop sequence as argument when calling gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses and building the Gimple statement. * tree-pretty-print.cc (dump_omp_clause): Call dump_omp_iterators for to/from clauses with iterators. * tree.cc (omp_clause_num_ops): Add extra operand for OMP_CLAUSE_FROM and OMP_CLAUSE_TO. * tree.h (OMP_CLAUSE_HAS_ITERATORS): Add check for OMP_CLAUSE_TO and OMP_CLAUSE_FROM. (OMP_CLAUSE_ITERATORS): Likewise. gcc/testsuite/ * c-c++-common/gomp/target-update-iterators-1.c: New. * c-c++-common/gomp/target-update-iterators-2.c: New. * c-c++-common/gomp/target-update-iterators-3.c: New. libgomp/ * target.c (gomp_update): Call gomp_merge_iterator_maps. Free allocated variables. * testsuite/libgomp.c-c++-common/target-update-iterators-1.c: New. * testsuite/libgomp.c-c++-common/target-update-iterators-2.c: New. * testsuite/libgomp.c-c++-common/target-update-iterators-3.c: New.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r--gcc/c/c-parser.cc55
1 files changed, 45 insertions, 10 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 8c85cce..f1c7efc 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20988,8 +20988,11 @@ c_parser_omp_clause_device_type (c_parser *parser, tree list)
to ( variable-list )
OpenMP 5.1:
- from ( [present :] variable-list )
- to ( [present :] variable-list ) */
+ from ( [motion-modifier[,] [motion-modifier[,]...]:] variable-list )
+ to ( [motion-modifier[,] [motion-modifier[,]...]:] variable-list )
+
+ motion-modifier:
+ present | iterator (iterators-definition) */
static tree
c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind,
@@ -21001,20 +21004,27 @@ c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind,
return list;
int pos = 1, colon_pos = 0;
+ int iterator_length = 0;
while (c_parser_peek_nth_token_raw (parser, pos)->type == CPP_NAME)
{
- if (c_parser_peek_nth_token_raw (parser, pos + 1)->type == CPP_COMMA)
- pos += 2;
- else if (c_parser_peek_nth_token_raw (parser, pos + 1)->type
- == CPP_OPEN_PAREN)
+ const char *identifier =
+ IDENTIFIER_POINTER (c_parser_peek_nth_token_raw (parser, pos)->value);
+ if (c_parser_peek_nth_token_raw (parser, pos + 1)->type
+ == CPP_OPEN_PAREN)
{
unsigned int npos = pos + 2;
if (c_parser_check_balanced_raw_token_sequence (parser, &npos)
- && (c_parser_peek_nth_token_raw (parser, npos)->type
- == CPP_CLOSE_PAREN))
- pos = npos + 1;
+ && (c_parser_peek_nth_token_raw (parser, npos)->type
+ == CPP_CLOSE_PAREN))
+ {
+ if (strcmp (identifier, "iterator") == 0)
+ iterator_length = npos - pos + 1;
+ pos = npos;
+ }
}
+ if (c_parser_peek_nth_token_raw (parser, pos + 1)->type == CPP_COMMA)
+ pos += 2;
else
pos++;
if (c_parser_peek_nth_token_raw (parser, pos)->type == CPP_COLON)
@@ -21027,6 +21037,7 @@ c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind,
int present_modifier = false;
int mapper_modifier = false;
tree mapper_name = NULL_TREE;
+ tree iterators = NULL_TREE;
for (int pos = 1; pos < colon_pos; ++pos)
{
@@ -21048,6 +21059,17 @@ c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind,
present_modifier++;
c_parser_consume_token (parser);
}
+ else if (strcmp ("iterator", p) == 0)
+ {
+ if (iterators)
+ {
+ c_parser_error (parser, "too many %<iterator%> modifiers");
+ parens.skip_until_found_close (parser);
+ return list;
+ }
+ iterators = c_parser_omp_iterators (parser);
+ pos += iterator_length - 1;
+ }
else if (strcmp ("mapper", p) == 0)
{
c_parser_consume_token (parser);
@@ -21104,7 +21126,7 @@ c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind,
else
{
c_parser_error (parser, "%<to%> or %<from%> clause with modifier "
- "other than %<present%> or %<mapper%>");
+ "other than %<iterator%>, %<mapper%> or %<present%>");
parens.skip_until_found_close (parser);
return list;
}
@@ -21141,6 +21163,19 @@ c_parser_omp_clause_from_to (c_parser *parser, enum omp_clause_code kind,
OMP_CLAUSE_CHAIN (last_new) = name;
}
+ if (iterators)
+ {
+ tree block = pop_scope ();
+ if (iterators == error_mark_node)
+ iterators = NULL_TREE;
+ else
+ TREE_VEC_ELT (iterators, 5) = block;
+ }
+
+ if (iterators)
+ for (tree c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
+ OMP_CLAUSE_ITERATORS (c) = iterators;
+
return nl;
}