MLIR  19.0.0git
Classes | Macros | Functions
Fusion.cpp File Reference
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Linalg/Passes.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/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/Dominance.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include <optional>
#include <set>

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. More...
 
static Range getRangeFromOperandShape (OpBuilder &b, Location loc, Value shapedOperand, unsigned dim)
 Get the loop range for a dimension dim based on the shapedOperand. More...
 
static LinalgOp fuse (OpBuilder &b, LinalgOp producerOp, AffineMap producerMap, OpOperand &consumerOpOperand)
 Fuses the producer into the loop immediately enclosing the consumer. More...
 
static void getProducerOfTensor (Value tensor, OpResult &opResult)
 Walk back use-def chain through scf::For yields. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "linalg-fusion"

Definition at line 35 of file Fusion.cpp.

Function Documentation

◆ fuse() [1/2]

static 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 113 of file Fusion.cpp.

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

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

◆ fuse() [2/2]

static 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 183 of file Fusion.cpp.

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

◆ getProducerOfTensor()

static 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 202 of file Fusion.cpp.

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

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

◆ getRangeFromOperandShape()

static 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 170 of file Fusion.cpp.

References mlir::Value::getDefiningOp().

Referenced by fuse().

◆ getShapeDefiningLoopRange()

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

Definition at line 67 of file Fusion.cpp.

Referenced by fuse().

◆ getTiledOperands()

static SmallVector<Value> getTiledOperands ( LinalgOp  producer)
static

Definition at line 106 of file Fusion.cpp.

Referenced by fuse().