MLIR  19.0.0git
Public Member Functions | Public Attributes | List of all members
mlir::affine::MemRefRegion Struct Reference

A region of a memref's data space; this is typically constructed by analyzing load/store op's on this memref and the index space of loops surrounding such op's. More...

#include "mlir/Dialect/Affine/Analysis/Utils.h"

Public Member Functions

 MemRefRegion (Location loc)
 
LogicalResult compute (Operation *op, unsigned loopDepth, const ComputationSliceState *sliceState=nullptr, bool addMemRefDimBounds=true)
 Computes the memory region accessed by this memref with the region represented as constraints symbolic/parametric in 'loopDepth' loops surrounding opInst. More...
 
FlatAffineValueConstraintsgetConstraints ()
 
const FlatAffineValueConstraintsgetConstraints () const
 
bool isWrite () const
 
void setWrite (bool flag)
 
std::optional< int64_t > getConstantBoundingSizeAndShape (SmallVectorImpl< int64_t > *shape=nullptr, std::vector< SmallVector< int64_t, 4 >> *lbs=nullptr, SmallVectorImpl< int64_t > *lbDivisors=nullptr) const
 Returns a constant upper bound on the number of elements in this region if bounded by a known constant (always possible for static shapes), std::nullopt otherwise. More...
 
void getLowerAndUpperBound (unsigned pos, AffineMap &lbMap, AffineMap &ubMap) const
 Gets the lower and upper bound map for the dimensional variable at pos. More...
 
std::optional< int64_t > getConstantBoundOnDimSize (unsigned pos, SmallVectorImpl< int64_t > *lb=nullptr, int64_t *lbFloorDivisor=nullptr) const
 A wrapper around FlatAffineValueConstraints::getConstantBoundOnDimSize(). More...
 
std::optional< int64_t > getRegionSize ()
 Returns the size of this MemRefRegion in bytes. More...
 
LogicalResult unionBoundingBox (const MemRefRegion &other)
 
unsigned getRank () const
 Returns the rank of the memref that this region corresponds to. More...
 

Public Attributes

Value memref
 Memref that this region corresponds to. More...
 
bool write = false
 Read or write. More...
 
Location loc
 If there is more than one load/store op associated with the region, the location information would correspond to one of those op's. More...
 
FlatAffineValueConstraints cst
 Region (data space) of the memref accessed. More...
 

Detailed Description

A region of a memref's data space; this is typically constructed by analyzing load/store op's on this memref and the index space of loops surrounding such op's.

Definition at line 430 of file Utils.h.

Constructor & Destructor Documentation

◆ MemRefRegion()

mlir::affine::MemRefRegion::MemRefRegion ( Location  loc)
inlineexplicit

Definition at line 431 of file Utils.h.

Member Function Documentation

◆ compute()

LogicalResult MemRefRegion::compute ( Operation op,
unsigned  loopDepth,
const ComputationSliceState sliceState = nullptr,
bool  addMemRefDimBounds = true 
)

Computes the memory region accessed by this memref with the region represented as constraints symbolic/parametric in 'loopDepth' loops surrounding opInst.

Computes the memory region accessed by this memref with the region represented as constraints symbolic/parametric in 'loopDepth' loops surrounding opInst and any additional Function symbols.

