[Mlir-commits] [mlir] Introduce new Unroll And Jam loop transform for SCF/Affine loops (PR #94142)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Fri Jun 14 08:41:15 PDT 2024


================
@@ -473,6 +496,185 @@ LogicalResult mlir::loopUnrollByFactor(
   return success();
 }
 
+/// Check if bounds of all inner loops are defined outside of `forOp`
+/// and return false if not.
+static bool areInnerBoundsInvariant(scf::ForOp forOp) {
+  auto walkResult = forOp.walk([&](scf::ForOp innerForOp) {
+    if (!forOp.isDefinedOutsideOfLoop(innerForOp.getLowerBound()) ||
+        !forOp.isDefinedOutsideOfLoop(innerForOp.getUpperBound()) ||
+        !forOp.isDefinedOutsideOfLoop(innerForOp.getStep()))
+      return WalkResult::interrupt();
+
+    return WalkResult::advance();
+  });
+  return !walkResult.wasInterrupted();
+}
+
+/// Unrolls and jams this loop by the specified factor.
+LogicalResult mlir::loopUnrollJamByFactor(scf::ForOp forOp,
----------------
ftynse wrote:

This has a rather large overlap with the affine version, can we minimize it somehow? Specifically, can the implementation be ported to operate on `LoopLikeOpInterface` instead of specific loops? It would then live with the interface. If not, hoist out common parts, possible with templating or callbacks, and put it in the interface or utils.

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


More information about the Mlir-commits mailing list