[Mlir-commits] [mlir] [mlir][Transform dial] Expose convert-linalg-to-affine-loops transf (PR #211308)
Guillaume Iooss
llvmlistbot at llvm.org
Fri Jul 31 06:22:59 PDT 2026
================
@@ -4593,6 +4593,41 @@ DiagnosedSilenceableFailure transform::DecomposeWinogradOp::applyToOne(
return DiagnosedSilenceableFailure::success();
}
+//===----------------------------------------------------------------------===//
+// LinAlgToAffine
+//===----------------------------------------------------------------------===//
+
+DiagnosedSilenceableFailure transform::LinAlgToAffineOp::applyToOne(
+ transform::TransformRewriter &rewriter, linalg::LinalgOp target,
+ ApplyToEachResultList &results, TransformState &state) {
+ if (! isa<GenericOp>(target)) {
+ return DiagnosedSilenceableFailure::definiteFailure();
+ }
+
+ rewriter.setInsertionPoint(target);
+
+ FailureOr<LinalgLoops> generic = linalgOpToAffineLoops(rewriter, target);
+ if (succeeded(generic)) {
+ assert(! generic->empty() && "expected at least one loop");
----------------
guillaumeiooss wrote:
Ok, that question is the reason why it took me so much time to correct my pull request.
a) Here are some details:
- There are indeed 0-D generic, and the original pass (`-convert-linalg-to-affine-loops`) can manage them.
- However, the function exposed is only returning the newly created list of (unordered) `AffineForOp` that surrounds the newly created block of instruction. When we have no loop, this causes an issue where an empty list is returned, and I am not able to reach the newly constructed operations.
- Worse: the transform Dialect operation requires a single output, or a finite fixed-size of output operations. Which means that if the number of instruction inside a linalg.generic is large, returning all the newly created operations is not possible at the transform Dialect level.
b) Therefore, I picked the following options (that can be discussed):
- Case N-D, N>0 : No Change (and I have applied all the commentaries you gave / thanks for the feedback btw)
- Case 0-D: I create a `scf.ExecuteRegionOp` that contains the instructions of the `linalg.generic` (with no `affine.AffineForOp`) and I returns it. I had to mimic part of the `lib/Dialect/Linalg/Transforms/Loops.cpp` file, for the special case of 0-D (which simplifies the generation, since there are no access function).
Notice that this was the simplest option I saw (that did not touch other files such as `Loop.cpp`), but this is far from being the only one. If you prefer an alternative, I am open to discussion.
c) The commit with all the corrections (for all branches of this conversation) is coming in a few minutes, once the LLVM checks ends.
https://github.com/llvm/llvm-project/pull/211308
More information about the Mlir-commits
mailing list