diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -605,95 +605,6 @@ return RankedTensorType::get(staticSizes, elementType); } -static Value getCollapsedInitTensor(OpBuilder &builder, - TensorReshapeOp reshapeOp) { - Location loc = reshapeOp.getLoc(); - SmallVector dynamicShapes; - SmallVector staticShapes; - auto reassociation = reshapeOp.getReassociationMaps(); - Value src = reshapeOp.src(); - RankedTensorType srcType = reshapeOp.getSrcType(); - ArrayRef srcShape = srcType.getShape(); - for (auto map : reassociation) { - Value linearizedDynamicDim = nullptr; - int64_t linearizedStaticDim = 1; - for (unsigned i : llvm::map_range(map.getResults(), [](AffineExpr e) { - return e.cast().getPosition(); - })) { - if (ShapedType::isDynamic(srcShape[i])) { - Value shapeVal = builder.create(loc, src, i); - if (linearizedDynamicDim) { - linearizedDynamicDim = - builder.create(loc, linearizedDynamicDim, shapeVal); - } else { - linearizedDynamicDim = shapeVal; - } - } else { - linearizedStaticDim *= srcShape[i]; - } - } - if (linearizedDynamicDim) { - if (linearizedStaticDim != 1) { - linearizedDynamicDim = builder.create( - loc, linearizedDynamicDim, - builder.create(loc, linearizedStaticDim)); - } - dynamicShapes.push_back(linearizedDynamicDim); - staticShapes.push_back(ShapedType::kDynamicSize); - } else { - staticShapes.push_back(linearizedStaticDim); - } - } - return builder.create(loc, dynamicShapes, staticShapes, - srcType.getElementType()); -} - -static Value getExpandedInitTensor(OpBuilder &builder, - TensorReshapeOp reshapeOp) { - SmallVector dynamicShapes; - SmallVector staticShapes; - auto reassociation = reshapeOp.getReassociationMaps(); - Value src = reshapeOp.src(); - RankedTensorType srcType = reshapeOp.getSrcType(); - ArrayRef srcShape = srcType.getShape(); - ArrayRef dstShape = reshapeOp.getResultType().getShape(); - Location loc = reshapeOp.getLoc(); - for (auto map : enumerate(reassociation)) { - int64_t linearizedStaticDim = 1; - bool hasDynamic = false; - for (unsigned i : - llvm::map_range(map.value().getResults(), [](AffineExpr e) { - return e.cast().getPosition(); - })) { - if (ShapedType::isDynamic(dstShape[i])) { - // Only one of the dimensions of the expanded shape should be dynamic. - if (hasDynamic) - return nullptr; - hasDynamic = true; - staticShapes.push_back(ShapedType::kDynamicSize); - continue; - } - staticShapes.push_back(dstShape[i]); - linearizedStaticDim *= dstShape[i]; - } - if (hasDynamic) { - // If the expanded dimensions has a dynamic shape, the src shape must be - // dynamic as well. - if (!ShapedType::isDynamic(srcShape[map.index()])) - return nullptr; - Value dynamicDim = builder.create(loc, src, map.index()); - if (linearizedStaticDim != 1) { - dynamicDim = builder.create( - loc, dynamicDim, - builder.create(loc, linearizedStaticDim)); - } - dynamicShapes.push_back(dynamicDim); - } - } - return builder.create(loc, dynamicShapes, staticShapes, - srcType.getElementType()); -} - namespace { /// Change the type of the result of a `linalg.init_tensor` by making the result /// type statically sized along dimension that in the original operation where