Skip to content

Commit 47dc524

Browse files
committed
Address review comments
1 parent ab19c32 commit 47dc524

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
@@ -2172,28 +2172,22 @@ static bool genOMPCompositeDispatch(
21722172
mlir::Location loc, const ConstructQueue &queue,
21732173
ConstructQueue::const_iterator item, DataSharingProcessor &dsp) {
21742174
using llvm::omp::Directive;
2175-
using llvm::omp::getLeafConstructs, lower::omp::matchLeafSequence;
2175+
using lower::omp::matchLeafSequence;
21762176

2177-
if (matchLeafSequence(
2178-
item, queue,
2179-
getLeafConstructs(Directive::OMPD_distribute_parallel_do)))
2177+
if (matchLeafSequence(item, queue, Directive::OMPD_distribute_parallel_do))
21802178
genCompositeDistributeParallelDo(converter, symTable, semaCtx, eval, loc,
21812179
queue, item, dsp);
2182-
else if (matchLeafSequence(
2183-
item, queue,
2184-
getLeafConstructs(Directive::OMPD_distribute_parallel_do_simd)))
2180+
else if (matchLeafSequence(item, queue,
2181+
Directive::OMPD_distribute_parallel_do_simd))
21852182
genCompositeDistributeParallelDoSimd(converter, symTable, semaCtx, eval,
21862183
loc, queue, item, dsp);
2187-
else if (matchLeafSequence(
2188-
item, queue, getLeafConstructs(Directive::OMPD_distribute_simd)))
2184+
else if (matchLeafSequence(item, queue, Directive::OMPD_distribute_simd))
21892185
genCompositeDistributeSimd(converter, symTable, semaCtx, eval, loc, queue,
21902186
item, dsp);
2191-
else if (matchLeafSequence(item, queue,
2192-
getLeafConstructs(Directive::OMPD_do_simd)))
2187+
else if (matchLeafSequence(item, queue, Directive::OMPD_do_simd))
21932188
genCompositeDoSimd(converter, symTable, semaCtx, eval, loc, queue, item,
21942189
dsp);
2195-
else if (matchLeafSequence(item, queue,
2196-
getLeafConstructs(Directive::OMPD_taskloop_simd)))
2190+
else if (matchLeafSequence(item, queue, Directive::OMPD_taskloop_simd))
21972191
genCompositeTaskloopSimd(converter, symTable, semaCtx, eval, loc, queue,
21982192
item, dsp);
21992193
else
@@ -2322,18 +2316,11 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
23222316
// that use this construct, add a single construct for now.
23232317
genSingleOp(converter, symTable, semaCtx, eval, loc, queue, item);
23242318
break;
2325-
2326-
// Composite constructs
2327-
case llvm::omp::Directive::OMPD_distribute_parallel_do:
2328-
case llvm::omp::Directive::OMPD_distribute_parallel_do_simd:
2329-
case llvm::omp::Directive::OMPD_distribute_simd:
2330-
case llvm::omp::Directive::OMPD_do_simd:
2331-
case llvm::omp::Directive::OMPD_taskloop_simd:
2332-
// Composite constructs should have been split into a sequence of leaf
2333-
// constructs and lowered by genOMPCompositeDispatch().
2334-
llvm_unreachable("Unexpected composite construct.");
2335-
break;
23362319
default:
2320+
// Combined and composite constructs should have been split into a sequence
2321+
// of leaf constructs when building the construct queue.
2322+
assert(!llvm::omp::isLeafConstruct(dir) &&
2323+
"Unexpected compound construct.");
23372324
break;
23382325
}
23392326

0 commit comments

Comments
 (0)