MLIR 22.0.0git
Fusion.cpp File Reference
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Linalg/Transforms/Transforms.h"
#include "mlir/Dialect/Linalg/Utils/Utils.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Tensor/Utils/Utils.h"
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/Dominance.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/Support/Debug.h"

Go to the source code of this file.

Classes

struct  ShapeDimension
 Implements a simple high-level fusion pass on linalg structured operations. More...

Macros

#define DEBUG_TYPE   "linalg-fusion"

Functions

static ShapeDimension getShapeDefiningLoopRange (LinalgOp op, unsigned loopDepth, bool fromSubViewOpOnly=false)
static SmallVector< ValuegetTiledOperands (LinalgOp producer)
static LinalgOp fuse (OpBuilder &b, LinalgOp producer, const DenseMap< unsigned, Range > &fusedLoopsAndRanges)
 Fuses the producer by cloning the producer.
static Range getRangeFromOperandShape (OpBuilder &b, Location loc, Value shapedOperand, unsigned dim)
 Get the loop range for a dimension dim based on the shapedOperand.
static LinalgOp fuse (OpBuilder &b, LinalgOp producerOp, AffineMap producerMap, OpOperand &consumerOpOperand)
 Fuses the producer into the loop immediately enclosing the consumer.
static void getProducerOfTensor (Value tensor, OpResult &opResult)
 Walk back use-def chain through scf::For yields.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "linalg-fusion"

Definition at line 26 of file Fusion.cpp.

Function Documentation

◆ fuse() [1/2]

LinalgOp fuse ( OpBuilder & b,
LinalgOp producer,
const DenseMap< unsigned, Range > & fusedLoopsAndRanges )
static

Fuses the producer by cloning the producer.

The fusedLoopsAndRanges provides the loop range information for the fused loops. The rest are obtained from the producer itself, since they are not tiled + fused.

omitPartialTileCheck=

Definition at line 103 of file Fusion.cpp.

References b, mlir::clone(), mlir::linalg::createFoldedDimOp(), mlir::MutableOperandRange::getAsOperandRange(), mlir::OperandRange::getBeginOperandIndex(), getShapeDefiningLoopRange(), getTiledOperands(), mlir::getType(), mlir::linalg::makeTiledShapes(), mlir::Range::offset, and mlir::linalg::offsetIndices().

Referenced by fuse(), and mlir::linalg::fuseProducerOfTensor().

◆ fuse() [2/2]

LinalgOp fuse ( OpBuilder & b,
LinalgOp producerOp,
AffineMap producerMap,
OpOperand & consumerOpOperand )
static

Fuses the producer into the loop immediately enclosing the consumer.

This is achieved by "recomputing" the producer at the time it is needed just before the consumer.

Definition at line 173 of file Fusion.cpp.

References b, fuse(), mlir::IROperand< DerivedT, IRValueT >::get(), mlir::Operation::getLoc(), mlir::detail::IROperandBase::getOwner(), getRangeFromOperandShape(), and mlir::AffineMap::getResults().

◆ getProducerOfTensor()

void getProducerOfTensor ( Value tensor,
OpResult & opResult )
static

Walk back use-def chain through scf::For yields.

Sets producer and outputIndex if it finds a producer LinalgOp

Definition at line 192 of file Fusion.cpp.

Referenced by mlir::linalg::fuseProducerOfTensor().

◆ getRangeFromOperandShape()

Range getRangeFromOperandShape ( OpBuilder & b,
Location loc,
Value shapedOperand,
unsigned dim )
static

Get the loop range for a dimension dim based on the shapedOperand.

It is expected to be defined by a subview op or an extract_slice op.

Definition at line 160 of file Fusion.cpp.

References b, and mlir::Value::getDefiningOp().

Referenced by fuse().

◆ getShapeDefiningLoopRange()

ShapeDimension getShapeDefiningLoopRange ( LinalgOp op,
unsigned loopDepth,
bool fromSubViewOpOnly = false )
static

Definition at line 58 of file Fusion.cpp.

References mlir::AffineMap::getResults().

Referenced by fuse().

◆ getTiledOperands()

SmallVector< Value > getTiledOperands ( LinalgOp producer)
static

Definition at line 96 of file Fusion.cpp.

Referenced by fuse().