Skip to content

Commit 93aafb2

Browse files
committed
Special handling of tile directive when dealing with start end end loop directives.
1 parent 732a785 commit 93aafb2

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

flang/lib/Semantics/canonicalize-omp.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,13 @@ class CanonicalizationOfOmp {
160160
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
161161
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
162162
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
163-
std::get<std::optional<
163+
auto &innerLoop = std::get<std::optional<
164164
common::Indirection<parser::OpenMPLoopConstruct>>>(
165-
loops.back()->t) = std::move(*innerOmpLoop);
165+
loops.back()->t);
166+
innerLoop = std::move(*innerOmpLoop);
166167
// Retrieveing the address so that DoConstruct or inner loop can be
167168
// set later.
168-
loops.push_back(&(std::get<std::optional<
169-
common::Indirection<parser::OpenMPLoopConstruct>>>(
170-
loops.back()->t)
171-
.value()
172-
.value()));
169+
loops.push_back(&(innerLoop.value().value()));
173170
nextIt = block.erase(nextIt);
174171
}
175172
}
@@ -186,9 +183,23 @@ class CanonicalizationOfOmp {
186183
while (nextIt != block.end() && !loops.empty()) {
187184
if (auto *endDir{
188185
GetConstructIf<parser::OmpEndLoopDirective>(*nextIt)}) {
189-
std::get<std::optional<parser::OmpEndLoopDirective>>(
190-
loops.back()->t) = std::move(*endDir);
191-
nextIt = block.erase(nextIt);
186+
auto &endOmpDirective{
187+
std::get<parser::OmpLoopDirective>(endDir->t)};
188+
auto &loopBegin{
189+
std::get<parser::OmpBeginLoopDirective>(loops.back()->t)};
190+
auto &loopDir{std::get<parser::OmpLoopDirective>(loopBegin.t)};
191+
192+
// If the directive is a tile we try to match the corresponding
193+
// end tile if it exsists. If it is not a tile directive we
194+
// always assign the end loop directive and fall back on the
195+
// existing directive structure checks.
196+
if (loopDir.v != llvm::omp::Directive::OMPD_tile ||
197+
loopDir.v == endOmpDirective.v) {
198+
std::get<std::optional<parser::OmpEndLoopDirective>>(
199+
loops.back()->t) = std::move(*endDir);
200+
nextIt = block.erase(nextIt);
201+
}
202+
192203
loops.pop_back();
193204
} else {
194205
// If there is a mismatch bail out.

0 commit comments

Comments
 (0)