MLIR  17.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 dependency graph for TileUsingInterface.cpp:

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...
 
static bool tileDividesIterationDomain (Range loopRange)
 
static OpFoldResult getBoundedTileSize (OpBuilder &b, Location loc, Range loopRange, Value iv, Value tileSize)
 Returns the bounded tile size given the current iv, loopRange and tileSize, i.e., min(tileSize, range.end() - iv). More...
 
static SmallVector< scf::ForOp > generateTileLoopNest (OpBuilder &builder, Location loc, ArrayRef< Range > loopRanges, ArrayRef< Value > tileSizeVals, SmallVector< OpFoldResult > &offsets, SmallVector< OpFoldResult > &sizes)
 Generate an empty loop nest that represents the tiled loop nest shell. More...
 
static SmallVector< ValueyieldTiledValues (RewriterBase &rewriter, ValueRange initValues, ValueRange yieldedValues, ArrayRef< SmallVector< OpFoldResult >> tileOffsetsList, ArrayRef< SmallVector< OpFoldResult >> tileSizesList, MutableArrayRef< scf::ForOp > loops)
 For a value to be yielded (yieldedValue) from within a loop nest loops, construct the destructive update pattern that inserts the yielded value into a destination tensor provided by initValue at offset tileOffsets and size tileSizes. More...
 
static void updateDestinationOperandsForTiledOp (OpBuilder &builder, ValueRange tiledOpDestinationValues, ValueRange bbArgsList)
 If the tiled operation is destination passing style, update the slice of the destination used (which refers to the untiled destination) to use the corresponding region argument of the innermost loop. More...
 
static SmallVector< ValueyieldTiledValues (RewriterBase &rewriter, ArrayRef< Value > initValues, Operation *tiledOp, ArrayRef< SmallVector< OpFoldResult >> tileOffsetsList, ArrayRef< SmallVector< OpFoldResult >> tileSizesList, MutableArrayRef< scf::ForOp > loops)
 Helper method to yield the values of the tiled op, as well as update the destination operands of the tiled op, if it is a destination passing style op. 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 28 of file TileUsingInterface.cpp.

Function Documentation

◆ 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 51 of file TileUsingInterface.cpp.

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

◆ generateTileLoopNest()

static SmallVector<scf::ForOp> generateTileLoopNest ( OpBuilder builder,
Location  loc,
ArrayRef< Range loopRanges,
ArrayRef< Value tileSizeVals,
SmallVector< OpFoldResult > &  offsets,
SmallVector< OpFoldResult > &  sizes 
)
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.
  • tileSizeVals 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.

Definition at line 113 of file TileUsingInterface.cpp.

References mlir::OpBuilder::create(), mlir::detail::enumerate(), getBoundedTileSize(), mlir::getValueOrCreateConstantIndexOp(), mlir::m_Zero(), mlir::matchPattern(), and mlir::OpBuilder::setInsertionPoint().

Referenced by mlir::scf::tileReductionUsingScf(), and mlir::scf::tileUsingSCFForOp().

◆ getBoundedTileSize()

static OpFoldResult getBoundedTileSize ( OpBuilder b,
Location  loc,
Range  loopRange,
Value  iv,
Value  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 492 of file TileUsingInterface.cpp.

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

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

◆ tileDividesIterationDomain()

static bool tileDividesIterationDomain ( Range  loopRange)
static

◆ updateDestinationOperandsForTiledOp()

static void updateDestinationOperandsForTiledOp ( OpBuilder builder,
ValueRange  tiledOpDestinationValues,
ValueRange  bbArgsList 
)
static

If the tiled operation is destination passing style, update the slice of the destination used (which refers to the untiled destination) to use the corresponding region argument of the innermost loop.

%0 =
scf.for %iv0 = ... iter_args(%arg = %0) {
%1 = tensor.extract_slice %0
%2 = tiled_op
%3 = tensor.insert_slice %2 into %arg
scf.yield %3
}

is transformed to

scf.for %iv0 = ... iter_args(%arg = %0) {
%1 = tensor.extract_slice %arg
%2 = tiled_op
%3 = tensor.insert_slice %2 into %arg
scf.yield %3
}

Definition at line 237 of file TileUsingInterface.cpp.

References mlir::detail::enumerate().

Referenced by mlir::scf::tileAndFuseProducerOfSlice(), mlir::scf::tileReductionUsingScf(), mlir::scf::yieldReplacementForFusedProducer(), and yieldTiledValues().

◆ yieldTiledValues() [1/2]

static SmallVector<Value> yieldTiledValues ( RewriterBase rewriter,
ArrayRef< Value initValues,
Operation tiledOp,
ArrayRef< SmallVector< OpFoldResult >>  tileOffsetsList,
ArrayRef< SmallVector< OpFoldResult >>  tileSizesList,
MutableArrayRef< scf::ForOp >  loops 
)
static

Helper method to yield the values of the tiled op, as well as update the destination operands of the tiled op, if it is a destination passing style op.

Definition at line 252 of file TileUsingInterface.cpp.

References mlir::Operation::getResults(), updateDestinationOperandsForTiledOp(), and yieldTiledValues().

◆ yieldTiledValues() [2/2]

static SmallVector<Value> yieldTiledValues ( RewriterBase rewriter,
ValueRange  initValues,
ValueRange  yieldedValues,
ArrayRef< SmallVector< OpFoldResult >>  tileOffsetsList,
ArrayRef< SmallVector< OpFoldResult >>  tileSizesList,
MutableArrayRef< scf::ForOp >  loops 
)
static

For a value to be yielded (yieldedValue) from within a loop nest loops, construct the destructive update pattern that inserts the yielded value into a destination tensor provided by initValue at offset tileOffsets and size tileSizes.

For example,

scf.for %iv0 = ... {
%0 = tiled_op
}

is transformed to

scf.for %iv0 = ... iter_args(%arg = %0) {
%1 = tensor.extract_slice %arg
%2 = tiled_op
%3 = tensor.insert_slice %2 into %arg
scf.yield %3
}

TODO: This API can be cleaned up by using SubsetExtractOpInterface.

Definition at line 177 of file TileUsingInterface.cpp.

References mlir::OpBuilder::create(), mlir::detail::enumerate(), mlir::RewriterBase::eraseOp(), mlir::Builder::getIndexAttr(), and mlir::replaceLoopNestWithNewYields().

Referenced by mlir::scf::tileReductionUsingScf(), mlir::scf::tileUsingSCFForOp(), mlir::scf::yieldReplacementForFusedProducer(), and yieldTiledValues().