30 assert(((resType.getNumDynamicDims() == dynOutDims.size()) ||
31 dynOutDims.empty()) &&
32 "Either none or all output dynamic dims must be specified!");
41 for (
const auto [idx, val] :
enumerate(resType.getShape())) {
42 bool isDimDynamic = ShapedType::isDynamic(val);
43 bool updatePadHigh = !isDimDynamic || !dynOutDims.empty();
60 return b.
create<PadOp>(loc, resType, source, low, high, pad, nofold);
66 auto tensorTy = cast<RankedTensorType>(rankedTensor.
getType());
69 if (en.value() == ShapedType::kDynamic)
70 dynamicDims.push_back(
71 b.
create<tensor::DimOp>(loc, rankedTensor, en.index()));
76 FailureOr<RankedTensorType>
79 if (transposeVector.empty())
80 return rankedTensorType;
83 transposeVector.size() !=
static_cast<size_t>(rankedTensorType.getRank()))
90 RankedTensorType transposedTensorType =
91 RTTBuilder(rankedTensorType).
setShape(transposedShape);
92 return transposedTensorType;
104 PackingMetadata &packingMetadata) {
105 int64_t numPackedDims = innerDimsPos.size();
107 llvm::to_vector(llvm::seq<int64_t>(rank - numPackedDims, rank));
108 packingMetadata = computePackingMetadata(rank, innerDimsPos);
113 if (!outerPerm.empty())
120 return packInverseDestPermutation;
125 PackingMetadata pMetadata;
126 int64_t packedRank = packOp.getDestType().getRank();
131 return packInvDestPerm;
135 PackingMetadata metadata;
141 PackingMetadata &metadata) {
142 int64_t unpackRank = unpackOp.getSourceType().getRank();
147 return unpackInvSrcPerm;
151 llvm::SmallBitVector droppedDims = op.getDroppedDims();
153 RankedTensorType resultType = op.getDestType();
156 for (int64_t resultDim = 0; resultDim < resultType.getRank(); ++resultDim) {
157 if (droppedDims.test(resultDim)) {
160 if (resultType.getDimSize(resultDim) != 1)
165 {op.getSource(), srcDim}, {op.getResult(), resultDim});
166 if (failed(equalDimSize) || !*equalDimSize)
175 llvm::SmallBitVector droppedDims = op.getDroppedDims();
176 int64_t resultDim = 0;
179 RankedTensorType sourceType = op.getSourceType();
180 for (int64_t dim = 0, e = sourceType.getRank(); dim < e; ++dim) {
181 if (droppedDims.test(dim)) {
184 if (sourceType.getDimSize(dim) != 1)
189 {op.getSource(), dim}, {op.getResult(), resultDim});
190 if (failed(equalDimSize) || !*equalDimSize)
static SmallVector< int64_t > computePackUnPackPerm(int64_t rank, ArrayRef< int64_t > &innerDimsPos, ArrayRef< int64_t > &outerPerm, PackingMetadata &packingMetadata)
The permutation can be obtained from two permutations: a) Compute the permutation vector to move the ...
Base type for affine expression.
IntegerAttr getIndexAttr(int64_t value)
MLIRContext * getContext() const
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class represents a single result from folding an operation.
This is a builder type that keeps local references to arguments.
Builder & setShape(ArrayRef< int64_t > newShape)
static FailureOr< bool > areEqual(const Variable &var1, const Variable &var2)
Compute whether the given variables are equal.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Constructs an AffineApplyOp that applies map to operands after composing the map with the maps of any...
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
SmallVector< int64_t > getUnPackInverseSrcPerm(tensor::UnPackOp unpackOp)
Shell function to compute the Source Permutation of unPackOp.
SmallVector< Value > createDynamicDimValues(OpBuilder &b, Location loc, Value rankedTensor)
bool isCastLikeInsertSliceOp(InsertSliceOp op)
A tensor.insert_slice is a cast-like operation if it merely rank-extends the source tensor or inserts...
bool isCastLikeExtractSliceOp(ExtractSliceOp op)
A tensor.extract_slice is a cast-like operation if it merely rank-reduces unit dimensions of the sour...
OpFoldResult getMixedSize(OpBuilder &builder, Location loc, Value value, int64_t dim)
Return the dimension of the given tensor value.
SmallVector< int64_t > getPackInverseDestPerm(tensor::PackOp packOp)
Shell function to compute the Destination Permutation of PackOp This function uses the helper functio...
PadOp createPadHighOp(RankedTensorType resType, Value source, Value pad, bool nofold, Location loc, OpBuilder &builder, SmallVector< Value > dynOutDim={})
FailureOr< RankedTensorType > computeTransposedType(RankedTensorType rankedTensorType, ArrayRef< int64_t > transposeVector)
Returns the transposed rankedTensorType if transposeVector is non-empty.
Include the generated interface declarations.
void bindDims(MLIRContext *ctx, AffineExprTy &...exprs)
Bind a list of AffineExpr references to DimExpr at positions: [0 .
SmallVector< int64_t > computePermutationVector(int64_t permSize, ArrayRef< int64_t > positions, ArrayRef< int64_t > desiredPositions)
Return a permutation vector of size permSize that would result in moving positions into desiredPositi...
void applyPermutationToVector(SmallVector< T, N > &inVec, ArrayRef< int64_t > permutation)
Apply the permutation defined by permutation to inVec.
bool isPermutationVector(ArrayRef< int64_t > interchange)
Method to check if an interchange vector is a permutation.