MLIR  20.0.0git
Classes | Macros | Functions
AffineOps.cpp File Reference
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/IR/AffineValueMap.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/UB/IR/UBOps.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/AffineExprVisitor.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/ShapedOpInterfaces.h"
#include "mlir/Interfaces/ValueBoundsOpInterface.h"
#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallVectorExtras.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include <numeric>
#include <optional>
#include "mlir/Dialect/Affine/IR/AffineOpsDialect.cpp.inc"
#include "mlir/Dialect/Affine/IR/AffineOps.cpp.inc"

Go to the source code of this file.

Classes

struct  DeduplicateAffineMinMaxExpressions< T >
 Remove duplicated expressions in affine min/max ops. More...
 
struct  MergeAffineMinMaxOp< T >
 Merge an affine min/max op to its consumers if its consumer is also an affine min/max op. More...
 
struct  CanonicalizeAffineMinMaxOpExprAndTermOrder< T >
 Canonicalize the affine map result expression order of an affine min/max operation. More...
 
struct  CanonicalizeSingleResultAffineMinMaxOp< T >
 

Macros

#define DEBUG_TYPE   "affine-ops"
 
#define GET_OP_LIST
 
#define GET_OP_CLASSES
 

Functions

static bool remainsLegalAfterInline (Value value, Region *src, Region *dest, const IRMapping &mapping, function_ref< bool(Value, Region *)> legalityCheck)
 Checks if value known to be a legal affine dimension or symbol in src region remains legal if the operation that uses it is inlined into dest with the given value mapping. More...
 
static bool remainsLegalAfterInline (ValueRange values, Region *src, Region *dest, const IRMapping &mapping, function_ref< bool(Value, Region *)> legalityCheck)
 Checks if all values known to be legal affine dimensions or symbols in src remain so if their respective users are inlined into dest. More...
 
template<typename OpTy >
static bool remainsLegalAfterInline (OpTy op, Region *src, Region *dest, const IRMapping &mapping)
 Checks if an affine read or write operation remains legal after inlining from src to dest. More...
 
template<>
bool LLVM_ATTRIBUTE_UNUSED remainsLegalAfterInline (AffineApplyOp op, Region *src, Region *dest, const IRMapping &mapping)
 Checks if an affine apply operation remains legal after inlining from src to dest. More...
 
template<typename AnyMemRefDefOp >
static bool isMemRefSizeValidSymbol (AnyMemRefDefOp memrefDefOp, unsigned index, Region *region)
 Returns true if the 'index' dimension of the memref defined by memrefDefOp is a statically shaped one or defined using a valid symbol for region. More...
 
static bool isDimOpValidSymbol (ShapedDimOpInterface dimOp, Region *region)
 Returns true if the result of the dim op is a valid symbol for region. More...
 
static bool isValidAffineIndexOperand (Value value, Region *region)
 
static void printDimAndSymbolList (Operation::operand_iterator begin, Operation::operand_iterator end, unsigned numDims, OpAsmPrinter &printer)
 Prints dimension and symbol list. More...
 
template<typename OpTy >
static LogicalResult verifyDimAndSymbolIdentifiers (OpTy &op, Operation::operand_range operands, unsigned numDims)
 Utility function to verify that a set of operands are valid dimension and symbol identifiers. More...
 
static int64_t getLargestKnownDivisor (AffineExpr e, ArrayRef< Value > operands)
 Returns the largest known divisor of e. More...
 
static bool isNonNegativeBoundedBy (AffineExpr e, ArrayRef< Value > operands, int64_t k)
 Check if e is known to be: 0 <= e < k. More...
 
static bool isQTimesDPlusR (AffineExpr e, ArrayRef< Value > operands, int64_t &div, AffineExpr &quotientTimesDiv, AffineExpr &rem)
 Check if expression e is of the form d*e_1 + e_2 where 0 <= e_2 < d. More...
 
static std::optional< int64_t > getLowerBound (Value iv)
 Gets the constant lower bound on an iv. More...
 
static std::optional< int64_t > getUpperBound (Value iv)
 Gets the constant upper bound on an affine.for iv. More...
 
