MLIR  17.0.0git
Namespaces | Classes | Typedefs | Enumerations | Functions
mlir::vector Namespace Reference

Namespaces

 detail
 

Classes

struct  LowerVectorsOptions
 Helper structure used to hold the different options of LowerVectorsOp. More...
 
struct  WarpExecuteOnLane0LoweringOptions
 
struct  UnrollVectorOptions
 Options that control the vector unrolling. More...
 
struct  VectorTransformsOptions
 Structure to control the behavior of vector transform patterns. More...
 

Typedefs

using DistributionMapFn = std::function< AffineMap(Value)>
 

Enumerations

enum class  BroadcastableToResult { Success = 0 , SourceRankHigher = 1 , DimensionMismatch = 2 , SourceTypeNotAVector = 3 }
 Return whether srcType can be broadcast to dstVectorType under the semantics of the vector.broadcast op. More...
 

Functions

void buildTerminatedBody (OpBuilder &builder, Location loc)
 Default callback to build a region with a 'vector.yield' terminator with no arguments. More...
 
BroadcastableToResult isBroadcastableTo (Type srcType, VectorType dstVectorType, std::pair< int, int > *mismatchingDims=nullptr)
 
void populateVectorToVectorCanonicalizationPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect a set of vector-to-vector canonicalization patterns. More...
 
void populateShapeCastFoldingPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect a set of vector.shape_cast folding patterns. More...
 
void populateCastAwayVectorLeadingOneDimPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect a set of leading one dimension removal patterns. More...
 
void populateVectorTransferDropUnitDimsPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect a set of one dimension removal patterns. More...
 
void populateFlattenVectorTransferPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect a set of patterns to flatten n-D vector transfers on contiguous memref. More...
 
void populateBubbleVectorBitCastOpPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect a set of patterns that bubble up/down bitcast ops. More...
 
void populateVectorMaskMaterializationPatterns (RewritePatternSet &patterns, bool force32BitVectorIndices, PatternBenefit benefit=1)
 These patterns materialize masks for various vector ops such as transfers. More...
 
IntegerType getVectorSubscriptType (Builder &builder)
 Returns the integer type required for subscripts in the vector dialect. More...
 
ArrayAttr getVectorSubscriptAttr (Builder &b, ArrayRef< int64_t > values)
 Returns an integer array attribute containing the given values using the integer type required for subscripts in the vector dialect. More...
 
Value getVectorReductionOp (arith::AtomicRMWKind op, OpBuilder &builder, Location loc, Value vector)
 Returns the value obtained by reducing the vector into a scalar using the operation kind associated with a binary AtomicRMWKind op. More...
 
bool isLastMemrefDimUnitStride (MemRefType type)
 Return true if the last dimension of the MemRefType has unit stride. More...
 
AffineMap getTransferMinorIdentityMap (ShapedType shapedType, VectorType vectorType)
 Build the default minor identity map suitable for a vector transfer. More...
 
bool checkSameValueRAW (TransferWriteOp defWrite, TransferReadOp read)
 Return true if the transfer_write fully writes the data accessed by the transfer_read. More...
 
bool checkSameValueWAW (TransferWriteOp write, TransferWriteOp priorWrite)
 Return true if the write op fully over-write the priorWrite transfer_write op. More...
 
bool isDisjointTransferIndices (VectorTransferOpInterface transferA, VectorTransferOpInterface transferB)
 Same behavior as isDisjointTransferSet but doesn't require the operations to have the same tensor/memref. More...
 
bool isDisjointTransferSet (VectorTransferOpInterface transferA, VectorTransferOpInterface transferB)
 Return true if we can prove that the transfer operations access disjoint memory. More...
 
Value makeArithReduction (OpBuilder &b, Location loc, CombiningKind kind, Value v1, Value acc, Value mask=Value())
 Return the result value of reducing two scalar/vector values with the corresponding arith operation. More...
 
bool isParallelIterator (Attribute attr)
 Returns true if attr has "parallel" iterator type semantics. More...
 
bool isReductionIterator (Attribute attr)
 Returns true if attr has "reduction" iterator type semantics. More...
 
void createMaskOpRegion (OpBuilder &builder, Operation *maskableOp)
 Create the vector.yield-ended region of a vector.mask op with maskableOp as masked operation. More...
 
OperationmaskOperation (OpBuilder &builder, Operation *maskableOp, Value mask, Value passthru=Value())
 Creates a vector.mask operation around a maskable operation. More...
 
Value selectPassthru (OpBuilder &builder, Value mask, Value newValue, Value passthru)
 Creates a vector select operation that picks values from newValue or passthru for each result vector lane based on mask. More...
 
void registerTransformDialectExtension (DialectRegistry &registry)
 
void registerBufferizableOpInterfaceExternalModels (DialectRegistry &registry)
 
void populateVectorContractLoweringPatterns (RewritePatternSet &patterns, VectorTransformsOptions options, PatternBenefit benefit=1, bool disableOuterProductLowering=false)
 Populate the pattern set with the following patterns: More...
 
void populateVectorOuterProductLoweringPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Populate the pattern set with the following patterns: More...
 
void populateVectorMultiReductionLoweringPatterns (RewritePatternSet &patterns, VectorMultiReductionLowering options, PatternBenefit benefit=1)
 Collect a set of patterns to convert vector.multi_reduction op into a sequence of vector.reduction ops. More...
 
void populateVectorBroadcastLoweringPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Populate the pattern set with the following patterns: More...
 
void populateVectorMaskOpLoweringPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Populate the pattern set with the following patterns: More...
 
void populateScalarVectorTransferLoweringPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collects patterns that lower scalar vector transfer ops to memref loads and stores when beneficial. More...
 
void populateVectorShapeCastLoweringPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Populate the pattern set with the following patterns: More...
 
void populateVectorTransposeLoweringPatterns (RewritePatternSet &patterns, VectorTransformsOptions options, PatternBenefit benefit=1)
 Populate the pattern set with the following patterns: More...
 
void populateVectorTransferLoweringPatterns (RewritePatternSet &patterns, std::optional< unsigned > maxTransferRank=std::nullopt, PatternBenefit benefit=1)
 Populate the pattern set with the following patterns: More...
 
void populateVectorTransferPermutationMapLoweringPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect a set of transfer read/write lowering patterns that simplify the permutation map (e.g., converting it to a minor identity map) by inserting broadcasts and transposes. More...
 
void populateVectorScanLoweringPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Populate the pattern set with the following patterns: More...
 
void populateVectorGatherLoweringPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Populate the pattern set with the following patterns: More...
 
void populateVectorMaskLoweringPatternsForSideEffectingOps (RewritePatternSet &patterns)
 Populates instances of MaskOpRewritePattern to lower masked operations with vector.mask. More...
 
std::unique_ptr< PasscreateVectorBufferizePass ()
 Creates an instance of the vector dialect bufferization pass. More...
 
std::unique_ptr< PasscreateLowerVectorMaskPass ()
 Creates an instance of the vector.mask lowering pass. More...
 
void populateWarpExecuteOnLane0OpToScfForPattern (RewritePatternSet &patterns, const WarpExecuteOnLane0LoweringOptions &options, PatternBenefit benefit=1)
 
void populateVectorContractCanonicalizeMatmulToMMT (RewritePatternSet &patterns, std::function< LogicalResult(vector::ContractionOp)> constraint=[](vector::ContractionOp) { return success();}, PatternBenefit=1)
 Canonicalization of a vector.contraction a, b, c with row-major matmul semantics to a contraction with MMT semantics (matrix matrix multiplication with the RHS transposed). More...
 
void populateVectorReductionToContractPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect patterns to convert reduction op to vector.contract and fold transpose/broadcast ops into the contract. More...
 
void populateVectorTransferFullPartialPatterns (RewritePatternSet &patterns, const VectorTransformsOptions &options)
 Populate patterns with the following patterns. More...
 
void populateVectorTransferCollapseInnerMostContiguousDimsPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Collect a set of patterns to reduce the rank of the operands of vector transfer ops to operate on the largest contigious vector. More...
 
