[Mlir-commits] [mlir] [mlir] Add Memref Normalization support for reinterpret_cast op (PR #133417)
Uday Bondhugula
llvmlistbot at llvm.org
Fri Apr 4 07:52:50 PDT 2025
================
@@ -1098,90 +1098,12 @@ void mlir::affine::affineScalarReplace(func::FuncOp f, DominanceInfo &domInfo,
op->erase();
}
-// Private helper function to transform memref.load with reduced rank.
-// This function will modify the indices of the memref.load to match the
-// newMemRef.
-LogicalResult transformMemRefLoadWithReducedRank(
- Operation *op, Value oldMemRef, Value newMemRef, unsigned memRefOperandPos,
- ArrayRef<Value> extraIndices, ArrayRef<Value> extraOperands,
- ArrayRef<Value> symbolOperands, AffineMap indexRemap) {
- unsigned oldMemRefRank = cast<MemRefType>(oldMemRef.getType()).getRank();
- unsigned newMemRefRank = cast<MemRefType>(newMemRef.getType()).getRank();
- unsigned oldMapNumInputs = oldMemRefRank;
- SmallVector<Value, 4> oldMapOperands(
- op->operand_begin() + memRefOperandPos + 1,
- op->operand_begin() + memRefOperandPos + 1 + oldMapNumInputs);
- SmallVector<Value, 4> oldMemRefOperands;
- oldMemRefOperands.assign(oldMapOperands.begin(), oldMapOperands.end());
- SmallVector<Value, 4> remapOperands;
- remapOperands.reserve(extraOperands.size() + oldMemRefRank +
- symbolOperands.size());
- remapOperands.append(extraOperands.begin(), extraOperands.end());
- remapOperands.append(oldMemRefOperands.begin(), oldMemRefOperands.end());
- remapOperands.append(symbolOperands.begin(), symbolOperands.end());
-
- SmallVector<Value, 4> remapOutputs;
- remapOutputs.reserve(oldMemRefRank);
- SmallVector<Value, 4> affineApplyOps;
-
- OpBuilder builder(op);
-
- if (indexRemap &&
- indexRemap != builder.getMultiDimIdentityMap(indexRemap.getNumDims())) {
- // Remapped indices.
- for (auto resultExpr : indexRemap.getResults()) {
- auto singleResMap = AffineMap::get(
- indexRemap.getNumDims(), indexRemap.getNumSymbols(), resultExpr);
- auto afOp = builder.create<AffineApplyOp>(op->getLoc(), singleResMap,
- remapOperands);
- remapOutputs.push_back(afOp);
- affineApplyOps.push_back(afOp);
- }
- } else {
- // No remapping specified.
- remapOutputs.assign(remapOperands.begin(), remapOperands.end());
- }
-
- SmallVector<Value, 4> newMapOperands;
- newMapOperands.reserve(newMemRefRank);
-
- // Prepend 'extraIndices' in 'newMapOperands'.
- for (Value extraIndex : extraIndices) {
- assert((isValidDim(extraIndex) || isValidSymbol(extraIndex)) &&
- "invalid memory op index");
- newMapOperands.push_back(extraIndex);
- }
-
- // Append 'remapOutputs' to 'newMapOperands'.
- newMapOperands.append(remapOutputs.begin(), remapOutputs.end());
-
- // Create new fully composed AffineMap for new op to be created.
- assert(newMapOperands.size() == newMemRefRank);
-
- OperationState state(op->getLoc(), op->getName());
- // Construct the new operation using this memref.
- state.operands.reserve(newMapOperands.size() + extraIndices.size());
- state.operands.push_back(newMemRef);
-
- // Insert the new memref map operands.
- state.operands.append(newMapOperands.begin(), newMapOperands.end());
-
- state.types.reserve(op->getNumResults());
- for (auto result : op->getResults())
- state.types.push_back(result.getType());
-
- // Copy over the attributes from the old operation to the new operation.
- for (auto namedAttr : op->getAttrs()) {
- state.attributes.push_back(namedAttr);
- }
-
- // Create the new operation.
- auto *repOp = builder.create(state);
- op->replaceAllUsesWith(repOp);
- op->erase();
-
- return success();
+// Checks if `op` is non dereferencing.
+// TODO: This hardcoded check will be removed once the right interface is added.
----------------
bondhugula wrote:
Should this TODO be removed now?
https://github.com/llvm/llvm-project/pull/133417
More information about the Mlir-commits
mailing list