[Mlir-commits] [flang] [llvm] [mlir] [flang][OpenMP] Enable tiling (PR #143715)
Sergio Afonso
llvmlistbot at llvm.org
Thu Aug 28 07:14:21 PDT 2025
================
@@ -595,9 +656,44 @@ bool collectLoopRelatedInfo(
if (auto *clause =
ClauseFinder::findUniqueClause<omp::clause::Collapse>(clauses)) {
collapseValue = evaluate::ToInt64(clause->v).value();
- found = true;
+ numCollapse = collapseValue;
+ }
+
+ // Collect sizes from tile directive if present
+ std::int64_t sizesLengthValue = 0l;
+ if (auto *ompCons{eval.getIf<parser::OpenMPConstruct>()}) {
+ if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u)}) {
+ const auto &nestedOptional =
+ std::get<std::optional<parser::NestedConstruct>>(ompLoop->t);
+ assert(nestedOptional.has_value() &&
+ "Expected a DoConstruct or OpenMPLoopConstruct");
+ const auto *innerConstruct =
+ std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
+ &(nestedOptional.value()));
+ if (innerConstruct) {
+ const auto &innerLoopDirective = innerConstruct->value();
+ const auto &innerBegin =
+ std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
+ const auto &innerDirective =
+ std::get<parser::OmpLoopDirective>(innerBegin.t).v;
+
+ if (innerDirective == llvm::omp::Directive::OMPD_tile) {
+ // Get the size values from parse tree and convert to a vector
+ const auto &innerClauseList{
+ std::get<parser::OmpClauseList>(innerBegin.t)};
+ for (const auto &clause : innerClauseList.v)
+ if (const auto tclause{
+ std::get_if<parser::OmpClause::Sizes>(&clause.u)}) {
+ sizesLengthValue = tclause->v.size();
+ }
+ }
+ }
+ }
}
+ collapseValue = collapseValue - sizesLengthValue;
+ collapseValue =
+ collapseValue < sizesLengthValue ? sizesLengthValue : collapseValue;
----------------
skatrak wrote:
Nit: I find this logic confusing for what it is, and using a variable named `collapseValue` to represent the number of nested loops becomes misleading when we add tiling into the mix. How about:
```suggestion
int64_t nestedLoops = std::max(collapseValue, numTileSizes);
```
We would return `collapseValue` from the function, remove the `numCollapse` variable, rename `sizesLengthValue` to `numTileSizes` and replace the do-while loop with `for (int64_t i = 0; i < nestedLoops; ++i)`.
https://github.com/llvm/llvm-project/pull/143715
More information about the Mlir-commits
mailing list