MLIR  15.0.0git
Classes | Macros | Functions
TensorOps.cpp File Reference
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/Arithmetic/Utils/Utils.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributeInterfaces.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/TypeUtilities.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "mlir/Dialect/Tensor/IR/TensorOps.cpp.inc"
+ Include dependency graph for TensorOps.cpp:

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...
 

Macros

#define GET_OP_CLASSES
 

Functions

static TensorType joinShapes (TensorType one, TensorType two)
 Compute a TensorType that has the joined shape knowledge of the two given TensorTypes. More...
 
static int64_t getNumElements (ShapedType type)
 
static RankedTensorType computeTensorReshapeCollapsedType (RankedTensorType type, ArrayRef< AffineMap > reassociation)
 Compute the RankedTensorType obtained by applying reassociation to type. More...
 
template<typename TensorReshapeOp , bool isExpansion = std::is_same< TensorReshapeOp, ExpandShapeOp>::value>
static LogicalResult verifyTensorReshapeOp (TensorReshapeOp op, RankedTensorType expandedType, RankedTensorType collapsedType)
 
template<typename OpTy >
static LogicalResult produceSliceErrorMsg (SliceVerificationResult result, OpTy op, Type expectedType)
 
static RankedTensorType getCanonicalSliceResultType (unsigned resultRank, RankedTensorType sourceType, ArrayRef< OpFoldResult > mixedOffsets, ArrayRef< OpFoldResult > mixedSizes, ArrayRef< OpFoldResult > mixedStrides)
 Infer the canonical type of the result of an extract_slice op. More...
 
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 (ShapedType srcType, ShapedType dstType, ArrayAttr staticOffsets, ArrayAttr staticSizes, ArrayAttr staticStrides, ShapedType *expectedType=nullptr)
 
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...
 
void printInferType (OpAsmPrinter &printer, Operation *op, Value optOperand, Type typeToInfer, Type typeToInferFrom)
 
ParseResult parseInferType (OpAsmParser &parser, Optional< OpAsmParser::UnresolvedOperand > optOperand, Type &typeToInfer, Type typeToInferFrom)
 

Macro Definition Documentation

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 2195 of file TensorOps.cpp.

Function Documentation

◆ computeTensorReshapeCollapsedType()

static RankedTensorType computeTensorReshapeCollapsedType ( RankedTensorType  type,
ArrayRef< AffineMap reassociation 
)
static

◆ foldExtractAfterInsertSlice()

static Value foldExtractAfterInsertSlice ( ExtractSliceOp  extractOp)
static

If we have an ExtractSliceOp consuming an InsertSliceOp with the same slice, we can return the InsertSliceOp's source directly.

Definition at line 1404 of file TensorOps.cpp.

References foldIdentityOffsetSizeAndStrideOpInterface(), mlir::Value::getDefiningOp(), and mlir::succeeded().

◆ foldIdentityOffsetSizeAndStrideOpInterface()

static LogicalResult foldIdentityOffsetSizeAndStrideOpInterface ( OffsetSizeAndStrideOpInterface  op,
ShapedType  shapedType 
)
static

◆ foldInsertAfterInsertSlice()

static LogicalResult foldInsertAfterInsertSlice ( InsertSliceOp  insertOp)
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:

%0 = tensor.insert_slice %slice0 into %input[0, 0] [64, 64] [1, 1]
%1 = tensor.insert_slice %slice1 into %0[0, 0] [64, 64] [1, 1]

folds into:

%1 = tensor.insert_slice %slice1 into %input[0, 0] [64, 64] [1, 1]

Definition at line 1529 of file TensorOps.cpp.

References mlir::RewritePatternSet::add(), mlir::tensor::canFoldIntoConsumerOp(), mlir::canonicalizeSubViewPart(), mlir::Type::cast(), mlir::OpBuilder::create(), mlir::OpBuilder::createOrFold(), mlir::failure(), foldIdentityOffsetSizeAndStrideOpInterface(), mlir::getConstantIntValue(), mlir::Value::getType(), mlir::matchConstantIndex(), mlir::matchPattern(), mlir::tensor::preservesStaticInformation(), mlir::RewriterBase::replaceOp(), mlir::RewriterBase::replaceOpWithNewOp(), mlir::succeeded(), mlir::success(), mlir::Success, and verifyInsertSliceOp().

◆ getCanonicalSliceResultType()

static RankedTensorType getCanonicalSliceResultType ( unsigned  resultRank,
RankedTensorType  sourceType,
ArrayRef< OpFoldResult mixedOffsets,
ArrayRef< OpFoldResult mixedSizes,
ArrayRef< OpFoldResult mixedStrides 
)
static

◆ getNumElements()

static int64_t getNumElements ( ShapedType  type)
static

Definition at line 751 of file TensorOps.cpp.

References mlir::Type::cast(), mlir::convertReassociationIndicesToExprs(), mlir::Type::dyn_cast(), mlir::TensorType::getElementType(), mlir::getSymbolLessAffineMaps(), mlir::Value::getType(), mlir::success(), and mlir::verify().

Referenced by mlir::DenseElementsAttr::complex_float_value_end(), mlir::DenseElementsAttr::complex_value_end(), computeMemRefRankReductionMask(), convertStructType(), mlir::python::PyAffineExpr::createFromCapsule(), mlir::python::PyAffineMap::createFromCapsule(), mlir::DenseIntElementsAttr::end(), mlir::spirv::CompositeType::getCapabilities(), mlir::DenseElementsAttr::getComplexFloatValues(), mlir::DenseElementsAttr::getComplexIntValues(), getDimPosition(), mlir::spirv::StructType::getElementType(), mlir::spirv::StructType::getElementTypes(), getFirstIntValue(), mlir::Sliceable< Derived, ElementTy >::getItem(), mlir::spirv::StructType::getMemberDecorations(), mlir::spirv::StructType::getMemberOffset(), getPushConstantVariable(), mlir::spirv::ArrayType::getSizeInBytes(), mlir::DenseElementsAttr::getValues(), hasOneBranchOpTo(), isDefinedByCallTo(), CanonicalizeSingleResultAffineMinMaxOp< T >::matchAndRewrite(), mlirElementsAttrGetNumElements(), mlir::spirv::StructType::MemberDecorationInfo::operator<(), mlir::AffineDmaStartOp::print(), mlir::AffineDmaWaitOp::print(), mlir::DenseElementsAttr::raw_int_end(), mlir::DenseElementsAttr::size(), mlir::DenseElementsAttr::value_end(), verifyCoopMatrixMulAdd(), and mlir::python::PySymbolTable::walkSymbolTables().

◆ joinShapes()

static TensorType joinShapes ( TensorType  one,
TensorType  two 
)
static

◆ parseInferType()

ParseResult parseInferType ( OpAsmParser parser,
Optional< OpAsmParser::UnresolvedOperand optOperand,
Type typeToInfer,
Type  typeToInferFrom 
)

◆ printInferType()

void printInferType ( OpAsmPrinter printer,
Operation op,
Value  optOperand,
Type  typeToInfer,
Type  typeToInferFrom 
)

Definition at line 1760 of file TensorOps.cpp.

◆ produceSliceErrorMsg()

template<typename OpTy >
static LogicalResult produceSliceErrorMsg ( SliceVerificationResult  result,
OpTy  op,
Type  expectedType 
)
static

◆ verifyInsertSliceOp()

static SliceVerificationResult verifyInsertSliceOp ( ShapedType  srcType,
ShapedType  dstType,
ArrayAttr  staticOffsets,
ArrayAttr  staticSizes,
ArrayAttr  staticStrides,
ShapedType *  expectedType = nullptr 
)
static

◆ verifyTensorReshapeOp()

template<typename TensorReshapeOp , bool isExpansion = std::is_same< TensorReshapeOp, ExpandShapeOp>::value>
static LogicalResult verifyTensorReshapeOp ( TensorReshapeOp  op,
RankedTensorType  expandedType,
RankedTensorType  collapsedType 
)
static