[Mlir-commits] [mlir] [MLIR][SCF] Fold dim ops of iter_args to respective init_args (PR #109973)
Prashant Kumar
llvmlistbot at llvm.org
Thu Sep 26 12:22:16 PDT 2024
================
@@ -103,6 +103,44 @@ struct DimOfReifyRankedShapedTypeOpInterface : public OpRewritePattern<OpTy> {
return success();
}
};
+
+/// Fold dim ops of iter_args to dim ops of their respective init args. E.g.:
+///
+/// ```
+/// %0 = ... : tensor<?x?xf32>
+/// scf.forall ... shared_outs(%arg0 = %0) -> (tensor<?x?xf32>) {
+/// %1 = tensor.dim %arg0, %c0 : tensor<?x?xf32>
+/// ...
+/// }
+/// ```
+///
+/// is folded to:
+///
+/// ```
+/// %0 = ... : tensor<?x?xf32>
+/// scf.forall ... shared_outs(%arg0 = %0) -> (tensor<?x?xf32>) {
+/// %1 = tensor.dim %0, %c0 : tensor<?x?xf32>
+/// ...
+/// }
+/// ```
+struct IterArgsToInitArgs : public OpRewritePattern<tensor::DimOp> {
+ using OpRewritePattern<tensor::DimOp>::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(tensor::DimOp dimOp,
+ PatternRewriter &rewriter) const final {
+ auto blockArg = dyn_cast<BlockArgument>(dimOp.getSource());
+ if (!blockArg)
+ return failure();
+ auto loopLikeOp =
+ dyn_cast<LoopLikeOpInterface>(blockArg.getParentBlock()->getParentOp());
----------------
pashu123 wrote:
Makes sense! I'll revert this patch. I didn't think about this case.
https://github.com/llvm/llvm-project/pull/109973
More information about the Mlir-commits
mailing list