[RS6000] fix rtl-checking internal compiler error
[official-gcc.git] / libgfortran / caf / libcaf.h
blob1bb5176a6c1f6c49cf2ff2d684b86b860f06a762
1 /* Common declarations for all of GNU Fortran libcaf implementations.
2 Copyright (C) 2011-2016 Free Software Foundation, Inc.
3 Contributed by Tobias Burnus <burnus@net-b.de>
5 This file is part of the GNU Fortran Coarray Runtime Library (libcaf).
7 Libcaf is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 Libcaf is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef LIBCAF_H
27 #define LIBCAF_H
29 #include <stdbool.h>
30 #include <stddef.h> /* For size_t. */
31 #include <stdint.h> /* For int32_t. */
33 #include "libgfortran.h"
35 #if 0
36 #ifndef __GNUC__
37 #define __attribute__(x)
38 #define likely(x) (x)
39 #define unlikely(x) (x)
40 #else
41 #define likely(x) __builtin_expect(!!(x), 1)
42 #define unlikely(x) __builtin_expect(!!(x), 0)
43 #endif
45 /* Definitions of the Fortran 2008 standard; need to kept in sync with
46 ISO_FORTRAN_ENV, cf. libgfortran.h. */
47 #define STAT_UNLOCKED 0
48 #define STAT_LOCKED 1
49 #define STAT_LOCKED_OTHER_IMAGE 2
50 #define STAT_STOPPED_IMAGE 6000
51 #endif
53 /* Describes what type of array we are registerring. Keep in sync with
54 gcc/fortran/trans.h. */
55 typedef enum caf_register_t {
56 CAF_REGTYPE_COARRAY_STATIC,
57 CAF_REGTYPE_COARRAY_ALLOC,
58 CAF_REGTYPE_LOCK_STATIC,
59 CAF_REGTYPE_LOCK_ALLOC,
60 CAF_REGTYPE_CRITICAL,
61 CAF_REGTYPE_EVENT_STATIC,
62 CAF_REGTYPE_EVENT_ALLOC,
63 CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY,
64 CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY
66 caf_register_t;
68 /* Describes the action to take on _caf_deregister. Keep in sync with
69 gcc/fortran/trans.h. */
70 typedef enum caf_deregister_t {
71 CAF_DEREGTYPE_COARRAY_DEREGISTER,
72 CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY
74 caf_deregister_t;
76 typedef void* caf_token_t;
77 typedef gfc_array_void gfc_descriptor_t;
79 /* Linked list of static coarrays registered. */
80 typedef struct caf_static_t {
81 caf_token_t token;
82 struct caf_static_t *prev;
84 caf_static_t;
86 /* When there is a vector subscript in this dimension, nvec == 0, otherwise,
87 lower_bound, upper_bound, stride contains the bounds relative to the declared
88 bounds; kind denotes the integer kind of the elements of vector[]. */
89 typedef struct caf_vector_t {
90 size_t nvec;
91 union {
92 struct {
93 void *vector;
94 int kind;
95 } v;
96 struct {
97 ptrdiff_t lower_bound, upper_bound, stride;
98 } triplet;
99 } u;
101 caf_vector_t;
103 typedef enum caf_ref_type_t {
104 /* Reference a component of a derived type, either regular one or an
105 allocatable or pointer type. For regular ones idx in caf_reference_t is
106 set to -1. */
107 CAF_REF_COMPONENT,
108 /* Reference an allocatable array. */
109 CAF_REF_ARRAY,
110 /* Reference a non-allocatable/non-pointer array. */
111 CAF_REF_STATIC_ARRAY
112 } caf_ref_type_t;
114 typedef enum caf_array_ref_t {
115 /* No array ref. This terminates the array ref. */
116 CAF_ARR_REF_NONE = 0,
117 /* Reference array elements given by a vector. Only for this mode
118 caf_reference_t.u.a.dim[i].v is valid. */
119 CAF_ARR_REF_VECTOR,
120 /* A full array ref (:). */
121 CAF_ARR_REF_FULL,
122 /* Reference a range on elements given by start, end and stride. */
123 CAF_ARR_REF_RANGE,
124 /* Only a single item is referenced given in the start member. */
125 CAF_ARR_REF_SINGLE,
126 /* An array ref of the kind (i:), where i is an arbitrary valid index in the
127 array. The index i is given in the start member. */
128 CAF_ARR_REF_OPEN_END,
129 /* An array ref of the kind (:i), where the lower bound of the array ref
130 is given by the remote side. The index i is given in the end member. */
131 CAF_ARR_REF_OPEN_START
132 } caf_array_ref_t;
134 /* References to remote components of a derived type. */
135 typedef struct caf_reference_t {
136 /* A pointer to the next ref or NULL. */
137 struct caf_reference_t *next;
138 /* The type of the reference. */
139 /* caf_ref_type_t, replaced by int to allow specification in fortran FE. */
140 int type;
141 /* The size of an item referenced in bytes. I.e. in an array ref this is
142 the factor to advance the array pointer with to get to the next item.
143 For component refs this gives just the size of the element referenced. */
144 size_t item_size;
145 union {
146 struct {
147 /* The offset (in bytes) of the component in the derived type. */
148 ptrdiff_t offset;
149 /* The offset (in bytes) to the caf_token associated with this
150 component. NULL, when not allocatable/pointer ref. */
151 ptrdiff_t caf_token_offset;
152 } c;
153 struct {
154 /* The mode of the array ref. See CAF_ARR_REF_*. */
155 /* caf_array_ref_t, replaced by unsigend char to allow specification in
156 fortran FE. */
157 unsigned char mode[GFC_MAX_DIMENSIONS];
158 /* The type of a static array. Unset for array's with descriptors. */
159 int static_array_type;
160 /* Subscript refs (s) or vector refs (v). */
161 union {
162 struct {
163 /* The start and end boundary of the ref and the stride. */
164 index_type start, end, stride;
165 } s;
166 struct {
167 /* nvec entries of kind giving the elements to reference. */
168 void *vector;
169 /* The number of entries in vector. */
170 size_t nvec;
171 /* The integer kind used for the elements in vector. */
172 int kind;
173 } v;
174 } dim[GFC_MAX_DIMENSIONS];
175 } a;
176 } u;
177 } caf_reference_t;
179 void _gfortran_caf_init (int *, char ***);
180 void _gfortran_caf_finalize (void);
182 int _gfortran_caf_this_image (int);
183 int _gfortran_caf_num_images (int, int);
185 void _gfortran_caf_register (size_t, caf_register_t, caf_token_t *,
186 gfc_descriptor_t *, int *, char *, int);
187 void _gfortran_caf_deregister (caf_token_t *, caf_deregister_t, int *, char *,
188 int);
190 void _gfortran_caf_sync_all (int *, char *, int);
191 void _gfortran_caf_sync_memory (int *, char *, int);
192 void _gfortran_caf_sync_images (int, int[], int *, char *, int);
194 void _gfortran_caf_stop_numeric (int32_t)
195 __attribute__ ((noreturn));
196 void _gfortran_caf_stop_str (const char *, int32_t)
197 __attribute__ ((noreturn));
198 void _gfortran_caf_error_stop_str (const char *, int32_t)
199 __attribute__ ((noreturn));
200 void _gfortran_caf_error_stop (int32_t) __attribute__ ((noreturn));
202 void _gfortran_caf_co_broadcast (gfc_descriptor_t *, int, int *, char *, int);
203 void _gfortran_caf_co_sum (gfc_descriptor_t *, int, int *, char *, int);
204 void _gfortran_caf_co_min (gfc_descriptor_t *, int, int *, char *, int, int);
205 void _gfortran_caf_co_max (gfc_descriptor_t *, int, int *, char *, int, int);
206 void _gfortran_caf_co_reduce (gfc_descriptor_t *, void* (*) (void *, void*),
207 int, int, int *, char *, int, int);
209 void _gfortran_caf_get (caf_token_t, size_t, int, gfc_descriptor_t *,
210 caf_vector_t *, gfc_descriptor_t *, int, int, bool,
211 int *);
212 void _gfortran_caf_send (caf_token_t, size_t, int, gfc_descriptor_t *,
213 caf_vector_t *, gfc_descriptor_t *, int, int, bool,
214 int *);
215 void _gfortran_caf_sendget (caf_token_t, size_t, int, gfc_descriptor_t *,
216 caf_vector_t *, caf_token_t, size_t, int,
217 gfc_descriptor_t *, caf_vector_t *, int, int, bool);
219 void _gfortran_caf_get_by_ref (caf_token_t token, int image_idx,
220 gfc_descriptor_t *dst, caf_reference_t *refs, int dst_kind,
221 int src_kind, bool may_require_tmp, bool dst_reallocatable, int *stat);
222 void _gfortran_caf_send_by_ref (caf_token_t token, int image_index,
223 gfc_descriptor_t *src, caf_reference_t *refs, int dst_kind,
224 int src_kind, bool may_require_tmp, bool dst_reallocatable, int *stat);
225 void _gfortran_caf_sendget_by_ref (
226 caf_token_t dst_token, int dst_image_index, caf_reference_t *dst_refs,
227 caf_token_t src_token, int src_image_index, caf_reference_t *src_refs,
228 int dst_kind, int src_kind, bool may_require_tmp, int *dst_stat,
229 int *src_stat);
231 void _gfortran_caf_atomic_define (caf_token_t, size_t, int, void *, int *,
232 int, int);
233 void _gfortran_caf_atomic_ref (caf_token_t, size_t, int, void *, int *,
234 int, int);
235 void _gfortran_caf_atomic_cas (caf_token_t, size_t, int, void *, void *,
236 void *, int *, int, int);
237 void _gfortran_caf_atomic_op (int, caf_token_t, size_t, int, void *, void *,
238 int *, int, int);
240 void _gfortran_caf_lock (caf_token_t, size_t, int, int *, int *, char *, int);
241 void _gfortran_caf_unlock (caf_token_t, size_t, int, int *, char *, int);
242 void _gfortran_caf_event_post (caf_token_t, size_t, int, int *, char *, int);
243 void _gfortran_caf_event_wait (caf_token_t, size_t, int, int *, char *, int);
244 void _gfortran_caf_event_query (caf_token_t, size_t, int, int *, int *);
246 int _gfortran_caf_is_present (caf_token_t, int, caf_reference_t *);
248 #endif /* LIBCAF_H */