[Mlir-commits] [mlir] [mlir][MemRef] Add more ops to narrow type support, strided metadata expansion (PR #102228)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Aug 14 14:32:35 PDT 2024
================
@@ -1060,6 +1095,49 @@ class ExtractStridedMetadataOpCastFolder
}
};
+/// Replace `base, offset, sizes, strides = extract_strided_metadata(
+/// memory_space_cast(src) to dstTy)`
+/// with
+/// ```
+/// oldBase, offset, sizes, strides = extract_strided_metadata(src)
+/// destBaseTy = type(oldBase) with memory space from destTy
+/// base = memory_space_cast(oldBase) to destBaseTy
+/// ```
+///
+/// In other words, propagate metadata extraction accross memory space casts.
+class ExtractStridedMetadataOpMemorySpaceCastFolder
+ : public OpRewritePattern<memref::ExtractStridedMetadataOp> {
+ using OpRewritePattern::OpRewritePattern;
+
+ LogicalResult
+ matchAndRewrite(memref::ExtractStridedMetadataOp extractStridedMetadataOp,
+ PatternRewriter &rewriter) const override {
+ Location loc = extractStridedMetadataOp.getLoc();
+ Value source = extractStridedMetadataOp.getSource();
+ auto memSpaceCastOp = source.getDefiningOp<memref::MemorySpaceCastOp>();
+ if (!memSpaceCastOp)
+ return failure();
+ auto newExtractStridedMetadata =
+ rewriter.create<memref::ExtractStridedMetadataOp>(
+ loc, memSpaceCastOp.getSource());
+ SmallVector<Value> results(newExtractStridedMetadata.getResults());
+ if (!extractStridedMetadataOp.getBaseBuffer().use_empty()) {
----------------
MaheshRavishankar wrote:
Ok, that makes sense... Thanks for the explanation.
https://github.com/llvm/llvm-project/pull/102228
More information about the Mlir-commits
mailing list