30 struct ComposeSubViewOpPattern :
public OpRewritePattern<memref::SubViewOp> {
39 auto sourceOp = op.getSource().getDefiningOp<memref::SubViewOp>();
49 if (sourceOp.getSourceType().getRank() != sourceOp.getType().getRank()) {
58 if (llvm::all_of(strides, [](
OpFoldResult &valueOrAttr) {
59 Attribute attr = llvm::dyn_cast_if_present<Attribute>(valueOrAttr);
60 return attr && cast<IntegerAttr>(attr).getInt() == 1;
77 for (
auto it : llvm::zip(op.getMixedOffsets(), sourceOp.getMixedOffsets(),
78 op.getMixedSizes())) {
79 auto opOffset = std::get<0>(it);
80 auto sourceOffset = std::get<1>(it);
81 auto opSize = std::get<2>(it);
84 if (opSize.is<
Value>()) {
88 sizes.push_back(opSize);
89 Attribute opOffsetAttr = llvm::dyn_cast_if_present<Attribute>(opOffset),
91 llvm::dyn_cast_if_present<Attribute>(sourceOffset);
93 if (opOffsetAttr && sourceOffsetAttr) {
97 cast<IntegerAttr>(opOffsetAttr).getInt() +
98 cast<IntegerAttr>(sourceOffsetAttr).getInt()));
104 for (
auto valueOrAttr : {opOffset, sourceOffset}) {
105 if (
auto attr = llvm::dyn_cast_if_present<Attribute>(valueOrAttr)) {
106 expr = expr + cast<IntegerAttr>(attr).getInt();
110 affineApplyOperands.push_back(valueOrAttr.get<
Value>());
115 Value result = rewriter.
create<affine::AffineApplyOp>(
116 op.
getLoc(), map, affineApplyOperands);
117 offsets.push_back(result);
124 offsets, sizes, strides);
133 patterns.
add<ComposeSubViewOpPattern>(context);
Base type for affine expression.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
static AffineMap get(MLIRContext *context)
Returns a zero result affine map with no dimensions or symbols: () -> ().
Attributes are known-constant values of operations.
AffineExpr getAffineSymbolExpr(unsigned position)
AffineExpr getAffineConstantExpr(int64_t constant)
IntegerAttr getI64IntegerAttr(int64_t value)
MLIRContext is the top-level object for a collection of MLIR operations.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class represents a single result from folding an operation.
Location getLoc()
The source location the operation was defined or derived from.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
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)
Replaces the result op with a new op that is created without verification.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
void populateComposeSubViewPatterns(RewritePatternSet &patterns, MLIRContext *context)
This header declares functions that assist transformations in the MemRef dialect.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
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...
OpRewritePattern(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Patterns must specify the root operation name they match against, and can also specify the benefit of...