diff options
author | Sandra Loosemore <sloosemore@baylibre.com> | 2025-01-14 23:28:02 +0000 |
---|---|---|
committer | Sandra Loosemore <sloosemore@baylibre.com> | 2025-01-16 18:12:17 +0000 |
commit | 677e452e55e5a91e699d4f01cc9b88297cc41a0d (patch) | |
tree | 0679252841b0aa1379e9ac5435d4ebba0180ebfc /libgomp/testsuite | |
parent | 4e20914d3306d8898ce586313a40fb92ef0b8964 (diff) | |
download | gcc-677e452e55e5a91e699d4f01cc9b88297cc41a0d.zip gcc-677e452e55e5a91e699d4f01cc9b88297cc41a0d.tar.gz gcc-677e452e55e5a91e699d4f01cc9b88297cc41a0d.tar.bz2 |
OpenMP: C++ support for metadirectives and dynamic selectors.
Additional shared C/C++ testcases are included in a subsequent patch in this
series.
gcc/cp/ChangeLog
PR middle-end/112779
PR middle-end/113904
* cp-tree.h (struct saved_scope): Add new field
x_processing_omp_trait_property_expr.
(processing_omp_trait_property_expr): New.
* parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add
metadirective_p parameter and handle skipping over the parentheses
in a "for" statement.
(struct omp_metadirective_parse_data): New.
(mangle_metadirective_region_label): New.
(cp_parser_label_for_labeled_statement): Mangle label names in a
metadirective body.
(cp_parser_jump_statement): Likewise.
(cp_parser_omp_context_selector): Allow arbitrary expressions in
device_num and condition properties.
(cp_parser_omp_assumption_clauses): Handle C_OMP_DIR_META.
(analyze_metadirective_body): New.
(cp_parser_omp_metadirective): New.
(cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE.
* parser.h (struct cp_parser): Add omp_metadirective_state field.
* pt.cc (tsubst_omp_context_selector): New.
(tsubst_stmt): Handle OMP_METADIRECTIVE.
* semantics.cc (finish_id_expression_1): Don't diagnose use of
parameter outside function body in dynamic selector expressions here.
gcc/testsuite/
PR middle-end/112779
PR middle-end/113904
* c-c++-common/gomp/declare-variant-2.c: Adjust output for C++.
* g++.dg/gomp/declare-variant-class-1.C: New.
* g++.dg/gomp/declare-variant-class-2.C: New.
* g++.dg/gomp/metadirective-template-1.C: New.
libgomp/
PR middle-end/112779
PR middle-end/113904
* testsuite/libgomp.c++/metadirective-template-1.C: New.
* testsuite/libgomp.c++/metadirective-template-2.C: New.
* testsuite/libgomp.c++/metadirective-template-3.C: New.
Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>
Co-Authored-By: Sandra Loosemore <sandra@codesourcery.com>
Diffstat (limited to 'libgomp/testsuite')
3 files changed, 125 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.c++/metadirective-template-1.C b/libgomp/testsuite/libgomp.c++/metadirective-template-1.C new file mode 100644 index 0000000..4511536 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/metadirective-template-1.C @@ -0,0 +1,39 @@ +#include <stdio.h> + +template <bool tasking> +int +fib (int n) +{ + int i, j; + if (n < 2) + return n; + else if ( tasking && n < 8 ) // serial/taskless cutoff for n<8 + return fib<false> (n); + else + { +#pragma omp metadirective \ + when (user = {condition (tasking)}: task shared(i)) + i = fib<tasking> (n - 1); +#pragma omp metadirective \ + when (user = {condition (score(10): tasking)}: task shared(j)) + j = fib<tasking> (n - 2); +#pragma omp metadirective \ + when (user = {condition (tasking)}: taskwait) + return i + j; + } +} + +int +main () +{ + int n = 15, o = 610; +#pragma omp parallel +#pragma omp single + { + if (fib<true> (n) != o) + __builtin_abort (); + if (fib<false> (n) != o) + __builtin_abort (); + } + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/metadirective-template-2.C b/libgomp/testsuite/libgomp.c++/metadirective-template-2.C new file mode 100644 index 0000000..a116bfd --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/metadirective-template-2.C @@ -0,0 +1,43 @@ +# include <stdio.h> + +template <bool tasking> +int +fib (int n, bool flag) +{ + int i, j; + if (n < 2) + return n; + else if ( tasking && flag && n < 8 ) // serial/taskless cutoff for n<8 + return fib<false> (n, false); + else + { +#pragma omp metadirective \ + when (user = {condition (tasking && flag)}: task shared(i)) + i = fib<tasking> (n - 1, flag); +#pragma omp metadirective \ + when (user = {condition (score(10): tasking && flag)}: task shared(j)) + j = fib<tasking> (n - 2, flag); +#pragma omp metadirective \ + when (user = {condition (tasking && flag)}: taskwait) + return i + j; + } +} + +int +main () +{ + int n = 15, o = 610; +#pragma omp parallel +#pragma omp single + { + if (fib<true> (n, true) != o) + __builtin_abort (); + if (fib<true> (n, false) != o) + __builtin_abort (); + if (fib<false> (n, false) != o) + __builtin_abort (); + if (fib<false> (n, true) != o) + __builtin_abort (); + } + return 0; +} diff --git a/libgomp/testsuite/libgomp.c++/metadirective-template-3.C b/libgomp/testsuite/libgomp.c++/metadirective-template-3.C new file mode 100644 index 0000000..934ae49 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/metadirective-template-3.C @@ -0,0 +1,43 @@ +# include <stdio.h> + +template <bool tasking> +int +fib (int n, bool flag) +{ + int i, j; + if (n < 2) + return n; + else if ( tasking && flag && n < 8 ) // serial/taskless cutoff for n<8 + return fib<false> (n, false); + else + { +#pragma omp metadirective \ + when (user = {condition (tasking && flag)}: task shared(i)) \ + when (user = {condition (!tasking && !flag)}: nothing) \ + otherwise (error at(execution) message("oops 1")) + i = fib<tasking> (n - 1, flag); +#pragma omp metadirective \ + when (user = {condition (score(10): tasking && flag)}: task shared(j)) \ + when (user = {condition (tasking || flag)} : \ + error at(execution) message ("oops 2")) + j = fib<tasking> (n - 2, flag); +#pragma omp metadirective \ + when (user = {condition (tasking && flag)}: taskwait) + return i + j; + } +} + +int +main () +{ + int n = 15, o = 610; +#pragma omp parallel +#pragma omp single + { + if (fib<true> (n, true) != o) + __builtin_abort (); + if (fib<false> (n, false) != o) + __builtin_abort (); + } + return 0; +} |