MLIR  17.0.0git
Classes | Macros | Functions
HoistPadding.cpp File Reference
#include "mlir/Analysis/SliceAnalysis.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Linalg/Transforms/Hoisting.h"
#include "mlir/Dialect/Linalg/Transforms/Transforms.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/Tensor/Utils/Utils.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/IR/AsmState.h"
#include "mlir/IR/Dominance.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/Support/Debug.h"
+ Include dependency graph for HoistPadding.cpp:

Go to the source code of this file.

Classes

struct  HoistingAnalysis
 Analysis class to support tensor::PadOp hoisting across multiple enclosing loops. More...
 
struct  PackingLoopNestResult
 

Macros

#define DEBUG_TYPE   "hoist-padding"
 
#define DBGS()   (dbgs() << '[' << DEBUG_TYPE << "] ")
 

Functions

static bool debugPrintLoopInShortForm (Operation *op)
 
static void debugPrintBackwardSlice (SetVector< Operation * > &backwardSlice)
 
static void getAtMostNEnclosingLoops (tensor::PadOp padOp, int nLevels, SmallVector< scf::ForOp > &reverseEnclosingLoops)
 Return at most nLevels of immediately enclosing scf::ForOp loops. More...
 
static void computeBackwardSlice (tensor::PadOp padOp, scf::ForOp outermostEnclosingForOp, SetVector< Operation * > &backwardSlice)
 
static bool isDefinedOutsideOrConstant (scf::ForOp outer, Value v)
 
static Value buildLoopIterationCount (RewriterBase &rewriter, scf::ForOp outer, scf::ForOp forOp)
 Return the current iteration number in the loop (iv - lb).ceilDiv(step). More...
 
static PackingLoopNestResult buildPackingLoopNest (RewriterBase &rewriter, IRMapping &bvm, tensor::PadOp opToHoist, ArrayRef< int64_t > transposeVector, RankedTensorType transposedTensorType, tensor::EmptyOp emptyOp, const HoistingAnalysis &analysis)
 
static Value padThroughLoopIterArg (RewriterBase &rewriter, Value packedTensor, tensor::ExtractSliceOp sliceOp, scf::ForOp forOp)
 
static Value replaceByPackingLoopNestResult (RewriterBase &rewriter, const IRMapping &bvm, tensor::PadOp opToHoist, RankedTensorType transposedTensorType, const HoistingAnalysis &analysis, const PackingLoopNestResult &packingResult)
 Produce a tensor extracted from the packingResult. More...
 

Macro Definition Documentation

◆ DBGS

#define DBGS ( )    (dbgs() << '[' << DEBUG_TYPE << "] ")

Definition at line 32 of file HoistPadding.cpp.

◆ DEBUG_TYPE

#define DEBUG_TYPE   "hoist-padding"

Definition at line 30 of file HoistPadding.cpp.

Function Documentation

◆ buildLoopIterationCount()

static Value buildLoopIterationCount ( RewriterBase rewriter,
scf::ForOp  outer,
scf::ForOp  forOp 
)
static

Return the current iteration number in the loop (iv - lb).ceilDiv(step).

The returned Value is guaranteed not to depend on any loop comprised in [outer, forOp]. Return null if such a loop-independent quantity cannot be computed.

Definition at line 410 of file HoistPadding.cpp.

References mlir::bindDims(), mlir::bindSymbols(), mlir::ceilDiv(), mlir::OpBuilder::createOrFold(), mlir::Value::getLoc(), and isDefinedOutsideOrConstant().

Referenced by buildPackingLoopNest(), and replaceByPackingLoopNestResult().

◆ buildPackingLoopNest()

static PackingLoopNestResult buildPackingLoopNest ( RewriterBase rewriter,
IRMapping bvm,
tensor::PadOp  opToHoist,
ArrayRef< int64_t >  transposeVector,
RankedTensorType  transposedTensorType,
tensor::EmptyOp  emptyOp,
const HoistingAnalysis analysis 
)
static

◆ computeBackwardSlice()

static void computeBackwardSlice ( tensor::PadOp  padOp,
scf::ForOp  outermostEnclosingForOp,
SetVector< Operation * > &  backwardSlice 
)
static

◆ debugPrintBackwardSlice()

static void debugPrintBackwardSlice ( SetVector< Operation * > &  backwardSlice)
static

Definition at line 50 of file HoistPadding.cpp.

References DBGS, and debugPrintLoopInShortForm().

Referenced by HoistingAnalysis::HoistingAnalysis().

◆ debugPrintLoopInShortForm()

static bool debugPrintLoopInShortForm ( Operation op)
static

◆ getAtMostNEnclosingLoops()

static void getAtMostNEnclosingLoops ( tensor::PadOp  padOp,
int  nLevels,
SmallVector< scf::ForOp > &  reverseEnclosingLoops 
)
static

Return at most nLevels of immediately enclosing scf::ForOp loops.

Stops at the first parent that is not an scf::ForOp. Multi-loops such as scf.parallel or linalg.tiled_loop are not modeled atm. Control-flow and other containing ops with regions are not modeled atm.

Definition at line 144 of file HoistPadding.cpp.

References DBGS, debugPrintLoopInShortForm(), and mlir::Operation::getParentOp().

Referenced by HoistingAnalysis::HoistingAnalysis().

◆ isDefinedOutsideOrConstant()

static bool isDefinedOutsideOrConstant ( scf::ForOp  outer,
Value  v 
)
static

Definition at line 402 of file HoistPadding.cpp.

References mlir::m_Constant(), and mlir::matchPattern().

Referenced by buildLoopIterationCount().

◆ padThroughLoopIterArg()

static Value padThroughLoopIterArg ( RewriterBase rewriter,
Value  packedTensor,
tensor::ExtractSliceOp  sliceOp,
scf::ForOp  forOp 
)
static

◆ replaceByPackingLoopNestResult()

static Value replaceByPackingLoopNestResult ( RewriterBase rewriter,
const IRMapping bvm,
tensor::PadOp  opToHoist,
RankedTensorType  transposedTensorType,
const HoistingAnalysis analysis,
const PackingLoopNestResult packingResult 
)
static