MLIR 24.0.0git
LoopFusionUtils.cpp File Reference
#include "mlir/Dialect/Affine/LoopFusionUtils.h"
#include "mlir/Analysis/SliceAnalysis.h"
#include "mlir/Analysis/TopologicalSortUtils.h"
#include "mlir/Dialect/Affine/Analysis/AffineAnalysis.h"
#include "mlir/Dialect/Affine/Analysis/LoopAnalysis.h"
#include "mlir/Dialect/Affine/Analysis/Utils.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/LoopUtils.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/PatternMatch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugLog.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "affine-fusion-utils"

Functions

static void getLoadAndStoreMemRefAccesses (Operation *opA, DenseMap< Value, bool > &values)
static bool isDependentLoadOrStoreOp (Operation *op, DenseMap< Value, bool > &values)
 Returns true if 'op' is a load or store operation which access a memref accessed 'values' and at least one of the access is a store operation.
static Operation * getFirstDependentOpInRange (Operation *opA, Operation *opB)
static Operation * getLastDependentOpInRange (Operation *opA, Operation *opB)
static Operation * getFusedLoopNestInsertionPoint (AffineForOp srcForOp, AffineForOp dstForOp)
static bool gatherLoadsAndStores (AffineForOp forOp, SmallVectorImpl< Operation * > &loadAndStoreOps)
static unsigned getMaxLoopDepth (ArrayRef< Operation * > srcOps, ArrayRef< Operation * > dstOps)
 Returns the maximum loop depth at which we could fuse producer loop 'srcForOp' into consumer loop 'dstForOp' without violating data dependences.
static FusionResult computeSiblingSlice (ArrayRef< Operation * > opsA, ArrayRef< Operation * > opsB, Value memref, unsigned dstLoopDepth, unsigned numCommonLoops, bool isBackwardSlice, ComputationSliceState *srcSlice)
 Computes in 'srcSlice' the sibling fusion slice from a single pair of loads to 'memref' in 'opsA' and 'opsB', preferring a maximal one.
static LogicalResult promoteSingleIterReductionLoop (AffineForOp forOp, bool siblingFusionUser)
 Patch the loop body of a forOp that is a single iteration reduction loop into its containing block.
static int64_t getComputeCostHelper (Operation *forOp, LoopNestStats &stats, llvm::SmallDenseMap< Operation *, uint64_t, 8 > *tripCountOverrideMap, DenseMap< Operation *, int64_t > *computeCostMap)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "affine-fusion-utils"

Definition at line 29 of file LoopFusionUtils.cpp.

Function Documentation

◆ computeSiblingSlice()

FusionResult computeSiblingSlice ( ArrayRef< Operation * > opsA,
ArrayRef< Operation * > opsB,
Value memref,
unsigned dstLoopDepth,
unsigned numCommonLoops,
bool isBackwardSlice,
ComputationSliceState * srcSlice )
static

Computes in 'srcSlice' the sibling fusion slice from a single pair of loads to 'memref' in 'opsA' and 'opsB', preferring a maximal one.

Read-after-read pairs don't constrain legality, so the slices of all pairs aren't unioned.

Definition at line 248 of file LoopFusionUtils.cpp.

References b, mlir::affine::computeSliceUnion(), mlir::affine::FusionResult::FailIncorrectSlice, mlir::affine::FusionResult::FailPrecondition, mlir::affine::SliceComputationResult::IncorrectSliceFailure, load, result, slice(), mlir::affine::FusionResult::Success, and mlir::affine::SliceComputationResult::Success.

Referenced by mlir::affine::canFuseLoops().

◆ gatherLoadsAndStores()

bool gatherLoadsAndStores ( AffineForOp forOp,
SmallVectorImpl< Operation * > & loadAndStoreOps )
static

Definition at line 171 of file LoopFusionUtils.cpp.

Referenced by mlir::affine::canFuseLoops().

◆ getComputeCostHelper()

int64_t getComputeCostHelper ( Operation * forOp,
LoopNestStats & stats,
llvm::SmallDenseMap< Operation *, uint64_t, 8 > * tripCountOverrideMap,
DenseMap< Operation *, int64_t > * computeCostMap )
static

◆ getFirstDependentOpInRange()

Operation * getFirstDependentOpInRange ( Operation * opA,
Operation * opB )
static

◆ getFusedLoopNestInsertionPoint()

Operation * getFusedLoopNestInsertionPoint ( AffineForOp srcForOp,
AffineForOp dstForOp )
static

◆ getLastDependentOpInRange()

◆ getLoadAndStoreMemRefAccesses()

void getLoadAndStoreMemRefAccesses ( Operation * opA,
DenseMap< Value, bool > & values )
static

Definition at line 36 of file LoopFusionUtils.cpp.

References mlir::Operation::walk().

Referenced by getFirstDependentOpInRange(), and getLastDependentOpInRange().

◆ getMaxLoopDepth()

unsigned getMaxLoopDepth ( ArrayRef< Operation * > srcOps,
ArrayRef< Operation * > dstOps )
static

Returns the maximum loop depth at which we could fuse producer loop 'srcForOp' into consumer loop 'dstForOp' without violating data dependences.

Definition at line 187 of file LoopFusionUtils.cpp.

References mlir::affine::checkMemrefAccessDependence(), mlir::affine::gatherProducerConsumerMemrefs(), mlir::affine::getInnermostCommonLoopDepth(), mlir::affine::getNumCommonSurroundingLoops(), mlir::affine::hasDependence(), and result.

Referenced by mlir::affine::canFuseLoops().

◆ isDependentLoadOrStoreOp()

bool isDependentLoadOrStoreOp ( Operation * op,
DenseMap< Value, bool > & values )
static

Returns true if 'op' is a load or store operation which access a memref accessed 'values' and at least one of the access is a store operation.

Returns false otherwise.

Definition at line 51 of file LoopFusionUtils.cpp.

Referenced by getFirstDependentOpInRange(), and getLastDependentOpInRange().

◆ promoteSingleIterReductionLoop()

LogicalResult promoteSingleIterReductionLoop ( AffineForOp forOp,
bool siblingFusionUser )
static

Patch the loop body of a forOp that is a single iteration reduction loop into its containing block.

Definition at line 398 of file LoopFusionUtils.cpp.

References b, mlir::getForwardSlice(), success(), and mlir::topologicalSort().

Referenced by mlir::affine::fuseLoops().