[flang-commits] [flang] [flang][OpenMP] Map `teams loop` to `teams distribute` when required. (PR #127489)
Sergio Afonso via flang-commits
flang-commits at lists.llvm.org
Fri Feb 21 03:33:27 PST 2025
================
@@ -118,6 +119,64 @@ class GenericLoopConversionPattern
return result;
}
+ /// Checks whether a `teams loop` construct can be rewriten to `teams
+ /// distribute parallel do` or it has to be converted to `teams distribute`.
+ ///
+ /// This checks similar constrains to what is checked by `TeamsLoopChecker` in
+ /// SemaOpenMP.cpp in clang.
+ static bool teamsLoopCanBeParallelFor(mlir::omp::LoopOp loopOp) {
+ bool canBeParallelFor =
+ !loopOp
+ .walk<mlir::WalkOrder::PreOrder>([&](mlir::Operation *nestedOp) {
+ if (nestedOp == loopOp)
+ return mlir::WalkResult::advance();
+
+ if (auto nestedLoopOp =
+ mlir::dyn_cast<mlir::omp::LoopOp>(nestedOp)) {
+ GenericLoopCombinedInfo combinedInfo =
+ findGenericLoopCombineInfo(nestedLoopOp);
+
+ // Worksharing loops cannot be nested inside each other.
+ // Therefore, if the current `loop` directive nests another
+ // `loop` whose `bind` modifier is `parallel`, this `loop`
+ // directive cannot be mapped to `distribute parallel for`
+ // but rather only to `distribute`.
+ if (combinedInfo == GenericLoopCombinedInfo::Standalone &&
+ nestedLoopOp.getBindKind() &&
+ *nestedLoopOp.getBindKind() ==
+ mlir::omp::ClauseBindKind::Parallel)
+ return mlir::WalkResult::interrupt();
+
+ // TODO check for combined `parallel loop` when we support
+ // it.
+ }
+
+ if (auto callOp =
----------------
skatrak wrote:
Ultra-nit: `else if`.
https://github.com/llvm/llvm-project/pull/127489
More information about the flang-commits
mailing list