[Mlir-commits] [mlir] [mlir][scf] Implement Conversion from scf.parallel to Nested scf.for (PR #147692)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jul 21 09:14:02 PDT 2025


================
@@ -0,0 +1,91 @@
+//===- ParallelForToNestedFors.cpp - scf.parallel to nested scf.for ops --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Transforms SCF.ParallelOp to nested scf.for ops.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/SCF/IR/SCF.h"
+#include "mlir/Dialect/SCF/Transforms/Passes.h"
+#include "mlir/Dialect/SCF/Transforms/Transforms.h"
+#include "mlir/IR/PatternMatch.h"
+#include "llvm/Support/Debug.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_SCFPARALLELFORTONESTEDFORS
+#include "mlir/Dialect/SCF/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+
+LogicalResult mlir::scf::parallelForToNestedFors(RewriterBase &rewriter,
+                                                 scf::ParallelOp parallelOp,
+                                                 scf::ForOp *result) {
+
+  if (!parallelOp.getResults().empty()) {
+    parallelOp->emitError("Currently ScfParallel to ScfFor conversion "
+                          "doesn't support ScfParallel with results.");
+    return failure();
+  }
+
+  rewriter.setInsertionPoint(parallelOp);
+
+  Location loc = parallelOp.getLoc();
+  auto lowerBounds = parallelOp.getLowerBound();
+  auto upperBounds = parallelOp.getUpperBound();
+  auto steps = parallelOp.getStep();
----------------
Max191 wrote:

nit: spell out types (`SmallVector<Value>` instead of `auto`).

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


More information about the Mlir-commits mailing list