MLIR
20.0.0git
|
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributeInterfaces.h"
#include "mlir/IR/BuiltinTypeInterfaces.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Interfaces/DestinationStyleOpInterface.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/MathExtras.h"
#include <algorithm>
#include <optional>
#include "mlir/Dialect/Tensor/IR/TensorOps.cpp.inc"
Go to the source code of this file.
Classes | |
struct | SliceReturnTypeCanonicalizer |
Return the canonical type of the result of an extract_slice op. More... | |
struct | SliceCanonicalizer |
A canonicalizer wrapper to replace ExtractSliceOps. More... | |
struct | FoldTensorCastPackOp |
Folds a tensor.cast op into a consuming tensor::PackOp op if the tensor.cast has source that is more static than the consuming op. More... | |
struct | FoldTensorCastProducerOp |
Folds a tensor.cast op into a consuming DestinationStyleOpInterface op if the tensor.cast has source that is more static than the consuming op. More... | |
Macros | |
#define | GET_OP_CLASSES |
Functions | |
static llvm::SmallBitVector | getDroppedDims (ArrayRef< int64_t > reducedShape, ArrayRef< OpFoldResult > mixedSizes) |
Compute the dropped dimensions of a rank-reducing tensor.extract_slice op or rank-extending tensor.insert_slice op. More... | |
static RankedTensorType | foldDynamicToStaticDimSizes (RankedTensorType type, ValueRange dynamicSizes, SmallVector< Value > &foldedDynamicSizes) |
Given a ranked tensor type and a range of values that defines its dynamic dimension sizes, turn all dynamic sizes that have a constant value into static dimension sizes. More... | |
static TensorType | joinShapes (TensorType one, TensorType two) |
Compute a TensorType that has the joined shape knowledge of the two given TensorTypes. More... | |
static OpFoldResult | reshapeConstantSource (DenseElementsAttr source, TensorType result, std::optional< Attribute > cst=std::nullopt) |
Try to remove a tensor operation if it would only reshape a constant. More... | |
static LogicalResult | verifyGatherOrScatterDims (Operation *op, ArrayRef< int64_t > dims, ArrayRef< int64_t > indices, int64_t rank, StringRef gatherOrScatter, StringRef sourceOrDest) |
static int64_t | getNumElements (ShapedType type) |
template<typename TensorReshapeOp , bool isExpansion = std::is_same< TensorReshapeOp, ExpandShapeOp>::value> | |
static LogicalResult | verifyTensorReshapeOp (TensorReshapeOp op, RankedTensorType expandedType, RankedTensorType collapsedType) |
static LogicalResult | produceSliceErrorMsg (SliceVerificationResult result, Operation *op, RankedTensorType expectedType) |
static LogicalResult | foldIdentityOffsetSizeAndStrideOpInterface (OffsetSizeAndStrideOpInterface op, ShapedType shapedType) |
static Value | foldExtractAfterInsertSlice (ExtractSliceOp extractOp) |
If we have an ExtractSliceOp consuming an InsertSliceOp with the same slice, we can return the InsertSliceOp's source directly. More... | |
static SliceVerificationResult | verifyInsertSliceOp (RankedTensorType srcType, RankedTensorType dstType, ArrayRef< int64_t > staticOffsets, ArrayRef< int64_t > staticSizes, ArrayRef< int64_t > staticStrides, RankedTensorType *expectedType=nullptr) |
Rank-reducing type verification for both InsertSliceOp and ParallelInsertSliceOp. More... | |
static LogicalResult | foldInsertAfterInsertSlice (InsertSliceOp insertOp) |
If we have two consecutive InsertSliceOp writing to the same slice, we can mutate the second InsertSliceOp's destination to the first one's. More... | |
static Value | foldInsertAfterExtractSlice (InsertSliceOp insertOp) |
Folds round-trip extract/insert slice op pairs. More... | |
void | printInferType (OpAsmPrinter &printer, Operation *op, Value optOperand, Type typeToInfer, Type typeToInferFrom) |
ParseResult | parseInferType (OpAsmParser &parser, std::optional< OpAsmParser::UnresolvedOperand > optOperand, Type &typeToInfer, Type typeToInferFrom) |
template<typename OpTy > | |
static LogicalResult | reifyResultShapesImpl (OpTy op, OpBuilder &builder, ReifiedRankedShapedTypeDims &reifiedReturnShapes) |
template<typename OpTy > | |
static DenseMap< int64_t, OpFoldResult > | getDimAndTileMappingImpl (OpTy op) |
template<typename OpTy > | |
static SmallVector< OpFoldResult > | getMixedTilesImpl (OpTy op) |
template<typename OpTy > | |
static SmallVector< int64_t > | getStaticTilesImpl (OpTy op) |
static bool | isInvalidPackingPosSpecification (ArrayRef< int64_t > dimsPos, size_t rank) |
Returns true if dimsPos is invalid. More... | |
static bool | areAllInBound (ArrayRef< int64_t > sourceShape, ArrayRef< int64_t > limitShape) |
Returns true if the dimension of sourceShape is smaller than the dimension of the limitShape . More... | |
template<typename OpTy > | |
static LogicalResult | commonVerifierPackAndUnPackOp (OpTy packOrUnPack) |
template<typename OpTy > | |
static PackOrUnPackTransposeResult | commonPermutationOfPackAndUnPackOp (OpTy packOrUnPackOp, ArrayRef< int64_t > innerPermutation, ArrayRef< int64_t > outerPermutation) |
static SmallVector< int64_t > | asShapeWithAnyValueAsDynamic (ArrayRef< OpFoldResult > ofrs) |
Converts OpFoldResults to int64_t shape entries, unconditionally mapping all Value's to kDynamic, even if they are arith.constant values. More... | |
static SmallVector< int64_t > | getPackOpResultTypeShape (ArrayRef< int64_t > sourceShape, ArrayRef< int64_t > innerTileSizes, ArrayRef< int64_t > innerDimsPos, ArrayRef< int64_t > outerDimsPerm) |
Helper for PackOp::{getResultShape,inferPackedType}. More... | |
template<typename OpTy > | |
bool | areTilesAndTiledDimsAllConstant (OpTy op) |
Returns true if the tiles and the tiled dims are constant. More... | |
static bool | hasSameInnerOuterAttribute (PackOp packOp, UnPackOp unPackOp) |
static bool | haveSameTiles (PackOp packOp, UnPackOp unPackOp) |
static bool | paddingIsNotNeeded (PackOp op) |
Returns true if the pack op does not need a padding value. More... | |
static bool | inferStaticShape (PackOp packOp, SmallVectorImpl< int64_t > &srcShape, SmallVectorImpl< int64_t > &destShape) |
Returns true if the srcShape or destShape is different from the one in packOp and populates each with the inferred static shape. More... | |
template<typename PackOrUnpackOp > | |
static bool | isLikePadUnPad (PackOrUnpackOp packOp, RankedTensorType packedTensorType) |
static bool | inferStaticShape (UnPackOp op, SmallVectorImpl< int64_t > &srcShape, SmallVectorImpl< int64_t > &destShape) |
Returns true if the srcShape or destShape is different from the one in op and populates each with the inferred static shape. More... | |
bool | foldTensorCastPrecondition (DestinationStyleOpInterface op) |
static SmallVector< Value > | getNewOperands (DestinationStyleOpInterface op, SmallVector< Type > &newResTy) |
#define GET_OP_CLASSES |
Definition at line 4933 of file TensorOps.cpp.
|
static |
Returns true if the dimension of sourceShape
is smaller than the dimension of the limitShape
.
Definition at line 3926 of file TensorOps.cpp.
Referenced by commonVerifierPackAndUnPackOp().
bool areTilesAndTiledDimsAllConstant | ( | OpTy | op | ) |
Returns true if the tiles and the tiled dims are constant.
Definition at line 4328 of file TensorOps.cpp.
References mlir::getConstantIntValue(), and mlir::tile().
|
static |
Converts OpFoldResults to int64_t shape entries, unconditionally mapping all Value's to kDynamic, even if they are arith.constant values.
Definition at line 4194 of file TensorOps.cpp.
References mlir::getConstantIntValue().
|
static |
Definition at line 4039 of file TensorOps.cpp.
References mlir::applyPermutationToVector(), and mlir::isPermutationVector().
|
static |
Definition at line 3941 of file TensorOps.cpp.
References areAllInBound(), mlir::Operation::emitError(), mlir::isConstantIntValue(), isInvalidPackingPosSpecification(), and mlir::tile().
|
static |
Given a ranked tensor type and a range of values that defines its dynamic dimension sizes, turn all dynamic sizes that have a constant value into static dimension sizes.
Definition at line 180 of file TensorOps.cpp.
References mlir::get(), and mlir::getConstantIntValue().
|
static |
If we have an ExtractSliceOp consuming an InsertSliceOp with the same slice, we can return the InsertSliceOp's source directly.
Definition at line 2602 of file TensorOps.cpp.
References mlir::Value::getDefiningOp().
|
static |
Definition at line 2580 of file TensorOps.cpp.
References mlir::getConstantIntValue().
|
static |
Folds round-trip extract/insert slice op pairs.
Example:
can be folded into val.
Definition at line 2748 of file TensorOps.cpp.
References mlir::Value::getDefiningOp().
|
static |
If we have two consecutive InsertSliceOp writing to the same slice, we can mutate the second InsertSliceOp's destination to the first one's.
Example:
folds into:
This pattern works with both InsertSliceOp and ParallelInsertSliceOp.
Definition at line 2728 of file TensorOps.cpp.
bool foldTensorCastPrecondition | ( | DestinationStyleOpInterface | op | ) |
Definition at line 4760 of file TensorOps.cpp.
Referenced by FoldTensorCastProducerOp::matchAndRewrite(), and FoldTensorCastPackOp::matchAndRewrite().
|
static |
Definition at line 3865 of file TensorOps.cpp.
|
static |
Compute the dropped dimensions of a rank-reducing tensor.extract_slice op or rank-extending tensor.insert_slice op.
Definition at line 136 of file TensorOps.cpp.
References mlir::detail::enumerate().
|
static |
Definition at line 3880 of file TensorOps.cpp.
References mlir::Builder::getI64IntegerAttr().
|
static |
Definition at line 4780 of file TensorOps.cpp.
References mlir::tensor::canFoldIntoConsumerOp().
Referenced by FoldTensorCastProducerOp::matchAndRewrite(), and FoldTensorCastPackOp::matchAndRewrite().
|
static |
Definition at line 1604 of file TensorOps.cpp.
|
static |
Helper for PackOp::{getResultShape,inferPackedType}.
Returns the shape of the packed type. Having a shared helper helps implement these two methods in a way that ensures that they agree on which dimensions are dynamic.
Definition at line 4209 of file TensorOps.cpp.
References mlir::applyPermutationToVector(), and mlir::detail::enumerate().
|
static |
Definition at line 3896 of file TensorOps.cpp.
References mlir::dispatchIndexOpFoldResults().
|
static |
Definition at line 4359 of file TensorOps.cpp.
References mlir::isIdentityPermutation().
|
static |
Definition at line 4373 of file TensorOps.cpp.
References mlir::isEqualConstantIntOrValue().
|
static |
Returns true if the srcShape
or destShape
is different from the one in packOp
and populates each with the inferred static shape.
Definition at line 4400 of file TensorOps.cpp.
References mlir::invertPermutationVector().
|
static |
Returns true if the srcShape
or destShape
is different from the one in op
and populates each with the inferred static shape.
Definition at line 4660 of file TensorOps.cpp.
References mlir::invertPermutationVector().
|
static |
Returns true if dimsPos
is invalid.
It is invalid when: a) It contains duplicate. b) At least one dimension is out of bound (dimPos
is >= 0 and < rank). c) The number of elements in dimsPos
is > than rank
.
Definition at line 3909 of file TensorOps.cpp.
Referenced by commonVerifierPackAndUnPackOp().
|
static |
Definition at line 4493 of file TensorOps.cpp.
|
static |
Compute a TensorType that has the joined shape knowledge of the two given TensorTypes.
The element types need to match.
Definition at line 386 of file TensorOps.cpp.
References mlir::get(), mlir::TensorType::getElementType(), and mlir::TensorType::hasRank().
|
static |
Returns true if the pack op does not need a padding value.
Definition at line 4386 of file TensorOps.cpp.
ParseResult parseInferType | ( | OpAsmParser & | parser, |
std::optional< OpAsmParser::UnresolvedOperand > | optOperand, | ||
Type & | typeToInfer, | ||
Type | typeToInferFrom | ||
) |
Definition at line 3033 of file TensorOps.cpp.
void printInferType | ( | OpAsmPrinter & | printer, |
Operation * | op, | ||
Value | optOperand, | ||
Type | typeToInfer, | ||
Type | typeToInferFrom | ||
) |
Definition at line 3029 of file TensorOps.cpp.
|
static |
Definition at line 2307 of file TensorOps.cpp.
References mlir::ElemTypeMismatch, mlir::Operation::emitError(), mlir::RankTooLarge, mlir::SizeMismatch, and mlir::Success.
|
static |
Definition at line 3853 of file TensorOps.cpp.
References mlir::tensor::getMixedSizes().
|
static |
Try to remove a tensor operation if it would only reshape a constant.
Removes the op and replaces the constant with a new constant of the result shape. When an optional cst attribute is passed, it is reshaped only if the splat value matches the value in the attribute.
Definition at line 1127 of file TensorOps.cpp.
References mlir::DenseElementsAttr::getSplatValue(), mlir::DenseElementsAttr::isSplat(), and mlir::DenseElementsAttr::resizeSplat().
|
static |
Definition at line 1346 of file TensorOps.cpp.
References mlir::Operation::emitOpError().
|
static |
Rank-reducing type verification for both InsertSliceOp and ParallelInsertSliceOp.
Definition at line 2689 of file TensorOps.cpp.
References mlir::isRankReducedType().
|
static |
Definition at line 1828 of file TensorOps.cpp.
References mlir::tensor::isSameTypeWithoutEncoding(), and mlir::verifyReshapeLikeTypes().