[Mlir-commits] [mlir] [mlir] Add Memref Normalization support for reinterpret_cast op (PR #133417)
Uday Bondhugula
llvmlistbot at llvm.org
Fri Apr 25 03:25:06 PDT 2025
================
@@ -1845,6 +1781,95 @@ LogicalResult mlir::affine::normalizeMemRef(AllocLikeOp allocOp) {
return success();
}
+LogicalResult
+mlir::affine::normalizeMemRef(memref::ReinterpretCastOp reinterpretCastOp) {
+ MemRefType memrefType = reinterpretCastOp.getType();
+ AffineMap oldLayoutMap = memrefType.getLayout().getAffineMap();
+ Value oldMemRef = reinterpretCastOp.getResult();
+
+ // If `oldLayoutMap` is identity, `memrefType` is already normalized.
+ if (oldLayoutMap.isIdentity())
+ return success();
+
+ // Fetch a new memref type after normalizing the old memref to have an
+ // identity map layout.
+ MemRefType newMemRefType = normalizeMemRefType(memrefType);
+ newMemRefType.dump();
+ if (newMemRefType == memrefType)
+ // `oldLayoutMap` couldn't be transformed to an identity map.
+ return failure();
+
+ uint64_t newRank = newMemRefType.getRank();
+ SmallVector<Value> mapOperands(oldLayoutMap.getNumDims() +
+ oldLayoutMap.getNumSymbols());
+ SmallVector<Value> oldStrides = reinterpretCastOp.getStrides();
+ Location loc = reinterpretCastOp.getLoc();
+ // As `newMemRefType` is normalized, it is unit strided.
+ SmallVector<int64_t> newStaticStrides(newRank, 1);
+ SmallVector<int64_t> newStaticOffsets(newRank, 0);
+ ArrayRef<int64_t> oldShape = memrefType.getShape();
+ mlir::ValueRange oldSizes = reinterpretCastOp.getSizes();
+ unsigned idx = 0;
+ SmallVector<int64_t> newStaticSizes;
+ OpBuilder b(reinterpretCastOp);
+ // Collectthe map operands which will be used to compute the new normalized
----------------
bondhugula wrote:
Collect the ...
https://github.com/llvm/llvm-project/pull/133417
More information about the Mlir-commits
mailing list