diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -279,6 +279,14 @@ distribution = distributionOptions; return *this; } + + /// Delete the original operation after tiling. Default is true. + bool deleteAfterTiling = true; + LinalgTilingOptions & + setDeleteAfterTiling(bool value) { + deleteAfterTiling = value; + return *this; + } }; /// Canonicalization patterns relevant to apply after tiling patterns. These are diff --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp @@ -127,7 +127,8 @@ // New marker if specified. marker.replaceLinalgMarker(rewriter, res->op.getOperation()); - rewriter.eraseOp(op); + if (options.deleteAfterTiling) + rewriter.eraseOp(op); return success(); }