Skip to content
Snippets Groups Projects
Commit a651e6d5 authored by Jakub Jelinek's avatar Jakub Jelinek
Browse files

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.
parent c64b0947
No related branches found
No related tags found
Loading
Showing
with 689 additions and 262 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment