9#ifndef MLIR_DIALECT_SCF_TRANSFORMS_TILEUSINGINTERFACE_H
10#define MLIR_DIALECT_SCF_TRANSFORMS_TILEUSINGINTERFACE_H
41using InnerTileAlignmentFnTy = std::function<SmallVector<InnerTileAlignment>(
46struct SCFTilingOptions {
48 enum class LoopType { ForOp, ForallOp, CustomOp };
49 LoopType loopType = LoopType::ForOp;
50 SCFTilingOptions &setLoopType(LoopType type) {
64 tileSizeComputationFunction = std::move(fun);
75 interchangeVector = llvm::to_vector(interchange);
81 InnerTileAlignmentFnTy innerTileAlignmentFn =
nullptr;
82 SCFTilingOptions &setInnerTileAlignmentFn(InnerTileAlignmentFnTy fn) {
83 innerTileAlignmentFn = std::move(fn);
93 innerTileAlignmentFn =
116 numThreadsComputationFunction = std::move(fun);
129 mappingVector = llvm::to_vector(mapping);
142 reductionStrategy = strategy;
151 reductionDims.clear();
152 reductionDims.insert(dims.begin(), dims.end());
194 struct CustomLoopHeaderInfo {
212 using GenerateLoopHeaderFn = std::function<FailureOr<CustomLoopHeaderInfo>(
227 using GenerateLoopTerminatorFn = std::function<LogicalResult(
235 GenerateLoopHeaderFn generateLoopHeaderFn =
nullptr;
237 GenerateLoopTerminatorFn generateLoopTerminatorFn =
nullptr;
241 setCustomLoopGenerationFns(GenerateLoopHeaderFn headerFn,
242 GenerateLoopTerminatorFn terminatorFn) {
243 generateLoopHeaderFn = std::move(headerFn);
244 generateLoopTerminatorFn = std::move(terminatorFn);
250struct SCFTilingResult {
276 const SCFTilingOptions &
options);
302 tensor::ExtractSliceOp candidateSliceOp,
OpResult originalProducer,
303 bool isDestinationOperand)>;
307 bool) -> std::optional<ControlFnResult> {
336std::optional<SCFFuseProducerOfSliceResult>
338 tensor::ExtractSliceOp candidateSliceOp,
340 const InnerTileAlignmentFnTy &fn =
nullptr);
400 scf::SCFFuseProducerOfSliceResult fusedProducerInfo,
444FailureOr<SCFTileAndFuseResult>
446 TilingInterface consumer,
469FailureOr<scf::SCFFuseConsumerOfSliceResult>
473 const InnerTileAlignmentFnTy &fn =
nullptr);
483FailureOr<scf::SCFFuseConsumerOfSliceResult>
486 const InnerTileAlignmentFnTy &fn =
nullptr);
490FailureOr<SmallVector<scf::ForOp>>
517FailureOr<scf::SCFTilingResult>
static llvm::ManagedStatic< PassManagerOptions > options
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
This is a value defined by a result of an operation.
Operation is the basic unit of execution within MLIR.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
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...
std::function< SmallVector< OpFoldResult >(OpBuilder &, Operation *)> SCFTileSizeComputationFunction
SmallVector< Operation * > mergeOps
Computation function returning, for the op currently being tiled or fused, the per-iteration-domain-d...
Include the generated interface declarations.
FailureOr< scf::SCFTilingResult > tileReductionUsingScf(RewriterBase &b, PartialReductionOpInterface op, ArrayRef< OpFoldResult > tileSizes)
Method to tile a reduction and generate a parallel op within a serial loop.
ReductionTilingStrategy
Tiling can be thought of as splitting a dimension into 2 and materializing the outer dimension as a l...
FailureOr< scf::SCFFuseConsumerOfSliceResult > tileAndFuseConsumerOfSlices(RewriterBase &rewriter, ArrayRef< Operation * > candidateSlices, MutableArrayRef< LoopLikeOpInterface > loops, const InnerTileAlignmentFnTy &fn=nullptr)
When the consumer is a linalg.pack/linalg.unpack, fn (if non-null) is invoked with the consumer and c...
FailureOr< scf::SCFFuseConsumerOfSliceResult > tileAndFuseConsumer(RewriterBase &rewriter, Operation *consumer, MutableArrayRef< LoopLikeOpInterface > loops, const InnerTileAlignmentFnTy &fn=nullptr)
Fuse the consumer operation into the loop nest provided by loops.
llvm::SetVector< T, Vector, Set, N > SetVector
FailureOr< SCFTileAndFuseResult > tileConsumerAndFuseProducersUsingSCF(RewriterBase &rewriter, TilingInterface consumer, const SCFTileAndFuseOptions &options)
Method to tile and fuse a sequence of operations, by tiling the consumer and fusing its producers.
FailureOr< SmallVector< scf::ForOp > > lowerToLoopsUsingSCFForOp(RewriterBase &rewriter, TilingInterface op)
Method to lower an op that implements the TilingInterface to loops/scalars.
FailureOr< SmallVector< Operation * > > yieldReplacementForFusedProducer(RewriterBase &rewriter, tensor::ExtractSliceOp sliceOp, scf::SCFFuseProducerOfSliceResult fusedProducerInfo, MutableArrayRef< LoopLikeOpInterface > loops, ArrayRef< unsigned > yieldResultNumber=ArrayRef< unsigned >{})
Reconstruct the fused producer from within the tiled-and-fused code.
std::optional< SCFFuseProducerOfSliceResult > tileAndFuseProducerOfSlice(RewriterBase &rewriter, tensor::ExtractSliceOp candidateSliceOp, MutableArrayRef< LoopLikeOpInterface > loops, const InnerTileAlignmentFnTy &fn=nullptr)
Fuse the producer of the source of candidateSliceOp by computing the required slice of the producer i...
FailureOr< SCFTilingResult > tileUsingSCF(RewriterBase &rewriter, TilingInterface op, const SCFTilingOptions &options)
Method to tile an op that implements the TilingInterface using scf.for for iterating over the tiles.
Fuse the consumer candidateSlices by computing the required slice of the consumer in-place.
SmallVector< Operation * > tiledOps
SmallVector< OpOperand * > origConsumerOperands
SmallVector< OpOperand * > tiledAndFusedConsumerOperands
Result of fusing the producer of the source of a tensor.extract_slice.
SmallVector< Operation * > generatedSlices
SmallVector< Operation * > tiledOps
Value tiledAndFusedProducer
Control function to check if a slice needs to be fused or not, The control function receives 1) the s...
bool yieldProducerReplacement
Set to true if the loop nest has to return a replacement value for the fused producer.
Options used to control tile + fuse.
std::optional< FrozenRewritePatternSet > cleanupPatterns
An optional set of rewrite patterns to apply to the results of tiling before fusion.
std::function< std::optional< ControlFnResult >( tensor::ExtractSliceOp candidateSliceOp, OpResult originalProducer, bool isDestinationOperand)> ControlFnTy
SCFTileAndFuseOptions & setFusionControlFn(ControlFnTy controlFn)
SCFTileAndFuseOptions & setTilingOptions(SCFTilingOptions options)
SCFTilingOptions tilingOptions
The tiling options used to control the tiling of the consumer.
ControlFnTy fusionControlFn
The default control function implements greedy fusion without yielding a replacement for any of the f...
Transformation information returned after tile and fuse.
SmallVector< LoopLikeOpInterface > loops
The scf.for operations that iterate over the tiles.
llvm::SetVector< Operation * > tiledAndFusedOps
List of tiled and fused operations generated.
llvm::SetVector< Operation * > fusedProducers
List of untiled operations that were fused with the tiled consumer.
llvm::DenseMap< Value, Value > replacements
The replacement values to use for the tiled and fused operations.