Skip to content

Commit 60aa4b0

Browse files
committed
Special handling of tile directive when dealing with start end end loop directives.
1 parent d362617 commit 60aa4b0

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
@@ -145,16 +145,13 @@ class CanonicalizationOfOmp {
145145
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
146146
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
147147
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
148-
std::get<std::optional<
148+
auto &innerLoop = std::get<std::optional<
149149
common::Indirection<parser::OpenMPLoopConstruct>>>(
150-
loops.back()->t) = std::move(*innerOmpLoop);
150+
loops.back()->t);
151+
innerLoop = std::move(*innerOmpLoop);
151152
// Retrieveing the address so that DoConstruct or inner loop can be
152153
// set later.
153-
loops.push_back(&(std::get<std::optional<
154-
common::Indirection<parser::OpenMPLoopConstruct>>>(
155-
loops.back()->t)
156-
.value()
157-
.value()));
154+
loops.push_back(&(innerLoop.value().value()));
158155
nextIt = block.erase(nextIt);
159156
}
160157
}
@@ -169,9 +166,23 @@ class CanonicalizationOfOmp {
169166
while (nextIt != block.end() && !loops.empty()) {
170167
if (auto *endDir{
171168
GetConstructIf<parser::OmpEndLoopDirective>(*nextIt)}) {
172-
std::get<std::optional<parser::OmpEndLoopDirective>>(
173-
loops.back()->t) = std::move(*endDir);
174-
nextIt = block.erase(nextIt);
169+
auto &endOmpDirective{
170+
std::get<parser::OmpLoopDirective>(endDir->t)};
171+
auto &loopBegin{
172+
std::get<parser::OmpBeginLoopDirective>(loops.back()->t)};
173+
auto &loopDir{std::get<parser::OmpLoopDirective>(loopBegin.t)};
174+
175+
// If the directive is a tile we try to match the corresponding
176+
// end tile if it exsists. If it is not a tile directive we
177+
// always assign the end loop directive and fall back on the
178+
// existing directive structure checks.
179+
if (loopDir.v != llvm::omp::Directive::OMPD_tile ||
180+
loopDir.v == endOmpDirective.v) {
181+
std::get<std::optional<parser::OmpEndLoopDirective>>(
182+
loops.back()->t) = std::move(*endDir);
183+
nextIt = block.erase(nextIt);
184+
}
185+
175186
loops.pop_back();
176187
} else {
177188
// If there is a mismatch bail out.

0 commit comments

Comments
 (0)