[Mlir-commits] [mlir] [mlir][Transform dial] Expose convert-linalg-to-affine-loops transf (PR #211308)
Guillaume Iooss
llvmlistbot at llvm.org
Mon Jul 27 04:20:26 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");
+
+ // "generic" contains all new "AffineForOp", while we need to topmost one.
+ // Since all linalg operators are perfectly nested loops, these operators
+ // are totally ordered through the ancestor relation.
+ Operation* opFirst = *(generic->begin());
+ for (auto itop = generic->begin(); itop!=generic->end(); itop++) {
+ if ( (*itop)->isProperAncestor(opFirst)) {
+ opFirst = *itop;
+ }
----------------
guillaumeiooss wrote:
During construction, they add these loops to a SetVector (`mlir/lib/Dialect/Linalg/Transforms/Loops.cpp` :: lines 239 + 250`), before converting it into a list. So, I don't think we can assume anything about the order of loops.
https://github.com/llvm/llvm-project/pull/211308
More information about the Mlir-commits
mailing list