MLIR  16.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/Analysis/DependenceAnalysis.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 <set>
+ Include dependency graph for Fusion.cpp:

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 bool isStructurallyFusableProducer (LinalgOp producer, Value consumedView, LinalgOp consumer)
 
static FailureOr< LinalgDependenceGraph::LinalgDependenceGraphElemfindFusableProducer (OpOperand &consumerOpOperand, const LinalgDependenceGraph &dependenceGraph)
 For consumer with buffer semantics, find the Linalg operation on buffers that is the last writer of consumerOpOperand. 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

◆ findFusableProducer()

static FailureOr<LinalgDependenceGraph::LinalgDependenceGraphElem> findFusableProducer ( OpOperand consumerOpOperand,
const LinalgDependenceGraph dependenceGraph 
)
static

For consumer with buffer semantics, find the Linalg operation on buffers that is the last writer of consumerOpOperand.

For now the fusable dependence is returned as an instance of the dependenceGraph.

Definition at line 277 of file Fusion.cpp.

References mlir::failure(), mlir::IROperand< DerivedT, IRValueT >::get(), mlir::linalg::LinalgDependenceGraph::getDependencesInto(), mlir::linalg::LinalgDependenceGraph::getDependenceTypeStr(), mlir::OpOperand::getOperandNumber(), mlir::detail::IROperandBase::getOwner(), and mlir::linalg::isFusableInto().

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

◆ 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::Builder::getIndexAttr(), getShapeDefiningLoopRange(), getTiledOperands(), mlir::linalg::makeTiledShapes(), mlir::Range::offset, and mlir::linalg::offsetIndices().

Referenced by fuse(), mlir::linalg::fuseProducerOfBuffer(), 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 193 of file Fusion.cpp.

References mlir::Value::cast(), 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 379 of file Fusion.cpp.

References mlir::Value::cast(), mlir::Value::dyn_cast(), mlir::Value::getDefiningOp(), mlir::Value::getType(), and mlir::Type::isa().

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

References mlir::Value::getDefiningOp().

Referenced by fuse().

◆ getShapeDefiningLoopRange()

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

◆ getTiledOperands()

static SmallVector<Value> getTiledOperands ( LinalgOp  producer)
static

Definition at line 106 of file Fusion.cpp.

Referenced by fuse().

◆ isStructurallyFusableProducer()

static bool isStructurallyFusableProducer ( LinalgOp  producer,
Value  consumedView,
LinalgOp  consumer 
)
static

Definition at line 208 of file Fusion.cpp.

References mlir::DominanceInfo::dominates().

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