void populateVectorInsertExtractStridedSliceDecompositionPatterns (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Populate patterns with the following patterns. More...
 
void populateVectorExtractStridedSliceToExtractInsertChainPatterns (RewritePatternSet &patterns, std::function< bool(ExtractStridedSliceOp)> controlFn=nullptr, PatternBenefit benefit=1)
 Populate patterns with a pattern to breaks down 1-D extract_strided_slice ops into a chain of Extract ops to extract each element from the source, and then a chain of Insert ops to insert to the target vector. More...
 
void populateVectorInsertExtractStridedSliceTransforms (RewritePatternSet &patterns, PatternBenefit benefit=1)
 Populate patterns with the following patterns. More...
 
void populateVectorUnrollPatterns (RewritePatternSet &patterns, const UnrollVectorOptions &options, PatternBenefit benefit=1)
 Collect a set of pattern to unroll vector operations to a smaller shapes. More...
 
LogicalResult splitFullAndPartialTransfer (RewriterBase &b, VectorTransferOpInterface xferOp, VectorTransformsOptions options=VectorTransformsOptions(), scf::IfOp *ifOp=nullptr)
 Split a vector.transfer operation into an in-bounds (i.e., no out-of-bounds masking) fastpath and a slowpath. More...
 
void transferOpflowOpt (RewriterBase &rewriter, Operation *rootOp)
 Implements transfer op write to read forwarding and dead transfer write optimizations. More...
 
Value createOrFoldDimOp (OpBuilder &b, Location loc, Value source, int64_t dim)
 Helper function that creates a memref::DimOp or tensor::DimOp depending on the type of source. More...
 

Typedef Documentation

◆ DistributionMapFn

using mlir::vector::DistributionMapFn = typedef std::function<AffineMap(Value)>

Definition at line 43 of file VectorDistribution.h.

Enumeration Type Documentation

◆ BroadcastableToResult

Return whether srcType can be broadcast to dstVectorType under the semantics of the vector.broadcast op.

Enumerator
Success 
SourceRankHigher 
DimensionMismatch 
SourceTypeNotAVector 

Definition at line 61 of file VectorOps.h.

Function Documentation

◆ buildTerminatedBody()

void mlir::vector::buildTerminatedBody ( OpBuilder builder,
Location  loc 
)

Default callback to build a region with a 'vector.yield' terminator with no arguments.

Definition at line 107 of file VectorOps.cpp.

References mlir::OpBuilder::create().

◆ checkSameValueRAW()

bool mlir::vector::checkSameValueRAW ( TransferWriteOp  defWrite,
TransferReadOp  read 
)

Return true if the transfer_write fully writes the data accessed by the transfer_read.

◆ checkSameValueWAW()

bool mlir::vector::checkSameValueWAW ( TransferWriteOp  write,
TransferWriteOp  priorWrite 
)

Return true if the write op fully over-write the priorWrite transfer_write op.

◆ createLowerVectorMaskPass()

std::unique_ptr< Pass > mlir::vector::createLowerVectorMaskPass ( )

Creates an instance of the vector.mask lowering pass.

Definition at line 309 of file LowerVectorMask.cpp.

◆ createMaskOpRegion()

void mlir::vector::createMaskOpRegion ( OpBuilder builder,
Operation maskableOp 
)

Create the vector.yield-ended region of a vector.mask op with maskableOp as masked operation.

◆ createOrFoldDimOp()

Value mlir::vector::createOrFoldDimOp ( OpBuilder b,
Location  loc,
Value  source,
int64_t  dim 
)

Helper function that creates a memref::DimOp or tensor::DimOp depending on the type of source.

Definition at line 37 of file VectorUtils.cpp.

References mlir::OpBuilder::createOrFold(), mlir::Value::getType(), and mlir::Type::isa().

Referenced by createInBoundsCond(), and createSubViewIntersection().

◆ createVectorBufferizePass()

std::unique_ptr< Pass > mlir::vector::createVectorBufferizePass ( )

Creates an instance of the vector dialect bufferization pass.

Definition at line 53 of file Bufferize.cpp.

◆ getTransferMinorIdentityMap()

AffineMap mlir::vector::getTransferMinorIdentityMap ( ShapedType  shapedType,
VectorType  vectorType 
)

Build the default minor identity map suitable for a vector transfer.

This also handles the case memref<... x vector<...>> -> vector<...> in which the rank of the identity map must take the vector element type into account.

Definition at line 142 of file VectorOps.cpp.

References mlir::AffineMap::get(), mlir::getAffineConstantExpr(), and mlir::AffineMap::getMinorIdentityMap().

◆ getVectorReductionOp()

Value mlir::vector::getVectorReductionOp ( arith::AtomicRMWKind  op,
OpBuilder builder,
Location  loc,
Value  vector 
)

Returns the value obtained by reducing the vector into a scalar using the operation kind associated with a binary AtomicRMWKind op.

Definition at line 489 of file VectorOps.cpp.

References mlir::OpBuilder::create(), mlir::emitOptionalError(), and mlir::Value::getLoc().

Referenced by vectorizeAffineForOp().

◆ getVectorSubscriptAttr()

ArrayAttr mlir::vector::getVectorSubscriptAttr ( Builder b,
ArrayRef< int64_t >  values 
)

Returns an integer array attribute containing the given values using the integer type required for subscripts in the vector dialect.

Definition at line 290 of file VectorOps.cpp.

References mlir::Builder::getI64ArrayAttr().

◆ getVectorSubscriptType()

IntegerType mlir::vector::getVectorSubscriptType ( Builder builder)

Returns the integer type required for subscripts in the vector dialect.

Definition at line 286 of file VectorOps.cpp.

References mlir::Builder::getIntegerType().

◆ isBroadcastableTo()

BroadcastableToResult mlir::vector::isBroadcastableTo ( Type  srcType,
VectorType  dstVectorType,
std::pair< int, int > *  mismatchingDims = nullptr 
)

◆ isDisjointTransferIndices()

bool mlir::vector::isDisjointTransferIndices ( VectorTransferOpInterface  transferA,
VectorTransferOpInterface  transferB 
)

Same behavior as isDisjointTransferSet but doesn't require the operations to have the same tensor/memref.

This allows comparing operations accessing different tensors.

Definition at line 177 of file VectorOps.cpp.

References mlir::presburger::abs().

Referenced by findHoistableMatchingTransferRead(), isDisjointTransferSet(), and isTensorChunkAccessedByUnknownOp().

◆ isDisjointTransferSet()

bool mlir::vector::isDisjointTransferSet ( VectorTransferOpInterface  transferA,
VectorTransferOpInterface  transferB 
)

Return true if we can prove that the transfer operations access disjoint memory.

Definition at line 209 of file VectorOps.cpp.

References isDisjointTransferIndices().

Referenced by mlir::linalg::hoistRedundantVectorTransfers().

◆ isLastMemrefDimUnitStride()

bool mlir::vector::isLastMemrefDimUnitStride ( MemRefType  type)

Return true if the last dimension of the MemRefType has unit stride.

Also return true for memrefs with no strides.

Definition at line 135 of file VectorOps.cpp.

References mlir::getStridesAndOffset(), and mlir::succeeded().

◆ isParallelIterator()

bool mlir::vector::isParallelIterator ( Attribute  attr)
inline

Returns true if attr has "parallel" iterator type semantics.

Definition at line 165 of file VectorOps.h.

References mlir::Attribute::cast().

Referenced by contractSupportsMMAMatrixType().

◆ isReductionIterator()

bool mlir::vector::isReductionIterator ( Attribute  attr)
inline

Returns true if attr has "reduction" iterator type semantics.

Definition at line 170 of file VectorOps.h.

References mlir::Attribute::cast().

Referenced by contractSupportsMMAMatrixType(), and getReductionIndex().

◆ makeArithReduction()

Value mlir::vector::makeArithReduction ( OpBuilder b,
Location  loc,
CombiningKind  kind,
Value  v1,
Value  acc,
Value  mask = Value() 
)

Return the result value of reducing two scalar/vector values with the corresponding arith operation.

Referenced by createContractArithOp().

◆ maskOperation()

Operation* mlir::vector::maskOperation ( OpBuilder builder,
Operation maskableOp,
Value  mask,
Value  passthru = Value() 
)

Creates a vector.mask operation around a maskable operation.

Returns the vector.mask operation if the mask provided is valid. Otherwise, returns the maskable operation itself.

Referenced by VectorizationState::maskOperation().

◆ populateBubbleVectorBitCastOpPatterns()

void mlir::vector::populateBubbleVectorBitCastOpPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collect a set of patterns that bubble up/down bitcast ops.

These patterns move vector.bitcast ops to be before insert ops or after extract ops where suitable. With them, bitcast will happen on smaller vectors and there are more chances to share extract/insert ops.

Definition at line 1140 of file VectorTransforms.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateCastAwayVectorLeadingOneDimPatterns()

void mlir::vector::populateCastAwayVectorLeadingOneDimPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collect a set of leading one dimension removal patterns.

These patterns insert vector.shape_cast to remove leading one dimensions to expose more canonical forms of read/write/insert/extract operations. With them, there are more chances that we can cancel out extract-insert pairs or forward write-read pairs.

Definition at line 440 of file VectorDropLeadUnitDim.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and populateShapeCastFoldingPatterns().

◆ populateFlattenVectorTransferPatterns()

void mlir::vector::populateFlattenVectorTransferPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collect a set of patterns to flatten n-D vector transfers on contiguous memref.

These patterns insert memref.collapse_shape + vector.shape_cast patterns to transform multiple small n-D transfers into a larger 1-D transfer where the memref contiguity properties allow it.

Definition at line 761 of file VectorTransferOpTransforms.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and populateShapeCastFoldingPatterns().

◆ populateScalarVectorTransferLoweringPatterns()

void mlir::vector::populateScalarVectorTransferLoweringPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collects patterns that lower scalar vector transfer ops to memref loads and stores when beneficial.

Definition at line 746 of file VectorTransferOpTransforms.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateShapeCastFoldingPatterns()

void mlir::vector::populateShapeCastFoldingPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

◆ populateVectorBroadcastLoweringPatterns()

void mlir::vector::populateVectorBroadcastLoweringPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Populate the pattern set with the following patterns:

[TransferReadToVectorLoadLowering] Progressive lowering of BroadcastOp to ExtractOp + InsertOp + lower-D BroadcastOp until dim 1.

Definition at line 153 of file LowerVectorBroadcast.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorContractCanonicalizeMatmulToMMT()

void mlir::vector::populateVectorContractCanonicalizeMatmulToMMT ( RewritePatternSet patterns,
std::function< LogicalResult(vector::ContractionOp)>  constraint = [](vector::ContractionOp) { return success(); },
PatternBenefit  benefit = 1 
)

Canonicalization of a vector.contraction a, b, c with row-major matmul semantics to a contraction with MMT semantics (matrix matrix multiplication with the RHS transposed).

This specific form is meant to have the vector operands are organized such that the reduction dimension is contiguous. Example:

vector.contract {indexing_maps = [affine_map<(m, n, k) -> (m, k)>,
affine_map<(m, n, k) -> (n, k)>,
affine_map<(m, n, k) -> (m, n)>],
iterator_types = ["parallel", "parallel", "reduction"],
kind = #vector.kind<add>} %a, %b, %c : ...

The constraint predicate is used to decide which vector.contraction ops to filter out.

Definition at line 1148 of file VectorTransforms.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

Referenced by mlir::populatePrepareVectorToMMAPatterns().

◆ populateVectorContractLoweringPatterns()

void mlir::vector::populateVectorContractLoweringPatterns ( RewritePatternSet patterns,
VectorTransformsOptions  options,
PatternBenefit  benefit = 1,
bool  disableOuterProductLowering = false 
)

Populate the pattern set with the following patterns:

[OuterProductOpLowering] Progressively lower a vector.outerproduct to linearized vector.extract + vector.fma + vector.insert.

[ContractionOpLowering] Progressive lowering of ContractionOp. One: x = vector.contract with at least one free/batch dimension is replaced by: a = vector.contract with one less free/batch dimension b = vector.contract with one less free/batch dimension

[ContractionOpToMatmulOpLowering] Progressively lower a vector.contract with row-major matmul semantics to linearized vector.shape_cast + vector.matmul on the way to llvm.matrix.multiply.

[ContractionOpToDotLowering] Progressively lower a vector.contract with row-major matmul semantics to linearized vector.extract + vector.reduce + vector.insert.

[ContractionOpToOuterProductOpLowering] Progressively lower a vector.contract with row-major matmul semantics to linearized vector.extract + vector.outerproduct + vector.insert.

Definition at line 1302 of file LowerVectorContract.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and options.

◆ populateVectorExtractStridedSliceToExtractInsertChainPatterns()

void mlir::vector::populateVectorExtractStridedSliceToExtractInsertChainPatterns ( RewritePatternSet patterns,
std::function< bool(ExtractStridedSliceOp)>  controlFn = nullptr,
PatternBenefit  benefit = 1 
)

Populate patterns with a pattern to breaks down 1-D extract_strided_slice ops into a chain of Extract ops to extract each element from the source, and then a chain of Insert ops to insert to the target vector.

If controlFn is not nullptr, the pattern will only be invoked on ops that controlFn returns true. Otherwise runs on ops.

Definition at line 342 of file VectorInsertExtractStridedSliceRewritePatterns.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorGatherLoweringPatterns()

void mlir::vector::populateVectorGatherLoweringPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Populate the pattern set with the following patterns:

[FlattenGather] Flattens 2 or more dimensional vector.gather ops by unrolling the outermost dimension.

[Gather1DToConditionalLoads] Turns 1-d vector.gather into a scalarized sequence of vector.loads or tensor.extracts. To avoid out-of-bounds memory accesses, these loads/extracts are made conditional using scf.if ops.

Definition at line 169 of file LowerVectorGather.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorInsertExtractStridedSliceDecompositionPatterns()

void mlir::vector::populateVectorInsertExtractStridedSliceDecompositionPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Populate patterns with the following patterns.

[DecomposeDifferentRankInsertStridedSlice]

RewritePattern for InsertStridedSliceOp where source and destination vectors have different ranks.

When ranks are different, InsertStridedSlice needs to extract a properly ranked vector from the destination vector into which to insert. This pattern only takes care of this extraction part and forwards the rest to [VectorInsertStridedSliceOpSameRankRewritePattern].

For a k-D source and n-D destination vector (k < n), we emit:

  1. ExtractOp to extract the (unique) (n-1)-D subvector into which to insert the k-D source.
  2. k-D -> (n-1)-D InsertStridedSlice op
  3. InsertOp that is the reverse of 1.

[DecomposeNDExtractStridedSlice]

For such cases, we can rewrite it to ExtractOp/ExtractElementOp + lower rank ExtractStridedSliceOp + InsertOp/InsertElementOp for the n-D case.

Definition at line 336 of file VectorInsertExtractStridedSliceRewritePatterns.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

Referenced by populateVectorInsertExtractStridedSliceTransforms().

◆ populateVectorInsertExtractStridedSliceTransforms()

void mlir::vector::populateVectorInsertExtractStridedSliceTransforms ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Populate patterns with the following patterns.

Populate the given list with patterns that convert from Vector to LLVM.

Patterns in populateVectorInsertExtractStridedSliceDecompositionPatterns();

[ConvertSameRankInsertStridedSliceIntoShuffle]

RewritePattern for InsertStridedSliceOp where source and destination vectors have the same rank. For each outermost index in the slice: begin end stride [offset : offset+size*stride : stride]

  1. ExtractOp one (k-1)-D source subvector and one (n-1)-D dest subvector.
  2. InsertStridedSlice (k-1)-D into (n-1)-D
  3. the destination subvector is inserted back in the proper place
  1. InsertOp that is the reverse of 1.

[Convert1DExtractStridedSliceIntoShuffle]

For such cases, we can lower it to a ShuffleOp.

Definition at line 351 of file VectorInsertExtractStridedSliceRewritePatterns.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and populateVectorInsertExtractStridedSliceDecompositionPatterns().

Referenced by mlir::populateVectorToLLVMConversionPatterns().

◆ populateVectorMaskLoweringPatternsForSideEffectingOps()

void mlir::vector::populateVectorMaskLoweringPatternsForSideEffectingOps ( RewritePatternSet patterns)

Populates instances of MaskOpRewritePattern to lower masked operations with vector.mask.

Patterns should rewrite the vector.mask operation and not its nested MaskableOpInterface.

Definition at line 303 of file LowerVectorMask.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorMaskMaterializationPatterns()

void mlir::vector::populateVectorMaskMaterializationPatterns ( RewritePatternSet patterns,
bool  force32BitVectorIndices,
PatternBenefit  benefit = 1 
)

These patterns materialize masks for various vector ops such as transfers.

Definition at line 1126 of file VectorTransforms.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorMaskOpLoweringPatterns()

void mlir::vector::populateVectorMaskOpLoweringPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Populate the pattern set with the following patterns:

[CreateMaskOp] Progressive lowering of CreateMaskOp to lower-D CreateMaskOp until dim 1.

[ConstantMaskOp] Progressive lowering of ConstantMaskOp to lower-D ConstantMaskOp until dim 1.

Definition at line 165 of file LowerVectorMask.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorMultiReductionLoweringPatterns()

void mlir::vector::populateVectorMultiReductionLoweringPatterns ( RewritePatternSet patterns,
VectorMultiReductionLowering  options,
PatternBenefit  benefit = 1 
)

Collect a set of patterns to convert vector.multi_reduction op into a sequence of vector.reduction ops.

The patterns comprise:

[InnerOuterDimReductionConversion] Rewrites vector.multi_reduction such that all reduction dimensions are either innermost or outermost, by adding the proper vector.transpose operations.

[ReduceMultiDimReductionRank] Once in innermost or outermost reduction form, rewrites n-D vector.multi_reduction into 2-D vector.multi_reduction, by introducing vector.shape_cast ops to collapse + multi-reduce + expand back.

[TwoDimMultiReductionToElementWise] Once in 2-D vector.multi_reduction form, with an outermost reduction dimension, unroll the outer dimension to obtain a sequence of 1-D vector ops. This also has an opportunity for tree-reduction (in the future).

[TwoDimMultiReductionToReduction] Once in 2-D vector.multi_reduction form, with an innermost reduction dimension, unroll the outer dimension to obtain a sequence of extract + vector.reduction + insert. This can further lower to horizontal reduction ops.

[OneDimMultiReductionToTwoDim] For cases that reduce to 1-D vector<k> reduction (and are thus missing either a parallel or a reduction), we lift them back up to 2-D with a simple vector.shape_cast to vector<1xk> so that the other patterns can kick in, thus fully exiting out of the vector.multi_reduction abstraction.

Definition at line 448 of file LowerVectorMultiReduction.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and options.

◆ populateVectorOuterProductLoweringPatterns()

void mlir::vector::populateVectorOuterProductLoweringPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Populate the pattern set with the following patterns:

[OuterProductOpLowering] Progressively lower a vector.outerproduct to linearized vector.extract + vector.fma + vector.insert.

Definition at line 1312 of file LowerVectorContract.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorReductionToContractPatterns()

void mlir::vector::populateVectorReductionToContractPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collect patterns to convert reduction op to vector.contract and fold transpose/broadcast ops into the contract.

Definition at line 1156 of file VectorTransforms.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorScanLoweringPatterns()

void mlir::vector::populateVectorScanLoweringPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Populate the pattern set with the following patterns:

[ScanToArithOps] Convert vector.scan op into arith ops and vector.insert_strided_slice / vector.extract_strided_slice.

Definition at line 248 of file LowerVectorScan.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorShapeCastLoweringPatterns()

void mlir::vector::populateVectorShapeCastLoweringPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Populate the pattern set with the following patterns:

[ShapeCastOp2DDownCastRewritePattern] ShapeOp 2D -> 1D downcast serves the purpose of flattening 2-D to 1-D vectors progressively.

[ShapeCastOp2DUpCastRewritePattern] ShapeOp 1D -> 2D upcast serves the purpose of unflattening 2-D from 1-D vectors progressively.

[ShapeCastOpRewritePattern] Reference lowering to fully unrolled sequences of single element ExtractOp + InsertOp. Note that applying this pattern can almost always be considered a performance bug.

Definition at line 172 of file LowerVectorShapeCast.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorToVectorCanonicalizationPatterns()

void mlir::vector::populateVectorToVectorCanonicalizationPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collect a set of vector-to-vector canonicalization patterns.

◆ populateVectorTransferCollapseInnerMostContiguousDimsPatterns()

void mlir::vector::populateVectorTransferCollapseInnerMostContiguousDimsPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collect a set of patterns to reduce the rank of the operands of vector transfer ops to operate on the largest contigious vector.

These patterns are useful when lowering to dialects with 1d vector type such as llvm and it will result fewer memory reads.

Definition at line 1164 of file VectorTransforms.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorTransferDropUnitDimsPatterns()

void mlir::vector::populateVectorTransferDropUnitDimsPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collect a set of one dimension removal patterns.

These patterns insert rank-reducing memref.subview ops to remove one dimensions. With them, there are more chances that we can avoid potentially exensive vector.shape_cast operations.

Definition at line 753 of file VectorTransferOpTransforms.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and populateShapeCastFoldingPatterns().

◆ populateVectorTransferFullPartialPatterns()

void mlir::vector::populateVectorTransferFullPartialPatterns ( RewritePatternSet patterns,
const VectorTransformsOptions options 
)

Populate patterns with the following patterns.

  • VectorTransferFullPartialRewriter

Split a vector.transfer operation into an in-bounds (i.e., no out-of-bounds masking) fast path and a slow path.

Example (a 2-D vector.transfer_read): ``` %1 = vector.transfer_read %0[...], pad : memref<A...>, vector<...> ``` is transformed into: ``` %1:3 = scf.if (inBounds) { // fast path, direct cast memref.cast A: memref<A...> to compatibleMemRefType scf.yield view : compatibleMemRefType, index, index } else { // slow path, not in-bounds vector.transfer or linalg.copy. memref.cast alloc: memref<B...> to compatibleMemRefType scf.yield %4 : compatibleMemRefType, index, index */ // } /** %0 = vector.transfer_read %1#0[%1#1, %1#2] {in_bounds = [true ... true]} `` wherealloc` is a top of the function alloca'ed buffer of one vector.

Preconditions:

  1. xferOp.permutation_map() must be a minor identity map
  2. the rank of the xferOp.memref() and the rank of the xferOp.vector() must be equal. This will be relaxed in the future but requires rank-reducing subviews.

Definition at line 671 of file VectorTransferSplitRewritePatterns.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and options.

◆ populateVectorTransferLoweringPatterns()

void mlir::vector::populateVectorTransferLoweringPatterns ( RewritePatternSet patterns,
std::optional< unsigned >  maxTransferRank = std::nullopt,
PatternBenefit  benefit = 1 
)

Populate the pattern set with the following patterns:

[TransferReadToVectorLoadLowering] Progressive lowering of transfer_read.This pattern supports lowering of vector.transfer_read to a combination of vector.load and vector.broadcast

[TransferWriteToVectorStoreLowering] Progressive lowering of transfer_write. This pattern supports lowering of vector.transfer_write to vector.store

[VectorLoadToMemrefLoadLowering] Replace a 0-d vector.load with a memref.load + vector.broadcast.

[VectorStoreToMemrefStoreLowering] Replace a 0-d vector.store with a vector.extractelement + memref.store.

These patterns lower transfer ops to simpler ops like vector.load, vector.store and vector.broadcast. Only transfers with a transfer rank of a most maxTransferRank are lowered. This is useful when combined with VectorToSCF, which reduces the rank of vector transfer ops.

Definition at line 593 of file LowerVectorTransfer.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

Referenced by mlir::populateVectorToLLVMConversionPatterns().

◆ populateVectorTransferPermutationMapLoweringPatterns()

void mlir::vector::populateVectorTransferPermutationMapLoweringPatterns ( RewritePatternSet patterns,
PatternBenefit  benefit = 1 
)

Collect a set of transfer read/write lowering patterns that simplify the permutation map (e.g., converting it to a minor identity map) by inserting broadcasts and transposes.

More specifically:

[TransferReadPermutationLowering] Lower transfer_read op with permutation into a transfer_read with a permutation map composed of leading zeros followed by a minor identity + vector.transpose op. Ex: vector.transfer_read ... permutation_map: (d0, d1, d2) -> (0, d1) into: v = vector.transfer_read ... permutation_map: (d0, d1, d2) -> (d1, 0) vector.transpose v, [1, 0]

vector.transfer_read ... permutation_map: (d0, d1, d2, d3) -> (0, 0, 0, d1, d3) into: v = vector.transfer_read ... permutation_map: (d0, d1, d2, d3) -> (0, 0, d1, 0, d3) vector.transpose v, [0, 1, 3, 2, 4] Note that an alternative is to transform it to linalg.transpose + vector.transfer_read to do the transpose in memory instead.

[TransferWritePermutationLowering] Lower transfer_write op with permutation into a transfer_write with a minor identity permutation map. (transfer_write ops cannot have broadcasts.) Ex: vector.transfer_write v ... permutation_map: (d0, d1, d2) -> (d2, d0, d1) into: tmp = vector.transpose v, [2, 0, 1] vector.transfer_write tmp ... permutation_map: (d0, d1, d2) -> (d0, d1, d2)

vector.transfer_write v ... permutation_map: (d0, d1, d2, d3) -> (d3, d2) into: tmp = vector.transpose v, [1, 0] v = vector.transfer_write tmp ... permutation_map: (d0, d1, d2, d3) -> (d2, d3)

[TransferOpReduceRank] Lower transfer_read op with broadcast in the leading dimensions into transfer_read of lower rank + vector.broadcast. Ex: vector.transfer_read ... permutation_map: (d0, d1, d2, d3) -> (0, d1, 0, d3) into: v = vector.transfer_read ... permutation_map: (d0, d1, d2, d3) -> (d1, 0, d3) vector.broadcast v

Definition at line 356 of file LowerVectorTransfer.cpp.

References mlir::RewritePatternSet::add(), and mlir::RewritePatternSet::getContext().

◆ populateVectorTransposeLoweringPatterns()

void mlir::vector::populateVectorTransposeLoweringPatterns ( RewritePatternSet patterns,
VectorTransformsOptions  options,
PatternBenefit  benefit = 1 
)

Populate the pattern set with the following patterns:

[TransposeOpLowering]

[TransposeOp2DToShuffleLowering]

Definition at line 205 of file LowerVectorTranspose.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and options.

◆ populateVectorUnrollPatterns()

void mlir::vector::populateVectorUnrollPatterns ( RewritePatternSet patterns,
const UnrollVectorOptions options,
PatternBenefit  benefit = 1 
)

Collect a set of pattern to unroll vector operations to a smaller shapes.

options structure controls which operations are unrolled and the target shape. op is unrolled to the targetShape as follows, for each of its operands:

  1. the unrolled type unrolledVectorType and number of unrolled instances numUnrolledInstances are computed from the targetShape. For now it is assumed the unrolling factors divide the vector sizes.
  2. ExtractStridedSlice are created to break-up the vector operands.
  3. the original op is cloned numUnrolledInstances times, once for each result.
  4. InsertStridedSlice are inserted to re-assemble the slices into the original vectore shape.

Example:

opA(operand0, operand1) // numUnrolledInstances = 3

    operand0                   operand1
       |                          |
     fork                       fork
<----------gather all fork ops --------->
      /|\                        /|\
  f00 f01 f02                f10 f11 f12
<---------- clone op 3 times --------->
  opA0(f00, f10), opA1(f01, f11), opA2(f02, f12)
         \            |            /

<-----------------— join ----------------------—>

Other local patterns then kick in iteratively (including DCE) and compose to combine the ExtractStridedSlice/InsertStridedSlice.

Definition at line 645 of file VectorUnroll.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and options.

◆ populateWarpExecuteOnLane0OpToScfForPattern()

void mlir::vector::populateWarpExecuteOnLane0OpToScfForPattern ( RewritePatternSet patterns,
const WarpExecuteOnLane0LoweringOptions options,
PatternBenefit  benefit = 1 
)

◆ registerBufferizableOpInterfaceExternalModels()

void mlir::vector::registerBufferizableOpInterfaceExternalModels ( DialectRegistry registry)

◆ registerTransformDialectExtension()

void mlir::vector::registerTransformDialectExtension ( DialectRegistry registry)

Definition at line 181 of file VectorTransformOps.cpp.

References mlir::DialectRegistry::addExtensions().

Referenced by mlir::registerAllDialects().

◆ selectPassthru()

Value mlir::vector::selectPassthru ( OpBuilder builder,
Value  mask,
Value  newValue,
Value  passthru 
)

Creates a vector select operation that picks values from newValue or passthru for each result vector lane based on mask.

This utility is used to propagate the pass-thru value for masked-out or expeculatively executed lanes. VP intrinsics do not support pass-thru values and every mask-out lane is set to poison. LLVM backends are usually able to match op + select patterns and fold them into a native target instructions.

Referenced by createContractArithOp().

◆ splitFullAndPartialTransfer()

LogicalResult mlir::vector::splitFullAndPartialTransfer ( RewriterBase b,
VectorTransferOpInterface  xferOp,
VectorTransformsOptions  options = VectorTransformsOptions(),
scf::IfOp *  ifOp = nullptr 
)

Split a vector.transfer operation into an in-bounds (i.e., no out-of-bounds masking) fastpath and a slowpath.

If ifOp is not null and the result is success, theifOp` points to the newly created conditional upon function return. To accomodate for the fact that the original vector.transfer indexing may be arbitrary and the slow path indexes @[0...0] in the temporary buffer, the scf.if op returns a view and values of type index. At this time, only vector.transfer_read case is implemented.

Example (a 2-D vector.transfer_read): ``` %1 = vector.transfer_read %0[...], pad : memref<A...>, vector<...> ``` is transformed into: ``` %1:3 = scf.if (inBounds) { // fastpath, direct cast memref.cast A: memref<A...> to compatibleMemRefType scf.yield view : compatibleMemRefType, index, index } else { // slowpath, not in-bounds vector.transfer or linalg.copy. memref.cast alloc: memref<B...> to compatibleMemRefType scf.yield %4 : compatibleMemRefType, index, index */ // } /** %0 = vector.transfer_read %1#0[%1#1, %1#2] {in_bounds = [true ... true]} `` wherealloc` is a top of the function alloca'ed buffer of one vector.

Preconditions:

  1. xferOp.permutation_map() must be a minor identity map
  2. the rank of the xferOp.memref() and the rank of the xferOp.vector() must be equal. This will be relaxed in the future but requires rank-reducing subviews.

For vector.transfer_read: If ifOp is not null and the result is success, theifOp` points to the newly created conditional upon function return. To accomodate for the fact that the original vector.transfer indexing may be arbitrary and the slow path indexes @[0...0] in the temporary buffer, the scf.if op returns a view and values of type index.

Example (a 2-D vector.transfer_read): ``` %1 = vector.transfer_read %0[...], pad : memref<A...>, vector<...> ``` is transformed into: ``` %1:3 = scf.if (inBounds) { // fastpath, direct cast memref.cast A: memref<A...> to compatibleMemRefType scf.yield view : compatibleMemRefType, index, index } else { // slowpath, not in-bounds vector.transfer or linalg.copy. memref.cast alloc: memref<B...> to compatibleMemRefType scf.yield %4 : compatibleMemRefType, index, index */ // } /** %0 = vector.transfer_read %1#0[%1#1, %1#2] {in_bounds = [true ... true]} `` wherealloc` is a top of the function alloca'ed buffer of one vector.

For vector.transfer_write: There are 2 conditional blocks. First a block to decide which memref and indices to use for an unmasked, inbounds write. Then a conditional block to further copy a partial buffer into the final result in the slow path case.

Example (a 2-D vector.transfer_write): ``` vector.transfer_write arg, %0[...], pad : memref<A...>, vector<...> ``` is transformed into: ``` %1:3 = scf.if (inBounds) { memref.cast A: memref<A...> to compatibleMemRefType scf.yield view : compatibleMemRefType, index, index } else { memref.cast alloc: memref<B...> to compatibleMemRefType scf.yield %4 : compatibleMemRefType, index, index } %0 = vector.transfer_write arg, %1#0[%1#1, %1#2] {in_bounds = [true ... true]} scf.if (notInBounds) { // slowpath: not in-bounds vector.transfer or linalg.copy. } `` wherealloc` is a top of the function alloca'ed buffer of one vector.

Preconditions:

  1. xferOp.permutation_map() must be a minor identity map
  2. the rank of the xferOp.source() and the rank of the xferOp.vector() must be equal. This will be relaxed in the future but requires rank-reducing subviews.

Definition at line 519 of file VectorTransferSplitRewritePatterns.cpp.

References mlir::Type::cast(), mlir::clone(), mlir::OpBuilder::clone(), mlir::OpBuilder::create(), createFullPartialLinalgCopy(), createFullPartialVectorTransferRead(), createFullPartialVectorTransferWrite(), createInBoundsCond(), mlir::RewriterBase::eraseOp(), mlir::failure(), mlir::Region::front(), getAutomaticAllocationScope(), mlir::Builder::getBoolArrayAttr(), getCastCompatibleMemRefType(), mlir::Builder::getI64IntegerAttr(), mlir::Builder::getIndexType(), mlir::Operation::getLoc(), getLocationToWriteFullVec(), mlir::Operation::getNumRegions(), mlir::Operation::getRegion(), mlir::Value::getType(), mlir::IRMapping::map(), None, options, mlir::Operation::setAttr(), mlir::OpBuilder::setInsertionPoint(), mlir::OpBuilder::setInsertionPointToStart(), splitFullAndPartialTransferPrecondition(), mlir::succeeded(), mlir::success(), and mlir::RewriterBase::updateRootInPlace().

◆ transferOpflowOpt()

void mlir::vector::transferOpflowOpt ( RewriterBase rewriter,
Operation rootOp 
)

Implements transfer op write to read forwarding and dead transfer write optimizations.

Definition at line 729 of file VectorTransferOpTransforms.cpp.

References mlir::Operation::walk().