static std::optional< int64_t > getUpperBound (AffineExpr expr, unsigned numDims, unsigned numSymbols, ArrayRef< Value > operands)
 Determine a constant upper bound for expr if one exists while exploiting values in operands. More...
 
static std::optional< int64_t > getLowerBound (AffineExpr expr, unsigned numDims, unsigned numSymbols, ArrayRef< Value > operands)
 Determine a constant lower bound for expr if one exists while exploiting values in operands. More...
 
static void simplifyExprAndOperands (AffineExpr &expr, unsigned numDims, unsigned numSymbols, ArrayRef< Value > operands)
 Simplify expr while exploiting information from the values in operands. More...
 
static void simplifyMinOrMaxExprWithOperands (AffineMap &map, ArrayRef< Value > operands, bool isMax)
 Simplify the expressions in map while making use of lower or upper bounds of its operands. More...
 
static void LLVM_ATTRIBUTE_UNUSED simplifyMapWithOperands (AffineMap &map, ArrayRef< Value > operands)
 Simplify the map while exploiting information on the values in operands. More...
 
static LogicalResult replaceDimOrSym (AffineMap *map, unsigned dimOrSymbolPosition, SmallVectorImpl< Value > &dims, SmallVectorImpl< Value > &syms)
 Replace all occurrences of AffineExpr at position pos in map by the defining AffineApplyOp expression and operands. More...
 
static void composeAffineMapAndOperands (AffineMap *map, SmallVectorImpl< Value > *operands)
 Iterate over operands and fold away all those produced by an AffineApplyOp iteratively. More...
 
static void composeMultiResultAffineMap (AffineMap &map, SmallVectorImpl< Value > &operands)
 Composes the given affine map with the given list of operands, pulling in the maps from any affine.apply operations that supply the operands. More...
 
