MLIR  17.0.0git
SwapExtractSliceWithProducerPatterns.cpp
Go to the documentation of this file.
1 //===- SwapExtractSliceWithProducerPatterns.cpp ---------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Swap a `tensor.extract_slice` with the producer of the source if the producer
10 // implements the `TilingInterface`. When used in conjunction with tiling this
11 // effectively tiles + fuses the producer with its consumer.
12 //
13 //===----------------------------------------------------------------------===//
14 
20 
21 using namespace mlir;
22 
24  OpBuilder &builder, tensor::ExtractSliceOp sliceOp, OpResult producer) {
25  auto producerOp = dyn_cast<TilingInterface>(producer.getOwner());
26  if (!producerOp)
27  return failure();
28 
29  // `TilingInterface` currently only supports strides being 1.
30  if (llvm::any_of(sliceOp.getMixedStrides(), [](OpFoldResult ofr) {
31  return !isConstantIntValue(ofr, 1);
32  }))
33  return failure();
34 
35  FailureOr<Value> tiledResult = producerOp.generateResultTileValue(
36  builder, producer.getResultNumber(), sliceOp.getMixedOffsets(),
37  sliceOp.getMixedSizes());
38  if (failed(tiledResult))
39  return failure();
40 
41  return *tiledResult;
42 }
This class provides support for representing a failure result, or a valid value of type T.
Definition: LogicalResult.h:78
This class helps build Operations.
Definition: Builders.h:199
This class represents a single result from folding an operation.
Definition: OpDefinition.h:233
This is a value defined by a result of an operation.
Definition: Value.h:450
Operation * getOwner() const
Returns the operation that owns this result.
Definition: Value.h:459
unsigned getResultNumber() const
Returns the number of this result.
Definition: Value.h:462
FailureOr< Value > replaceExtractSliceWithTiledProducer(OpBuilder &builder, tensor::ExtractSliceOp sliceOp, OpResult producerOp)
Pattern to swap an tensor.extract_slice with its producer when the producer implements the TilingInte...
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72