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

Michael Klemm via flang-commits flang-commits at lists.llvm.org
Mon Jan 27 02:14:11 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);
----------------
mjklemm wrote:

PS: It might be a good idea to have some heuristics in the future that use SIMD where beneficial vs. not using SIMD instructions.  But I guess that something that is beyond this PR and will also influence the general decision whether or not to code-gen SIMD instructions.

I'm wondering if we should have a tag for such implicitly generated SIMD construct to distinguish them from the programmer actually having written `simd` in their code, so that we can still differentiate these loops later. 

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


More information about the flang-commits mailing list