19#include "llvm/Support/Debug.h"
21#define DEBUG_TYPE "tensor-swap-slices"
28 auto producerOp = dyn_cast<TilingInterface>(producer.
getOwner());
33 if (!llvm::all_of(sliceOp.getMixedStrides(),
isOneInteger))
36 FailureOr<TilingResult> tiledResult = producerOp.generateResultTileValue(
38 sliceOp.getMixedSizes(), innerTileAlignments);
39 if (failed(tiledResult))
44 llvm::SmallBitVector droppedDims = sliceOp.getDroppedDims();
45 if (droppedDims.any()) {
46 assert(tiledResult->tiledValues.size() == 1 &&
47 "expected only a single tiled result value to replace the extract "
53 auto newSliceOp = tensor::ExtractSliceOp::create(
54 builder, sliceOp.getLoc(), sliceOp.
getType(),
55 tiledResult->tiledValues[0], offsets, sliceOp.getMixedSizes(), strides);
56 tiledResult->tiledValues[0] = newSliceOp;
57 tiledResult->generatedSlices.push_back(newSliceOp);
67 if (sliceOps.empty()) {
69 { llvm::dbgs() <<
"expected candidate slices list to be non-empty"; });
72 if (sliceOps.size() != consumerOperands.size()) {
75 <<
"expected as many operands as the number of slices passed";
80 dyn_cast<TilingInterface>(consumerOperands.front()->getOwner());
83 for (
auto *opOperand : consumerOperands.drop_front()) {
84 if (opOperand->getOwner() != consumerOp) {
87 <<
"expected all consumer operands to be from the same operation";
93 auto consumerOperandNums = llvm::map_to_vector(
94 consumerOperands, [](
OpOperand *opOperand) ->
unsigned {
99 for (
auto sliceOp : sliceOps) {
102 if (!llvm::all_of(sliceOp.getMixedStrides(),
isOneInteger))
107 allOffsets.emplace_back(std::move(offsets));
108 allSizes.emplace_back(std::move(sizes));
110 FailureOr<TilingResult> tiledResult =
111 consumerOp.getTiledImplementationFromOperandTiles(
112 builder, consumerOperandNums, allOffsets, allSizes,
113 innerTileAlignments);
114 if (failed(tiledResult))
IntegerAttr getIndexAttr(int64_t value)
Ty getType(Args &&...args)
Get or construct an instance of the type Ty with provided arguments.
This class helps build Operations.
This class represents an operand of an operation.
unsigned getOperandNumber() const
Return which operand this is in the OpOperand list of the Operation.
This is a value defined by a result of an operation.
Operation * getOwner() const
Returns the operation that owns this result.
unsigned getResultNumber() const
Returns the number of this result.
FailureOr< TilingResult > replaceExtractSliceWithTiledProducer(OpBuilder &builder, tensor::ExtractSliceOp sliceOp, OpResult producerOp, ArrayRef< InnerTileAlignment > innerTileAlignments={})
Method to swap an tensor.extract_slice with its producer when the producer implements the TilingInter...
FailureOr< TilingResult > replaceInsertSlicesWithTiledConsumer(OpBuilder &builder, ArrayRef< tensor::InsertSliceOp > sliceOps, ArrayRef< OpOperand * > consumerOperands, ArrayRef< InnerTileAlignment > innerTileAlignments={})
Method to swap tensor.insert_slices with their consumers when the consumer implements the TilingInter...
Include the generated interface declarations.
bool isOneInteger(OpFoldResult v)
Return true if v is an IntegerAttr with value 1.