28 struct ComposeSubViewOpPattern : 
public OpRewritePattern<memref::SubViewOp> {
 
   31   LogicalResult matchAndRewrite(memref::SubViewOp op,
 
   37     auto sourceOp = op.getSource().getDefiningOp<memref::SubViewOp>();
 
   47     if (sourceOp.getSourceType().getRank() != sourceOp.getType().getRank()) {
 
   53         opStrides = op.getMixedStrides(),
 
   54         sourceStrides = sourceOp.getMixedStrides();
 
   58     int64_t sourceStrideValue;
 
   59     for (
auto &&[opStride, sourceStride] :
 
   60          llvm::zip(opStrides, sourceStrides)) {
 
   61       Attribute opStrideAttr = dyn_cast_if_present<Attribute>(opStride);
 
   62       Attribute sourceStrideAttr = dyn_cast_if_present<Attribute>(sourceStride);
 
   63       if (!opStrideAttr || !sourceStrideAttr)
 
   65       sourceStrideValue = cast<IntegerAttr>(sourceStrideAttr).getInt();
 
   67           cast<IntegerAttr>(opStrideAttr).getInt() * sourceStrideValue));
 
   80     for (
auto &&[opOffset, sourceOffset, sourceStride, opSize] :
 
   81          llvm::zip(op.getMixedOffsets(), sourceOp.getMixedOffsets(),
 
   82                    sourceOp.getMixedStrides(), op.getMixedSizes())) {
 
   83       sizes.push_back(opSize);
 
   84       Attribute opOffsetAttr = llvm::dyn_cast_if_present<Attribute>(opOffset),
 
   86                     llvm::dyn_cast_if_present<Attribute>(sourceOffset),
 
   88                     llvm::dyn_cast_if_present<Attribute>(sourceStride);
 
   89       if (opOffsetAttr && sourceOffsetAttr) {
 
   94             cast<IntegerAttr>(opOffsetAttr).getInt() *
 
   95                 cast<IntegerAttr>(sourceStrideAttr).getInt() +
 
   96             cast<IntegerAttr>(sourceOffsetAttr).getInt()));
 
  102         if (
auto attr = llvm::dyn_cast_if_present<Attribute>(sourceOffset)) {
 
  107           affineApplyOperands.push_back(cast<Value>(sourceOffset));
 
  112         if (
auto attr = llvm::dyn_cast_if_present<Attribute>(opOffset)) {
 
  113           expr = expr + cast<IntegerAttr>(attr).getInt() *
 
  114                             cast<IntegerAttr>(sourceStrideAttr).getInt();
 
  118                          cast<IntegerAttr>(sourceStrideAttr).getInt();
 
  119           affineApplyOperands.push_back(cast<Value>(opOffset));
 
  123         Value result = affine::AffineApplyOp::create(rewriter, op.getLoc(), map,
 
  124                                                      affineApplyOperands);
 
  125         offsets.push_back(result);
 
  132         op, op.getType(), sourceOp.getSource(), offsets, sizes, strides);
 
  141   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.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
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 represents an instance of an SSA value in the MLIR system, representing a computable value...
void populateComposeSubViewPatterns(RewritePatternSet &patterns, MLIRContext *context)
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
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...