Skip to content

Commit 61af447

Browse files
committed
Address review comments
1 parent aa0403a commit 61af447

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

flang/lib/Lower/OpenMP/Decomposer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,19 @@ ConstructQueue buildConstructQueue(
100100

101101
bool matchLeafSequence(ConstructQueue::const_iterator item,
102102
const ConstructQueue &queue,
103-
llvm::ArrayRef<llvm::omp::Directive> directives) {
103+
llvm::omp::Directive directive) {
104+
llvm::ArrayRef<llvm::omp::Directive> leafDirs =
105+
llvm::omp::getLeafConstructsOrSelf(directive);
106+
104107
for (auto [dir, leaf] :
105-
llvm::zip_longest(directives, llvm::make_range(item, queue.end()))) {
106-
if (!dir || !leaf)
108+
llvm::zip_longest(leafDirs, llvm::make_range(item, queue.end()))) {
109+
if (!dir.has_value() || !leaf.has_value())
107110
return false;
108111

109-
if (dir.value() != leaf.value().id)
112+
if (*dir != leaf->id)
110113
return false;
111114
}
115+
112116
return true;
113117
}
114118

flang/lib/Lower/OpenMP/Decomposer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ ConstructQueue buildConstructQueue(mlir::ModuleOp modOp,
4949
bool isLastItemInQueue(ConstructQueue::const_iterator item,
5050
const ConstructQueue &queue);
5151

52-
/// Try to match a sequence of \c directives to the range of leaf constructs
53-
/// starting from \c item to the end of the \c queue.
52+
/// Try to match the leaf constructs conforming the given \c directive to the
53+
/// range of leaf constructs starting from \c item to the end of the \c queue.
54+
/// If \c directive doesn't represent a compound directive, check that \c item
55+
/// matches that directive and is the only element before the end of the
56+
/// \c queue.
5457
bool matchLeafSequence(ConstructQueue::const_iterator item,
5558
const ConstructQueue &queue,
56-
llvm::ArrayRef<llvm::omp::Directive> directives);
59+
llvm::omp::Directive directive);
5760
} // namespace Fortran::lower::omp
5861

5962
#endif // FORTRAN_LOWER_OPENMP_DECOMPOSER_H

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,28 +2168,22 @@ static bool genOMPCompositeDispatch(
21682168
mlir::Location loc, const ConstructQueue &queue,
21692169
ConstructQueue::const_iterator item, DataSharingProcessor &dsp) {
21702170
using llvm::omp::Directive;
2171-
using llvm::omp::getLeafConstructs, lower::omp::matchLeafSequence;
2171+
using lower::omp::matchLeafSequence;
21722172

2173-
if (matchLeafSequence(
2174-
item, queue,
2175-
getLeafConstructs(Directive::OMPD_distribute_parallel_do)))
2173+
if (matchLeafSequence(item, queue, Directive::OMPD_distribute_parallel_do))
21762174
genCompositeDistributeParallelDo(converter, symTable, semaCtx, eval, loc,
21772175
queue, item, dsp);
2178-
else if (matchLeafSequence(
2179-
item, queue,
2180-
getLeafConstructs(Directive::OMPD_distribute_parallel_do_simd)))
2176+
else if (matchLeafSequence(item, queue,
2177+
Directive::OMPD_distribute_parallel_do_simd))
21812178
genCompositeDistributeParallelDoSimd(converter, symTable, semaCtx, eval,
21822179
loc, queue, item, dsp);
2183-
else if (matchLeafSequence(
2184-
item, queue, getLeafConstructs(Directive::OMPD_distribute_simd)))
2180+
else if (matchLeafSequence(item, queue, Directive::OMPD_distribute_simd))
21852181
genCompositeDistributeSimd(converter, symTable, semaCtx, eval, loc, queue,
21862182
item, dsp);
2187-
else if (matchLeafSequence(item, queue,
2188-
getLeafConstructs(Directive::OMPD_do_simd)))
2183+
else if (matchLeafSequence(item, queue, Directive::OMPD_do_simd))
21892184
genCompositeDoSimd(converter, symTable, semaCtx, eval, loc, queue, item,
21902185
dsp);
2191-
else if (matchLeafSequence(item, queue,
2192-
getLeafConstructs(Directive::OMPD_taskloop_simd)))
2186+
else if (matchLeafSequence(item, queue, Directive::OMPD_taskloop_simd))
21932187
genCompositeTaskloopSimd(converter, symTable, semaCtx, eval, loc, queue,
21942188
item, dsp);
21952189
else
@@ -2318,18 +2312,11 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
23182312
// that use this construct, add a single construct for now.
23192313
genSingleOp(converter, symTable, semaCtx, eval, loc, queue, item);
23202314
break;
2321-
2322-
// Composite constructs
2323-
case llvm::omp::Directive::OMPD_distribute_parallel_do:
2324-
case llvm::omp::Directive::OMPD_distribute_parallel_do_simd:
2325-
case llvm::omp::Directive::OMPD_distribute_simd:
2326-
case llvm::omp::Directive::OMPD_do_simd:
2327-
case llvm::omp::Directive::OMPD_taskloop_simd:
2328-
// Composite constructs should have been split into a sequence of leaf
2329-
// constructs and lowered by genOMPCompositeDispatch().
2330-
llvm_unreachable("Unexpected composite construct.");
2331-
break;
23322315
default:
2316+
// Combined and composite constructs should have been split into a sequence
2317+
// of leaf constructs when building the construct queue.
2318+
assert(!llvm::omp::isLeafConstruct(dir) &&
2319+
"Unexpected compound construct.");
23332320
break;
23342321
}
23352322

0 commit comments

Comments
 (0)