MLIR  16.0.0git
Classes | Macros | Functions
LoopUtils.cpp File Reference
#include "mlir/Dialect/Affine/LoopUtils.h"
#include "mlir/Analysis/SliceAnalysis.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/IR/AffineValueMap.h"
#include "mlir/Dialect/Affine/Utils.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
+ Include dependency graph for LoopUtils.cpp:

Go to the source code of this file.

Classes

struct  JamBlockGatherer
 
struct  StrideInfo
 

Macros

#define DEBUG_TYPE   "LoopUtils"
 

Functions

static void getCleanupLoopLowerBound (AffineForOp forOp, unsigned unrollFactor, AffineMap &cleanupLbMap, SmallVectorImpl< Value > &cleanupLbOperands)
 Computes the cleanup loop lower bound of the loop being unrolled with the specified unroll factor; this bound will also be upper bound of the main part of the unrolled loop. More...
 
static void replaceIterArgsAndYieldResults (AffineForOp forOp)
 Helper to replace uses of loop carried values (iter_args) and loop yield values while promoting single iteration affine.for ops. More...
 
static AffineForOp generateShiftedLoop (AffineMap lbMap, AffineMap ubMap, const std::vector< std::pair< uint64_t, ArrayRef< Operation *>>> &opGroupQueue, unsigned offset, AffineForOp srcForOp, OpBuilder b)
 Generates an affine.for op with the specified lower and upper bounds while generating the right IV remappings to realize shifts for operations in its body. More...
 
static bool checkTilingLegalityImpl (MutableArrayRef< mlir::AffineForOp > origLoops)
 Checks the legality of tiling of a hyper-rectangular loop nest by simply checking if there is a 'negative' dependence in the memrefs present in the loop nest. More...
 
LogicalResult checkTilingLegality (MutableArrayRef< mlir::AffineForOp > origLoops)
 Checks whether hyper-rectangular loop tiling of the nest represented by origLoops is valid. More...
 
LogicalResult checkIfHyperRectangular (MutableArrayRef< AffineForOp > input)
 Checks whether a loop nest is hyper-rectangular or not. More...
 
template<typename t >
LogicalResult performPreTilingChecks (MutableArrayRef< AffineForOp > input, ArrayRef< t > tileSizes)
 Check if the input nest is supported for tiling and whether tiling would be legal or not. More...
 
static void moveLoopBodyImpl (AffineForOp src, AffineForOp dest, Block::iterator loc)
 Move the loop body of AffineForOp 'src' from 'src' into the specified location in destination's body, ignoring the terminator. More...
 
void moveLoopBody (AffineForOp src, AffineForOp dest)
 Move the loop body of AffineForOp 'src' from 'src' to the start of dest body. More...
 
void constructTiledLoopNest (MutableArrayRef< AffineForOp > origLoops, AffineForOp rootAffineForOp, unsigned width, MutableArrayRef< AffineForOp > tiledLoops)
 Constructs tiled loop nest, without setting the loop bounds and move the body of the original loop nest to the tiled loop nest. More...
 
static void setIntraTileBoundsParametric (OpBuilder &b, AffineForOp origLoop, AffineForOp newInterTileLoop, AffineForOp newIntraTileLoop, Value tileSize)
 Set lower and upper bounds of intra-tile loops for parametric tiling. More...
 
static void setInterTileBoundsParametric (OpBuilder &b, AffineForOp origLoop, AffineForOp newLoop, Value tileSize)
 Set lower and upper bounds of inter-tile loops for parametric tiling. More...
 
static void constructParametricallyTiledIndexSetHyperRect (MutableArrayRef< AffineForOp > origLoops, MutableArrayRef< AffineForOp > newLoops, ArrayRef< Value > tileSizes)
 Constructs and sets new loop bounds after tiling for the case of hyper-rectangular index sets, where the bounds of one dimension do not depend on other dimensions and tiling parameters are captured from SSA values. More...
 
