[Mlir-commits] [mlir] [mlir] Extract forall_to_for logic into reusable function and add pass (PR #89636)

Jorn Tuyls llvmlistbot at llvm.org
Tue Apr 23 04:40:15 PDT 2024


================
@@ -0,0 +1,90 @@
+//===- ForallToFor.cpp - scf.forall to scf.for loop conversion ------------===//
+//
+// 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.ForallOp's into SCF.ForOp's.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/SCF/Transforms/Passes.h"
+
+#include "mlir/Dialect/SCF/IR/SCF.h"
+#include "mlir/Dialect/SCF/Transforms/Transforms.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_SCFFORALLTOFORLOOP
+#include "mlir/Dialect/SCF/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace llvm;
+using namespace mlir;
+using scf::ForallOp;
+using scf::ForOp;
+using scf::LoopNest;
+
+LogicalResult
+mlir::scf::forallToForLoop(RewriterBase &rewriter, scf::ForallOp forallOp,
+                           SmallVector<Operation *> *results = nullptr) {
+  rewriter.setInsertionPoint(forallOp);
+
+  if (!forallOp.getOutputs().empty()) {
+    return forallOp.emitOpError()
+           << "unsupported shared outputs (didn't bufferize?)";
+  }
----------------
jtuyls wrote:

`DiagnosedSilenceableFailure` doesn't seem to be used outside transform ops and other standalone functions all seem to return a `LogicalResult`, for example: https://github.com/llvm/llvm-project/blob/34da233ec61ed6db6f9d7b41a51bf85aa046c99d/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp#L176. Do we really want to introduce the use of `DiagnosedSilenceableFailure` outside of the transform ops here? And shouldn't the transform op user still be able to suppress the error as the transform op emits a silenceable failure here: https://github.com/llvm/llvm-project/pull/89636/files#diff-248fafbd7e6f22b57d1b44053b4679730ea925971633758cf6dd5b1e1bb289c9R85 ?

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


More information about the Mlir-commits mailing list