18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallVector.h"
31 static TilingInterface
40 sizesCopy[dimension] = size;
41 offsetsCopy[dimension] = offset;
44 FailureOr<TilingResult> tilingResult =
45 op.getTiledImplementation(b, offsetsCopy, sizesCopy);
48 for (
auto [index, result] :
llvm::enumerate(tilingResult->tiledValues)) {
50 if (failed(op.getResultTilePosition(b, index, offsetsCopy, sizesCopy,
51 resultOffsets, resultSizes)))
56 loc, result, resultOperands[index], resultOffsets, resultSizes,
58 results.push_back(inserted);
61 assert(tilingResult->tiledOps.size() == 1 &&
62 "expected split part to return a single tiled operation");
63 return cast<TilingInterface>(tilingResult->tiledOps[0]);
66 std::pair<TilingInterface, TilingInterface>
73 if (dimension >= iterationSpace.size())
74 return std::make_pair(op, TilingInterface());
77 iterationSpace, [](
const Range &range) {
return range.
offset; }));
79 iterationSpace, [](
const Range &range) {
return range.
size; }));
85 rewriter, op.getLoc(),
89 {splitPoint, offsets[dimension], sizes[dimension]});
94 rewriter, op.getLoc(), d0 + d1 - d2,
95 {iterationSpace[dimension].offset, iterationSpace[dimension].size,
97 if (
auto attr = llvm::dyn_cast_if_present<Attribute>(remainingSize)) {
98 if (cast<IntegerAttr>(attr).getValue().isZero())
99 return {op, TilingInterface()};
105 rewriter, op.getLoc(), op, destinationTensors);
107 assert(succeeded(destStatus) &&
"failed to get destination tensors");
112 rewriter, op.getLoc(), op, offsets, sizes, destinationTensors, dimension,
113 minSplitPoint, iterationSpace[dimension].offset, firstResults);
119 unsigned numTotalOperands = op->getNumOperands();
120 unsigned numOutputOperands = firstResults.size();
121 op->setOperands(numTotalOperands - numOutputOperands, numOutputOperands,
127 rewriter, op.getLoc(), d0 + d1, {offsets[dimension], minSplitPoint});
129 TilingInterface secondPart =
130 createSplitPart(rewriter, op.getLoc(), op, offsets, sizes, firstResults,
131 dimension, remainingSize, totalOffset, secondResults);
134 if (!firstPart || !secondPart)
135 return {TilingInterface(), TilingInterface()};
139 return {firstPart, secondPart};
static TilingInterface createSplitPart(RewriterBase &b, Location loc, TilingInterface op, ArrayRef< OpFoldResult > offsets, ArrayRef< OpFoldResult > sizes, ValueRange resultOperands, unsigned dimension, OpFoldResult size, OpFoldResult offset, SmallVectorImpl< Value > &results)
Creates a part of the given op split along the iteration space dimension with the given size and an o...
Base type for affine expression.
static SmallVector< AffineMap, 4 > inferFromExprList(ArrayRef< ArrayRef< AffineExpr >> exprsList, MLIRContext *context)
Returns a vector of AffineMaps; each with as many results as exprs.size(), as many dims as the larges...
IntegerAttr getIndexAttr(int64_t value)
MLIRContext * getContext() const
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
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.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
void modifyOpInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around an in-place modification of an operation.
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...
OpFoldResult makeComposedFoldedAffineMin(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Constructs an AffineMinOp that computes a minimum across the results of applying map to operands,...
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Constructs an AffineApplyOp that applies map to operands after composing the map with the maps of any...
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
std::pair< TilingInterface, TilingInterface > splitOp(RewriterBase &rewriter, TilingInterface op, unsigned dimension, OpFoldResult splitPoint)
Split the given op into two parts along the given iteration space dimension at the specified splitPoi...
LogicalResult getOrCreateDestinations(OpBuilder &b, Location loc, Operation *op, SmallVector< Value > &result)
This is a helper function for DestinationStyleOpInterface.
Include the generated interface declarations.
void bindDims(MLIRContext *ctx, AffineExprTy &...exprs)
Bind a list of AffineExpr references to DimExpr at positions: [0 .
Represents a range (offset, size, and stride) where each element of the triple may be dynamic or stat...