[flang-commits] [flang] [flang][OpenMP] Support `bind` clause code-gen for standalone `loop`s (PR #122674)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Mon Jan 27 04:06:54 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);
----------------
skatrak wrote:

Thank you @mjklemm for the clarification. About tagging auto-generated operations for constructs that weren't part of the original program, I think that would be useful information for debugging purposes later on. This new attribute could be used for `omp.loop`, but also for `do concurrent` transformations, `workshare`, `workdistribute`, etc.

I think that we would probably want to implement the heuristic analysis on whether to SIMD within the `omp.loop` transformation pass and still create the `omp.simd` operation in that pass. The tag, attached in this case to `omp.simd`, could be used for all kinds of auto-generated operations using a dialect attribute (named something like `omp.origin` or `omp.derived`) and perhaps hold the name of the operation it was derived from, the reason it was transformed or something like that we could use when emitting any messages related to it later on.

I agree that the pass itself could emit some debug information about transformations that have been made, but I suppose that should be enabled by some compiler flag and not print it by default.

https://github.com/llvm/llvm-project/pull/122674


More information about the flang-commits mailing list