Skip to content

Commit 178191e

Browse files
committed
Fortran/OpenMP: Add omp loop [PR99928]
PR middle-end/99928 gcc/fortran/ChangeLog: * dump-parse-tree.c (show_omp_clauses): Handle bind clause. (show_omp_node): Handle loop directive. * frontend-passes.c (gfc_code_walker): Likewise. * gfortran.h (enum gfc_statement): Add ST_OMP_(END_)(TARGET_)(|PARALLEL_|TEAMS_)LOOP. (enum gfc_omp_bind_type): New. (gfc_omp_clauses): Use it. (enum gfc_exec_op): Add EXEC_OMP_(TARGET_)(|PARALLEL_|TEAMS_)LOOP. * match.h (gfc_match_omp_loop, gfc_match_omp_parallel_loop, gfc_match_omp_target_parallel_loop, gfc_match_omp_target_teams_loop, gfc_match_omp_teams_loop): New. * openmp.c (enum omp_mask1): Add OMP_CLAUSE_BIND. (gfc_match_omp_clauses): Handle it. (OMP_LOOP_CLAUSES, gfc_match_omp_loop, gfc_match_omp_teams_loop, gfc_match_omp_target_teams_loop, gfc_match_omp_parallel_loop, gfc_match_omp_target_parallel_loop): New. (resolve_omp_clauses, resolve_omp_do, omp_code_to_statement, gfc_resolve_omp_directive): Handle omp loop. * parse.c (decode_omp_directive case_exec_markers, gfc_ascii_statement, parse_omp_do, parse_executable): Likewise. (parse_omp_structured_block): Remove ST_ which use parse_omp_do. * resolve.c (gfc_resolve_blocks): Add omp loop. * st.c (gfc_free_statement): Likewise. * trans-openmp.c (gfc_trans_omp_clauses): Handle bind clause. (gfc_trans_omp_do, gfc_trans_omp_parallel_do, gfc_trans_omp_distribute, gfc_trans_omp_teams, gfc_trans_omp_target, gfc_trans_omp_directive): Handle loop directive. (gfc_split_omp_clauses): Likewise; fix firstprivate/lastprivate and (in_)reduction for taskloop. * trans.c (trans_code): Handle omp loop directive. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/pr99928-3.f90: Add 'default(none)', following C/C++ version of the patch. * gfortran.dg/gomp/loop-1.f90: New test. * gfortran.dg/gomp/loop-2.f90: New test. * gfortran.dg/gomp/pr99928-1.f90: New test; based on C/C++ test. * gfortran.dg/gomp/pr99928-11.f90: Likewise. * gfortran.dg/gomp/pr99928-2.f90: Likewise. * gfortran.dg/gomp/pr99928-4.f90: Likewise. * gfortran.dg/gomp/pr99928-5.f90: Likewise. * gfortran.dg/gomp/pr99928-6.f90: Likewise. * gfortran.dg/gomp/pr99928-8.f90: Likewise. * gfortran.dg/goacc/omp.f95: Use 'acc kernels loops' instead of 'acc loops' to hide unrelated bug for now. * gfortran.dg/goacc/omp-fixed.f: Likewise
1 parent b7dd2e4 commit 178191e

22 files changed

+1497
-81
lines changed

