diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-09-03 09:41:54 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-09-03 10:04:00 +0200 |
commit | a651e6d59188da8992f8bfae2df1cb4e6316f9e6 (patch) | |
tree | ea5383dc6af17ad39a90f8bd40dae7f62d1547ae /gcc/omp-low.cc | |
parent | c64b09471a8a06e929c70bf6017d7163776145e0 (diff) | |
download | gcc-a651e6d59188da8992f8bfae2df1cb4e6316f9e6.zip gcc-a651e6d59188da8992f8bfae2df1cb4e6316f9e6.tar.gz gcc-a651e6d59188da8992f8bfae2df1cb4e6316f9e6.tar.bz2 |
openmp: Partial OpenMP 5.2 doacross and omp_cur_iteration support
The following patch implements part of the OpenMP 5.2 changes related
to ordered loops and with the assumed resolution of
https://github.com/OpenMP/spec/issues/3302 issues.
The changes are:
1) the depend clause on stand-alone ordered constructs has been renamed
to doacross (because depend clause has different syntax on other
constructs) with some syntax changes below, depend clause is deprecated
(we'll deprecate stuff on the GCC side only when we have everything else
from 5.2 implemented)
depend(source) -> doacross(source:) or doacross(source:omp_cur_iteration)
depend(sink:vec) -> doacross(sink:vec) (where vec has the same syntax
as before)
2) in 5.1 and before it has been significant whether ordered clause has or
doesn't have an argument, if it didn't, only block-associated ordered
could appear in the body, if it did, only stand-alone ordered could appear
in the body, all loops had to be perfectly nested, no associated
range-based for loops, no linear clause on work-sharing loop and ordered
clause with an argument wasn't allowed on composite for simd.
In 5.2, whether ordered clause has or doesn't have an argument is
insignificant (except for bugs in the standard, #3302 mentions those),
if the argument is missing, it is simply treated as equal to collapse
argument (if any, otherwise 1). The implementation better should be able
to differentiate between ordered and doacross loops at compile time
which previously was through the absence or presence of the argument,
now it is done through looking at the body of the construct lexically
and looking for stand-alone ordered constructs. If there are any,
it is to be handled as doacross loop, otherwise it is ordered loop
(but in that case ordered argument if present must be equal to collapse
argument - 5.2 says instead it must be one, but that is clearly wrong
and mentioned in #3302) - stand-alone ordered constructs must appear
lexically in the body (and had to before as well). For the restrictions
mentioned above, the for simd restriction is gone (stand-alone ordered
can't appear in simd construct, so that is enough), and the other rules
are expected to be changed into something related to presence of
stand-alone ordered constructs in the body
3) 5.2 allows a new syntax, doacross(sink:omp_cur_iteration-1), which
means wait for previous iteration in the iteration space of all the
associated loops
The following patch implements that, except that we sorry for now
on the doacross(sink:omp_cur_iteration-1) syntax during omp expansion
because library side isn't done yet for it. It doesn't implement it for
the Fortran FE either.
Incrementally, I'd like to change the way we differentiate between
stand-alone and block-associated ordered constructs, because the current
way of looking for presence of doacross clause doesn't work well if those
clauses are removed because they had been invalid (wrong syntax or
unknown variables in it etc.) and of course implement
doacross(sink:omp_cur_iteration-1).
2022-09-03 Jakub Jelinek <jakub@redhat.com>
gcc/
* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DOACROSS.
(enum omp_clause_depend_kind): Remove OMP_CLAUSE_DEPEND_SOURCE
and OMP_CLAUSE_DEPEND_SINK, add OMP_CLAUSE_DEPEND_INVALID.
(enum omp_clause_doacross_kind): New type.
(struct tree_omp_clause): Add subcode.doacross_kind member.
* tree.h (OMP_CLAUSE_DEPEND_SINK_NEGATIVE): Remove.
(OMP_CLAUSE_DOACROSS_KIND): Define.
(OMP_CLAUSE_DOACROSS_SINK_NEGATIVE): Define.
(OMP_CLAUSE_DOACROSS_DEPEND): Define.
(OMP_CLAUSE_ORDERED_DOACROSS): Define.
* tree.cc (omp_clause_num_ops, omp_clause_code_name): Add
OMP_CLAUSE_DOACROSS entries.
* tree-nested.cc (convert_nonlocal_omp_clauses,
convert_local_omp_clauses): Handle OMP_CLAUSE_DOACROSS.
* tree-pretty-print.cc (dump_omp_clause): Don't handle
OMP_CLAUSE_DEPEND_SOURCE and OMP_CLAUSE_DEPEND_SINK. Handle
OMP_CLAUSE_DOACROSS.
* gimplify.cc (gimplify_omp_depend): Don't handle
OMP_CLAUSE_DEPEND_SOURCE and OMP_CLAUSE_DEPEND_SINK.
(gimplify_scan_omp_clauses): Likewise. Handle OMP_CLAUSE_DOACROSS.
(gimplify_adjust_omp_clauses): Handle OMP_CLAUSE_DOACROSS.
(find_standalone_omp_ordered): New function.
(gimplify_omp_for): When OMP_CLAUSE_ORDERED is present, search
body for OMP_ORDERED with OMP_CLAUSE_DOACROSS and if found,
set OMP_CLAUSE_ORDERED_DOACROSS.
(gimplify_omp_ordered): Don't handle OMP_CLAUSE_DEPEND_SINK or
OMP_CLAUSE_DEPEND_SOURCE, instead check OMP_CLAUSE_DOACROSS, adjust
diagnostics that presence or absence of ordered clause parameter
is irrelevant. Handle doacross(sink:omp_cur_iteration-1). Use
actual user name of the clause - doacross or depend - in diagnostics.
* omp-general.cc (omp_extract_for_data): Don't set fd->ordered
if !OMP_CLAUSE_ORDERED_DOACROSS (t). If
OMP_CLAUSE_ORDERED_DOACROSS (t) but !OMP_CLAUSE_ORDERED_EXPR (t),
set fd->ordered to -1 and set it after the loop in that case to
fd->collapse.
* omp-low.cc (check_omp_nesting_restrictions): Don't handle
OMP_CLAUSE_DEPEND_SOURCE nor OMP_CLAUSE_DEPEND_SINK, instead check
OMP_CLAUSE_DOACROSS. Use actual user name of the clause - doacross
or depend - in diagnostics. Diagnose mixing of stand-alone and
block associated ordered constructs binding to the same loop.
(lower_omp_ordered_clauses): Don't handle OMP_CLAUSE_DEPEND_SINK,
instead handle OMP_CLAUSE_DOACROSS.
(lower_omp_ordered): Look for OMP_CLAUSE_DOACROSS instead of
OMP_CLAUSE_DEPEND.
(lower_depend_clauses): Don't handle OMP_CLAUSE_DEPEND_SOURCE and
OMP_CLAUSE_DEPEND_SINK.
* omp-expand.cc (expand_omp_ordered_sink): Emit a sorry for
doacross(sink:omp_cur_iteration-1).
(expand_omp_ordered_source_sink): Use
OMP_CLAUSE_DOACROSS_SINK_NEGATIVE instead of
OMP_CLAUSE_DEPEND_SINK_NEGATIVE. Use actual user name of the clause
- doacross or depend - in diagnostics.
(expand_omp): Look for OMP_CLAUSE_DOACROSS clause instead of
OMP_CLAUSE_DEPEND.
(build_omp_regions_1): Likewise.
(omp_make_gimple_edges): Likewise.
* lto-streamer-out.cc (hash_tree): Handle OMP_CLAUSE_DOACROSS.
* tree-streamer-in.cc (unpack_ts_omp_clause_value_fields): Likewise.
* tree-streamer-out.cc (pack_ts_omp_clause_value_fields): Likewise.
gcc/c-family/
* c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_DOACROSS.
* c-omp.cc (c_finish_omp_depobj): Check also for OMP_CLAUSE_DOACROSS
clause and diagnose it. Don't handle OMP_CLAUSE_DEPEND_SOURCE and
OMP_CLAUSE_DEPEND_SINK. Assert kind is not OMP_CLAUSE_DEPEND_INVALID.
gcc/c/
* c-parser.cc (c_parser_omp_clause_name): Handle doacross.
(c_parser_omp_clause_depend_sink): Renamed to ...
(c_parser_omp_clause_doacross_sink): ... this. Add depend_p argument.
Handle parsing of doacross(sink:omp_cur_iteration-1). Use
OMP_CLAUSE_DOACROSS_SINK_NEGATIVE instead of
OMP_CLAUSE_DEPEND_SINK_NEGATIVE, build OMP_CLAUSE_DOACROSS instead
of OMP_CLAUSE_DEPEND and set OMP_CLAUSE_DOACROSS_DEPEND flag on it.
(c_parser_omp_clause_depend): Use OMP_CLAUSE_DOACROSS_SINK and
OMP_CLAUSE_DOACROSS_SOURCE instead of OMP_CLAUSE_DEPEND_SINK and
OMP_CLAUSE_DEPEND_SOURCE, build OMP_CLAUSE_DOACROSS for depend(source)
and set OMP_CLAUSE_DOACROSS_DEPEND on it.
(c_parser_omp_clause_doacross): New function.
(c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DOACROSS.
(c_parser_omp_depobj): Use OMP_CLAUSE_DEPEND_INVALID instead of
OMP_CLAUSE_DEPEND_SOURCE.
(c_parser_omp_for_loop): Don't diagnose here linear clause together
with ordered with argument.
(c_parser_omp_simd): Don't diagnose ordered clause with argument on
for simd.
(OMP_ORDERED_DEPEND_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_DOACROSS.
(c_parser_omp_ordered): Handle also doacross and adjust for it
diagnostic wording.
* c-typeck.cc (c_finish_omp_clauses): Handle OMP_CLAUSE_DOACROSS.
Don't handle OMP_CLAUSE_DEPEND_SOURCE and OMP_CLAUSE_DEPEND_SINK.
gcc/cp/
* parser.cc (cp_parser_omp_clause_name): Handle doacross.
(cp_parser_omp_clause_depend_sink): Renamed to ...
(cp_parser_omp_clause_doacross_sink): ... this. Add depend_p
argument. Handle parsing of doacross(sink:omp_cur_iteration-1). Use
OMP_CLAUSE_DOACROSS_SINK_NEGATIVE instead of
OMP_CLAUSE_DEPEND_SINK_NEGATIVE, build OMP_CLAUSE_DOACROSS instead
of OMP_CLAUSE_DEPEND and set OMP_CLAUSE_DOACROSS_DEPEND flag on it.
(cp_parser_omp_clause_depend): Use OMP_CLAUSE_DOACROSS_SINK and
OMP_CLAUSE_DOACROSS_SOURCE instead of OMP_CLAUSE_DEPEND_SINK and
OMP_CLAUSE_DEPEND_SOURCE, build OMP_CLAUSE_DOACROSS for depend(source)
and set OMP_CLAUSE_DOACROSS_DEPEND on it.
(cp_parser_omp_clause_doacross): New function.
(cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DOACROSS.
(cp_parser_omp_depobj): Use OMP_CLAUSE_DEPEND_INVALID instead of
OMP_CLAUSE_DEPEND_SOURCE.
(cp_parser_omp_for_loop): Don't diagnose here linear clause together
with ordered with argument.
(cp_parser_omp_simd): Don't diagnose ordered clause with argument on
for simd.
(OMP_ORDERED_DEPEND_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_DOACROSS.
(cp_parser_omp_ordered): Handle also doacross and adjust for it
diagnostic wording.
* pt.cc (tsubst_omp_clause_decl): Use
OMP_CLAUSE_DOACROSS_SINK_NEGATIVE instead of
OMP_CLAUSE_DEPEND_SINK_NEGATIVE.
(tsubst_omp_clauses): Handle OMP_CLAUSE_DOACROSS.
(tsubst_expr): Use OMP_CLAUSE_DEPEND_INVALID instead of
OMP_CLAUSE_DEPEND_SOURCE.
* semantics.cc (cp_finish_omp_clause_depend_sink): Rename to ...
(cp_finish_omp_clause_doacross_sink): ... this.
(finish_omp_clauses): Handle OMP_CLAUSE_DOACROSS. Don't handle
OMP_CLAUSE_DEPEND_SOURCE and OMP_CLAUSE_DEPEND_SINK.
gcc/fortran/
* trans-openmp.cc (gfc_trans_omp_clauses): Use
OMP_CLAUSE_DOACROSS_SINK_NEGATIVE instead of
OMP_CLAUSE_DEPEND_SINK_NEGATIVE, build OMP_CLAUSE_DOACROSS
clause instead of OMP_CLAUSE_DEPEND and set OMP_CLAUSE_DOACROSS_DEPEND
on it.
gcc/testsuite/
* c-c++-common/gomp/doacross-2.c: Adjust expected diagnostics.
* c-c++-common/gomp/doacross-5.c: New test.
* c-c++-common/gomp/doacross-6.c: New test.
* c-c++-common/gomp/nesting-2.c: Adjust expected diagnostics.
* c-c++-common/gomp/ordered-3.c: Likewise.
* c-c++-common/gomp/sink-3.c: Likewise.
* gfortran.dg/gomp/nesting-2.f90: Likewise.
Diffstat (limited to 'gcc/omp-low.cc')
-rw-r--r-- | gcc/omp-low.cc | 118 |
1 files changed, 61 insertions, 57 deletions
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index e9e4bd0..b32336b 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -3636,14 +3636,13 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx) break; case GIMPLE_OMP_TASK: for (c = gimple_omp_task_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c)) - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - && (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SOURCE - || OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS) { - enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_KIND (c); + enum omp_clause_doacross_kind kind = OMP_CLAUSE_DOACROSS_KIND (c); error_at (OMP_CLAUSE_LOCATION (c), - "%<depend(%s)%> is only allowed in %<omp ordered%>", - kind == OMP_CLAUSE_DEPEND_SOURCE ? "source" : "sink"); + "%<%s(%s)%> is only allowed in %<omp ordered%>", + OMP_CLAUSE_DOACROSS_DEPEND (c) ? "depend" : "doacross", + kind == OMP_CLAUSE_DOACROSS_SOURCE ? "source" : "sink"); return false; } break; @@ -3651,43 +3650,30 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx) for (c = gimple_omp_ordered_clauses (as_a <gomp_ordered *> (stmt)); c; c = OMP_CLAUSE_CHAIN (c)) { - if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND) + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DOACROSS) { - gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREADS - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SIMD); - continue; - } - enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_KIND (c); - if (kind == OMP_CLAUSE_DEPEND_SOURCE - || kind == OMP_CLAUSE_DEPEND_SINK) - { - tree oclause; - /* Look for containing ordered(N) loop. */ - if (ctx == NULL - || gimple_code (ctx->stmt) != GIMPLE_OMP_FOR - || (oclause - = omp_find_clause (gimple_omp_for_clauses (ctx->stmt), - OMP_CLAUSE_ORDERED)) == NULL_TREE) - { - error_at (OMP_CLAUSE_LOCATION (c), - "%<ordered%> construct with %<depend%> clause " - "must be closely nested inside an %<ordered%> " - "loop"); - return false; - } - else if (OMP_CLAUSE_ORDERED_EXPR (oclause) == NULL_TREE) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND) { error_at (OMP_CLAUSE_LOCATION (c), - "%<ordered%> construct with %<depend%> clause " - "must be closely nested inside a loop with " - "%<ordered%> clause with a parameter"); + "invalid depend kind in omp %<ordered%> %<depend%>"); return false; } + gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREADS + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SIMD); + continue; } - else + + tree oclause; + /* Look for containing ordered(N) loop. */ + if (ctx == NULL + || gimple_code (ctx->stmt) != GIMPLE_OMP_FOR + || (oclause + = omp_find_clause (gimple_omp_for_clauses (ctx->stmt), + OMP_CLAUSE_ORDERED)) == NULL_TREE) { error_at (OMP_CLAUSE_LOCATION (c), - "invalid depend kind in omp %<ordered%> %<depend%>"); + "%<ordered%> construct with %<depend%> clause " + "must be closely nested inside an %<ordered%> loop"); return false; } } @@ -3732,14 +3718,37 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx) "a loop region with an %<ordered%> clause"); return false; } - if (OMP_CLAUSE_ORDERED_EXPR (o) != NULL_TREE - && omp_find_clause (c, OMP_CLAUSE_DEPEND) == NULL_TREE) + if (omp_find_clause (c, OMP_CLAUSE_DOACROSS) == NULL_TREE) { - error_at (gimple_location (stmt), - "%<ordered%> region without %<depend%> clause may " - "not be closely nested inside a loop region with " - "an %<ordered%> clause with a parameter"); - return false; + if (OMP_CLAUSE_ORDERED_DOACROSS (o)) + { + error_at (gimple_location (stmt), + "%<ordered%> construct without %<doacross%> or " + "%<depend%> clauses must not have the same " + "binding region as %<ordered%> construct with " + "those clauses"); + return false; + } + else if (OMP_CLAUSE_ORDERED_EXPR (o)) + { + tree co + = omp_find_clause (gimple_omp_for_clauses (ctx->stmt), + OMP_CLAUSE_COLLAPSE); + HOST_WIDE_INT + o_n = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (o)); + HOST_WIDE_INT c_n = 1; + if (co) + c_n = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co)); + if (o_n != c_n) + { + error_at (gimple_location (stmt), + "%<ordered%> construct without %<doacross%> " + "or %<depend%> clauses binds to loop where " + "%<collapse%> argument %wd is different from " + "%<ordered%> argument %wd", c_n, o_n); + return false; + } + } } return true; case GIMPLE_OMP_TARGET: @@ -3793,14 +3802,12 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx) break; case GIMPLE_OMP_TARGET: for (c = gimple_omp_target_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c)) - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - && (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SOURCE - || OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS) { - enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_KIND (c); + enum omp_clause_doacross_kind kind = OMP_CLAUSE_DOACROSS_KIND (c); error_at (OMP_CLAUSE_LOCATION (c), "%<depend(%s)%> is only allowed in %<omp ordered%>", - kind == OMP_CLAUSE_DEPEND_SOURCE ? "source" : "sink"); + kind == OMP_CLAUSE_DOACROSS_SOURCE ? "source" : "sink"); return false; } if (is_gimple_omp_offloaded (stmt) @@ -9740,8 +9747,8 @@ lower_omp_ordered_clauses (gimple_stmt_iterator *gsi_p, gomp_ordered *ord_stmt, tree *list_p = gimple_omp_ordered_clauses_ptr (ord_stmt); tree c = gimple_omp_ordered_clauses (ord_stmt); - if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS + && OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK) { /* Merge depend clauses from multiple adjacent #pragma omp ordered depend(sink:...) constructs @@ -9763,8 +9770,8 @@ lower_omp_ordered_clauses (gimple_stmt_iterator *gsi_p, gomp_ordered *ord_stmt, gomp_ordered *ord_stmt2 = as_a <gomp_ordered *> (stmt); c = gimple_omp_ordered_clauses (ord_stmt2); if (c == NULL_TREE - || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND - || OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_SINK) + || OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DOACROSS + || OMP_CLAUSE_DOACROSS_KIND (c) != OMP_CLAUSE_DOACROSS_SINK) break; while (*list_p) list_p = &OMP_CLAUSE_CHAIN (*list_p); @@ -9831,8 +9838,8 @@ lower_omp_ordered_clauses (gimple_stmt_iterator *gsi_p, gomp_ordered *ord_stmt, { bool remove = false; - gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND); - if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_SINK) + gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DOACROSS); + if (OMP_CLAUSE_DOACROSS_KIND (c) != OMP_CLAUSE_DOACROSS_SINK) goto next_ordered_clause; tree vec; @@ -9983,7 +9990,7 @@ lower_omp_ordered (gimple_stmt_iterator *gsi_p, omp_context *ctx) OMP_CLAUSE_THREADS); if (omp_find_clause (gimple_omp_ordered_clauses (ord_stmt), - OMP_CLAUSE_DEPEND)) + OMP_CLAUSE_DOACROSS)) { /* FIXME: This is needs to be moved to the expansion to verify various conditions only testable on cfg with dominators computed, and also @@ -12359,9 +12366,6 @@ lower_depend_clauses (tree *pclauses, gimple_seq *iseq, gimple_seq *oseq) case OMP_CLAUSE_DEPEND_INOUTSET: cnt[4]++; break; - case OMP_CLAUSE_DEPEND_SOURCE: - case OMP_CLAUSE_DEPEND_SINK: - /* FALLTHRU */ default: gcc_unreachable (); } |