static void constructTiledIndexSetHyperRect (MutableArrayRef< AffineForOp > origLoops, MutableArrayRef< AffineForOp > newLoops, ArrayRef< unsigned > tileSizes)
 Constructs and sets new loop bounds after tiling for the case of hyper-rectangular index sets, where the bounds of one dimension do not depend on other dimensions. More...
 
static void generateUnrolledLoop (Block *loopBodyBlock, Value forOpIV, uint64_t unrollFactor, function_ref< Value(unsigned, Value, OpBuilder)> ivRemapFn, function_ref< void(unsigned, Operation *, OpBuilder)> annotateFn, ValueRange iterArgs, ValueRange yieldedValues)
 Generates unrolled copies of AffineForOp 'loopBodyBlock', with associated 'forOpIV' by 'unrollFactor', calling 'ivRemapFn' to remap 'forOpIV' for each unrolled body. More...
 
static LogicalResult generateCleanupLoopForUnroll (AffineForOp forOp, uint64_t unrollFactor)
 Helper to generate cleanup loop for unroll or unroll-and-jam when the trip count is not a multiple of unrollFactor. More...
 
static bool areInnerBoundsInvariant (AffineForOp forOp)
 Check if all control operands of all loops are defined outside of forOp and return false if not. More...
 
static bool checkLoopInterchangeDependences (const std::vector< SmallVector< DependenceComponent, 2 >> &depCompsVec, ArrayRef< AffineForOp > loops, ArrayRef< unsigned > loopPermMap)
 
static void augmentMapAndBounds (OpBuilder &b, Value iv, AffineMap *map, SmallVector< Value, 4 > *operands, int64_t offset=0)
 
static SmallVector< AffineForOp, 8 > stripmineSink (AffineForOp forOp, uint64_t factor, ArrayRef< AffineForOp > targets)
 
template<typename SizeType >
static AffineForOp stripmineSink (AffineForOp forOp, SizeType factor, AffineForOp target)
 
static void findHighestBlockForPlacement (const MemRefRegion &region, Block &block, Block::iterator &begin, Block::iterator &end, Block **copyPlacementBlock, Block::iterator *copyInPlacementStart, Block::iterator *copyOutPlacementStart)
 Given a memref region, determine the lowest depth at which transfers can be placed for it, and return the corresponding block, start and end positions in the block for placing incoming (read) and outgoing (write) copies respectively. More...
 
static void getMultiLevelStrides (const MemRefRegion &region, ArrayRef< int64_t > bufferShape, SmallVectorImpl< StrideInfo > *strideInfos)
 Returns striding information for a copy/transfer of this region with potentially multiple striding levels from outermost to innermost. More...
 
static AffineForOp generatePointWiseCopy (Location loc, Value memref, Value fastMemRef, ArrayRef< AffineMap > lbMaps, ArrayRef< Value > lbOperands, ArrayRef< AffineMap > ubMaps, ArrayRef< Value > ubOperands, ArrayRef< AffineExpr > fastBufOffsets, bool isCopyOut, OpBuilder b)
 Generates a point-wise copy from/to `memref' to/from `fastMemRef' and returns the outermost AffineForOp of the copy loop nest. More...
 
static InFlightDiagnostic LLVM_ATTRIBUTE_UNUSED emitRemarkForBlock (Block &block)
 
