[flang-commits] [flang] [flang][OpenMP] Support `bind` clause code-gen for standalone `loop`s (PR #122674)
Kareem Ergawy via flang-commits
flang-commits at lists.llvm.org
Tue Jan 21 06:13:24 PST 2025
================
@@ -117,7 +120,27 @@ class GenericLoopConversionPattern
return result;
}
- /// Rewrites standalone `loop` directives to equivalent `simd` constructs.
+ void rewriteStandaloneLoop(mlir::omp::LoopOp loopOp,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ using namespace mlir::omp;
+ std::optional<ClauseBindKind> bindKind = loopOp.getBindKind();
+
+ if (!bindKind.has_value())
+ return rewriteToSimdLoop(loopOp, rewriter);
+
+ switch (*loopOp.getBindKind()) {
+ case ClauseBindKind::Parallel:
+ return rewriteToWsloop(loopOp, rewriter);
+ case ClauseBindKind::Teams:
+ return rewriteToDistrbute(loopOp, rewriter);
----------------
ergawy wrote:
I think a standalone `loop` whose `bind` is `teams` is semantically equivalent to a `distribute` directive. I concluded this from the following parts of the spec:
```
1.3 Execution Model
....
When a loop construct is encountered, the iterations of the loop associated with the construct are
executed in the context of its encountering threads, as determined according to its binding region. If
the loop region binds to a teams region, the region is encountered by the set of primary threads
that execute the teams region.
```
So the loops iterations' are distributed among the primary/initial threads of the teams region.
https://github.com/llvm/llvm-project/pull/122674
More information about the flang-commits
mailing list