gcc/fortran/dump-parse-tree.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,19 @@ show_omp_clauses (gfc_omp_clauses *omp_clauses)
17181718
}
17191719
fprintf (dumpfile, " PROC_BIND(%s)", type);
17201720
}
1721+
if (omp_clauses->bind != OMP_BIND_UNSET)
1722+
{
1723+
const char *type;
1724+
switch (omp_clauses->bind)
1725+
{
1726+
case OMP_BIND_TEAMS: type = "TEAMS"; break;
1727+
case OMP_BIND_PARALLEL: type = "PARALLEL"; break;
1728+
case OMP_BIND_THREAD: type = "THREAD"; break;
1729+
default:
1730+
gcc_unreachable ();
1731+
}
1732+
fprintf (dumpfile, " BIND(%s)", type);
1733+
}
17211734
if (omp_clauses->num_teams)
17221735
{
17231736
fputs (" NUM_TEAMS(", dumpfile);
@@ -1896,6 +1909,7 @@ show_omp_node (int level, gfc_code *c)
18961909
case EXEC_OMP_DISTRIBUTE_SIMD: name = "DISTRIBUTE SIMD"; break;
18971910
case EXEC_OMP_DO: name = "DO"; break;
18981911
case EXEC_OMP_DO_SIMD: name = "DO SIMD"; break;
1912+
case EXEC_OMP_LOOP: name = "LOOP"; break;
18991913
case EXEC_OMP_FLUSH: name = "FLUSH"; break;
19001914
case EXEC_OMP_MASTER: name = "MASTER"; break;
19011915
case EXEC_OMP_MASTER_TASKLOOP: name = "MASTER TASKLOOP"; break;
@@ -1905,6 +1919,7 @@ show_omp_node (int level, gfc_code *c)
19051919
case EXEC_OMP_PARALLEL: name = "PARALLEL"; break;
19061920
case EXEC_OMP_PARALLEL_DO: name = "PARALLEL DO"; break;
19071921
case EXEC_OMP_PARALLEL_DO_SIMD: name = "PARALLEL DO SIMD"; break;
1922+
case EXEC_OMP_PARALLEL_LOOP: name = "PARALLEL LOOP"; break;
19081923
case EXEC_OMP_PARALLEL_MASTER: name = "PARALLEL MASTER"; break;
19091924
case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
19101925
name = "PARALLEL MASTER TASKLOOP"; break;
@@ -1924,6 +1939,7 @@ show_omp_node (int level, gfc_code *c)
19241939
case EXEC_OMP_TARGET_PARALLEL_DO: name = "TARGET PARALLEL DO"; break;
19251940
case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
19261941
name = "TARGET_PARALLEL_DO_SIMD"; break;
1942+
case EXEC_OMP_TARGET_PARALLEL_LOOP: name = "TARGET PARALLEL LOOP"; break;
19271943
case EXEC_OMP_TARGET_SIMD: name = "TARGET SIMD"; break;
19281944
case EXEC_OMP_TARGET_TEAMS: name = "TARGET TEAMS"; break;
19291945
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
@@ -1934,6 +1950,7 @@ show_omp_node (int level, gfc_code *c)
19341950
name = "TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD"; break;
19351951
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
19361952
name = "TARGET TEAMS DISTRIBUTE SIMD"; break;
1953+
case EXEC_OMP_TARGET_TEAMS_LOOP: name = "TARGET TEAMS LOOP"; break;
19371954
case EXEC_OMP_TARGET_UPDATE: name = "TARGET UPDATE"; break;
19381955
case EXEC_OMP_TASK: name = "TASK"; break;
19391956
case EXEC_OMP_TASKGROUP: name = "TASKGROUP"; break;
@@ -1948,6 +1965,7 @@ show_omp_node (int level, gfc_code *c)
19481965
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
19491966
name = "TEAMS DISTRIBUTE PARALLEL DO SIMD"; break;
19501967
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD: name = "TEAMS DISTRIBUTE SIMD"; break;
1968+
case EXEC_OMP_TEAMS_LOOP: name = "TEAMS LOOP"; break;
19511969
case EXEC_OMP_WORKSHARE: name = "WORKSHARE"; break;
19521970
default:
19531971
gcc_unreachable ();
@@ -1977,10 +1995,12 @@ show_omp_node (int level, gfc_code *c)
19771995
case EXEC_OMP_DISTRIBUTE_SIMD:
19781996
case EXEC_OMP_DO:
19791997
case EXEC_OMP_DO_SIMD:
1998+
case EXEC_OMP_LOOP:
19801999
case EXEC_OMP_ORDERED:
19812000
case EXEC_OMP_PARALLEL:
19822001
case EXEC_OMP_PARALLEL_DO:
19832002
case EXEC_OMP_PARALLEL_DO_SIMD:
2003+
case EXEC_OMP_PARALLEL_LOOP:
19842004
case EXEC_OMP_PARALLEL_MASTER:
19852005
case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
19862006
case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
@@ -1997,12 +2017,14 @@ show_omp_node (int level, gfc_code *c)
19972017
case EXEC_OMP_TARGET_PARALLEL:
19982018
case EXEC_OMP_TARGET_PARALLEL_DO:
19992019
case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
2020+
case EXEC_OMP_TARGET_PARALLEL_LOOP:
20002021
case EXEC_OMP_TARGET_SIMD:
20012022
case EXEC_OMP_TARGET_TEAMS:
20022023
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
20032024
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
20042025
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
20052026
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
2027+
case EXEC_OMP_TARGET_TEAMS_LOOP:
20062028
case EXEC_OMP_TARGET_UPDATE:
20072029
case EXEC_OMP_TASK:
20082030
case EXEC_OMP_TASKLOOP:
@@ -2012,6 +2034,7 @@ show_omp_node (int level, gfc_code *c)
20122034
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
20132035
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
20142036
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
2037+
case EXEC_OMP_TEAMS_LOOP:
20152038
case EXEC_OMP_WORKSHARE:
20162039
omp_clauses = c->ext.omp_clauses;
20172040
break;

gcc/fortran/frontend-passes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5542,6 +5542,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
55425542
case EXEC_OMP_PARALLEL:
55435543
case EXEC_OMP_PARALLEL_DO:
55445544
case EXEC_OMP_PARALLEL_DO_SIMD:
5545+
case EXEC_OMP_PARALLEL_LOOP:
55455546
case EXEC_OMP_PARALLEL_MASTER:
55465547
case EXEC_OMP_PARALLEL_MASTER_TASKLOOP:
55475548
case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
@@ -5567,6 +5568,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
55675568
case EXEC_OMP_DISTRIBUTE_SIMD:
55685569
case EXEC_OMP_DO:
55695570
case EXEC_OMP_DO_SIMD:
5571+
case EXEC_OMP_LOOP:
55705572
case EXEC_OMP_ORDERED:
55715573
case EXEC_OMP_SECTIONS:
55725574
case EXEC_OMP_SINGLE:
@@ -5581,19 +5583,22 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
55815583
case EXEC_OMP_TARGET_PARALLEL:
55825584
case EXEC_OMP_TARGET_PARALLEL_DO:
55835585
case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
5586+
case EXEC_OMP_TARGET_PARALLEL_LOOP:
55845587
case EXEC_OMP_TARGET_SIMD:
55855588
case EXEC_OMP_TARGET_TEAMS:
55865589
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
55875590
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
55885591
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
55895592
case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
5593+
case EXEC_OMP_TARGET_TEAMS_LOOP:
55905594
case EXEC_OMP_TARGET_UPDATE:
55915595
case EXEC_OMP_TASK:
55925596
case EXEC_OMP_TEAMS:
55935597
case EXEC_OMP_TEAMS_DISTRIBUTE:
55945598
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
55955599
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
55965600
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
5601+
case EXEC_OMP_TEAMS_LOOP:
55975602

55985603
/* Come to this label only from the
55995604
EXEC_OMP_PARALLEL_* cases above. */

gcc/fortran/gfortran.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,11 @@ enum gfc_statement
271271
ST_OMP_END_PARALLEL_MASTER_TASKLOOP, ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD,
272272
ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD, ST_OMP_MASTER_TASKLOOP,
273273
ST_OMP_END_MASTER_TASKLOOP, ST_OMP_MASTER_TASKLOOP_SIMD,
274-
ST_OMP_END_MASTER_TASKLOOP_SIMD, ST_NONE
274+
ST_OMP_END_MASTER_TASKLOOP_SIMD, ST_OMP_LOOP, ST_OMP_END_LOOP,
275+
ST_OMP_PARALLEL_LOOP, ST_OMP_END_PARALLEL_LOOP, ST_OMP_TEAMS_LOOP,
276+
ST_OMP_END_TEAMS_LOOP, ST_OMP_TARGET_PARALLEL_LOOP,
277+
ST_OMP_END_TARGET_PARALLEL_LOOP, ST_OMP_TARGET_TEAMS_LOOP,
278+
ST_OMP_END_TARGET_TEAMS_LOOP, ST_NONE
275279
};
276280

