MLIR  18.0.0git
Macros | Functions
TileUsingInterface.cpp File Reference
#include "mlir/Dialect/SCF/Transforms/TileUsingInterface.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SCF/Utils/Utils.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/DestinationStyleOpInterface.h"
#include "mlir/Interfaces/TilingInterface.h"
#include "llvm/Support/Debug.h"
#include <optional>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "tile-using-interface"
 

Functions

static SmallVector< int64_t > fillInterchangeVector (ArrayRef< int64_t > interchangeVector, size_t iterationDomainSize)
 Helper method to adjust the interchange vector to match the iteration domain. More...
 
template<typename SrcOpTy >
static SmallVector< Operation * > getAsOperations (ArrayRef< SrcOpTy > ops)
 Convert a list of ops of type SrcOpTy to list of Operation *. More...
 
template<typename SrcOpTy >
static SmallVector< Operation * > getAsOperations (const SmallVector< SrcOpTy > &ops)
 
template<typename DstOpTy >
static SmallVector< DstOpTy > castToTypedOperations (ArrayRef< Operation * > ops)
 Convert a list of Operation * to a list of `DstOpTy. More...
 
template<typename DstOpTy >
static SmallVector< DstOpTy > castToTypedOperations (const SmallVector< Operation * > &ops)
 
static bool tileDividesIterationDomain (Range loopRange)
 
static OpFoldResult getBoundedTileSize (OpBuilder &b, Location loc, Range loopRange, Value iv, OpFoldResult tileSize)
 Returns the bounded tile size given the current iv, loopRange and tileSize, i.e., min(tileSize, range.end() - iv). More...
 
static OperationcloneOpAndUpdateDestinationArgs (RewriterBase &rewriter, Operation *op, ValueRange newDestArgs)
 Clones the operation and updates the destination if the operation implements the DestinationStyleOpInterface. More...
 
static SmallVector< scf::ForOp > generateTileLoopNest (OpBuilder &builder, Location loc, ArrayRef< Range > loopRanges, ArrayRef< OpFoldResult > tileSizes, SmallVector< OpFoldResult > &offsets, SmallVector< OpFoldResult > &sizes, ValueRange destinationTensors={})
 Generate an empty loop nest that represents the tiled loop nest shell. More...
 
static void addInitOperandsToLoopNest (RewriterBase &rewriter, MutableArrayRef< scf::ForOp > loops, ValueRange newInitValues, llvm::function_ref< SmallVector< Value >(RewriterBase &rewriter, Value iv, ValueRange newRegionIterArgs)> getNewYieldValsFn)
 Method to add new init values to a loop nest. More...
 
static std::tuple< OpResult, std::optional< OpOperand * > > getUntiledProducerFromSliceSource (OpOperand *source, ArrayRef< scf::ForOp > loops)
 Return the untiled producer whose slice is used in a tiled consumer. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "tile-using-interface"

Definition at line 29 of file TileUsingInterface.cpp.

Function Documentation

◆ addInitOperandsToLoopNest()

static void addInitOperandsToLoopNest ( RewriterBase rewriter,
MutableArrayRef< scf::ForOp >  loops,
ValueRange  newInitValues,
llvm::function_ref< SmallVector< Value >(RewriterBase &rewriter, Value iv, ValueRange newRegionIterArgs)>  getNewYieldValsFn 
)
static

Method to add new init values to a loop nest.

Updates loops in-place with new loops that use the newInitValues. The outer-loops are updated to yield the new result values of the inner loop. For the innermost loop, the call back getNewYields is invoked to get the additional values to yield form the innermost loop.

Definition at line 205 of file TileUsingInterface.cpp.

References mlir::OpBuilder::create(), mlir::RewriterBase::mergeBlocks(), mlir::RewriterBase::replaceOp(), mlir::RewriterBase::replaceOpWithNewOp(), and mlir::OpBuilder::setInsertionPoint().

Referenced by mlir::scf::yieldReplacementForFusedProducer().

◆ castToTypedOperations() [1/2]

template<typename DstOpTy >
static SmallVector<DstOpTy> castToTypedOperations ( ArrayRef< Operation * >  ops)
static

Convert a list of Operation * to a list of `DstOpTy.

