26#define GEN_PASS_DEF_AFFINEFOLDMEMREFALIASOPS
27#include "mlir/Dialect/Affine/Transforms/Passes.h.inc"
47 rewriter, loc, affineMap.
getSubMap({i}), indicesOfr);
61 LogicalResult matchAndRewrite(AffineLoadOp loadOp,
62 PatternRewriter &rewriter)
const override {
63 auto subViewOp = loadOp.getMemref().getDefiningOp<memref::SubViewOp>();
70 loadOp.getLoc(), rewriter,
indices);
72 SmallVector<Value> sourceIndices;
74 rewriter, loadOp.getLoc(), subViewOp.getMixedOffsets(),
75 subViewOp.getMixedStrides(), subViewOp.getDroppedDims(),
indices,
84struct AffineLoadOpOfExpandShapeOpFolder final
88 LogicalResult matchAndRewrite(AffineLoadOp loadOp,
89 PatternRewriter &rewriter)
const override {
91 loadOp.getMemref().getDefiningOp<memref::ExpandShapeOp>();
98 loadOp.getLoc(), rewriter,
indices);
100 SmallVector<Value> sourceIndices;
104 loadOp.getLoc(), rewriter, expandShapeOp,
indices, sourceIndices,
108 loadOp, expandShapeOp.getViewSource(), sourceIndices);
113struct AffineLoadOpOfCollapseShapeOpFolder final
117 LogicalResult matchAndRewrite(AffineLoadOp loadOp,
118 PatternRewriter &rewriter)
const override {
119 auto collapseShapeOp =
120 loadOp.getMemref().getDefiningOp<memref::CollapseShapeOp>();
122 if (!collapseShapeOp)
127 loadOp.getLoc(), rewriter,
indices);
129 SmallVector<Value> sourceIndices;
131 loadOp.getLoc(), rewriter, collapseShapeOp,
indices, sourceIndices);
134 loadOp, collapseShapeOp.getViewSource(), sourceIndices);
139struct AffineStoreOpOfSubViewOpFolder final :
OpRewritePattern<AffineStoreOp> {
142 LogicalResult matchAndRewrite(AffineStoreOp storeOp,
143 PatternRewriter &rewriter)
const override {
144 auto subViewOp = storeOp.getMemref().getDefiningOp<memref::SubViewOp>();
152 storeOp.getLoc(), rewriter,
indices);
154 SmallVector<Value> sourceIndices;
156 rewriter, storeOp.getLoc(), subViewOp.getMixedOffsets(),
157 subViewOp.getMixedStrides(), subViewOp.getDroppedDims(),
indices,
161 storeOp, storeOp.getValue(), subViewOp.getSource(), sourceIndices);
166struct AffineStoreOpOfExpandShapeOpFolder final
170 LogicalResult matchAndRewrite(AffineStoreOp storeOp,
171 PatternRewriter &rewriter)
const override {
173 storeOp.getMemref().getDefiningOp<memref::ExpandShapeOp>();
180 storeOp.getLoc(), rewriter,
indices);
182 SmallVector<Value> sourceIndices;
186 storeOp.getLoc(), rewriter, expandShapeOp,
indices, sourceIndices,
190 storeOp, storeOp.getValueToStore(), expandShapeOp.getViewSource(),
196struct AffineStoreOpOfCollapseShapeOpFolder final
200 LogicalResult matchAndRewrite(AffineStoreOp storeOp,
201 PatternRewriter &rewriter)
const override {
202 auto collapseShapeOp =
203 storeOp.getMemref().getDefiningOp<memref::CollapseShapeOp>();
205 if (!collapseShapeOp)
211 storeOp.getLoc(), rewriter,
indices);
213 SmallVector<Value> sourceIndices;
215 storeOp.getLoc(), rewriter, collapseShapeOp,
indices, sourceIndices);
218 storeOp, storeOp.getValueToStore(), collapseShapeOp.getViewSource(),
229 .add<AffineLoadOpOfSubViewOpFolder, AffineLoadOpOfExpandShapeOpFolder,
230 AffineLoadOpOfCollapseShapeOpFolder, AffineStoreOpOfSubViewOpFolder,
231 AffineStoreOpOfExpandShapeOpFolder,
232 AffineStoreOpOfCollapseShapeOpFolder>(
patterns.getContext());
241struct AffineFoldMemRefAliasOpsPass final
243 AffineFoldMemRefAliasOpsPass> {
244 void runOnOperation()
override;
249void AffineFoldMemRefAliasOpsPass::runOnOperation() {
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
unsigned getNumResults() const
AffineMap getSubMap(ArrayRef< unsigned > resultPos) const
Returns the map consisting of the resultPos subset.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class represents a single result from folding an operation.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
void populateAffineFoldMemRefAliasOpPatterns(RewritePatternSet &patterns)
Appends patterns for folding memref aliasing ops into affine load/store ops into patterns.
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands, bool composeAffineMin=false)
Constructs an AffineApplyOp that applies map to operands after composing the map with the maps of any...
void resolveIndicesIntoOpWithOffsetsAndStrides(RewriterBase &rewriter, Location loc, ArrayRef< OpFoldResult > mixedSourceOffsets, ArrayRef< OpFoldResult > mixedSourceStrides, const llvm::SmallBitVector &rankReducedDims, ArrayRef< OpFoldResult > consumerIndices, SmallVectorImpl< Value > &resolvedIndices)
Given the 'consumerIndices' of a load/store operation operating on an op with offsets and strides,...
void resolveSourceIndicesCollapseShape(Location loc, PatternRewriter &rewriter, memref::CollapseShapeOp collapseShapeOp, ValueRange indices, SmallVectorImpl< Value > &sourceIndices)
Given the 'indices' of a load/store operation where the memref is a result of a collapse_shape op,...
void resolveSourceIndicesExpandShape(Location loc, PatternRewriter &rewriter, memref::ExpandShapeOp expandShapeOp, ValueRange indices, SmallVectorImpl< Value > &sourceIndices, bool startsInbounds)
Given the 'indices' of a load/store operation where the memref is a result of a expand_shape op,...
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(Region ®ion, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
const FrozenRewritePatternSet & patterns
Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...