static LogicalResult generateCopy (const MemRefRegion &region, Block *block, Block::iterator begin, Block::iterator end, Block *copyPlacementBlock, Block::iterator copyInPlacementStart, Block::iterator copyOutPlacementStart, AffineCopyOptions copyOptions, DenseMap< Value, Value > &fastBufferMap, DenseSet< Operation *> &copyNests, uint64_t *sizeInBytes, Block::iterator *nBegin, Block::iterator *nEnd)
 Creates a buffer in the faster memory space for the specified memref region; generates a copy from the lower memory space to this one, and replaces all loads/stores in the block range [`begin', `end') of `block' to load/store from that buffer. More...
 
static bool getFullMemRefAsRegion (Operation *op, unsigned numParamLoopIVs, MemRefRegion *region)
 Construct the memref region to just include the entire memref. More...
 
static void gatherLoopsInBlock (Block *block, unsigned currLoopDepth, std::vector< SmallVector< AffineForOp, 2 >> &depthToLoops)
 Gathers all AffineForOps in 'block' at 'currLoopDepth' in 'depthToLoops'. More...
 
static AffineIfOp createSeparationCondition (MutableArrayRef< AffineForOp > loops, OpBuilder b)
 Creates an AffineIfOp that encodes the conditional to choose between the constant trip count version and an unknown trip count version of this nest of loops. More...
 
static LogicalResult createFullTiles (MutableArrayRef< AffineForOp > inputNest, SmallVectorImpl< AffineForOp > &fullTileLoops, OpBuilder b)
 Create the full tile loop nest (along with its body). More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "LoopUtils"

Definition at line 34 of file LoopUtils.cpp.

Function Documentation

◆ areInnerBoundsInvariant()

static bool areInnerBoundsInvariant ( AffineForOp  forOp)
static

Check if all control operands of all loops are defined outside of forOp and return false if not.

Definition at line 1160 of file LoopUtils.cpp.

References mlir::WalkResult::advance(), and mlir::WalkResult::interrupt().

Referenced by mlir::loopUnrollJamByFactor().

◆ augmentMapAndBounds()

static void augmentMapAndBounds ( OpBuilder b,
Value  iv,
AffineMap map,
SmallVector< Value, 4 > *  operands,
int64_t  offset = 0 
)
static

◆ checkIfHyperRectangular()

LogicalResult checkIfHyperRectangular ( MutableArrayRef< AffineForOp >  input)

Checks whether a loop nest is hyper-rectangular or not.

Definition at line 441 of file LoopUtils.cpp.

References mlir::failed(), mlir::failure(), mlir::getIndexSet(), mlir::presburger::IntegerRelation::isHyperRectangular(), and mlir::success().

Referenced by performPreTilingChecks().

◆ checkLoopInterchangeDependences()

static bool checkLoopInterchangeDependences ( const std::vector< SmallVector< DependenceComponent, 2 >> &  depCompsVec,
ArrayRef< AffineForOp >  loops,
ArrayRef< unsigned loopPermMap 
)
static

◆ checkTilingLegality()

LogicalResult checkTilingLegality ( MutableArrayRef< mlir::AffineForOp >  origLoops)

Checks whether hyper-rectangular loop tiling of the nest represented by origLoops is valid.

The validity condition is from Irigoin and Triolet, which states that two tiles cannot depend on each other. We simplify such condition to just checking whether there is any negative dependence direction, since we have the prior knowledge that the tiling results will be hyper-rectangles, which are scheduled in the lexicographically increasing order on the vector of loop indices. This function will return failure when any dependence component is negative along any of origLoops.

Definition at line 436 of file LoopUtils.cpp.

References checkTilingLegalityImpl(), and mlir::success().

Referenced by performPreTilingChecks().

◆ checkTilingLegalityImpl()

static bool checkTilingLegalityImpl ( MutableArrayRef< mlir::AffineForOp >  origLoops)
static

Checks the legality of tiling of a hyper-rectangular loop nest by simply checking if there is a 'negative' dependence in the memrefs present in the loop nest.

If yes then tiling is invalid.

Definition at line 367 of file LoopUtils.cpp.

References mlir::checkMemrefAccessDependence(), mlir::Operation::dump(), mlir::hasDependence(), mlir::DependenceComponent::lb, mlir::MemRefAccess::opInst, mlir::FlatAffineValueConstraints::reset(), and mlir::DependenceComponent::ub.

Referenced by checkTilingLegality().

◆ constructParametricallyTiledIndexSetHyperRect()

static void constructParametricallyTiledIndexSetHyperRect ( MutableArrayRef< AffineForOp >  origLoops,
MutableArrayRef< AffineForOp >  newLoops,
ArrayRef< Value tileSizes 
)
static

Constructs and sets new loop bounds after tiling for the case of hyper-rectangular index sets, where the bounds of one dimension do not depend on other dimensions and tiling parameters are captured from SSA values.

Bounds of each dimension can thus be treated independently, and deriving the new bounds is much simpler and faster than for the case of tiling arbitrary polyhedral shapes.

Definition at line 745 of file LoopUtils.cpp.

References setInterTileBoundsParametric(), and setIntraTileBoundsParametric().

Referenced by mlir::tilePerfectlyNestedParametric().

◆ constructTiledIndexSetHyperRect()

static void constructTiledIndexSetHyperRect ( MutableArrayRef< AffineForOp >  origLoops,
MutableArrayRef< AffineForOp >  newLoops,
ArrayRef< unsigned tileSizes 
)
static

Constructs and sets new loop bounds after tiling for the case of hyper-rectangular index sets, where the bounds of one dimension do not depend on other dimensions.

Bounds of each dimension can thus be treated independently, and deriving the new bounds is much simpler and faster than for the case of tiling arbitrary polyhedral shapes.

Definition at line 773 of file LoopUtils.cpp.

References mlir::AffineMap::get(), mlir::getConstantTripCount(), mlir::getLargestDivisorOfTripCount(), mlir::AffineBound::getMap(), mlir::AffineMap::getNumDims(), mlir::AffineBound::getNumOperands(), mlir::AffineMap::getNumResults(), mlir::AffineMap::getNumSymbols(), mlir::AffineBound::getOperand(), and mlir::AffineMap::getResults().

Referenced by mlir::tilePerfectlyNested().

◆ constructTiledLoopNest()

void constructTiledLoopNest ( MutableArrayRef< AffineForOp >  origLoops,
AffineForOp  rootAffineForOp,
unsigned  width,
MutableArrayRef< AffineForOp >  tiledLoops 
)

Constructs tiled loop nest, without setting the loop bounds and move the body of the original loop nest to the tiled loop nest.

Definition at line 508 of file LoopUtils.cpp.

References mlir::OpBuilder::create(), mlir::Operation::getBlock(), mlir::Block::getOperations(), and moveLoopBody().

Referenced by mlir::tilePerfectlyNested(), and mlir::tilePerfectlyNestedParametric().

◆ createFullTiles()

static LogicalResult createFullTiles ( MutableArrayRef< AffineForOp >  inputNest,
SmallVectorImpl< AffineForOp > &  fullTileLoops,
OpBuilder  b 
)
static

◆ createSeparationCondition()

static AffineIfOp createSeparationCondition ( MutableArrayRef< AffineForOp >  loops,
OpBuilder  b 
)
static

◆ emitRemarkForBlock()

static InFlightDiagnostic LLVM_ATTRIBUTE_UNUSED emitRemarkForBlock ( Block block)
static

Definition at line 2020 of file LoopUtils.cpp.

References mlir::Operation::emitRemark(), and mlir::Block::getParentOp().

Referenced by generateCopy().

◆ findHighestBlockForPlacement()

static void findHighestBlockForPlacement ( const MemRefRegion region,
Block block,
Block::iterator begin,
Block::iterator end,
Block **  copyPlacementBlock,
Block::iterator copyInPlacementStart,
Block::iterator copyOutPlacementStart 
)
static

Given a memref region, determine the lowest depth at which transfers can be placed for it, and return the corresponding block, start and end positions in the block for placing incoming (read) and outgoing (write) copies respectively.

The lowest depth depends on whether the region being accessed is hoistable with respect to one or more immediately surrounding loops.

Definition at line 1868 of file LoopUtils.cpp.

References mlir::Block::begin(), mlir::MemRefRegion::getConstraints(), and mlir::getLoopIVs().

Referenced by mlir::affineDataCopyGenerate().

◆ gatherLoopsInBlock()

static void gatherLoopsInBlock ( Block block,
unsigned  currLoopDepth,
std::vector< SmallVector< AffineForOp, 2 >> &  depthToLoops 
)
static

Gathers all AffineForOps in 'block' at 'currLoopDepth' in 'depthToLoops'.

Definition at line 2595 of file LoopUtils.cpp.

Referenced by mlir::gatherLoops().

◆ generateCleanupLoopForUnroll()

static LogicalResult generateCleanupLoopForUnroll ( AffineForOp  forOp,
uint64_t  unrollFactor 
)
static

Helper to generate cleanup loop for unroll or unroll-and-jam when the trip count is not a multiple of unrollFactor.

Definition at line 1056 of file LoopUtils.cpp.

References mlir::failure(), getCleanupLoopLowerBound(), mlir::promoteIfSingleIteration(), and mlir::success().

Referenced by mlir::loopUnrollByFactor(), and mlir::loopUnrollJamByFactor().

◆ generateCopy()

static LogicalResult generateCopy ( const MemRefRegion region,
Block block,
Block::iterator  begin,
Block::iterator  end,
Block copyPlacementBlock,
Block::iterator  copyInPlacementStart,
Block::iterator  copyOutPlacementStart,
AffineCopyOptions  copyOptions,
DenseMap< Value, Value > &  fastBufferMap,
DenseSet< Operation *> &  copyNests,
uint64_t *  sizeInBytes,
Block::iterator nBegin,
Block::iterator nEnd 
)
static

Creates a buffer in the faster memory space for the specified memref region; generates a copy from the lower memory space to this one, and replaces all loads/stores in the block range [`begin', `end') of `block' to load/store from that buffer.

Returns failure if copies could not be generated due to yet unimplemented cases. copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock specify the insertion points where the incoming copies and outgoing copies, respectively, should be inserted (the insertion happens right before the insertion point). Since begin can itself be invalidated due to the memref rewriting done from this method, the output argument nBegin is set to its replacement (set to begin if no invalidation happens). Since outgoing copies could have been inserted at end, the output argument nEnd is set to the new end. sizeInBytes is set to the size of the fast buffer allocated.

Definition at line 2037 of file LoopUtils.cpp.

References mlir::Block::begin(), mlir::Type::cast(), mlir::OpBuilder::create(), emitRemarkForBlock(), mlir::failure(), mlir::AffineCopyOptions::fastMemorySpace, mlir::presburger::floorDiv(), mlir::fullyComposeAffineMapAndOperands(), mlir::AffineCopyOptions::generateDma, generatePointWiseCopy(), mlir::AffineMap::get(), mlir::Builder::getAffineDimExpr(), mlir::MemRefRegion::getConstantBoundingSizeAndShape(), mlir::MemRefRegion::getConstraints(), mlir::Builder::getContext(), mlir::MemRefRegion::getLowerAndUpperBound(), mlir::getMemRefSizeInBytes(), mlir::Builder::getMultiDimIdentityMap(), getMultiLevelStrides(), mlir::presburger::IntegerRelation::getNumCols(), mlir::presburger::IntegerRelation::getNumDimVars(), mlir::presburger::IntegerRelation::getNumSymbolVars(), mlir::presburger::IntegerRelation::getNumVars(), mlir::OpState::getOperation(), mlir::Block::getParent(), mlir::Region::getParentOfType(), mlir::Value::getType(), mlir::FlatAffineValueConstraints::getValues(), mlir::MemRefRegion::isWrite(), mlir::MemRefRegion::loc, mlir::MemRefRegion::memref, mlir::replaceAllMemRefUsesWith(), mlir::success(), and mlir::AffineCopyOptions::tagMemorySpace.

Referenced by mlir::affineDataCopyGenerate(), and mlir::generateCopyForMemRegion().

◆ generatePointWiseCopy()

static AffineForOp generatePointWiseCopy ( Location  loc,
Value  memref,
Value  fastMemRef,
ArrayRef< AffineMap lbMaps,
ArrayRef< Value lbOperands,
ArrayRef< AffineMap ubMaps,
ArrayRef< Value ubOperands,
ArrayRef< AffineExpr fastBufOffsets,
bool  isCopyOut,
OpBuilder  b 
)
static

Generates a point-wise copy from/to `memref' to/from `fastMemRef' and returns the outermost AffineForOp of the copy loop nest.

lbMaps and ubMaps along with lbOperands and ubOperands hold the lower and upper bound information for the copy loop nest. fastBufOffsets contain the expressions to be subtracted out from the respective copy loop iterators in order to index the fast buffer. If `copyOut' is true, generates a copy-out; otherwise a copy-in. Builder b should be set to the point the copy nest is inserted. The copy-in nest is generated as follows as an example for a 2-d region: for x = ... for y = ... fast_buf[x - offset_x][y - offset_y] = memref[x][y]

Definition at line 1948 of file LoopUtils.cpp.

References mlir::OpBuilder::atBlockTerminator(), mlir::canonicalizeMapAndOperands(), mlir::Type::cast(), mlir::OpBuilder::create(), mlir::createCanonicalizedAffineForOp(), mlir::fullyComposeAffineMapAndOperands(), mlir::AffineMap::get(), mlir::Builder::getAffineDimExpr(), mlir::Builder::getContext(), mlir::AffineMap::getNumInputs(), mlir::Value::getType(), and mlir::simplifyAffineMap().

Referenced by generateCopy().

◆ generateShiftedLoop()

static AffineForOp generateShiftedLoop ( AffineMap  lbMap,
AffineMap  ubMap,
const std::vector< std::pair< uint64_t, ArrayRef< Operation *>>> &  opGroupQueue,
unsigned  offset,
AffineForOp  srcForOp,
OpBuilder  b 
)
static

Generates an affine.for op with the specified lower and upper bounds while generating the right IV remappings to realize shifts for operations in its body.

The operations that go into the loop body are specified in opGroupQueue starting from the specified offset, and in that order. The first element of the pair specifies the shift applied to that group of operations; the shift is multiplied by the loop step before being applied. Returns nullptr if the generated loop simplifies to a single iteration one.

Definition at line 181 of file LoopUtils.cpp.

References mlir::OpBuilder::atBlockTerminator(), mlir::OpBuilder::create(), mlir::AffineMap::getNumInputs(), mlir::BlockAndValueMapping::map(), mlir::promoteIfSingleIteration(), and mlir::succeeded().

◆ generateUnrolledLoop()

static void generateUnrolledLoop ( Block loopBodyBlock,
Value  forOpIV,
uint64_t  unrollFactor,
function_ref< Value(unsigned, Value, OpBuilder)>  ivRemapFn,
function_ref< void(unsigned, Operation *, OpBuilder)>  annotateFn,
ValueRange  iterArgs,
ValueRange  yieldedValues 
)
static

Generates unrolled copies of AffineForOp 'loopBodyBlock', with associated 'forOpIV' by 'unrollFactor', calling 'ivRemapFn' to remap 'forOpIV' for each unrolled body.

If specified, annotates the Ops in each unrolled iteration using annotateFn.

Definition at line 1002 of file LoopUtils.cpp.

References mlir::OpBuilder::atBlockTerminator(), mlir::Block::begin(), mlir::Block::end(), mlir::Block::getTerminator(), mlir::BlockAndValueMapping::lookup(), mlir::BlockAndValueMapping::map(), mlir::Operation::setOperands(), and mlir::Value::use_empty().

Referenced by mlir::loopUnrollByFactor().

◆ getCleanupLoopLowerBound()

static void getCleanupLoopLowerBound ( AffineForOp  forOp,
unsigned  unrollFactor,
AffineMap cleanupLbMap,
SmallVectorImpl< Value > &  cleanupLbOperands 
)
static

Computes the cleanup loop lower bound of the loop being unrolled with the specified unroll factor; this bound will also be upper bound of the main part of the unrolled loop.

Computes the bound as an AffineMap with its operands or a null map when the trip count can't be expressed as an affine expression.

Definition at line 56 of file LoopUtils.cpp.

References mlir::canonicalizeMapAndOperands(), mlir::OpBuilder::create(), mlir::fullyComposeAffineMapAndOperands(), mlir::AffineMap::get(), mlir::Builder::getAffineDimExpr(), mlir::Builder::getContext(), mlir::AffineMap::getNumDims(), mlir::AffineMap::getNumResults(), mlir::AffineMap::getNumSymbols(), mlir::AffineMap::getResult(), mlir::getTripCountMapAndOperands(), and mlir::simplifyAffineMap().

Referenced by generateCleanupLoopForUnroll().

◆ getFullMemRefAsRegion()

static bool getFullMemRefAsRegion ( Operation op,
unsigned  numParamLoopIVs,
MemRefRegion region 
)
static

Construct the memref region to just include the entire memref.

Returns false dynamic shaped memref's for now. numParamLoopIVs is the number of enclosing loop IVs of op (starting from the outermost) that the region is parametric on.

Definition at line 2327 of file LoopUtils.cpp.

References mlir::Type::cast(), mlir::extractForInductionVars(), mlir::MemRefRegion::getConstraints(), mlir::getLoopIVs(), mlir::Value::getType(), mlir::presburger::IntegerRelation::LB, mlir::MemRefRegion::memref, mlir::MemRefRegion::setWrite(), and mlir::presburger::IntegerRelation::UB.

Referenced by mlir::affineDataCopyGenerate().

◆ getMultiLevelStrides()

static void getMultiLevelStrides ( const MemRefRegion region,
ArrayRef< int64_t >  bufferShape,
SmallVectorImpl< StrideInfo > *  strideInfos 
)
static

Returns striding information for a copy/transfer of this region with potentially multiple striding levels from outermost to innermost.

For an n-dimensional region, there can be at most n-1 levels of striding successively nested.

Definition at line 1912 of file LoopUtils.cpp.

References mlir::Type::cast(), mlir::Value::getType(), and mlir::MemRefRegion::memref.

Referenced by generateCopy().

◆ moveLoopBody()

void moveLoopBody ( AffineForOp  src,
AffineForOp  dest 
)

Move the loop body of AffineForOp 'src' from 'src' to the start of dest body.

Definition at line 502 of file LoopUtils.cpp.

References moveLoopBodyImpl().

Referenced by constructTiledLoopNest().

◆ moveLoopBodyImpl()

static void moveLoopBodyImpl ( AffineForOp  src,
AffineForOp  dest,
Block::iterator  loc 
)
static

Move the loop body of AffineForOp 'src' from 'src' into the specified location in destination's body, ignoring the terminator.

Definition at line 493 of file LoopUtils.cpp.

Referenced by moveLoopBody().

◆ performPreTilingChecks()

template<typename t >
LogicalResult performPreTilingChecks ( MutableArrayRef< AffineForOp >  input,
ArrayRef< t >  tileSizes 
)

Check if the input nest is supported for tiling and whether tiling would be legal or not.

Definition at line 462 of file LoopUtils.cpp.

References checkIfHyperRectangular(), checkTilingLegality(), mlir::failed(), mlir::failure(), mlir::isPerfectlyNested(), and mlir::success().

Referenced by mlir::tilePerfectlyNested(), and mlir::tilePerfectlyNestedParametric().

◆ replaceIterArgsAndYieldResults()

static void replaceIterArgsAndYieldResults ( AffineForOp  forOp)
static

Helper to replace uses of loop carried values (iter_args) and loop yield values while promoting single iteration affine.for ops.

Definition at line 114 of file LoopUtils.cpp.

Referenced by mlir::promoteIfSingleIteration().

◆ setInterTileBoundsParametric()

static void setInterTileBoundsParametric ( OpBuilder b,
AffineForOp  origLoop,
AffineForOp  newLoop,
Value  tileSize 
)
static

◆ setIntraTileBoundsParametric()

static void setIntraTileBoundsParametric ( OpBuilder b,
AffineForOp  origLoop,
AffineForOp  newInterTileLoop,
AffineForOp  newIntraTileLoop,
Value  tileSize 
)
static

◆ stripmineSink() [1/2]

static SmallVector<AffineForOp, 8> stripmineSink ( AffineForOp  forOp,
uint64_t  factor,
ArrayRef< AffineForOp >  targets 
)
static

◆ stripmineSink() [2/2]

template<typename SizeType >
static AffineForOp stripmineSink ( AffineForOp  forOp,
SizeType  factor,
AffineForOp  target 
)
static

Definition at line 1680 of file LoopUtils.cpp.