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,
135 loadOp, collapseShapeOp.getViewSource(), sourceIndices);
140struct AffineStoreOpOfSubViewOpFolder final :
OpRewritePattern<AffineStoreOp> {
143 LogicalResult matchAndRewrite(AffineStoreOp storeOp,
144 PatternRewriter &rewriter)
const override {
145 auto subViewOp = storeOp.getMemref().getDefiningOp<memref::SubViewOp>();
153 storeOp.getLoc(), rewriter,
indices);
155 SmallVector<Value> sourceIndices;
157 rewriter, storeOp.getLoc(), subViewOp.getMixedOffsets(),
158 subViewOp.getMixedStrides(), subViewOp.getDroppedDims(),
indices,
162 storeOp, storeOp.getValue(), subViewOp.getSource(), sourceIndices);
167struct AffineStoreOpOfExpandShapeOpFolder final
171 LogicalResult matchAndRewrite(AffineStoreOp storeOp,
172 PatternRewriter &rewriter)
const override {
174 storeOp.getMemref().getDefiningOp<memref::ExpandShapeOp>();
181 storeOp.getLoc(), rewriter,
indices);
183 SmallVector<Value> sourceIndices;
187 storeOp.getLoc(), rewriter, expandShapeOp,
indices, sourceIndices,
191 storeOp, storeOp.getValueToStore(), expandShapeOp.getViewSource(),
197struct AffineStoreOpOfCollapseShapeOpFolder final
201 LogicalResult matchAndRewrite(AffineStoreOp storeOp,
202 PatternRewriter &rewriter)
const override {
203 auto collapseShapeOp =
204 storeOp.getMemref().getDefiningOp<memref::CollapseShapeOp>();
206 if (!collapseShapeOp)
212 storeOp.getLoc(), rewriter,
indices);
214 SmallVector<Value> sourceIndices;
216 storeOp.getLoc(), rewriter, collapseShapeOp,
indices, sourceIndices,
220 storeOp, storeOp.getValueToStore(), collapseShapeOp.getViewSource(),
231 .
add<AffineLoadOpOfSubViewOpFolder, AffineLoadOpOfExpandShapeOpFolder,
232 AffineLoadOpOfCollapseShapeOpFolder, AffineStoreOpOfSubViewOpFolder,
233 AffineStoreOpOfExpandShapeOpFolder,
234 AffineStoreOpOfCollapseShapeOpFolder>(patterns.
getContext());
243struct AffineFoldMemRefAliasOpsPass final
245 AffineFoldMemRefAliasOpsPass> {
246 void runOnOperation()
override;
251void 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...
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.
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, bool startsInbounds)
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...
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...