Skip to content

Commit ec0ed50

Browse files
committed
[Flang][OpenMP][Lower] Refactor lowering of compound constructs
This patch simplifies the lowering from PFT to MLIR of OpenMP compound constructs (i.e. combined and composite). The new approach consists of iteratively processing the outermost leaf construct of the given combined construct until it cannot be split further. Both leaf constructs and composite ones have `gen...()` functions that are called when appropriate. This approach enables treating a leaf construct the same way regardless of if it appeared as part of a combined construct, and it also enables the lowering of composite constructs as a single unit. Previous corner cases are now handled in a more straightforward way and comments pointing to the relevant spec section are added. Directive sets are also completed with missing LOOP related constructs.
1 parent 0416ec4 commit ec0ed50

File tree

2 files changed

+335
-154
lines changed

2 files changed

+335
-154
lines changed

flang/include/flang/Semantics/openmp-directive-sets.h

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ static const OmpDirectiveSet topDistributeSet{
3232

3333
static const OmpDirectiveSet allDistributeSet{
3434
OmpDirectiveSet{
35-
llvm::omp::OMPD_target_teams_distribute,
36-
llvm::omp::OMPD_target_teams_distribute_parallel_do,
37-
llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
38-
llvm::omp::OMPD_target_teams_distribute_simd,
39-
llvm::omp::OMPD_teams_distribute,
40-
llvm::omp::OMPD_teams_distribute_parallel_do,
41-
llvm::omp::OMPD_teams_distribute_parallel_do_simd,
42-
llvm::omp::OMPD_teams_distribute_simd,
35+
Directive::OMPD_target_teams_distribute,
36+
Directive::OMPD_target_teams_distribute_parallel_do,
37+
Directive::OMPD_target_teams_distribute_parallel_do_simd,
38+
Directive::OMPD_target_teams_distribute_simd,
39+
Directive::OMPD_teams_distribute,
40+
Directive::OMPD_teams_distribute_parallel_do,
41+
Directive::OMPD_teams_distribute_parallel_do_simd,
42+
Directive::OMPD_teams_distribute_simd,
4343
} | topDistributeSet,
4444
};
4545

@@ -63,10 +63,24 @@ static const OmpDirectiveSet allDoSet{
6363
} | topDoSet,
6464
};
6565

