Skip to content

Commit 71c41bf

Browse files
author
Damian Rouson
authored
Merge pull request #8 from sourceryinstitute/teams
Merge sourceryinstitute/master into sourceryinstitute/teams
2 parents 7204ca4 + 62bf309 commit 71c41bf

22 files changed

+487
-14
lines changed

gcc/fortran/array.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec *as, int init,
158158
bool matched_bracket = false;
159159
gfc_expr *tmp;
160160
bool stat_just_seen = false;
161-
161+
bool team_just_seen = false;
162+
162163
memset (ar, '\0', sizeof (*ar));
163164

164165
ar->where = gfc_current_locus;
@@ -230,7 +231,21 @@ gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec *as, int init,
230231
if (m == MATCH_ERROR)
231232
return MATCH_ERROR;
232233

234+
team_just_seen = false;
233235
stat_just_seen = false;
236+
237+
if (gfc_match(" , team = %e",&tmp) == MATCH_YES && ar->stat == NULL)
238+
{
239+
ar->team = tmp;
240+
team_just_seen = true;
241+
}
242+
243+
if (ar->team && !team_just_seen)
244+
{
245+
gfc_error ("TEAM= attribute in %C misplaced");
246+
return MATCH_ERROR;
247+
}
248+
234249
if (gfc_match(" , stat = %e",&tmp) == MATCH_YES && ar->stat == NULL)
235250
{
236251
ar->stat = tmp;

gcc/fortran/check.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,20 @@ gfc_check_failed_or_stopped_images (gfc_expr *team, gfc_expr *kind)
12131213
return true;
12141214
}
12151215

1216+
bool
1217+
gfc_check_get_team (gfc_expr *level)
1218+
{
1219+
if (level)
1220+
{
1221+
gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
1222+
gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
1223+
&level->where);
1224+
return false;
1225+
}
1226+
1227+
return true;
1228+
}
1229+
12161230

12171231
bool
12181232
gfc_check_atomic_cas (gfc_expr *atom, gfc_expr *old, gfc_expr *compare,

gcc/fortran/dump-parse-tree.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,22 @@ show_code_node (int level, gfc_code *c)
18691869
fputs ("FAIL IMAGE ", dumpfile);
18701870
break;
18711871

1872+
case EXEC_CHANGE_TEAM:
1873+
fputs ("CHANGE TEAM", dumpfile);
1874+
break;
1875+
1876+
case EXEC_END_TEAM:
1877+
fputs ("END TEAM", dumpfile);
1878+
break;
1879+
1880+
case EXEC_FORM_TEAM:
1881+
fputs ("FORM TEAM", dumpfile);
1882+
break;
1883+
1884+
case EXEC_SYNC_TEAM:
1885+
fputs ("SYNC TEAM", dumpfile);
1886+
break;
1887+
18721888
case EXEC_SYNC_ALL:
18731889
fputs ("SYNC ALL ", dumpfile);
18741890
if (c->expr2 != NULL)

gcc/fortran/expr.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4982,6 +4982,24 @@ gfc_ref_this_image (gfc_ref *ref)
49824982
return true;
49834983
}
49844984

4985+
gfc_expr *
4986+
gfc_find_team_co(gfc_expr *e)
4987+
{
4988+
gfc_ref *ref;
4989+
4990+
for (ref = e->ref; ref; ref = ref->next)
4991+
if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0)
4992+
return ref->u.ar.team;
4993+
4994+
if (e->value.function.actual->expr)
4995+
for (ref = e->value.function.actual->expr->ref; ref;
4996+
ref = ref->next)
4997+
if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0)
4998+
return ref->u.ar.team;
4999+
5000+
return NULL;
5001+
}
5002+
49855003
gfc_expr *
49865004
gfc_find_stat_co(gfc_expr *e)
49875005
{

gcc/fortran/gfortran.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ enum gfc_statement
263263
ST_OMP_TASKLOOP_SIMD, ST_OMP_END_TASKLOOP_SIMD, ST_OMP_ORDERED_DEPEND,
264264
ST_PROCEDURE, ST_GENERIC, ST_CRITICAL, ST_END_CRITICAL,
265265
ST_GET_FCN_CHARACTERISTICS, ST_LOCK, ST_UNLOCK, ST_EVENT_POST,
266-
ST_EVENT_WAIT,ST_FAIL_IMAGE,ST_NONE
266+
ST_EVENT_WAIT, ST_FAIL_IMAGE, ST_FORM_TEAM, ST_CHANGE_TEAM,
267+
ST_END_TEAM, ST_SYNC_TEAM, ST_NONE
267268
};
268269

