[flang] [llvm] [mlir] [flang][OpenMP] Enable tiling (PR #143715)
Jan Leyonberg via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 21 08:32:54 PDT 2025
================
@@ -131,20 +133,48 @@ class CanonicalizationOfOmp {
// Ignore compiler directives.
if (GetConstructIf<parser::CompilerDirective>(*nextIt))
continue;
+ // Keep track of the loops to handle the end loop directives
+ std::stack<parser::OpenMPLoopConstruct *> loops;
+ loops.push(&x);
+ if (auto *innerConstruct{
+ GetConstructIf<parser::OpenMPConstruct>(*nextIt)}) {
+ if (auto *innerOmpLoop{
+ std::get_if<parser::OpenMPLoopConstruct>(&innerConstruct->u)}) {
+ auto &innerBeginDir{
+ std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
+ auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
+ if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
+ std::get<std::optional<
+ common::Indirection<parser::OpenMPLoopConstruct>>>(
+ loops.top()->t) = std::move(*innerOmpLoop);
+ // Retrieveing the address so that DoConstruct or inner loop can be
+ // set later.
+ loops.push(&(std::get<std::optional<
+ common::Indirection<parser::OpenMPLoopConstruct>>>(
+ loops.top()->t)
+ .value()
+ .value()));
+ nextIt = block.erase(nextIt);
+ }
+ }
+ }
if (auto *doCons{GetConstructIf<parser::DoConstruct>(*nextIt)}) {
if (doCons->GetLoopControl()) {
- // move DoConstruct
- std::get<std::optional<parser::DoConstruct>>(x.t) =
+ std::get<std::optional<parser::DoConstruct>>(loops.top()->t) =
std::move(*doCons);
nextIt = block.erase(nextIt);
// try to match OmpEndLoopDirective
- if (nextIt != block.end()) {
+ while (nextIt != block.end() && !loops.empty()) {
if (auto *endDir{
GetConstructIf<parser::OmpEndLoopDirective>(*nextIt)}) {
- std::get<std::optional<parser::OmpEndLoopDirective>>(x.t) =
- std::move(*endDir);
- block.erase(nextIt);
+ std::get<std::optional<parser::OmpEndLoopDirective>>(
+ loops.top()->t) = std::move(*endDir);
----------------
jsjodin wrote:
I looked into this and before this there was not checking for any mismatches, however in CheckDirectiveStructure.h is the code that makes sure that things are matched properly and errors out if not. I will take a look at this code and see if it needs improvement in any way. If there are no tests cases using tile in clause-validiy01/02 I can add that also.
https://github.com/llvm/llvm-project/pull/143715
More information about the llvm-commits
mailing list