template<typename OpTy >
static OpTy makeComposedMinMax (OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
 
template<typename OpTy >
static OpFoldResult makeComposedFoldedMinMax (OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
 
template<class MapOrSet >
static void canonicalizePromotedSymbols (MapOrSet *mapOrSet, SmallVectorImpl< Value > *operands)
 
template<class MapOrSet >
static void canonicalizeMapOrSetAndOperands (MapOrSet *mapOrSet, SmallVectorImpl< Value > *operands)
 
static ParseResult parseBound (bool isLower, OperationState &result, OpAsmParser &p)
 Parse a for operation loop bounds. More...
 
static void printBound (AffineMapAttr boundMap, Operation::operand_range boundOperands, const char *prefix, OpAsmPrinter &p)
 
static LogicalResult foldLoopBounds (AffineForOp forOp)
 Fold the constant bounds of a loop. More...
 
static LogicalResult canonicalizeLoopBounds (AffineForOp forOp)
 Canonicalize the bounds of the given loop. More...
 
static bool hasTrivialZeroTripCount (AffineForOp op)
 Returns true if the affine.for has zero iterations in trivial cases. More...
 
template<typename BoundListTy , typename LoopCreatorTy >
static void buildAffineLoopNestImpl (OpBuilder &builder, Location loc, BoundListTy lbs, BoundListTy ubs, ArrayRef< int64_t > steps, function_ref< void(OpBuilder &, Location, ValueRange)> bodyBuilderFn, LoopCreatorTy &&loopCreatorFn)
 Builds an affine loop nest, using "loopCreatorFn" to create individual loop operations. More...
 
static AffineForOp buildAffineLoopFromConstants (OpBuilder &builder, Location loc, int64_t lb, int64_t ub, int64_t step, AffineForOp::BodyBuilderFn bodyBuilderFn)
 Creates an affine loop from the bounds known to be constants. More...
 
static AffineForOp buildAffineLoopFromValues (OpBuilder &builder, Location loc, Value lb, Value ub, int64_t step, AffineForOp::BodyBuilderFn bodyBuilderFn)
 Creates an affine loop from the bounds that may or may not be constants. More...
 
static void composeSetAndOperands (IntegerSet &set, SmallVectorImpl< Value > &operands)
 Compose any affine.apply ops feeding into operands of the integer set set by composing the maps of such affine.apply ops with the integer set constraints. More...
 
static LogicalResult verifyMemoryOpIndexing (Operation *op, AffineMapAttr mapAttr, Operation::operand_range mapOperands, MemRefType memrefType, unsigned numIndexOperands)
 Verify common indexing invariants of affine.load, affine.store, affine.vector_load and affine.vector_store. More...
 
template<typename T >
static LogicalResult verifyAffineMinMaxOp (T op)
 
template<typename T >
static void printAffineMinMaxOp (OpAsmPrinter &p, T op)
 
template<typename T >
static ParseResult parseAffineMinMaxOp (OpAsmParser &parser, OperationState &result)
 
template<typename T >
static OpFoldResult foldMinMaxOp (T op, ArrayRef< Attribute > operands)
 Fold an affine min or max operation with the given operands. More...
 
static LogicalResult canonicalizeMapExprAndTermOrder (AffineMap &map)
 Canonicalize the result expression order of an affine map and return success if the order changed. More...
 
static bool isResultTypeMatchAtomicRMWKind (Type resultType, arith::AtomicRMWKind op)
 
static LogicalResult canonicalizeLoopBounds (AffineParallelOp op)
 Canonicalize the bounds of the given loop. More...
 
static void printMinMaxBound (OpAsmPrinter &p, AffineMapAttr mapAttr, DenseIntElementsAttr group, ValueRange operands, StringRef keyword)
 Prints a lower(upper) bound of an affine parallel loop with max(min) conditions in it. More...
 
static ParseResult deduplicateAndResolveOperands (OpAsmParser &parser, ArrayRef< SmallVector< OpAsmParser::UnresolvedOperand >> operands, SmallVectorImpl< Value > &uniqueOperands, SmallVectorImpl< AffineExpr > &replacements, AffineExprKind kind)
 Given a list of lists of parsed operands, populates uniqueOperands with unique operands. More...
 
static ParseResult parseAffineMapWithMinMax (OpAsmParser &parser, OperationState &result, MinMaxKind kind)
 Parses an affine map that can contain a min/max for groups of its results, e.g., max(expr-1, expr-2), expr-3, max(expr-4, expr-5, expr-6). More...
 
static LogicalResult verifyVectorMemoryOp (Operation *op, MemRefType memrefType, VectorType vectorType)
 Verify common invariants of affine.vector_load and affine.vector_store. More...
 
static std::optional< SmallVector< int64_t > > foldCstValueToCstAttrBasis (ArrayRef< OpFoldResult > mixedBasis, MutableOperandRange mutableDynamicBasis, ArrayRef< Attribute > dynamicBasis)
 Given mixed basis of affine.delinearize_index/linearize_index replace constant SSA values with the constant integer value and return the new static basis. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "affine-ops"

Definition at line 40 of file AffineOps.cpp.

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 5107 of file AffineOps.cpp.

◆ GET_OP_LIST

#define GET_OP_LIST

Function Documentation

◆ buildAffineLoopFromConstants()

static AffineForOp buildAffineLoopFromConstants ( OpBuilder builder,
Location  loc,
int64_t  lb,
int64_t  ub,
int64_t  step,
AffineForOp::BodyBuilderFn  bodyBuilderFn 
)
static

Creates an affine loop from the bounds known to be constants.

Definition at line 2653 of file AffineOps.cpp.

References mlir::OpBuilder::create().

Referenced by buildAffineLoopFromValues(), and mlir::affine::buildAffineLoopNest().

◆ buildAffineLoopFromValues()

static AffineForOp buildAffineLoopFromValues ( OpBuilder builder,
Location  loc,
Value  lb,
Value  ub,
int64_t  step,
AffineForOp::BodyBuilderFn  bodyBuilderFn 
)
static

Creates an affine loop from the bounds that may or may not be constants.

Definition at line 2662 of file AffineOps.cpp.

References buildAffineLoopFromConstants(), mlir::OpBuilder::create(), mlir::getConstantIntValue(), and mlir::Builder::getDimIdentityMap().

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

◆ buildAffineLoopNestImpl()

template<typename BoundListTy , typename LoopCreatorTy >
static void buildAffineLoopNestImpl ( OpBuilder builder,
Location  loc,
BoundListTy  lbs,
BoundListTy  ubs,
ArrayRef< int64_t >  steps,
function_ref< void(OpBuilder &, Location, ValueRange)>  bodyBuilderFn,
LoopCreatorTy &&  loopCreatorFn 
)
static

Builds an affine loop nest, using "loopCreatorFn" to create individual loop operations.

Definition at line 2612 of file AffineOps.cpp.

References mlir::OpBuilder::create(), and mlir::OpBuilder::setInsertionPointToStart().

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

◆ canonicalizeLoopBounds() [1/2]

static LogicalResult canonicalizeLoopBounds ( AffineForOp  forOp)
static

◆ canonicalizeLoopBounds() [2/2]

static LogicalResult canonicalizeLoopBounds ( AffineParallelOp  op)
static

◆ canonicalizeMapExprAndTermOrder()

static LogicalResult canonicalizeMapExprAndTermOrder ( AffineMap map)
static

Canonicalize the result expression order of an affine map and return success if the order changed.

The function flattens the map's affine expressions to coefficient arrays and sorts them in lexicographic order. A coefficient array contains a multiplier for every dimension/symbol and a constant term. The canonicalization fails if a result expression is not pure or if the flattening requires local variables that, unlike dimensions and symbols, have no global order.

Definition at line 3425 of file AffineOps.cpp.

References mlir::AffineMap::get(), mlir::AffineMap::getContext(), mlir::AffineMap::getNumDims(), mlir::AffineMap::getNumResults(), mlir::AffineMap::getNumSymbols(), mlir::AffineMap::getResult(), mlir::AffineMap::getResults(), mlir::SimpleAffineExprFlattener::operandExprStack, and mlir::AffineExprVisitor< SubClass, RetTy >::walkPostOrder().

Referenced by CanonicalizeAffineMinMaxOpExprAndTermOrder< T >::matchAndRewrite().

◆ canonicalizeMapOrSetAndOperands()

template<class MapOrSet >
static void canonicalizeMapOrSetAndOperands ( MapOrSet *  mapOrSet,
SmallVectorImpl< Value > *  operands 
)
static

◆ canonicalizePromotedSymbols()

template<class MapOrSet >
static void canonicalizePromotedSymbols ( MapOrSet *  mapOrSet,
SmallVectorImpl< Value > *  operands 
)
static

◆ composeAffineMapAndOperands()

static void composeAffineMapAndOperands ( AffineMap map,
SmallVectorImpl< Value > *  operands 
)
static

◆ composeMultiResultAffineMap()

static void composeMultiResultAffineMap ( AffineMap map,
SmallVectorImpl< Value > &  operands 
)
static

◆ composeSetAndOperands()

static void composeSetAndOperands ( IntegerSet set,
SmallVectorImpl< Value > &  operands 
)
static

◆ deduplicateAndResolveOperands()

static ParseResult deduplicateAndResolveOperands ( OpAsmParser parser,
ArrayRef< SmallVector< OpAsmParser::UnresolvedOperand >>  operands,
SmallVectorImpl< Value > &  uniqueOperands,
SmallVectorImpl< AffineExpr > &  replacements,
AffineExprKind  kind 
)
static

Given a list of lists of parsed operands, populates uniqueOperands with unique operands.

Also populates replacements with affine expressions of kindthat can be used to update affine maps previously accepting a operandsto acceptuniqueOperands` instead.

Definition at line 4064 of file AffineOps.cpp.

References mlir::DimId, mlir::getAffineDimExpr(), mlir::getAffineSymbolExpr(), mlir::AsmParser::getBuilder(), mlir::AsmParser::getContext(), mlir::Builder::getIndexType(), mlir::OpAsmParser::resolveOperands(), and mlir::SymbolId.

Referenced by parseAffineMapWithMinMax().

◆ foldCstValueToCstAttrBasis()

static std::optional<SmallVector<int64_t> > foldCstValueToCstAttrBasis ( ArrayRef< OpFoldResult mixedBasis,
MutableOperandRange  mutableDynamicBasis,
ArrayRef< Attribute dynamicBasis 
)
static

Given mixed basis of affine.delinearize_index/linearize_index replace constant SSA values with the constant integer value and return the new static basis.

In case no such candidate for replacement exists, this utility returns std::nullopt.

Definition at line 4577 of file AffineOps.cpp.

References mlir::MutableOperandRange::erase(), and mlir::getConstantIntValue().

◆ foldLoopBounds()

static LogicalResult foldLoopBounds ( AffineForOp  forOp)
static

Fold the constant bounds of a loop.

Definition at line 2185 of file AffineOps.cpp.

References mlir::AffineMap::constantFold(), mlir::AffineMap::getNumResults(), mlir::m_Constant(), and mlir::matchPattern().

◆ foldMinMaxOp()

template<typename T >
static OpFoldResult foldMinMaxOp ( op,
ArrayRef< Attribute operands 
)
static

Fold an affine min or max operation with the given operands.

The operand list may contain nulls, which are interpreted as the operand not being a constant.

Definition at line 3262 of file AffineOps.cpp.

References mlir::get().

◆ getLargestKnownDivisor()

static int64_t getLargestKnownDivisor ( AffineExpr  e,
ArrayRef< Value operands 
)
static

Returns the largest known divisor of e.

Exploits information from the values in operands.

Definition at line 624 of file AffineOps.cpp.

References mlir::affine::getForInductionVarOwner(), and mlir::AffineExpr::getLargestKnownDivisor().

Referenced by isQTimesDPlusR(), and simplifyExprAndOperands().

◆ getLowerBound() [1/2]

static std::optional<int64_t> getLowerBound ( AffineExpr  expr,
unsigned  numDims,
unsigned  numSymbols,
ArrayRef< Value operands 
)
static

Determine a constant lower bound for expr if one exists while exploiting values in operands.

Note that the upper bound is an inclusive one. expr is guaranteed to be less than or equal to it.

Definition at line 763 of file AffineOps.cpp.

References mlir::getBoundForAffineExpr(), getLowerBound(), and getUpperBound().

◆ getLowerBound() [2/2]

static std::optional<int64_t> getLowerBound ( Value  iv)
static

Gets the constant lower bound on an iv.

Definition at line 714 of file AffineOps.cpp.

References mlir::affine::getForInductionVarOwner().

Referenced by getLowerBound(), getUpperBound(), simplifyExprAndOperands(), and simplifyMinOrMaxExprWithOperands().

◆ getUpperBound() [1/2]

static std::optional<int64_t> getUpperBound ( AffineExpr  expr,
unsigned  numDims,
unsigned  numSymbols,
ArrayRef< Value operands 
)
static

Determine a constant upper bound for expr if one exists while exploiting values in operands.

Note that the upper bound is an inclusive one. expr is guaranteed to be less than or equal to it.

Definition at line 740 of file AffineOps.cpp.

References mlir::getBoundForAffineExpr(), getLowerBound(), and getUpperBound().

◆ getUpperBound() [2/2]

static std::optional<int64_t> getUpperBound ( Value  iv)
static

Gets the constant upper bound on an affine.for iv.

Definition at line 722 of file AffineOps.cpp.

References mlir::affine::getForInductionVarOwner().

Referenced by getLowerBound(), getUpperBound(), simplifyExprAndOperands(), and simplifyMinOrMaxExprWithOperands().

◆ hasTrivialZeroTripCount()

static bool hasTrivialZeroTripCount ( AffineForOp  op)
static

Returns true if the affine.for has zero iterations in trivial cases.

Definition at line 2373 of file AffineOps.cpp.

◆ isDimOpValidSymbol()

static bool isDimOpValidSymbol ( ShapedDimOpInterface  dimOp,
Region region 
)
static

Returns true if the result of the dim op is a valid symbol for region.

Definition at line 348 of file AffineOps.cpp.

References mlir::getConstantIntValue(), isMemRefSizeValidSymbol(), and mlir::affine::isTopLevelValue().

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

◆ isMemRefSizeValidSymbol()

template<typename AnyMemRefDefOp >
static bool isMemRefSizeValidSymbol ( AnyMemRefDefOp  memrefDefOp,
unsigned  index,
Region region 
)
static

Returns true if the 'index' dimension of the memref defined by memrefDefOp is a statically shaped one or defined using a valid symbol for region.

Definition at line 329 of file AffineOps.cpp.

References mlir::affine::isValidSymbol().

Referenced by isDimOpValidSymbol().

◆ isNonNegativeBoundedBy()

static bool isNonNegativeBoundedBy ( AffineExpr  e,
ArrayRef< Value operands,
int64_t  k 
)
static

Check if e is known to be: 0 <= e < k.

Handles the simple cases of e being an affine dim expression or a constant.

Definition at line 662 of file AffineOps.cpp.

References mlir::affine::getForInductionVarOwner().

Referenced by isQTimesDPlusR(), and simplifyExprAndOperands().

◆ isQTimesDPlusR()

static bool isQTimesDPlusR ( AffineExpr  e,
ArrayRef< Value operands,
int64_t &  div,
AffineExpr quotientTimesDiv,
AffineExpr rem 
)
static

Check if expression e is of the form d*e_1 + e_2 where 0 <= e_2 < d.

Set div to d, quotientTimesDiv to e_1 and rem to e_2 if the expression is in that form.

Definition at line 690 of file AffineOps.cpp.

References mlir::Add, getLargestKnownDivisor(), and isNonNegativeBoundedBy().

Referenced by simplifyExprAndOperands().

◆ isResultTypeMatchAtomicRMWKind()

static bool isResultTypeMatchAtomicRMWKind ( Type  resultType,
arith::AtomicRMWKind  op 
)
static

Definition at line 3859 of file AffineOps.cpp.

◆ isValidAffineIndexOperand()

static bool isValidAffineIndexOperand ( Value  value,
Region region 
)
static

◆ makeComposedFoldedMinMax()

template<typename OpTy >
static OpFoldResult makeComposedFoldedMinMax ( OpBuilder b,
Location  loc,
AffineMap  map,
ArrayRef< OpFoldResult operands 
)
static

◆ makeComposedMinMax()

template<typename OpTy >
static OpTy makeComposedMinMax ( OpBuilder b,
Location  loc,
AffineMap  map,
ArrayRef< OpFoldResult operands 
)
static

◆ parseAffineMapWithMinMax()

static ParseResult parseAffineMapWithMinMax ( OpAsmParser parser,
OperationState result,
MinMaxKind  kind 
)
static

Parses an affine map that can contain a min/max for groups of its results, e.g., max(expr-1, expr-2), expr-3, max(expr-4, expr-5, expr-6).

Populates result attributes with the map (flat list of expressions) and the grouping (list of integers that specify how many expressions to put into each min/max) attributes. Deduplicates repeated operands.

parallel-bound ::= ( parallel-group-list ) parallel-group-list ::= parallel-group (, parallel-group-list)? parallel-group ::= simple-group | min-max-group simple-group ::= expr-of-ssa-ids min-max-group ::= ( min | max ) ( expr-of-ssa-ids-list ) expr-of-ssa-ids-list ::= expr-of-ssa-ids (, expr-of-ssa-id-list)?

Examples: (%0, min(%1 + %2, %3), %4, min(%5 floordiv 32, %6)) (%0, max(%1 - 2 * %2))

Definition at line 4111 of file AffineOps.cpp.

References mlir::OperationState::addAttribute(), mlir::OperationState::attributes, deduplicateAndResolveOperands(), mlir::DimId, mlir::NamedAttrList::erase(), mlir::AffineMap::get(), mlir::get(), mlir::AsmParser::getBuilder(), mlir::AsmParser::getContext(), mlir::Builder::getEmptyAffineMap(), mlir::Builder::getI32TensorAttr(), mlir::OperationState::operands, mlir::AsmParser::Paren, mlir::OpAsmParser::parseAffineExprOfSSAIds(), mlir::OpAsmParser::parseAffineMapOfSSAIds(), mlir::AsmParser::parseCommaSeparatedList(), mlir::AsmParser::parseLParen(), mlir::AsmParser::parseOptionalKeyword(), mlir::AsmParser::parseOptionalRParen(), mlir::AsmParser::parseRParen(), and mlir::SymbolId.

◆ parseAffineMinMaxOp()

template<typename T >
static ParseResult parseAffineMinMaxOp ( OpAsmParser parser,
OperationState result 
)
static

◆ parseBound()

static ParseResult parseBound ( bool  isLower,
OperationState result,
OpAsmParser p 
)
static

◆ printAffineMinMaxOp()

template<typename T >
static void printAffineMinMaxOp ( OpAsmPrinter p,
op 
)
static

Definition at line 3226 of file AffineOps.cpp.

References mlir::OpAsmPrinter::printOptionalAttrDict().

◆ printBound()

static void printBound ( AffineMapAttr  boundMap,
Operation::operand_range  boundOperands,
const char *  prefix,
OpAsmPrinter p 
)
static

◆ printDimAndSymbolList()

static void printDimAndSymbolList ( Operation::operand_iterator  begin,
Operation::operand_iterator  end,
unsigned  numDims,
OpAsmPrinter printer 
)
static

Prints dimension and symbol list.

Definition at line 471 of file AffineOps.cpp.

Referenced by printBound().

◆ printMinMaxBound()

static void printMinMaxBound ( OpAsmPrinter p,
AffineMapAttr  mapAttr,
DenseIntElementsAttr  group,
ValueRange  operands,
StringRef  keyword 
)
static

Prints a lower(upper) bound of an affine parallel loop with max(min) conditions in it.

mapAttr is a flat list of affine expressions and group identifies which of the those expressions form max/min groups. operands are the SSA values of dimensions and symbols and keyword is either "min" or "max".

Definition at line 3996 of file AffineOps.cpp.

References mlir::get(), mlir::AffineMap::getNumDims(), mlir::AffineMap::getResult(), mlir::AffineMap::getSliceMap(), mlir::OpAsmPrinter::printAffineExprOfSSAIds(), and mlir::OpAsmPrinter::printAffineMapOfSSAIds().

◆ remainsLegalAfterInline() [1/4]

template<>
bool LLVM_ATTRIBUTE_UNUSED remainsLegalAfterInline ( AffineApplyOp  op,
Region src,
Region dest,
const IRMapping mapping 
)

Checks if an affine apply operation remains legal after inlining from src to dest.

Definition at line 126 of file AffineOps.cpp.

References mlir::affine::isValidDim(), mlir::affine::isValidSymbol(), and remainsLegalAfterInline().

◆ remainsLegalAfterInline() [2/4]

template<typename OpTy >
static bool remainsLegalAfterInline ( OpTy  op,
Region src,
Region dest,
const IRMapping mapping 
)
static

Checks if an affine read or write operation remains legal after inlining from src to dest.

Definition at line 100 of file AffineOps.cpp.

References mlir::AffineMap::getNumDims(), mlir::AffineMap::getNumSymbols(), mlir::affine::isValidDim(), mlir::affine::isValidSymbol(), and remainsLegalAfterInline().

◆ remainsLegalAfterInline() [3/4]

static bool remainsLegalAfterInline ( Value  value,
Region src,
Region dest,
const IRMapping mapping,
function_ref< bool(Value, Region *)>  legalityCheck 
)
static

Checks if value known to be a legal affine dimension or symbol in src region remains legal if the operation that uses it is inlined into dest with the given value mapping.

legalityCheck is either isValidDim or isValidSymbol, depending on the value being required to remain a valid dimension or symbol.

Definition at line 60 of file AffineOps.cpp.

References mlir::Value::getDefiningOp(), mlir::affine::isTopLevelValue(), mlir::IRMapping::lookup(), mlir::m_Constant(), and mlir::matchPattern().

Referenced by remainsLegalAfterInline().

◆ remainsLegalAfterInline() [4/4]

static bool remainsLegalAfterInline ( ValueRange  values,
Region src,
Region dest,
const IRMapping mapping,
function_ref< bool(Value, Region *)>  legalityCheck 
)
static

Checks if all values known to be legal affine dimensions or symbols in src remain so if their respective users are inlined into dest.

Definition at line 89 of file AffineOps.cpp.

References remainsLegalAfterInline().

◆ replaceDimOrSym()

static LogicalResult replaceDimOrSym ( AffineMap map,
unsigned  dimOrSymbolPosition,
SmallVectorImpl< Value > &  dims,
SmallVectorImpl< Value > &  syms 
)
static

Replace all occurrences of AffineExpr at position pos in map by the defining AffineApplyOp expression and operands.

When dimOrSymbolPosition < dims.size(), AffineDimExpr@[pos] is replaced. When dimOrSymbolPosition >= dims.size(), AffineSymbolExpr@[pos - dims.size()] is replaced. Mutate map,dims and syms in place as follows:

  1. dims and syms are only appended to.
  2. map dim and symbols are gradually shifted to higher positions.
  3. Old dim and sym entries are replaced by nullptr This avoids the need for any bookkeeping.

Definition at line 1024 of file AffineOps.cpp.

References mlir::affine::canonicalizeMapAndOperands(), mlir::getAffineDimExpr(), mlir::getAffineSymbolExpr(), mlir::AffineMap::getContext(), mlir::Value::getDefiningOp(), mlir::AffineMap::getNumDims(), mlir::AffineMap::getNumResults(), mlir::AffineMap::getNumSymbols(), mlir::AffineMap::getResult(), mlir::AffineMap::replace(), mlir::AffineMap::shiftDims(), and mlir::AffineMap::shiftSymbols().

Referenced by composeAffineMapAndOperands().

◆ simplifyExprAndOperands()

static void simplifyExprAndOperands ( AffineExpr expr,
unsigned  numDims,
unsigned  numSymbols,
ArrayRef< Value operands 
)
static

◆ simplifyMapWithOperands()

static void LLVM_ATTRIBUTE_UNUSED simplifyMapWithOperands ( AffineMap map,
ArrayRef< Value operands 
)
static

◆ simplifyMinOrMaxExprWithOperands()

static void simplifyMinOrMaxExprWithOperands ( AffineMap map,
ArrayRef< Value operands,
bool  isMax 
)
static

Simplify the expressions in map while making use of lower or upper bounds of its operands.

If isMax is true, the map is to be treated as a max of its result expressions, and min otherwise. Eg: min (d0, d1) -> (8, 4 * d0 + d1) can be simplified to (8) if the operands are respectively lower bounded by 2 and 0 (the second expression can't be lower than 8).

Definition at line 890 of file AffineOps.cpp.

References mlir::detail::enumerate(), mlir::AffineMap::get(), mlir::getAffineConstantExpr(), mlir::getBoundForAffineExpr(), mlir::AffineExpr::getContext(), mlir::AffineMap::getContext(), getLowerBound(), mlir::AffineMap::getNumDims(), mlir::AffineMap::getNumResults(), mlir::AffineMap::getNumSymbols(), mlir::AffineMap::getResults(), and getUpperBound().

Referenced by canonicalizeLoopBounds().

◆ verifyAffineMinMaxOp()

template<typename T >
static LogicalResult verifyAffineMinMaxOp ( op)
static

Definition at line 3213 of file AffineOps.cpp.

◆ verifyDimAndSymbolIdentifiers()

template<typename OpTy >
static LogicalResult verifyDimAndSymbolIdentifiers ( OpTy &  op,
Operation::operand_range  operands,
unsigned  numDims 
)
static

Utility function to verify that a set of operands are valid dimension and symbol identifiers.

The operands should be laid out such that the dimension operands are before the symbol operands. This function returns failure if there was an invalid operand. An operation is provided to emit any necessary errors.

Definition at line 503 of file AffineOps.cpp.

References mlir::affine::getAffineScope(), mlir::affine::isValidDim(), and mlir::affine::isValidSymbol().

◆ verifyMemoryOpIndexing()

static LogicalResult verifyMemoryOpIndexing ( Operation op,
AffineMapAttr  mapAttr,
Operation::operand_range  mapOperands,
MemRefType  memrefType,
unsigned  numIndexOperands 
)
static

Verify common indexing invariants of affine.load, affine.store, affine.vector_load and affine.vector_store.

Definition at line 3044 of file AffineOps.cpp.

References mlir::Operation::emitOpError(), mlir::affine::getAffineScope(), mlir::AffineMap::getNumInputs(), mlir::AffineMap::getNumResults(), and isValidAffineIndexOperand().

◆ verifyVectorMemoryOp()

static LogicalResult verifyVectorMemoryOp ( Operation op,
MemRefType  memrefType,
VectorType  vectorType 
)
static

Verify common invariants of affine.vector_load and affine.vector_store.

Definition at line 4398 of file AffineOps.cpp.

References mlir::Operation::emitOpError().