277281
/* Types of interfaces that we can have. Assignment interfaces are
@@ -1401,6 +1405,14 @@ enum gfc_omp_memorder
14011405
OMP_MEMORDER_RELAXED
14021406
};
14031407

1408+
enum gfc_omp_bind_type
1409+
{
1410+
OMP_BIND_UNSET,
1411+
OMP_BIND_TEAMS,
1412+
OMP_BIND_PARALLEL,
1413+
OMP_BIND_THREAD
1414+
};
1415+
14041416
typedef struct gfc_omp_clauses
14051417
{
14061418
struct gfc_expr *if_expr;
@@ -1421,6 +1433,7 @@ typedef struct gfc_omp_clauses
14211433
enum gfc_omp_cancel_kind cancel;
14221434
enum gfc_omp_proc_bind_kind proc_bind;
14231435
enum gfc_omp_depend_op depobj_update;
1436+
enum gfc_omp_bind_type bind;
14241437
struct gfc_expr *safelen_expr;
14251438
struct gfc_expr *simdlen_expr;
14261439
struct gfc_expr *num_teams;
@@ -2717,7 +2730,8 @@ enum gfc_exec_op
27172730
EXEC_OMP_TASKLOOP, EXEC_OMP_TASKLOOP_SIMD, EXEC_OMP_SCAN, EXEC_OMP_DEPOBJ,
27182731
EXEC_OMP_PARALLEL_MASTER, EXEC_OMP_PARALLEL_MASTER_TASKLOOP,
27192732
EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD, EXEC_OMP_MASTER_TASKLOOP,
2720-
EXEC_OMP_MASTER_TASKLOOP_SIMD
2733+
EXEC_OMP_MASTER_TASKLOOP_SIMD, EXEC_OMP_LOOP, EXEC_OMP_PARALLEL_LOOP,
2734+
EXEC_OMP_TEAMS_LOOP, EXEC_OMP_TARGET_PARALLEL_LOOP, EXEC_OMP_TARGET_TEAMS_LOOP
27212735
};
27222736

27232737
typedef struct gfc_code

gcc/fortran/match.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ match gfc_match_omp_distribute_parallel_do_simd (void);
167167
match gfc_match_omp_distribute_simd (void);
168168
match gfc_match_omp_do (void);
169169
match gfc_match_omp_do_simd (void);
170+
match gfc_match_omp_loop (void);
170171
match gfc_match_omp_flush (void);
171172
match gfc_match_omp_master (void);
172173
match gfc_match_omp_master_taskloop (void);
@@ -176,6 +177,7 @@ match gfc_match_omp_ordered_depend (void);
176177
match gfc_match_omp_parallel (void);
177178
match gfc_match_omp_parallel_do (void);
178179
match gfc_match_omp_parallel_do_simd (void);
180+
match gfc_match_omp_parallel_loop (void);
179181
match gfc_match_omp_parallel_master (void);
180182
match gfc_match_omp_parallel_master_taskloop (void);
181183
match gfc_match_omp_parallel_master_taskloop_simd (void);
@@ -193,12 +195,14 @@ match gfc_match_omp_target_exit_data (void);
193195
match gfc_match_omp_target_parallel (void);
194196
match gfc_match_omp_target_parallel_do (void);
195197
match gfc_match_omp_target_parallel_do_simd (void);
198+
match gfc_match_omp_target_parallel_loop (void);
196199
match gfc_match_omp_target_simd (void);
197200
match gfc_match_omp_target_teams (void);
198201
match gfc_match_omp_target_teams_distribute (void);
199202
match gfc_match_omp_target_teams_distribute_parallel_do (void);
200203
match gfc_match_omp_target_teams_distribute_parallel_do_simd (void);
201204
match gfc_match_omp_target_teams_distribute_simd (void);
205+
match gfc_match_omp_target_teams_loop (void);
202206
match gfc_match_omp_target_update (void);
203207
match gfc_match_omp_task (void);
204208
match gfc_match_omp_taskgroup (void);
@@ -211,6 +215,7 @@ match gfc_match_omp_teams_distribute (void);
211215
match gfc_match_omp_teams_distribute_parallel_do (void);
212216
match gfc_match_omp_teams_distribute_parallel_do_simd (void);
213217
match gfc_match_omp_teams_distribute_simd (void);
218+
match gfc_match_omp_teams_loop (void);
214219
match gfc_match_omp_threadprivate (void);
215220
match gfc_match_omp_workshare (void);
216221
match gfc_match_omp_end_critical (void);

0 commit comments

Comments
 (0)