@@ -160,16 +160,13 @@ class CanonicalizationOfOmp {
160
160
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t )};
161
161
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t )};
162
162
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
163
- std::get<std::optional<
163
+ auto &innerLoop = std::get<std::optional<
164
164
common::Indirection<parser::OpenMPLoopConstruct>>>(
165
- loops.back ()->t ) = std::move (*innerOmpLoop);
165
+ loops.back ()->t );
166
+ innerLoop = std::move (*innerOmpLoop);
166
167
// Retrieveing the address so that DoConstruct or inner loop can be
167
168
// 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 ()));
173
170
nextIt = block.erase (nextIt);
174
171
}
175
172
}
@@ -186,9 +183,23 @@ class CanonicalizationOfOmp {
186
183
while (nextIt != block.end () && !loops.empty ()) {
187
184
if (auto *endDir{
188
185
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
+
192
203
loops.pop_back ();
193
204
} else {
194
205
// If there is a mismatch bail out.
0 commit comments