The computed region's 'cst' field has exactly as many dimensional variables as the rank of the memref, and potentially additional symbolic variables which could include any of the loop IVs surrounding opInst up until 'loopDepth' and another additional Function symbols involved with the access (for eg., those appear in affine.apply's, loop bounds, etc.). If 'sliceState' is non-null, operands from 'sliceState' are added as symbols, and the following constraints are added to the system: *) Inequality constraints which represent loop bounds for 'sliceState' operands which are loop IVS (these represent the destination loop IVs of the slice, and are added as symbols to MemRefRegion's constraint system). *) Inequality constraints for the slice bounds in 'sliceState', which represent the bounds on the loop IVs in this constraint system w.r.t to slice operands (which correspond to symbols). If 'addMemRefDimBounds' is true, constant upper/lower bounds [0, memref.getDimSize(i)) are added for each MemRef dimension 'i'.

For example, the memref region for this operation at loopDepth = 1 will be:

affine.for i = 0 to 32 { affine.for ii = i to (d0) -> (d0 + 8) (i) { load A[ii] } }

{memref = A, write = false, {i <= m0 <= i + 7} } The last field is a 2-d FlatAffineValueConstraints symbolic in i.

Definition at line 1044 of file Utils.cpp.

Referenced by createPrivateMemRef(), and isFusionProfitable().

◆ getConstantBoundingSizeAndShape()

std::optional< int64_t > MemRefRegion::getConstantBoundingSizeAndShape ( SmallVectorImpl< int64_t > *  shape = nullptr,
std::vector< SmallVector< int64_t, 4 >> *  lbs = nullptr,
SmallVectorImpl< int64_t > *  lbDivisors = nullptr 
) const

Returns a constant upper bound on the number of elements in this region if bounded by a known constant (always possible for static shapes), std::nullopt otherwise.

Note that the symbols of the region are treated specially, i.e., the returned bounding constant holds for any given value of the symbol variables. The 'shape' vector is set to the corresponding dimension-wise bounds major to minor. The number of elements and all the dimension-wise bounds are guaranteed to be non-negative. We use int64_t instead of uint64_t since index types can be at most int64_t. lbs are set to the lower bounds for each of the rank dimensions, and lbDivisors contains the corresponding denominators for floorDivs.

Definition at line 942 of file Utils.cpp.

References mlir::affine::FlatAffineValueConstraints::addBound(), mlir::presburger::IntegerRelation::getConstantBoundOnDimSize64(), and mlir::presburger::IntegerRelation::getNumSymbolVars().

Referenced by createPrivateMemRef(), and generateCopy().

◆ getConstantBoundOnDimSize()

std::optional<int64_t> mlir::affine::MemRefRegion::getConstantBoundOnDimSize ( unsigned  pos,
SmallVectorImpl< int64_t > *  lb = nullptr,
int64_t *  lbFloorDivisor = nullptr 
) const
inline

A wrapper around FlatAffineValueConstraints::getConstantBoundOnDimSize().

'pos' corresponds to the position of the memref shape's dimension (major to minor) which matches 1:1 with the dimensional variable positions in 'cst'.

Definition at line 500 of file Utils.h.

References cst, mlir::presburger::IntegerRelation::getConstantBoundOnDimSize64(), and getRank().

◆ getConstraints() [1/2]

FlatAffineValueConstraints* mlir::affine::MemRefRegion::getConstraints ( )
inline

Definition at line 469 of file Utils.h.

References cst.

Referenced by createPrivateMemRef(), findHighestBlockForPlacement(), generateCopy(), and unionBoundingBox().

◆ getConstraints() [2/2]

const FlatAffineValueConstraints* mlir::affine::MemRefRegion::getConstraints ( ) const
inline

Definition at line 470 of file Utils.h.

References cst.

◆ getLowerAndUpperBound()

void MemRefRegion::getLowerAndUpperBound ( unsigned  pos,
AffineMap lbMap,
AffineMap ubMap 
) const

Gets the lower and upper bound map for the dimensional variable at pos.

Definition at line 1003 of file Utils.cpp.

References mlir::AffineMap::getNumInputs().

Referenced by generateCopy().

◆ getRank()

unsigned MemRefRegion::getRank ( ) const

Returns the rank of the memref that this region corresponds to.

Definition at line 938 of file Utils.cpp.

Referenced by getConstantBoundOnDimSize().

◆ getRegionSize()

std::optional< int64_t > MemRefRegion::getRegionSize ( )

Returns the size of this MemRefRegion in bytes.

Definition at line 1215 of file Utils.cpp.

References mlir::affine::getMemRefIntOrFloatEltSizeInBytes().

Referenced by isFusionProfitable().

◆ isWrite()

bool mlir::affine::MemRefRegion::isWrite ( ) const
inline

Definition at line 471 of file Utils.h.

References write.

Referenced by generateCopy().

◆ setWrite()

void mlir::affine::MemRefRegion::setWrite ( bool  flag)
inline

Definition at line 472 of file Utils.h.

References write.

◆ unionBoundingBox()

LogicalResult MemRefRegion::unionBoundingBox ( const MemRefRegion other)

Definition at line 1022 of file Utils.cpp.

References getConstraints(), and memref.

Member Data Documentation

◆ cst

FlatAffineValueConstraints mlir::affine::MemRefRegion::cst

Region (data space) of the memref accessed.

This set will thus have at least as many dimensional variables as the shape dimensionality of the memref, and these are the leading dimensions of the set appearing in that order (major to minor / outermost to innermost). There may be additional variables since getMemRefRegion() is called with a specific loop depth, and thus the region is symbolic in the outer surrounding loops at that depth.

Definition at line 533 of file Utils.h.

Referenced by getConstantBoundOnDimSize(), and getConstraints().

◆ loc

Location mlir::affine::MemRefRegion::loc

If there is more than one load/store op associated with the region, the location information would correspond to one of those op's.

Definition at line 524 of file Utils.h.

Referenced by generateCopy().

◆ memref

Value mlir::affine::MemRefRegion::memref

Memref that this region corresponds to.

Definition at line 517 of file Utils.h.

Referenced by generateCopy(), mlir::affine::generateCopyForMemRegion(), getMultiLevelStrides(), and unionBoundingBox().

◆ write

bool mlir::affine::MemRefRegion::write = false

Read or write.

Definition at line 520 of file Utils.h.

Referenced by isWrite(), and setWrite().


The documentation for this struct was generated from the following files: