diff options
author | Tobias Burnus <burnus@net-b.de> | 2014-07-12 21:00:47 +0200 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2014-07-12 21:00:47 +0200 |
commit | 7f4aaf912bdab4fe3ccad012add9a1d00a26dab1 (patch) | |
tree | 9038e580c528fda84a1b16297c39c9848284db75 /gcc/fortran | |
parent | 0eb5f1586fa04fd82180135917b2c80511473c6b (diff) | |
download | gcc-7f4aaf912bdab4fe3ccad012add9a1d00a26dab1.zip gcc-7f4aaf912bdab4fe3ccad012add9a1d00a26dab1.tar.gz gcc-7f4aaf912bdab4fe3ccad012add9a1d00a26dab1.tar.bz2 |
check.c (gfc_check_atomic): Update for STAT=.
gcc/fortran/
2014-07-12 Tobias Burnus <burnus@net-b.de>
* check.c (gfc_check_atomic): Update for STAT=.
(gfc_check_atomic_def, gfc_check_atomic_ref): Update call.
(gfc_check_atomic_op, gfc_check_atomic_cas,
gfc_check_atomic_fetch_op): New.
* gfortran.h (gfc_isym_id): GFC_ISYM_ATOMIC_CAS,
* GFC_ISYM_ATOMIC_ADD,
GFC_ISYM_ATOMIC_AND, GFC_ISYM_ATOMIC_OR, GFC_ISYM_ATOMIC_XOR,
GFC_ISYM_ATOMIC_FETCH_ADD, GFC_ISYM_ATOMIC_FETCH_AND,
GFC_ISYM_ATOMIC_FETCH_OR and GFC_ISYM_ATOMIC_FETCH_XOR.
* intrinsic.c (add_subroutines): Handle them.
* intrinsic.texi: Add documentation for them.
(ATOMIC_REF, ATOMIC_DEFINE): Add STAT=.
(ISO_FORTRAN_ENV): Add STAT_FAILED_IMAGE.
* intrinsic.h (gfc_check_atomic_op, gfc_check_atomic_cas,
gfc_check_atomic_fetch_op): New
prototypes.
* libgfortran.h (libgfortran_stat_codes): Add
* GFC_STAT_FAILED_IMAGE.
* iso-fortran-env.def: Add it.
* trans-intrinsic.c (conv_intrinsic_atomic_op): Renamed from
conv_intrinsic_atomic_ref; handle more atomics.
(conv_intrinsic_atomic_def): Handle STAT=.
(conv_intrinsic_atomic_cas): New.
(gfc_conv_intrinsic_subroutine): Handle new atomics.
gcc/testsuite/
2014-07-12 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/coarray_atomic_1.f90: Update dg-error.
* gfortran.dg/coarray_atomic_2.f90: New.
* gfortran.dg/coarray_atomic_3.f90: New.
* gfortran.dg/coarray_atomic_4.f90: New.
* gfortran.dg/coarray/atomic_2.f90: New.
From-SVN: r212483
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 25 | ||||
-rw-r--r-- | gcc/fortran/check.c | 147 | ||||
-rw-r--r-- | gcc/fortran/gfortran.h | 9 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.c | 79 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.h | 8 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.texi | 520 | ||||
-rw-r--r-- | gcc/fortran/iso-fortran-env.def | 2 | ||||
-rw-r--r-- | gcc/fortran/libgfortran.h | 3 | ||||
-rw-r--r-- | gcc/fortran/trans-intrinsic.c | 219 |
9 files changed, 957 insertions, 55 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index daf0040..2771ea7 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,28 @@ +2014-07-12 Tobias Burnus <burnus@net-b.de> + + * check.c (gfc_check_atomic): Update for STAT=. + (gfc_check_atomic_def, gfc_check_atomic_ref): Update call. + (gfc_check_atomic_op, gfc_check_atomic_cas, + gfc_check_atomic_fetch_op): New. + * gfortran.h (gfc_isym_id): GFC_ISYM_ATOMIC_CAS, GFC_ISYM_ATOMIC_ADD, + GFC_ISYM_ATOMIC_AND, GFC_ISYM_ATOMIC_OR, GFC_ISYM_ATOMIC_XOR, + GFC_ISYM_ATOMIC_FETCH_ADD, GFC_ISYM_ATOMIC_FETCH_AND, + GFC_ISYM_ATOMIC_FETCH_OR and GFC_ISYM_ATOMIC_FETCH_XOR. + * intrinsic.c (add_subroutines): Handle them. + * intrinsic.texi: Add documentation for them. + (ATOMIC_REF, ATOMIC_DEFINE): Add STAT=. + (ISO_FORTRAN_ENV): Add STAT_FAILED_IMAGE. + * intrinsic.h (gfc_check_atomic_op, gfc_check_atomic_cas, + gfc_check_atomic_fetch_op): New + prototypes. + * libgfortran.h (libgfortran_stat_codes): Add GFC_STAT_FAILED_IMAGE. + * iso-fortran-env.def: Add it. + * trans-intrinsic.c (conv_intrinsic_atomic_op): Renamed from + conv_intrinsic_atomic_ref; handle more atomics. + (conv_intrinsic_atomic_def): Handle STAT=. + (conv_intrinsic_atomic_cas): New. + (gfc_conv_intrinsic_subroutine): Handle new atomics. + 2014-07-09 Bernd Schmidt <bernds@codesourcery.com> * trans-array.c (gfc_build_constant_array_constructor): Build a diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index 10944eb..eff2c4c 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -1006,12 +1006,11 @@ gfc_check_atan2 (gfc_expr *y, gfc_expr *x) static bool -gfc_check_atomic (gfc_expr *atom, gfc_expr *value) +gfc_check_atomic (gfc_expr *atom, int atom_no, gfc_expr *value, int val_no, + gfc_expr *stat, int stat_no) { - if (atom->expr_type == EXPR_FUNCTION - && atom->value.function.isym - && atom->value.function.isym->id == GFC_ISYM_CAF_GET) - atom = atom->value.function.actual->expr; + if (!scalar_check (atom, atom_no) || !scalar_check (value, val_no)) + return false; if (!(atom->ts.type == BT_INTEGER && atom->ts.kind == gfc_atomic_int_kind) && !(atom->ts.type == BT_LOGICAL @@ -1032,27 +1031,41 @@ gfc_check_atomic (gfc_expr *atom, gfc_expr *value) if (atom->ts.type != value->ts.type) { - gfc_error ("ATOM and VALUE argument of the %s intrinsic function shall " - "have the same type at %L", gfc_current_intrinsic, - &value->where); + gfc_error ("'%s' argument of '%s' intrinsic at %L shall have the same " + "type as '%s' at %L", gfc_current_intrinsic_arg[val_no]->name, + gfc_current_intrinsic, &value->where, + gfc_current_intrinsic_arg[atom_no]->name, &atom->where); return false; } + if (stat != NULL) + { + if (!type_check (stat, stat_no, BT_INTEGER)) + return false; + if (!scalar_check (stat, stat_no)) + return false; + if (!variable_check (stat, stat_no, false)) + return false; + if (!kind_value_check (stat, stat_no, gfc_default_integer_kind)) + return false; + + if (!gfc_notify_std (GFC_STD_F2008_TS, "STAT= argument to %s at %L", + gfc_current_intrinsic, &stat->where)) + return false; + } + return true; } bool -gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value) +gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value, gfc_expr *stat) { if (atom->expr_type == EXPR_FUNCTION && atom->value.function.isym && atom->value.function.isym->id == GFC_ISYM_CAF_GET) atom = atom->value.function.actual->expr; - if (!scalar_check (atom, 0) || !scalar_check (value, 1)) - return false; - if (!gfc_check_vardef_context (atom, false, false, false, NULL)) { gfc_error ("ATOM argument of the %s intrinsic function at %L shall be " @@ -1060,15 +1073,32 @@ gfc_check_atomic_def (gfc_expr *atom, gfc_expr *value) return false; } - return gfc_check_atomic (atom, value); + return gfc_check_atomic (atom, 0, value, 1, stat, 2); } bool -gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom) +gfc_check_atomic_op (gfc_expr *atom, gfc_expr *value, gfc_expr *stat) { - if (!scalar_check (value, 0) || !scalar_check (atom, 1)) - return false; + if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind) + { + gfc_error ("ATOM argument at %L to intrinsic function %s shall be an " + "integer of ATOMIC_INT_KIND", &atom->where, + gfc_current_intrinsic); + return false; + } + + return gfc_check_atomic_def (atom, value, stat); +} + + +bool +gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom, gfc_expr *stat) +{ + if (atom->expr_type == EXPR_FUNCTION + && atom->value.function.isym + && atom->value.function.isym->id == GFC_ISYM_CAF_GET) + atom = atom->value.function.actual->expr; if (!gfc_check_vardef_context (value, false, false, false, NULL)) { @@ -1077,7 +1107,90 @@ gfc_check_atomic_ref (gfc_expr *value, gfc_expr *atom) return false; } - return gfc_check_atomic (atom, value); + return gfc_check_atomic (atom, 1, value, 0, stat, 2); +} + + +bool +gfc_check_atomic_cas (gfc_expr *atom, gfc_expr *old, gfc_expr *compare, + gfc_expr *new_val, gfc_expr *stat) +{ + if (atom->expr_type == EXPR_FUNCTION + && atom->value.function.isym + && atom->value.function.isym->id == GFC_ISYM_CAF_GET) + atom = atom->value.function.actual->expr; + + if (!gfc_check_atomic (atom, 0, new_val, 3, stat, 4)) + return false; + + if (!scalar_check (old, 1) || !scalar_check (compare, 2)) + return false; + + if (!same_type_check (atom, 0, old, 1)) + return false; + + if (!same_type_check (atom, 0, compare, 2)) + return false; + + if (!gfc_check_vardef_context (atom, false, false, false, NULL)) + { + gfc_error ("ATOM argument of the %s intrinsic function at %L shall be " + "definable", gfc_current_intrinsic, &atom->where); + return false; + } + + if (!gfc_check_vardef_context (old, false, false, false, NULL)) + { + gfc_error ("OLD argument of the %s intrinsic function at %L shall be " + "definable", gfc_current_intrinsic, &old->where); + return false; + } + + return true; +} + + +bool +gfc_check_atomic_fetch_op (gfc_expr *atom, gfc_expr *value, gfc_expr *old, + gfc_expr *stat) +{ + if (atom->expr_type == EXPR_FUNCTION + && atom->value.function.isym + && atom->value.function.isym->id == GFC_ISYM_CAF_GET) + atom = atom->value.function.actual->expr; + + if (atom->ts.type != BT_INTEGER || atom->ts.kind != gfc_atomic_int_kind) + { + gfc_error ("ATOM argument at %L to intrinsic function %s shall be an " + "integer of ATOMIC_INT_KIND", &atom->where, + gfc_current_intrinsic); + return false; + } + + if (!gfc_check_atomic (atom, 0, value, 1, stat, 3)) + return false; + + if (!scalar_check (old, 2)) + return false; + + if (!same_type_check (atom, 0, old, 2)) + return false; + + if (!gfc_check_vardef_context (atom, false, false, false, NULL)) + { + gfc_error ("ATOM argument of the %s intrinsic function at %L shall be " + "definable", gfc_current_intrinsic, &atom->where); + return false; + } + + if (!gfc_check_vardef_context (old, false, false, false, NULL)) + { + gfc_error ("OLD argument of the %s intrinsic function at %L shall be " + "definable", gfc_current_intrinsic, &old->where); + return false; + } + + return true; } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 3481319..f1750da 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -332,8 +332,17 @@ enum gfc_isym_id GFC_ISYM_ATAN, GFC_ISYM_ATAN2, GFC_ISYM_ATANH, + GFC_ISYM_ATOMIC_ADD, + GFC_ISYM_ATOMIC_AND, + GFC_ISYM_ATOMIC_CAS, GFC_ISYM_ATOMIC_DEF, + GFC_ISYM_ATOMIC_FETCH_ADD, + GFC_ISYM_ATOMIC_FETCH_AND, + GFC_ISYM_ATOMIC_FETCH_OR, + GFC_ISYM_ATOMIC_FETCH_XOR, + GFC_ISYM_ATOMIC_OR, GFC_ISYM_ATOMIC_REF, + GFC_ISYM_ATOMIC_XOR, GFC_ISYM_BGE, GFC_ISYM_BGT, GFC_ISYM_BIT_SIZE, diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index bf784b5..d681d70 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -3038,17 +3038,88 @@ add_subroutines (void) make_noreturn(); - add_sym_2s ("atomic_define", GFC_ISYM_ATOMIC_DEF, CLASS_ATOMIC, + add_sym_3s ("atomic_define", GFC_ISYM_ATOMIC_DEF, CLASS_ATOMIC, BT_UNKNOWN, 0, GFC_STD_F2008, gfc_check_atomic_def, NULL, gfc_resolve_atomic_def, "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, - "value", BT_INTEGER, di, REQUIRED, INTENT_IN); + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); - add_sym_2s ("atomic_ref", GFC_ISYM_ATOMIC_REF, CLASS_ATOMIC, + add_sym_3s ("atomic_ref", GFC_ISYM_ATOMIC_REF, CLASS_ATOMIC, BT_UNKNOWN, 0, GFC_STD_F2008, gfc_check_atomic_ref, NULL, gfc_resolve_atomic_ref, "value", BT_INTEGER, di, REQUIRED, INTENT_OUT, - "atom", BT_INTEGER, di, REQUIRED, INTENT_IN); + "atom", BT_INTEGER, di, REQUIRED, INTENT_IN, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_5s ("atomic_cas", GFC_ISYM_ATOMIC_CAS, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_cas, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_INOUT, + "old", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "compare", BT_INTEGER, di, REQUIRED, INTENT_IN, + "new", BT_INTEGER, di, REQUIRED, INTENT_IN, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_3s ("atomic_add", GFC_ISYM_ATOMIC_ADD, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_op, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_3s ("atomic_and", GFC_ISYM_ATOMIC_AND, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_op, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_3s ("atomic_or", GFC_ISYM_ATOMIC_OR, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_op, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_3s ("atomic_xor", GFC_ISYM_ATOMIC_XOR, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_op, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_4s ("atomic_fetch_add", GFC_ISYM_ATOMIC_FETCH_ADD, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_fetch_op, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + "old", BT_INTEGER, di, REQUIRED, INTENT_OUT, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_4s ("atomic_fetch_and", GFC_ISYM_ATOMIC_FETCH_AND, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_fetch_op, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + "old", BT_INTEGER, di, REQUIRED, INTENT_OUT, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_4s ("atomic_fetch_or", GFC_ISYM_ATOMIC_FETCH_OR, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_fetch_op, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + "old", BT_INTEGER, di, REQUIRED, INTENT_OUT, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); + + add_sym_4s ("atomic_fetch_xor", GFC_ISYM_ATOMIC_FETCH_XOR, CLASS_ATOMIC, + BT_UNKNOWN, 0, GFC_STD_F2008_TS, + gfc_check_atomic_fetch_op, NULL, NULL, + "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT, + "value", BT_INTEGER, di, REQUIRED, INTENT_IN, + "old", BT_INTEGER, di, REQUIRED, INTENT_OUT, + stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT); add_sym_0s ("backtrace", GFC_ISYM_BACKTRACE, GFC_STD_GNU, NULL); diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h index 05cd146..9437171 100644 --- a/gcc/fortran/intrinsic.h +++ b/gcc/fortran/intrinsic.h @@ -38,8 +38,12 @@ bool gfc_check_allocated (gfc_expr *); bool gfc_check_associated (gfc_expr *, gfc_expr *); bool gfc_check_atan_2 (gfc_expr *, gfc_expr *); bool gfc_check_atan2 (gfc_expr *, gfc_expr *); -bool gfc_check_atomic_def (gfc_expr *, gfc_expr *); -bool gfc_check_atomic_ref (gfc_expr *, gfc_expr *); +bool gfc_check_atomic_cas (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *, + gfc_expr *); +bool gfc_check_atomic_def (gfc_expr *, gfc_expr *, gfc_expr *); +bool gfc_check_atomic_fetch_op (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *); +bool gfc_check_atomic_op (gfc_expr *, gfc_expr *, gfc_expr *); +bool gfc_check_atomic_ref (gfc_expr *, gfc_expr *, gfc_expr *); bool gfc_check_besn (gfc_expr *, gfc_expr *); bool gfc_check_bessel_n2 (gfc_expr *, gfc_expr *, gfc_expr *); bool gfc_check_bge_bgt_ble_blt (gfc_expr *, gfc_expr *); diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi index 87f6478..2cf6dfe 100644 --- a/gcc/fortran/intrinsic.texi +++ b/gcc/fortran/intrinsic.texi @@ -60,8 +60,17 @@ Some basic guidelines for editing this document: * @code{ATAN}: ATAN, Arctangent function * @code{ATAN2}: ATAN2, Arctangent function * @code{ATANH}: ATANH, Inverse hyperbolic tangent function +* @code{ATOMIC_ADD}: ATOMIC_ADD, Atomic ADD operation +* @code{ATOMIC_AND}: ATOMIC_AND, Atomic bitwise AND operation +* @code{ATOMIC_CAS}: ATOMIC_CAS, Atomic compare and swap +* @code{ATOMIC_FETCH_ADD}: ATOMIC_FETCH_ADD, Atomic ADD operation with prior fetch +* @code{ATOMIC_FETCH_AND}: ATOMIC_FETCH_AND, Atomic bitwise AND operation with prior fetch +* @code{ATOMIC_FETCH_OR}: ATOMIC_FETCH_OR, Atomic bitwise OR operation with prior fetch +* @code{ATOMIC_FETCH_XOR}: ATOMIC_FETCH_XOR, Atomic bitwise XOR operation with prior fetch +* @code{ATOMIC_OR}: ATOMIC_OR, Atomic bitwise OR operation * @code{ATOMIC_DEFINE}: ATOMIC_DEFINE, Setting a variable atomically * @code{ATOMIC_REF}: ATOMIC_REF, Obtaining the value of a variable atomically +* @code{ATOMIC_XOR}: ATOMIC_XOR, Atomic bitwise OR operation * @code{BACKTRACE}: BACKTRACE, Show a backtrace * @code{BESSEL_J0}: BESSEL_J0, Bessel function of the first kind of order 0 * @code{BESSEL_J1}: BESSEL_J1, Bessel function of the first kind of order 1 @@ -1554,6 +1563,159 @@ Inverse function: @ref{TANH} +@node ATOMIC_ADD +@section @code{ATOMIC_ADD} --- Atomic ADD operation +@fnindex ATOMIC_ADD +@cindex Atomic subroutine, add + +@table @asis +@item @emph{Description}: +@code{ATOMIC_ADD(ATOM, VALUE)} atomically adds the value of @var{VAR} to the +variable @var{ATOM}. When @var{STAT} is present and the invokation was +successful, it is assigned the value 0. If it is present and the invokation +has failed, it is assigned a positive value; in particular, for a coindexed +@var{ATOM}, if the remote image has stopped, it is assigned the value of +@code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has +failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_ADD (ATOM, VALUE [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of integer +type with @code{ATOMIC_INT_KIND} kind. +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + integer(atomic_int_kind) :: atom[*] + call atomic_add (atom[1], this_image()) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_FETCH_ADD}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_AND}, @ref{ATOMIC_OR}, @ref{ATOMIC_XOR} +@end table + + + + +@node ATOMIC_AND +@section @code{ATOMIC_AND} --- Atomic bitwise AND operation +@fnindex ATOMIC_AND +@cindex Atomic subroutine, AND + +@table @asis +@item @emph{Description}: +@code{ATOMIC_AND(ATOM, VALUE)} atomically defines @var{ATOM} with the bitwise +AND between the values of @var{ATOM} and @var{VALUE}. When @var{STAT} is present +and the invokation was successful, it is assigned the value 0. If it is present +and the invokation has failed, it is assigned a positive value; in particular, +for a coindexed @var{ATOM}, if the remote image has stopped, it is assigned the +value of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote +image has failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_AND (ATOM, VALUE [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of integer +type with @code{ATOMIC_INT_KIND} kind. +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + integer(atomic_int_kind) :: atom[*] + call atomic_and (atom[1], int(b'10100011101')) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_FETCH_AND}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_ADD}, @ref{ATOMIC_OR}, @ref{ATOMIC_XOR} +@end table + + + +@node ATOMIC_CAS +@section @code{ATOMIC_CAS} --- Atomic compare and swap +@fnindex ATOMIC_DEFINE +@cindex Atomic subroutine, compare and swap + +@table @asis +@item @emph{Description}: +@code{ATOMIC_CAS} compares the variable @var{ATOM} with the value of +@var{COMPARE}; if the value is the same, @var{ATOM} is set to the value +of @var{NEW}. Additionally, @var{OLD} is set to the value of @var{ATOM} +that was used for the comparison. When @var{STAT} is present and the invokation +was successful, it is assigned the value 0. If it is present and the invokation +has failed, it is assigned a positive value; in particular, for a coindexed +@var{ATOM}, if the remote image has stopped, it is assigned the value of +@code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has +failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_CAS (ATOM, OLD, COMPARE, NEW [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of either integer +type with @code{ATOMIC_INT_KIND} kind or logical type with +@code{ATOMIC_LOGICAL_KIND} kind. +@item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}. +@item @var{COMPARE} @tab Scalar variable of the same type and kind as +@var{ATOM}. +@item @var{NEW} @tab Scalar variable of the same type as @var{ATOM}. If kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + logical(atomic_logical_kind) :: atom[*], prev + call atomic_cas (atom[1], prev, .false., .true.)) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_REF}, @ref{ISO_FORTRAN_ENV} +@end table + + + @node ATOMIC_DEFINE @section @code{ATOMIC_DEFINE} --- Setting a variable atomically @fnindex ATOMIC_DEFINE @@ -1562,25 +1724,31 @@ Inverse function: @ref{TANH} @table @asis @item @emph{Description}: @code{ATOMIC_DEFINE(ATOM, VALUE)} defines the variable @var{ATOM} with the value -@var{VALUE} atomically. +@var{VALUE} atomically. When @var{STAT} is present and the invokation was +successful, it is assigned the value 0. If it is present and the invokation +has failed, it is assigned a positive value; in particular, for a coindexed +@var{ATOM}, if the remote image has stopped, it is assigned the value of +@code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has +failed, the value @code{STAT_FAILED_IMAGE}. @item @emph{Standard}: -Fortran 2008 and later +Fortran 2008 and later; with @var{STAT}, TS 18508 or later @item @emph{Class}: Atomic subroutine @item @emph{Syntax}: -@code{CALL ATOMIC_DEFINE(ATOM, VALUE)} +@code{CALL ATOMIC_DEFINE (ATOM, VALUE [, STAT])} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @item @var{ATOM} @tab Scalar coarray or coindexed variable of either integer - type with @code{ATOMIC_INT_KIND} kind or logical type - with @code{ATOMIC_LOGICAL_KIND} kind. -@item @var{VALURE} @tab Scalar and of the same type as @var{ATOM}. If the kind - is different, the value is converted to the kind of - @var{ATOM}. +type with @code{ATOMIC_INT_KIND} kind or logical type with +@code{ATOMIC_LOGICAL_KIND} kind. + +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. @end multitable @item @emph{Example}: @@ -1593,7 +1761,263 @@ end program atomic @end smallexample @item @emph{See also}: -@ref{ATOMIC_REF}, @ref{ISO_FORTRAN_ENV} +@ref{ATOMIC_REF}, @ref{ATOMIC_CAS}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_ADD}, @ref{ATOMIC_AND}, @ref{ATOMIC_OR}, @ref{ATOMIC_XOR} +@end table + + + +@node ATOMIC_FETCH_ADD +@section @code{ATOMIC_FETCH_ADD} --- Atomic ADD operation with prior fetch +@fnindex ATOMIC_FETCH_ADD +@cindex Atomic subroutine, ADD with fetch + +@table @asis +@item @emph{Description}: +@code{ATOMIC_FETCH_ADD(ATOM, VALUE, OLD)} atomically stores the value of +@var{ATOM} in @var{OLD} and adds the value of @var{VAR} to the +variable @var{ATOM}. When @var{STAT} is present and the invokation was +successful, it is assigned the value 0. If it is present and the invokation +has failed, it is assigned a positive value; in particular, for a coindexed +@var{ATOM}, if the remote image has stopped, it is assigned the value of +@code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has +failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_FETCH_ADD (ATOM, VALUE, old [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of integer +type with @code{ATOMIC_INT_KIND} kind. +@code{ATOMIC_LOGICAL_KIND} kind. + +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + integer(atomic_int_kind) :: atom[*], old + call atomic_add (atom[1], this_image(), old) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_ADD}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_FETCH_AND}, @ref{ATOMIC_FETCH_OR}, @ref{ATOMIC_FETCH_XOR} +@end table + + + +@node ATOMIC_FETCH_AND +@section @code{ATOMIC_FETCH_AND} --- Atomic bitwise AND operation with prior fetch +@fnindex ATOMIC_FETCH_AND +@cindex Atomic subroutine, AND with fetch + +@table @asis +@item @emph{Description}: +@code{ATOMIC_AND(ATOM, VALUE)} atomically stores the value of @var{ATOM} in +@var{OLD} and defines @var{ATOM} with the bitwise AND between the values of +@var{ATOM} and @var{VALUE}. When @var{STAT} is present and the invokation was +successful, it is assigned the value 0. If it is present and the invokation has +failed, it is assigned a positive value; in particular, for a coindexed +@var{ATOM}, if the remote image has stopped, it is assigned the value of +@code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has +failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_FETCH_AND (ATOM, VALUE, OLD [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of integer +type with @code{ATOMIC_INT_KIND} kind. +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + integer(atomic_int_kind) :: atom[*], old + call atomic_fetch_and (atom[1], int(b'10100011101'), old) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_AND}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_FETCH_ADD}, @ref{ATOMIC_FETCH_OR}, @ref{ATOMIC_FETCH_XOR} +@end table + + + +@node ATOMIC_FETCH_OR +@section @code{ATOMIC_FETCH_OR} --- Atomic bitwise OR operation with prior fetch +@fnindex ATOMIC_FETCH_OR +@cindex Atomic subroutine, OR with fetch + +@table @asis +@item @emph{Description}: +@code{ATOMIC_OR(ATOM, VALUE)} atomically stores the value of @var{ATOM} in +@var{OLD} and defines @var{ATOM} with the bitwise OR between the values of +@var{ATOM} and @var{VALUE}. When @var{STAT} is present and the invokation was +successful, it is assigned the value 0. If it is present and the invokation has +failed, it is assigned a positive value; in particular, for a coindexed +@var{ATOM}, if the remote image has stopped, it is assigned the value of +@code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has +failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_FETCH_OR (ATOM, VALUE, OLD [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of integer +type with @code{ATOMIC_INT_KIND} kind. +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + integer(atomic_int_kind) :: atom[*], old + call atomic_fetch_or (atom[1], int(b'10100011101'), old) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_OR}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_FETCH_ADD}, @ref{ATOMIC_FETCH_AND}, @ref{ATOMIC_FETCH_XOR} +@end table + + + +@node ATOMIC_FETCH_XOR +@section @code{ATOMIC_FETCH_XOR} --- Atomic bitwise XOR operation with prior fetch +@fnindex ATOMIC_FETCH_XOR +@cindex Atomic subroutine, XOR with fetch + +@table @asis +@item @emph{Description}: +@code{ATOMIC_XOR(ATOM, VALUE)} atomically stores the value of @var{ATOM} in +@var{OLD} and defines @var{ATOM} with the bitwise XOR between the values of +@var{ATOM} and @var{VALUE}. When @var{STAT} is present and the invokation was +successful, it is assigned the value 0. If it is present and the invokation has +failed, it is assigned a positive value; in particular, for a coindexed +@var{ATOM}, if the remote image has stopped, it is assigned the value of +@code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image has +failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_FETCH_XOR (ATOM, VALUE, OLD [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of integer +type with @code{ATOMIC_INT_KIND} kind. +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{OLD} @tab Scalar of the same type and kind as @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + integer(atomic_int_kind) :: atom[*], old + call atomic_fetch_xor (atom[1], int(b'10100011101'), old) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_XOR}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_FETCH_ADD}, @ref{ATOMIC_FETCH_AND}, @ref{ATOMIC_FETCH_OR} +@end table + + + +@node ATOMIC_OR +@section @code{ATOMIC_OR} --- Atomic bitwise OR operation +@fnindex ATOMIC_OR +@cindex Atomic subroutine, OR + +@table @asis +@item @emph{Description}: +@code{ATOMIC_OR(ATOM, VALUE)} atomically defines @var{ATOM} with the bitwise +AND between the values of @var{ATOM} and @var{VALUE}. When @var{STAT} is present +and the invokation was successful, it is assigned the value 0. If it is present +and the invokation has failed, it is assigned a positive value; in particular, +for a coindexed @var{ATOM}, if the remote image has stopped, it is assigned the +value of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote +image has failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_OR (ATOM, VALUE [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of integer +type with @code{ATOMIC_INT_KIND} kind. +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + integer(atomic_int_kind) :: atom[*] + call atomic_or (atom[1], int(b'10100011101')) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_FETCH_OR}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_ADD}, @ref{ATOMIC_OR}, @ref{ATOMIC_XOR} @end table @@ -1606,25 +2030,31 @@ end program atomic @table @asis @item @emph{Description}: @code{ATOMIC_DEFINE(ATOM, VALUE)} atomically assigns the value of the -variable @var{ATOM} to @var{VALUE}. +variable @var{ATOM} to @var{VALUE}. When @var{STAT} is present and the +invokation was successful, it is assigned the value 0. If it is present and the +invokation has failed, it is assigned a positive value; in particular, for a +coindexed @var{ATOM}, if the remote image has stopped, it is assigned the value +of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote image +has failed, the value @code{STAT_FAILED_IMAGE}. + @item @emph{Standard}: -Fortran 2008 and later +Fortran 2008 and later; with @var{STAT}, TS 18508 or later @item @emph{Class}: Atomic subroutine @item @emph{Syntax}: -@code{CALL ATOMIC_REF(VALUE, ATOM)} +@code{CALL ATOMIC_REF(VALUE, ATOM [, STAT])} @item @emph{Arguments}: @multitable @columnfractions .15 .70 -@item @var{VALURE} @tab Scalar and of the same type as @var{ATOM}. If the kind - is different, the value is converted to the kind of - @var{ATOM}. +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. @item @var{ATOM} @tab Scalar coarray or coindexed variable of either integer - type with @code{ATOMIC_INT_KIND} kind or logical type - with @code{ATOMIC_LOGICAL_KIND} kind. +type with @code{ATOMIC_INT_KIND} kind or logical type with +@code{ATOMIC_LOGICAL_KIND} kind. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. @end multitable @item @emph{Example}: @@ -1643,10 +2073,59 @@ end program atomic @end smallexample @item @emph{See also}: -@ref{ATOMIC_DEFINE}, @ref{ISO_FORTRAN_ENV} +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_CAS}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_FETCH_ADD}, @ref{ATOMIC_FETCH_AND}, @ref{ATOMIC_FETCH_OR}, +@ref{ATOMIC_FETCH_XOR} @end table +@node ATOMIC_XOR +@section @code{ATOMIC_XOR} --- Atomic bitwise OR operation +@fnindex ATOMIC_XOR +@cindex Atomic subroutine, XOR + +@table @asis +@item @emph{Description}: +@code{ATOMIC_AND(ATOM, VALUE)} atomically defines @var{ATOM} with the bitwise +XOR between the values of @var{ATOM} and @var{VALUE}. When @var{STAT} is present +and the invokation was successful, it is assigned the value 0. If it is present +and the invokation has failed, it is assigned a positive value; in particular, +for a coindexed @var{ATOM}, if the remote image has stopped, it is assigned the +value of @code{ISO_FORTRAN_ENV}'s @code{STAT_STOPPED_IMAGE} and if the remote +image has failed, the value @code{STAT_FAILED_IMAGE}. + +@item @emph{Standard}: +TS 18508 or later + +@item @emph{Class}: +Atomic subroutine + +@item @emph{Syntax}: +@code{CALL ATOMIC_XOR (ATOM, VALUE [, STAT])} + +@item @emph{Arguments}: +@multitable @columnfractions .15 .70 +@item @var{ATOM} @tab Scalar coarray or coindexed variable of integer +type with @code{ATOMIC_INT_KIND} kind. +@item @var{VALUE} @tab Scalar of the same type as @var{ATOM}. If the kind +is different, the value is converted to the kind of @var{ATOM}. +@item @var{STAT} @tab (optional) Scalar default-kind integer variable. +@end multitable + +@item @emph{Example}: +@smallexample +program atomic + use iso_fortran_env + integer(atomic_int_kind) :: atom[*] + call atomic_xor (atom[1], int(b'10100011101')) +end program atomic +@end smallexample + +@item @emph{See also}: +@ref{ATOMIC_DEFINE}, @ref{ATOMIC_FETCH_XOR}, @ref{ISO_FORTRAN_ENV}, +@ref{ATOMIC_ADD}, @ref{ATOMIC_OR}, @ref{ATOMIC_XOR} +@end table + @node BACKTRACE @section @code{BACKTRACE} --- Show a backtrace @@ -13252,6 +13731,11 @@ Positive, scalar default-integer constant used as STAT= return value if the argument in the statement requires synchronisation with an image, which has initiated the termination of the execution. (Fortran 2008 or later.) +@item @code{STAT_FAILED_IMAGE}: +Positive, scalar default-integer constant used as STAT= return value if the +argument in the statement requires communication with an image, which has +is in the failed state. (TS 18508 or later.) + @item @code{STAT_UNLOCKED}: Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to denote that the lock variable is unlocked. (Fortran 2008 or later.) diff --git a/gcc/fortran/iso-fortran-env.def b/gcc/fortran/iso-fortran-env.def index ebadaef..c1d990a 100644 --- a/gcc/fortran/iso-fortran-env.def +++ b/gcc/fortran/iso-fortran-env.def @@ -85,6 +85,8 @@ NAMED_INTCST (ISOFORTRANENV_FILE_STAT_LOCKED_OTHER_IMAGE, \ GFC_STAT_LOCKED_OTHER_IMAGE, GFC_STD_F2008) NAMED_INTCST (ISOFORTRANENV_FILE_STAT_STOPPED_IMAGE, "stat_stopped_image", \ GFC_STAT_STOPPED_IMAGE, GFC_STD_F2008) +NAMED_INTCST (ISOFORTRANENV_FILE_STAT_FAILED_IMAGE, "stat_failed_image", \ + GFC_STAT_FAILED_IMAGE, GFC_STD_F2008_TS) NAMED_INTCST (ISOFORTRANENV_FILE_STAT_UNLOCKED, "stat_unlocked", \ GFC_STAT_UNLOCKED, GFC_STD_F2008) diff --git a/gcc/fortran/libgfortran.h b/gcc/fortran/libgfortran.h index 1f8616f..b90dac6 100644 --- a/gcc/fortran/libgfortran.h +++ b/gcc/fortran/libgfortran.h @@ -115,7 +115,8 @@ typedef enum GFC_STAT_UNLOCKED = 0, GFC_STAT_LOCKED, GFC_STAT_LOCKED_OTHER_IMAGE, - GFC_STAT_STOPPED_IMAGE = 6000 /* See LIBERROR_INQUIRE_INTERNAL_UNIT above. */ + GFC_STAT_STOPPED_IMAGE = 6000, /* See LIBERROR_INQUIRE_INTERNAL_UNIT above. */ + GFC_STAT_FAILED_IMAGE } libgfortran_stat_codes; diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 5aa5683..a285e9d 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -8339,25 +8339,104 @@ conv_co_minmaxsum (gfc_code *code) static tree -conv_intrinsic_atomic_def (gfc_code *code) +conv_intrinsic_atomic_op (gfc_code *code) { - gfc_se atom, value; - stmtblock_t block; + gfc_se atom, value, old; + tree tmp; + stmtblock_t block, post_block; gfc_expr *atom_expr = code->ext.actual->expr; + gfc_expr *stat; + built_in_function fn; if (atom_expr->expr_type == EXPR_FUNCTION && atom_expr->value.function.isym && atom_expr->value.function.isym->id == GFC_ISYM_CAF_GET) atom_expr = atom_expr->value.function.actual->expr; + gfc_start_block (&block); + gfc_init_block (&post_block); gfc_init_se (&atom, NULL); gfc_init_se (&value, NULL); + atom.want_pointer = 1; gfc_conv_expr (&atom, atom_expr); + gfc_add_block_to_block (&block, &atom.pre); + gfc_add_block_to_block (&post_block, &atom.post); gfc_conv_expr (&value, code->ext.actual->next->expr); + gfc_add_block_to_block (&block, &value.pre); + gfc_add_block_to_block (&post_block, &value.post); - gfc_init_block (&block); - gfc_add_modify (&block, atom.expr, - fold_convert (TREE_TYPE (atom.expr), value.expr)); + switch (code->resolved_isym->id) + { + case GFC_ISYM_ATOMIC_ADD: + case GFC_ISYM_ATOMIC_FETCH_ADD: + fn = BUILT_IN_ATOMIC_FETCH_ADD_N; + break; + case GFC_ISYM_ATOMIC_AND: + case GFC_ISYM_ATOMIC_FETCH_AND: + fn = BUILT_IN_ATOMIC_FETCH_AND_N; + break; + case GFC_ISYM_ATOMIC_DEF: + fn = BUILT_IN_ATOMIC_STORE_N; + break; + case GFC_ISYM_ATOMIC_OR: + case GFC_ISYM_ATOMIC_FETCH_OR: + fn = BUILT_IN_ATOMIC_FETCH_OR_N; + break; + case GFC_ISYM_ATOMIC_XOR: + case GFC_ISYM_ATOMIC_FETCH_XOR: + fn = BUILT_IN_ATOMIC_FETCH_XOR_N; + break; + default: + gcc_unreachable (); + } + + tmp = TREE_TYPE (TREE_TYPE (atom.expr)); + fn = (built_in_function) ((int) fn + + exact_log2 (tree_to_uhwi (TYPE_SIZE_UNIT (tmp))) + + 1); + tmp = builtin_decl_explicit (fn); + tree itype = TREE_TYPE (TREE_TYPE (atom.expr)); + tmp = builtin_decl_explicit (fn); + + switch (code->resolved_isym->id) + { + case GFC_ISYM_ATOMIC_ADD: + case GFC_ISYM_ATOMIC_AND: + case GFC_ISYM_ATOMIC_DEF: + case GFC_ISYM_ATOMIC_OR: + case GFC_ISYM_ATOMIC_XOR: + stat = code->ext.actual->next->next->expr; + tmp = build_call_expr_loc (input_location, tmp, 3, atom.expr, + fold_convert (itype, value.expr), + build_int_cst (NULL, MEMMODEL_RELAXED)); + gfc_add_expr_to_block (&block, tmp); + break; + default: + stat = code->ext.actual->next->next->next->expr; + gfc_init_se (&old, NULL); + gfc_conv_expr (&old, code->ext.actual->next->next->expr); + gfc_add_block_to_block (&block, &old.pre); + gfc_add_block_to_block (&post_block, &old.post); + tmp = build_call_expr_loc (input_location, tmp, 3, atom.expr, + fold_convert (itype, value.expr), + build_int_cst (NULL, MEMMODEL_RELAXED)); + gfc_add_modify (&block, old.expr, + fold_convert (TREE_TYPE (old.expr), tmp)); + break; + } + + /* STAT= */ + if (stat != NULL) + { + gcc_assert (stat->expr_type == EXPR_VARIABLE); + gfc_init_se (&value, NULL); + gfc_conv_expr_val (&value, stat); + gfc_add_block_to_block (&block, &value.pre); + gfc_add_block_to_block (&post_block, &value.post); + gfc_add_modify (&block, value.expr, + build_int_cst (TREE_TYPE (value.expr), 0)); + } + gfc_add_block_to_block (&block, &post_block); return gfc_finish_block (&block); } @@ -8366,22 +8445,124 @@ static tree conv_intrinsic_atomic_ref (gfc_code *code) { gfc_se atom, value; - stmtblock_t block; - gfc_expr *atom_expr = code->ext.actual->expr; + tree tmp; + stmtblock_t block, post_block; + built_in_function fn; + gfc_expr *atom_expr = code->ext.actual->next->expr; if (atom_expr->expr_type == EXPR_FUNCTION && atom_expr->value.function.isym && atom_expr->value.function.isym->id == GFC_ISYM_CAF_GET) atom_expr = atom_expr->value.function.actual->expr; + gfc_start_block (&block); + gfc_init_block (&post_block); gfc_init_se (&atom, NULL); gfc_init_se (&value, NULL); - gfc_conv_expr (&value, atom_expr); - gfc_conv_expr (&atom, code->ext.actual->next->expr); + atom.want_pointer = 1; + gfc_conv_expr (&value, code->ext.actual->expr); + gfc_add_block_to_block (&block, &value.pre); + gfc_add_block_to_block (&post_block, &value.post); + gfc_conv_expr (&atom, atom_expr); + gfc_add_block_to_block (&block, &atom.pre); + gfc_add_block_to_block (&post_block, &atom.post); + + tmp = TREE_TYPE (TREE_TYPE (atom.expr)); + fn = (built_in_function) ((int) BUILT_IN_ATOMIC_LOAD_N + + exact_log2 (tree_to_uhwi (TYPE_SIZE_UNIT (tmp))) + + 1); + tmp = builtin_decl_explicit (fn); + tmp = build_call_expr_loc (input_location, tmp, 2, atom.expr, + build_int_cst (integer_type_node, + MEMMODEL_RELAXED)); + gfc_add_modify (&block, value.expr, + fold_convert (TREE_TYPE (value.expr), tmp)); + + /* STAT= */ + if (code->ext.actual->next->next->expr != NULL) + { + gcc_assert (code->ext.actual->next->next->expr->expr_type + == EXPR_VARIABLE); + gfc_init_se (&value, NULL); + gfc_conv_expr_val (&value, code->ext.actual->next->next->expr); + gfc_add_block_to_block (&block, &value.pre); + gfc_add_block_to_block (&post_block, &value.post); + gfc_add_modify (&block, value.expr, + build_int_cst (TREE_TYPE (value.expr), 0)); + } + gfc_add_block_to_block (&block, &post_block); + return gfc_finish_block (&block); +} + + +static tree +conv_intrinsic_atomic_cas (gfc_code *code) +{ + gfc_se argse; + tree tmp, atom, old, new_val, comp; + stmtblock_t block, post_block; + built_in_function fn; + gfc_expr *atom_expr = code->ext.actual->expr; + + if (atom_expr->expr_type == EXPR_FUNCTION + && atom_expr->value.function.isym + && atom_expr->value.function.isym->id == GFC_ISYM_CAF_GET) + atom_expr = atom_expr->value.function.actual->expr; gfc_init_block (&block); - gfc_add_modify (&block, value.expr, - fold_convert (TREE_TYPE (value.expr), atom.expr)); + gfc_init_block (&post_block); + gfc_init_se (&argse, NULL); + argse.want_pointer = 1; + gfc_conv_expr (&argse, atom_expr); + atom = argse.expr; + + gfc_init_se (&argse, NULL); + gfc_conv_expr (&argse, code->ext.actual->next->expr); + gfc_add_block_to_block (&block, &argse.pre); + gfc_add_block_to_block (&post_block, &argse.post); + old = argse.expr; + + gfc_init_se (&argse, NULL); + gfc_conv_expr (&argse, code->ext.actual->next->next->expr); + gfc_add_block_to_block (&block, &argse.pre); + gfc_add_block_to_block (&post_block, &argse.post); + comp = argse.expr; + + gfc_init_se (&argse, NULL); + gfc_conv_expr (&argse, code->ext.actual->next->next->next->expr); + gfc_add_block_to_block (&block, &argse.pre); + gfc_add_block_to_block (&post_block, &argse.post); + new_val = argse.expr; + + tmp = TREE_TYPE (TREE_TYPE (atom)); + fn = (built_in_function) ((int) BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N + + exact_log2 (tree_to_uhwi (TYPE_SIZE_UNIT (tmp))) + + 1); + tmp = builtin_decl_explicit (fn); + + gfc_add_modify (&block, old, comp); + tmp = build_call_expr_loc (input_location, tmp, 6, atom, + gfc_build_addr_expr (NULL, old), + fold_convert (TREE_TYPE (old), new_val), + boolean_false_node, + build_int_cst (NULL, MEMMODEL_RELAXED), + build_int_cst (NULL, MEMMODEL_RELAXED)); + gfc_add_expr_to_block (&block, tmp); + + /* STAT= */ + if (code->ext.actual->next->next->next->next->expr != NULL) + { + gcc_assert (code->ext.actual->next->next->next->next->expr->expr_type + == EXPR_VARIABLE); + gfc_init_se (&argse, NULL); + gfc_conv_expr_val (&argse, + code->ext.actual->next->next->next->next->expr); + gfc_add_block_to_block (&block, &argse.pre); + gfc_add_block_to_block (&post_block, &argse.post); + gfc_add_modify (&block, argse.expr, + build_int_cst (TREE_TYPE (argse.expr), 0)); + } + gfc_add_block_to_block (&block, &post_block); return gfc_finish_block (&block); } @@ -8632,8 +8813,20 @@ gfc_conv_intrinsic_subroutine (gfc_code *code) res = conv_intrinsic_move_alloc (code); break; + case GFC_ISYM_ATOMIC_CAS: + res = conv_intrinsic_atomic_cas (code); + break; + + case GFC_ISYM_ATOMIC_ADD: + case GFC_ISYM_ATOMIC_AND: case GFC_ISYM_ATOMIC_DEF: - res = conv_intrinsic_atomic_def (code); + case GFC_ISYM_ATOMIC_OR: + case GFC_ISYM_ATOMIC_XOR: + case GFC_ISYM_ATOMIC_FETCH_ADD: + case GFC_ISYM_ATOMIC_FETCH_AND: + case GFC_ISYM_ATOMIC_FETCH_OR: + case GFC_ISYM_ATOMIC_FETCH_XOR: + res = conv_intrinsic_atomic_op (code); break; case GFC_ISYM_ATOMIC_REF: |