MLIR
21.0.0git
|
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Interfaces/Utils/InferIntRangeCommon.h"
#include "mlir/Interfaces/ViewLikeInterface.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "mlir/Dialect/MemRef/IR/MemRefOps.cpp.inc"
Go to the source code of this file.
Classes | |
struct | AllocaScopeInliner |
Inline an AllocaScopeOp if either the direct parent is an allocation scope or it contains no allocation. More... | |
struct | AllocaScopeHoister |
Move allocations into an allocation scope, if it is legal to move them (e.g. More... | |
struct | CollapseShapeOpMemRefCastFolder |
struct | SubViewReturnTypeCanonicalizer |
Return the canonical type of the result of a subview. More... | |
struct | SubViewCanonicalizer |
A canonicalizer wrapper to replace SubViewOps. More... | |
Macros | |
#define | GET_OP_CLASSES |
Functions | |
static void | constifyIndexValues (SmallVectorImpl< OpFoldResult > &values, ArrayRef< int64_t > constValues) |
Helper function that sets values[i] to constValues[i] if the latter is a static value, as indicated by ShapedType::kDynamic. More... | |
template<typename AllocLikeOp > | |
static LogicalResult | verifyAllocLikeOp (AllocLikeOp op) |
static bool | isGuaranteedAutomaticAllocation (Operation *op) |
Given an operation, return whether this op is guaranteed to allocate an AutomaticAllocationScopeResource. More... | |
static bool | isOpItselfPotentialAutomaticAllocation (Operation *op) |
Given an operation, return whether this op itself could allocate an AutomaticAllocationScopeResource. More... | |
static bool | lastNonTerminatorInRegion (Operation *op) |
Return whether this op is the last non terminating op in a region. More... | |
static std::map< int64_t, unsigned > | getNumOccurences (ArrayRef< int64_t > vals) |
Return a map with key being elements in vals and data being number of occurences of it. More... | |
static FailureOr< llvm::SmallBitVector > | computeMemRefRankReductionMask (MemRefType originalType, MemRefType reducedType, ArrayRef< OpFoldResult > sizes) |
Given the originalType and a candidateReducedType whose shape is assumed to be a subset of originalType with some 1 entries erased, return the set of indices that specifies which of the entries of originalShape are dropped to obtain reducedShape . More... | |
template<typename Container > | |
static bool | replaceConstantUsesOf (OpBuilder &rewriter, Location loc, Container values, ArrayRef< OpFoldResult > maybeConstants) |
Helper function to perform the replacement of all constant uses of values by a materialized constant extracted from maybeConstants . More... | |
static void | printGlobalMemrefOpTypeAndInitialValue (OpAsmPrinter &p, GlobalOp op, TypeAttr type, Attribute initialValue) |
static ParseResult | parseGlobalMemrefOpTypeAndInitialValue (OpAsmParser &parser, TypeAttr &typeAttr, Attribute &initialValue) |
static LogicalResult | verifyCollapsedShape (Operation *op, ArrayRef< int64_t > collapsedShape, ArrayRef< int64_t > expandedShape, ArrayRef< ReassociationIndices > reassociation, bool allowMultipleDynamicDimsPerGroup) |
Helper function for verifying the shape of ExpandShapeOp and ResultShapeOp result and operand. More... | |
static FailureOr< StridedLayoutAttr > | computeExpandedLayoutMap (MemRefType srcType, ArrayRef< int64_t > resultShape, ArrayRef< ReassociationIndices > reassociation) |
Compute the layout map after expanding a given source MemRef type with the specified reassociation indices. More... | |
static FailureOr< StridedLayoutAttr > | computeCollapsedLayoutMap (MemRefType srcType, ArrayRef< ReassociationIndices > reassociation, bool strict=false) |
Compute the layout map after collapsing a given source MemRef type with the specified reassociation indices. More... | |
static bool | haveCompatibleOffsets (MemRefType t1, MemRefType t2) |
Return true if t1 and t2 have equal offsets (both dynamic or of same static value). More... | |
static bool | haveCompatibleStrides (MemRefType t1, MemRefType t2, const llvm::SmallBitVector &droppedDims) |
Return true if t1 and t2 have equal strides (both dynamic or of same static value). More... | |
static LogicalResult | produceSubViewErrorMsg (SliceVerificationResult result, Operation *op, Type expectedType) |
static MemRefType | getCanonicalSubViewResultType (MemRefType currentResultType, MemRefType currentSourceType, MemRefType sourceType, ArrayRef< OpFoldResult > mixedOffsets, ArrayRef< OpFoldResult > mixedSizes, ArrayRef< OpFoldResult > mixedStrides) |
Compute the canonical result type of a SubViewOp. More... | |
static bool | isTrivialSubViewOp (SubViewOp subViewOp) |
Helper method to check if a subview operation is trivially a no-op. More... | |
static MemRefType | inferTransposeResultType (MemRefType memRefType, AffineMap permutationMap) |
Build a strided memref type by applying permutationMap to memRefType . More... | |
#define GET_OP_CLASSES |
Definition at line 3584 of file MemRefOps.cpp.
|
static |
Compute the layout map after collapsing a given source MemRef type with the specified reassociation indices.
Note: All collapsed dims in a reassociation group must be contiguous. It is not possible to check this by inspecting a MemRefType in the general case. If non-contiguity cannot be checked statically, the collapse is assumed to be valid (and thus accepted by this function) unless strict = true
.
Definition at line 2381 of file MemRefOps.cpp.
References mlir::get(), and mlir::SaturatedInteger::wrap().
|
static |
Compute the layout map after expanding a given source MemRef type with the specified reassociation indices.
Definition at line 2186 of file MemRefOps.cpp.
References mlir::get(), and mlir::SaturatedInteger::wrap().
|
static |
Given the originalType
and a candidateReducedType
whose shape is assumed to be a subset of originalType
with some 1
entries erased, return the set of indices that specifies which of the entries of originalShape
are dropped to obtain reducedShape
.
This accounts for cases where there are multiple unit-dims, but only a subset of those are dropped. For MemRefTypes these can be disambiguated using the strides. If a dimension is dropped the stride must be dropped too.
Definition at line 873 of file MemRefOps.cpp.
References mlir::detail::enumerate(), and getNumOccurences().
Referenced by getCanonicalSubViewResultType().
|
static |
Helper function that sets values[i] to constValues[i] if the latter is a static value, as indicated by ShapedType::kDynamic.
If constValues[i] is dynamic, tries to extract a constant value from value[i] to allow for additional folding opportunities. Also convertes all existing attributes to index attributes. (They may be i64 attributes.)
Definition at line 97 of file MemRefOps.cpp.
References mlir::detail::enumerate(), mlir::getConstantIntValue(), getContext(), and mlir::Builder::getIndexAttr().
|
static |
Compute the canonical result type of a SubViewOp.
Call inferResultType
to deduce the result type for the given sourceType
. Additionally, reduce the rank of the inferred result type if currentResultType
is lower rank than currentSourceType
. Use this signature if sourceType
is updated together with the result type. In this case, it is important to compute the dropped dimensions using currentSourceType
whose strides align with currentResultType
.
Definition at line 3040 of file MemRefOps.cpp.
References computeMemRefRankReductionMask(), and mlir::get().
|
static |
Return a map with key being elements in vals
and data being number of occurences of it.
Use std::map, since the vals
here are strides and the dynamic stride value is the same as the tombstone value for DenseMap<int64_t>
.
Definition at line 858 of file MemRefOps.cpp.
Referenced by computeMemRefRankReductionMask().
|
static |
Return true if t1
and t2
have equal offsets (both dynamic or of same static value).
Definition at line 2874 of file MemRefOps.cpp.
|
static |
Return true if t1
and t2
have equal strides (both dynamic or of same static value).
Dimensions of t1
may be dropped in t2
; these must be marked as dropped in droppedDims
.
Definition at line 2885 of file MemRefOps.cpp.
|
static |
Build a strided memref type by applying permutationMap
to memRefType
.
Definition at line 3313 of file MemRefOps.cpp.
References mlir::get(), mlir::MemRefType::Builder::setLayout(), and mlir::MemRefType::Builder::setShape().
|
static |
Given an operation, return whether this op is guaranteed to allocate an AutomaticAllocationScopeResource.
Definition at line 359 of file MemRefOps.cpp.
References mlir::Operation::getResults().
|
static |
Given an operation, return whether this op itself could allocate an AutomaticAllocationScopeResource.
Note that this will not check whether an operation contained within the op can allocate.
Definition at line 378 of file MemRefOps.cpp.
References mlir::Operation::getResults(), and mlir::Operation::hasTrait().
Referenced by AllocaScopeInliner::matchAndRewrite().
|
static |
Helper method to check if a subview
operation is trivially a no-op.
This is the case if the all offsets are zero, all strides are 1, and the source shape is same as the size of the subview. In such cases, the subview can be folded into its source.
Definition at line 3104 of file MemRefOps.cpp.
References mlir::detail::enumerate(), and mlir::getConstantIntValue().
|
static |
Return whether this op is the last non terminating op in a region.
That is to say, it is in a one-block region and is only followed by a terminator. This prevents extending the lifetime of allocations.
Definition at line 401 of file MemRefOps.cpp.
References mlir::Operation::getBlock(), mlir::Region::getBlocks(), mlir::Operation::getParentRegion(), and mlir::Block::getTerminator().
Referenced by AllocaScopeInliner::matchAndRewrite(), and AllocaScopeHoister::matchAndRewrite().
|
static |
Definition at line 1509 of file MemRefOps.cpp.
References mlir::AsmParser::emitError(), mlir::get(), mlir::AsmParser::getContext(), mlir::AsmParser::getNameLoc(), mlir::memref::getTensorTypeFromMemRefType(), mlir::AsmParser::parseAttribute(), mlir::AsmParser::parseOptionalEqual(), mlir::AsmParser::parseOptionalKeyword(), and mlir::AsmParser::parseType().
|
static |
Definition at line 1495 of file MemRefOps.cpp.
References mlir::AsmPrinter::printAttributeWithoutType().
|
static |
Definition at line 2907 of file MemRefOps.cpp.
References mlir::ElemTypeMismatch, mlir::Operation::emitError(), mlir::LayoutMismatch, mlir::MemSpaceMismatch, mlir::RankTooLarge, mlir::SizeMismatch, and mlir::Success.
|
static |
Helper function to perform the replacement of all constant uses of values
by a materialized constant extracted from maybeConstants
.
values
and maybeConstants
are expected to have the same size.
Definition at line 1333 of file MemRefOps.cpp.
References mlir::OpBuilder::create(), mlir::getAsOpFoldResult(), and mlir::Operation::replaceUsesOfWith().
|
static |
Definition at line 130 of file MemRefOps.cpp.
|
static |
Helper function for verifying the shape of ExpandShapeOp and ResultShapeOp result and operand.
Layout maps are verified separately.
If allowMultipleDynamicDimsPerGroup
, multiple dynamic dimensions are allowed in a reassocation group.
Definition at line 2093 of file MemRefOps.cpp.
References mlir::Operation::emitOpError(), and mlir::detail::enumerate().