31 assert(((resType.getNumDynamicDims() == dynOutDims.size()) ||
32 dynOutDims.empty()) &&
33 "Either none or all output dynamic dims must be specified!");
42 for (
const auto [idx, val] :
enumerate(resType.getShape())) {
43 bool isDimDynamic = ShapedType::isDynamic(val);
44 bool updatePadHigh = !isDimDynamic || !dynOutDims.empty();
61 return b.
create<PadOp>(loc, resType, source, low, high, pad, nofold);
67 auto tensorTy = cast<RankedTensorType>(rankedTensor.
getType());
70 if (en.value() == ShapedType::kDynamic)
71 dynamicDims.push_back(
72 b.
create<tensor::DimOp>(loc, rankedTensor, en.index()));
77 FailureOr<RankedTensorType>
80 if (transposeVector.empty())
81 return rankedTensorType;
84 transposeVector.size() !=
static_cast<size_t>(rankedTensorType.getRank()))
91 RankedTensorType transposedTensorType =
92 RTTBuilder(rankedTensorType).
setShape(transposedShape);
93 return transposedTensorType;
98 const llvm::SmallBitVector &
dropDims) {
99 auto srcType = cast<ShapedType>(src.
getType());
100 int64_t rank = srcType.getRank();
101 assert(rank ==
static_cast<int64_t
>(
dropDims.size()) &&
102 "dropDims dimension does not match src tensor rank");
105 [&](
unsigned dim) { return srcType.getShape()[dim] == 1; }) &&
106 "Dropping non unit dimension");
111 int64_t nextDimToGroup = 0;
112 llvm::SmallBitVector keptDims(
dropDims);
114 int64_t lastSetBit = keptDims.find_last();
115 for (int64_t
setBit : keptDims.set_bits()) {
119 int64_t upTo =
setBit == lastSetBit ? rank - 1 :
setBit;
120 auto seq = llvm::seq_inclusive(nextDimToGroup, upTo);
121 reassocMaps.emplace_back(llvm::make_range(seq.begin(), seq.end()));
122 nextDimToGroup =
setBit + 1;
124 return b.
create<tensor::CollapseShapeOp>(loc, src, reassocMaps);
128 llvm::SmallBitVector droppedDims = op.getDroppedDims();
130 RankedTensorType resultType = op.getDestType();
133 for (int64_t resultDim = 0; resultDim < resultType.getRank(); ++resultDim) {
134 if (droppedDims.test(resultDim)) {
137 if (resultType.getDimSize(resultDim) != 1)
142 {op.getSource(), srcDim}, {op.getResult(), resultDim});
143 if (failed(equalDimSize) || !*equalDimSize)
152 llvm::SmallBitVector droppedDims = op.getDroppedDims();
153 int64_t resultDim = 0;
156 RankedTensorType sourceType = op.getSourceType();
157 for (int64_t dim = 0, e = sourceType.getRank(); dim < e; ++dim) {
158 if (droppedDims.test(dim)) {
161 if (sourceType.getDimSize(dim) != 1)
166 {op.getSource(), dim}, {op.getResult(), resultDim});
167 if (failed(equalDimSize) || !*equalDimSize)
static void setBit(char *rawData, size_t bitPos, bool value)
Set a bit to a specific value.
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 provides an abstraction over the different types of ranges over Values.
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< 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...
PadOp createPadHighOp(RankedTensorType resType, Value source, Value pad, bool nofold, Location loc, OpBuilder &builder, ValueRange dynOutDims=std::nullopt)
CollapseShapeOp dropGivenUnitDims(OpBuilder &b, Location loc, Value src, const llvm::SmallBitVector &dropDims)
Create tensor.collapse_shape to drop unit dimensions in dropDims in tensor src.
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.
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 .
void applyPermutationToVector(SmallVector< T, N > &inVec, ArrayRef< int64_t > permutation)
Apply the permutation defined by permutation to inVec.
SmallVector< int64_t > dropDims(ArrayRef< int64_t > inputPerm, ArrayRef< int64_t > dropPositions)
Returns a permutation vector that drop the input dims in dropPositions from inputPerm.
bool isPermutationVector(ArrayRef< int64_t > interchange)
Method to check if an interchange vector is a permutation.