Definition at line 72 of file TileUsingInterface.cpp.

◆ castToTypedOperations() [2/2]

template<typename DstOpTy >
static SmallVector<DstOpTy> castToTypedOperations ( const SmallVector< Operation * > &  ops)
static

Definition at line 78 of file TileUsingInterface.cpp.

◆ cloneOpAndUpdateDestinationArgs()

static Operation* cloneOpAndUpdateDestinationArgs ( RewriterBase rewriter,
Operation op,
ValueRange  newDestArgs 
)
static

Clones the operation and updates the destination if the operation implements the DestinationStyleOpInterface.

Definition at line 127 of file TileUsingInterface.cpp.

Referenced by mlir::scf::tileAndFuseProducerOfSlice().

◆ fillInterchangeVector()

static SmallVector<int64_t> fillInterchangeVector ( ArrayRef< int64_t >  interchangeVector,
size_t  iterationDomainSize 
)
static

Helper method to adjust the interchange vector to match the iteration domain.

Definition at line 46 of file TileUsingInterface.cpp.

◆ generateTileLoopNest()

static SmallVector<scf::ForOp> generateTileLoopNest ( OpBuilder builder,
Location  loc,
ArrayRef< Range loopRanges,
ArrayRef< OpFoldResult tileSizes,
SmallVector< OpFoldResult > &  offsets,
SmallVector< OpFoldResult > &  sizes,
ValueRange  destinationTensors = {} 
)
static

Generate an empty loop nest that represents the tiled loop nest shell.

  • loopRanges specifies the lb, ub and step of the untiled iteration space.
  • tileSizes is the tile sizes to use. Zero represent untiled loops.
  • In offsets and sizes return the multi-dimensional offset and size of the tile processed within the inner most loop. Note that this methods adds scf.yield operation for all but the innermost loop. These yield the value returned by the immediately inner loop. The caller is expected to add the scf.yield operation for the innermost loop.

Definition at line 146 of file TileUsingInterface.cpp.

◆ getAsOperations() [1/2]

template<typename SrcOpTy >
static SmallVector<Operation *> getAsOperations ( ArrayRef< SrcOpTy >  ops)
static

Convert a list of ops of type SrcOpTy to list of Operation *.

Definition at line 60 of file TileUsingInterface.cpp.

Referenced by getAsOperations(), and mlir::scf::tileConsumerAndFuseProducerGreedilyUsingSCFForOp().

◆ getAsOperations() [2/2]

template<typename SrcOpTy >
static SmallVector<Operation *> getAsOperations ( const SmallVector< SrcOpTy > &  ops)
static

Definition at line 66 of file TileUsingInterface.cpp.

References getAsOperations().

◆ getBoundedTileSize()

static OpFoldResult getBoundedTileSize ( OpBuilder b,
Location  loc,
Range  loopRange,
Value  iv,
OpFoldResult  tileSize 
)
static

◆ getUntiledProducerFromSliceSource()

static std::tuple<OpResult, std::optional<OpOperand *> > getUntiledProducerFromSliceSource ( OpOperand source,
ArrayRef< scf::ForOp >  loops 
)
static

Return the untiled producer whose slice is used in a tiled consumer.

The method traverses the tile loop nest (loops) if needed, and returns the iter_args of the outer most that is encountered. Traversing the iter_args indicates that this is a destination operand of the consumer. If there was no loop traversal needed, the second value of the returned tuple is empty.

Definition at line 530 of file TileUsingInterface.cpp.

References mlir::IROperand< DerivedT, IRValueT >::get().

Referenced by mlir::scf::tileAndFuseProducerOfSlice().

◆ tileDividesIterationDomain()

static bool tileDividesIterationDomain ( Range  loopRange)
static