269270
/* Types of interfaces that we can have. Assignment interfaces are
@@ -456,6 +457,7 @@ enum gfc_isym_id
456457
GFC_ISYM_GETLOG,
457458
GFC_ISYM_GETPID,
458459
GFC_ISYM_GETUID,
460+
GFC_ISYM_GET_TEAM,
459461
GFC_ISYM_GMTIME,
460462
GFC_ISYM_HOSTNM,
461463
GFC_ISYM_HUGE,
@@ -1913,6 +1915,7 @@ typedef struct gfc_array_ref
19131915
int dimen; /* # of components in the reference */
19141916
int codimen;
19151917
bool in_allocate; /* For coarray checks. */
1918+
gfc_expr *team;
19161919
gfc_expr *stat;
19171920
locus where;
19181921
gfc_array_spec *as;
@@ -2488,6 +2491,7 @@ enum gfc_exec_op
24882491
EXEC_OPEN, EXEC_CLOSE, EXEC_WAIT,
24892492
EXEC_READ, EXEC_WRITE, EXEC_IOLENGTH, EXEC_TRANSFER, EXEC_DT_END,
24902493
EXEC_BACKSPACE, EXEC_ENDFILE, EXEC_INQUIRE, EXEC_REWIND, EXEC_FLUSH,
2494+
EXEC_FORM_TEAM, EXEC_CHANGE_TEAM, EXEC_END_TEAM, EXEC_SYNC_TEAM,
24912495
EXEC_LOCK, EXEC_UNLOCK, EXEC_EVENT_POST, EXEC_EVENT_WAIT, EXEC_FAIL_IMAGE,
24922496
EXEC_OACC_KERNELS_LOOP, EXEC_OACC_PARALLEL_LOOP, EXEC_OACC_ROUTINE,
24932497
EXEC_OACC_PARALLEL, EXEC_OACC_KERNELS, EXEC_OACC_DATA, EXEC_OACC_HOST_DATA,
@@ -3202,6 +3206,7 @@ bool gfc_is_coarray (gfc_expr *);
32023206
int gfc_get_corank (gfc_expr *);
32033207
bool gfc_has_ultimate_allocatable (gfc_expr *);
32043208
bool gfc_has_ultimate_pointer (gfc_expr *);
3209+
gfc_expr* gfc_find_team_co (gfc_expr *);
32053210
gfc_expr* gfc_find_stat_co (gfc_expr *);
32063211
gfc_expr* gfc_build_intrinsic_call (gfc_namespace *, gfc_isym_id, const char*,
32073212
locus, unsigned, ...);

gcc/fortran/intrinsic.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,13 @@ add_functions (void)
19381938

19391939
make_generic ("getpid", GFC_ISYM_GETPID, GFC_STD_GNU);
19401940

1941+
add_sym_1 ("get_team", GFC_ISYM_GET_TEAM, CLASS_TRANSFORMATIONAL,
1942+
ACTUAL_NO, BT_INTEGER, di, GFC_STD_F2008_TS,
1943+
gfc_check_get_team,
1944+
NULL,
1945+
gfc_resolve_get_team,
1946+
"level", BT_INTEGER, di, OPTIONAL);
1947+
19411948
add_sym_0 ("getuid", GFC_ISYM_GETUID, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER,
19421949
di, GFC_STD_GNU, NULL, NULL, gfc_resolve_getuid);
19431950

gcc/fortran/intrinsic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ bool gfc_check_fn_r (gfc_expr *);
8383
bool gfc_check_fn_rc (gfc_expr *);
8484
bool gfc_check_fn_rc2008 (gfc_expr *);
8585
bool gfc_check_fnum (gfc_expr *);
86+
bool gfc_check_get_team (gfc_expr *);
8687
bool gfc_check_hostnm (gfc_expr *);
8788
bool gfc_check_huge (gfc_expr *);
8889
bool gfc_check_hypot (gfc_expr *, gfc_expr *);
@@ -299,6 +300,7 @@ gfc_expr *gfc_simplify_float (gfc_expr *);
299300
gfc_expr *gfc_simplify_floor (gfc_expr *, gfc_expr *);
300301
gfc_expr *gfc_simplify_fraction (gfc_expr *);
301302
gfc_expr *gfc_simplify_gamma (gfc_expr *);
303+
gfc_expr *gfc_simplify_get_team (gfc_expr *);
302304
gfc_expr *gfc_simplify_huge (gfc_expr *);
303305
gfc_expr *gfc_simplify_hypot (gfc_expr *, gfc_expr *);
304306
gfc_expr *gfc_simplify_iachar (gfc_expr *, gfc_expr *);
@@ -493,6 +495,7 @@ void gfc_resolve_gamma (gfc_expr *, gfc_expr *);
493495
void gfc_resolve_getcwd (gfc_expr *, gfc_expr *);
494496
void gfc_resolve_getgid (gfc_expr *);
495497
void gfc_resolve_getpid (gfc_expr *);
498+
void gfc_resolve_get_team (gfc_expr *, gfc_expr *);
496499
void gfc_resolve_getuid (gfc_expr *);
497500
void gfc_resolve_hostnm (gfc_expr *, gfc_expr *);
498501
void gfc_resolve_hypot (gfc_expr *, gfc_expr *, gfc_expr *);

gcc/fortran/iresolve.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,18 @@ gfc_resolve_image_status (gfc_expr *f, gfc_expr *image ATTRIBUTE_UNUSED,
28592859
f->value.function.name = image_status;
28602860
}
28612861

2862+
/* Resolve get_team (). */
2863+
2864+
void
2865+
gfc_resolve_get_team (gfc_expr *f, gfc_expr *level ATTRIBUTE_UNUSED)
2866+
{
2867+
static char get_team[] = "_gfortran_caf_get_team";
2868+
f->rank = 0;
2869+
f->ts.type = BT_INTEGER;
2870+
f->ts.kind = gfc_default_integer_kind;
2871+
f->value.function.name = get_team;
2872+
}
2873+
28622874

28632875
/* Resolve image_index (...). */
28642876

gcc/fortran/iso-fortran-env.def

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ NAMED_DERIVED_TYPE (ISOFORTRAN_LOCK_TYPE, "lock_type", \
125125

126126
NAMED_DERIVED_TYPE (ISOFORTRAN_EVENT_TYPE, "event_type", \
127127
flag_coarray == GFC_FCOARRAY_LIB
128-
? get_int_kind_from_node (ptr_type_node)
128+
? get_int_kind_from_node (ptr_type_node)
129+
: gfc_default_integer_kind, GFC_STD_F2008_TS)
130+
131+
NAMED_DERIVED_TYPE (ISOFORTRAN_TEAM_TYPE, "team_type", \
132+
flag_coarray == GFC_FCOARRAY_LIB
133+
? get_int_kind_from_node (ptr_type_node)
129134
: gfc_default_integer_kind, GFC_STD_F2008_TS)
130135

131136
#undef NAMED_INTCST

gcc/fortran/match.c

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,16 +1595,19 @@ gfc_match_if (gfc_statement *if_type)
15951595
match ("assign", gfc_match_assign, ST_LABEL_ASSIGNMENT)
15961596
match ("backspace", gfc_match_backspace, ST_BACKSPACE)
15971597
match ("call", gfc_match_call, ST_CALL)
1598+
match ("change team", gfc_match_change_team, ST_CHANGE_TEAM)
15981599
match ("close", gfc_match_close, ST_CLOSE)
15991600
match ("continue", gfc_match_continue, ST_CONTINUE)
16001601
match ("cycle", gfc_match_cycle, ST_CYCLE)
16011602
match ("deallocate", gfc_match_deallocate, ST_DEALLOCATE)
16021603
match ("end file", gfc_match_endfile, ST_END_FILE)
1604+
match ("end team", gfc_match_end_team, ST_END_TEAM)
16031605
match ("error stop", gfc_match_error_stop, ST_ERROR_STOP)
16041606
match ("event post", gfc_match_event_post, ST_EVENT_POST)
16051607
match ("event wait", gfc_match_event_wait, ST_EVENT_WAIT)
16061608
match ("exit", gfc_match_exit, ST_EXIT)
16071609
match ("fail image", gfc_match_fail_image, ST_FAIL_IMAGE)
1610+
match ("form team", gfc_match_form_team, ST_FORM_TEAM)
16081611
match ("flush", gfc_match_flush, ST_FLUSH)
16091612
match ("forall", match_simple_forall, ST_FORALL)
16101613
match ("go to", gfc_match_goto, ST_GOTO)
@@ -1620,6 +1623,7 @@ gfc_match_if (gfc_statement *if_type)
16201623
match ("rewind", gfc_match_rewind, ST_REWIND)
16211624
match ("stop", gfc_match_stop, ST_STOP)
16221625
match ("wait", gfc_match_wait, ST_WAIT)
1626+
match ("sync team", gfc_match_sync_team, ST_SYNC_TEAM)
16231627
match ("sync all", gfc_match_sync_all, ST_SYNC_CALL);
16241628
match ("sync images", gfc_match_sync_images, ST_SYNC_IMAGES);
16251629
match ("sync memory", gfc_match_sync_memory, ST_SYNC_MEMORY);
@@ -1659,7 +1663,6 @@ gfc_match_if (gfc_statement *if_type)
16591663
gfc_free_expr (expr);
16601664
return MATCH_ERROR;
16611665
}
1662-
16631666
/* At this point, we've matched the single IF and the action clause
16641667
is in new_st. Rearrange things so that the IF statement appears
16651668
in new_st. */
@@ -3343,6 +3346,136 @@ gfc_match_fail_image (void)
33433346
return MATCH_ERROR;
33443347
}
33453348

3349+
/* Match a FORM TEAM statement. */
3350+
3351+
match
3352+
gfc_match_form_team (void)
3353+
{
3354+
match m;
3355+
gfc_expr *teamid,*team;
3356+
3357+
if (!gfc_notify_std (GFC_STD_F2008_TS, "FORM TEAM statement at %C"))
3358+
return MATCH_ERROR;
3359+
3360+
if (gfc_match_char ('(') == MATCH_NO)
3361+
goto syntax;
3362+
3363+
new_st.op = EXEC_FORM_TEAM;
3364+
3365+
if (gfc_match ("%e", &teamid) != MATCH_YES)
3366+
goto syntax;
3367+
m = gfc_match_char (',');
3368+
if (m == MATCH_ERROR)
3369+
goto syntax;
3370+
if (gfc_match ("%e", &team) != MATCH_YES)
3371+
goto syntax;
3372+
3373+
m = gfc_match_char (')');
3374+
if (m == MATCH_NO)
3375+
goto syntax;
3376+
3377+
new_st.expr1 = teamid;
3378+
new_st.expr2 = team;
3379+
3380+
return MATCH_YES;
3381+
3382+
syntax:
3383+
gfc_syntax_error (ST_FORM_TEAM);
3384+
3385+
return MATCH_ERROR;
3386+
}
3387+
3388+
/* Match a CHANGE TEAM statement. */
3389+
3390+
match
3391+
gfc_match_change_team (void)
3392+
{
3393+
match m;
3394+
gfc_expr *team;
3395+
3396+
if (!gfc_notify_std (GFC_STD_F2008_TS, "CHANGE TEAM statement at %C"))
3397+
return MATCH_ERROR;
3398+
3399+
if (gfc_match_char ('(') == MATCH_NO)
3400+
goto syntax;
3401+
3402+
new_st.op = EXEC_CHANGE_TEAM;
3403+
3404+
/* if (gfc_match ("%e", &teamid) != MATCH_YES) */
3405+
/* goto syntax; */
3406+
/* m = gfc_match_char (','); */
3407+
/* if (m == MATCH_ERROR) */
3408+
/* goto syntax; */
3409+
if (gfc_match ("%e", &team) != MATCH_YES)
3410+
goto syntax;
3411+
3412+
m = gfc_match_char (')');
3413+
if (m == MATCH_NO)
3414+
goto syntax;
3415+
3416+
new_st.expr1 = team;
3417+
3418+
return MATCH_YES;
3419+
3420+
syntax:
3421+
gfc_syntax_error (ST_CHANGE_TEAM);
3422+
3423+
return MATCH_ERROR;
3424+
}
3425+
3426+
/* Match a END TEAM statement. */
3427+
3428+
match
3429+
gfc_match_end_team (void)
3430+
{
3431+
if (!gfc_notify_std (GFC_STD_F2008_TS, "END TEAM statement at %C"))
3432+
return MATCH_ERROR;
3433+
3434+
if (gfc_match_char ('(') == MATCH_YES)
3435+
goto syntax;
3436+
3437+
new_st.op = EXEC_END_TEAM;
3438+
3439+
return MATCH_YES;
3440+
3441+
syntax:
3442+
gfc_syntax_error (ST_END_TEAM);
3443+
3444+
return MATCH_ERROR;
3445+
}
3446+
3447+
/* Match a SYNC TEAM statement. */
3448+
3449+
match
3450+
gfc_match_sync_team (void)
3451+
{
3452+
match m;
3453+
gfc_expr *team;
3454+
3455+
if (!gfc_notify_std (GFC_STD_F2008_TS, "SYNC TEAM statement at %C"))
3456+
return MATCH_ERROR;
3457+
3458+
if (gfc_match_char ('(') == MATCH_NO)
3459+
goto syntax;
3460+
3461+
new_st.op = EXEC_SYNC_TEAM;
3462+
3463+
if (gfc_match ("%e", &team) != MATCH_YES)
3464+
goto syntax;
3465+
3466+
m = gfc_match_char (')');
3467+
if (m == MATCH_NO)
3468+
goto syntax;
3469+
3470+
new_st.expr1 = team;
3471+
3472+
return MATCH_YES;
3473+
3474+
syntax:
3475+
gfc_syntax_error (ST_SYNC_TEAM);
3476+
3477+
return MATCH_ERROR;
3478+
}
33463479

33473480
/* Match LOCK/UNLOCK statement. Syntax:
33483481
LOCK ( lock-variable [ , lock-stat-list ] )

0 commit comments

Comments
 (0)