@@ -145,16 +145,13 @@ class CanonicalizationOfOmp {
145
145
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t )};
146
146
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t )};
147
147
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
148
- std::get<std::optional<
148
+ auto &innerLoop = std::get<std::optional<
149
149
common::Indirection<parser::OpenMPLoopConstruct>>>(
150
- loops.back ()->t ) = std::move (*innerOmpLoop);
150
+ loops.back ()->t );
151
+ innerLoop = std::move (*innerOmpLoop);
151
152
// Retrieveing the address so that DoConstruct or inner loop can be
152
153
// 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 ()));
158
155
nextIt = block.erase (nextIt);
159
156
}
160
157
}
@@ -169,9 +166,23 @@ class CanonicalizationOfOmp {
169
166
while (nextIt != block.end () && !loops.empty ()) {
170
167
if (auto *endDir{
171
168
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
+
175
186
loops.pop_back ();
176
187
} else {
177
188
// If there is a mismatch bail out.
0 commit comments