12 #include "llvm/Support/Debug.h"
19 struct FoldExpandOfRankReducingExtract
25 RankedTensorType resultType = expandShapeOp.getResultType();
27 expandShapeOp.getSrc().getDefiningOp<ExtractSliceOp>();
30 RankedTensorType srcType = extractSliceOp.getSourceType();
35 RankedTensorType nonReducingExtractType = ExtractSliceOp::inferResultType(
36 srcType, extractSliceOp.getStaticOffsets(),
37 extractSliceOp.getStaticSizes(), extractSliceOp.getStaticStrides());
38 if (nonReducingExtractType != resultType)
45 expandShapeOp, extractSliceOp.getSource(), mixedOffsets, mixedSizes,
52 template <
typename OpTy>
58 auto collapseShapeOp =
59 insertSliceOp.getSource().template getDefiningOp<CollapseShapeOp>();
62 RankedTensorType srcType = collapseShapeOp.getSrcType();
67 RankedTensorType nonReducingInsertType =
69 insertSliceOp.getDestType().getElementType());
70 if (nonReducingInsertType != srcType)
77 insertSliceOp.getDest(), mixedOffsets,
78 mixedSizes, mixedStrides);
86 patterns.
add<FoldExpandOfRankReducingExtract,
87 FoldInsertOfRankReducingInsert<tensor::InsertSliceOp>,
88 FoldInsertOfRankReducingInsert<tensor::ParallelInsertSliceOp>>(
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
void populateReassociativeReshapeFoldingPatterns(RewritePatternSet &patterns)
Populates patterns with patterns that fold tensor.expand_shape and tensor.collapse_shape into other o...
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This class represents an efficient way to signal success or failure.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...