66+
static const OmpDirectiveSet topLoopSet{
67+
Directive::OMPD_loop,
68+
};
69+
70+
static const OmpDirectiveSet allLoopSet{
71+
OmpDirectiveSet{
72+
Directive::OMPD_parallel_loop,
73+
Directive::OMPD_target_parallel_loop,
74+
Directive::OMPD_target_teams_loop,
75+
Directive::OMPD_teams_loop,
76+
} | topLoopSet,
77+
};
78+
6679
static const OmpDirectiveSet topParallelSet{
6780
Directive::OMPD_parallel,
6881
Directive::OMPD_parallel_do,
6982
Directive::OMPD_parallel_do_simd,
83+
Directive::OMPD_parallel_loop,
7084
Directive::OMPD_parallel_masked_taskloop,
7185
Directive::OMPD_parallel_masked_taskloop_simd,
7286
Directive::OMPD_parallel_master_taskloop,
@@ -82,6 +96,7 @@ static const OmpDirectiveSet allParallelSet{
8296
Directive::OMPD_target_parallel,
8397
Directive::OMPD_target_parallel_do,
8498
Directive::OMPD_target_parallel_do_simd,
99+
Directive::OMPD_target_parallel_loop,
85100
Directive::OMPD_target_teams_distribute_parallel_do,
86101
Directive::OMPD_target_teams_distribute_parallel_do_simd,
87102
Directive::OMPD_teams_distribute_parallel_do,
@@ -118,12 +133,14 @@ static const OmpDirectiveSet topTargetSet{
118133
Directive::OMPD_target_parallel,
119134
Directive::OMPD_target_parallel_do,
120135
Directive::OMPD_target_parallel_do_simd,
136+
Directive::OMPD_target_parallel_loop,
121137
Directive::OMPD_target_simd,
122138
Directive::OMPD_target_teams,
123139
Directive::OMPD_target_teams_distribute,
124140
Directive::OMPD_target_teams_distribute_parallel_do,
125141
Directive::OMPD_target_teams_distribute_parallel_do_simd,
126142
Directive::OMPD_target_teams_distribute_simd,
143+
Directive::OMPD_target_teams_loop,
127144
};
128145

129146
static const OmpDirectiveSet allTargetSet{topTargetSet};
@@ -156,11 +173,12 @@ static const OmpDirectiveSet topTeamsSet{
156173

157174
static const OmpDirectiveSet allTeamsSet{
158175
OmpDirectiveSet{
159-
llvm::omp::OMPD_target_teams,
160-
llvm::omp::OMPD_target_teams_distribute,
161-
llvm::omp::OMPD_target_teams_distribute_parallel_do,
162-
llvm::omp::OMPD_target_teams_distribute_parallel_do_simd,
163-
llvm::omp::OMPD_target_teams_distribute_simd,
176+
Directive::OMPD_target_teams,
177+
Directive::OMPD_target_teams_distribute,
178+
Directive::OMPD_target_teams_distribute_parallel_do,
179+
Directive::OMPD_target_teams_distribute_parallel_do_simd,
180+
Directive::OMPD_target_teams_distribute_simd,
181+
Directive::OMPD_target_teams_loop,
164182
} | topTeamsSet,
165183
};
166184

@@ -178,6 +196,14 @@ static const OmpDirectiveSet allDistributeSimdSet{
178196
static const OmpDirectiveSet allDoSimdSet{allDoSet & allSimdSet};
179197
static const OmpDirectiveSet allTaskloopSimdSet{allTaskloopSet & allSimdSet};
180198

199+
static const OmpDirectiveSet compositeConstructSet{
200+
Directive::OMPD_distribute_parallel_do,
201+
Directive::OMPD_distribute_parallel_do_simd,
202+
Directive::OMPD_distribute_simd,
203+
Directive::OMPD_do_simd,
204+
Directive::OMPD_taskloop_simd,
205+
};
206+
181207
static const OmpDirectiveSet blockConstructSet{
182208
Directive::OMPD_master,
183209
Directive::OMPD_ordered,
@@ -201,30 +227,35 @@ static const OmpDirectiveSet loopConstructSet{
201227
Directive::OMPD_distribute_simd,
202228
Directive::OMPD_do,
203229
Directive::OMPD_do_simd,
230+
Directive::OMPD_loop,
204231
Directive::OMPD_masked_taskloop,
205232
Directive::OMPD_masked_taskloop_simd,
206233
Directive::OMPD_master_taskloop,
207234
Directive::OMPD_master_taskloop_simd,
208235
Directive::OMPD_parallel_do,
209236
Directive::OMPD_parallel_do_simd,
237+
Directive::OMPD_parallel_loop,
210238
Directive::OMPD_parallel_masked_taskloop,
211239
Directive::OMPD_parallel_masked_taskloop_simd,
212240
Directive::OMPD_parallel_master_taskloop,
213241
Directive::OMPD_parallel_master_taskloop_simd,
214242
Directive::OMPD_simd,
215243
Directive::OMPD_target_parallel_do,
216244
Directive::OMPD_target_parallel_do_simd,
245+
Directive::OMPD_target_parallel_loop,
217246
Directive::OMPD_target_simd,
218247
Directive::OMPD_target_teams_distribute,
219248
Directive::OMPD_target_teams_distribute_parallel_do,
220249
Directive::OMPD_target_teams_distribute_parallel_do_simd,
221250
Directive::OMPD_target_teams_distribute_simd,
251+
Directive::OMPD_target_teams_loop,
222252
Directive::OMPD_taskloop,
223253
Directive::OMPD_taskloop_simd,
224254
Directive::OMPD_teams_distribute,
225255
Directive::OMPD_teams_distribute_parallel_do,
226256
Directive::OMPD_teams_distribute_parallel_do_simd,
227257
Directive::OMPD_teams_distribute_simd,
258+
Directive::OMPD_teams_loop,
228259
Directive::OMPD_tile,
229260
Directive::OMPD_unroll,
230261
};

0 commit comments

Comments
 (0)