22 assert(map.
getNumResults() == 1 &&
"multiple results not supported yet");
24 switch (e.getKind()) {
27 cast<AffineConstantExpr>(e).getValue());
29 return operands[cast<AffineDimExpr>(e).getPosition()];
31 return operands[cast<AffineSymbolExpr>(e).getPosition() +
34 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
35 return b.
create<AddIOp>(loc, buildExpr(binaryExpr.getLHS()),
36 buildExpr(binaryExpr.getRHS()));
39 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
40 return b.
create<MulIOp>(loc, buildExpr(binaryExpr.getLHS()),
41 buildExpr(binaryExpr.getRHS()));
44 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
45 return b.
create<DivSIOp>(loc, buildExpr(binaryExpr.getLHS()),
46 buildExpr(binaryExpr.getRHS()));
49 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
50 return b.
create<CeilDivSIOp>(loc, buildExpr(binaryExpr.getLHS()),
51 buildExpr(binaryExpr.getRHS()));
54 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
55 return b.
create<RemSIOp>(loc, buildExpr(binaryExpr.getLHS()),
56 buildExpr(binaryExpr.getRHS()));
59 llvm_unreachable(
"unsupported AffineExpr kind");
72 boundMap, mapOperands, type, var, stopCondition, closedUB)))
77 for (
auto valueDim : mapOperands) {
78 Value value = valueDim.first;
79 std::optional<int64_t> dim = valueDim.second;
81 if (!dim.has_value()) {
84 operands.push_back(value);
88 assert(cast<ShapedType>(value.
getType()).isDynamicDim(*dim) &&
89 "expected dynamic dim");
90 if (isa<RankedTensorType>(value.
getType())) {
92 operands.push_back(b.
create<tensor::DimOp>(loc, value, *dim));
93 }
else if (isa<MemRefType>(value.
getType())) {
95 operands.push_back(b.
create<memref::DimOp>(loc, value, *dim));
97 llvm_unreachable(
"cannot generate DimOp for unsupported shaped type");
108 if (
auto expr = dyn_cast<AffineDimExpr>(boundMap.
getResult(0)))
109 return static_cast<OpFoldResult>(operands[expr.getPosition()]);
110 if (
auto expr = dyn_cast<AffineSymbolExpr>(boundMap.
getResult(0)))
112 operands[expr.getPosition() + boundMap.
getNumDims()]);
121 auto reifyToOperands = [&](
Value v, std::optional<int64_t> d,
131 stopCondition ? stopCondition : reifyToOperands,
138 auto reifyToOperands = [&](
Value v, std::optional<int64_t> d,
143 stopCondition ? stopCondition : reifyToOperands,
Base type for affine expression.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
int64_t getSingleConstantResult() const
Returns the constant result of this map.
bool isSingleConstant() const
Returns true if this affine map is a single result constant function.
unsigned getNumDims() const
unsigned getNumResults() const
AffineExpr getResult(unsigned idx) const
IntegerAttr getIndexAttr(int64_t value)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class represents a single result from folding an operation.
A variable that can be added to the constraint set as a "column".
A helper class to be used with ValueBoundsOpInterface.
static LogicalResult computeBound(AffineMap &resultMap, ValueDimList &mapOperands, presburger::BoundType type, const Variable &var, StopConditionFn stopCondition, bool closedUB=false)
Compute a bound for the given variable.
std::function< bool(Value, std::optional< int64_t >, ValueBoundsConstraintSet &cstr)> StopConditionFn
The stop condition when traversing the backward slice of a shaped value/ index-type value.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
Specialization of arith.constant op that returns an integer of index type.
FailureOr< OpFoldResult > reifyValueBound(OpBuilder &b, Location loc, presburger::BoundType type, const ValueBoundsConstraintSet::Variable &var, ValueBoundsConstraintSet::StopConditionFn stopCondition, bool closedUB=false)
Reify a bound for the given variable in terms of SSA values for which stopCondition is met.
FailureOr< OpFoldResult > reifyIndexValueBound(OpBuilder &b, Location loc, presburger::BoundType type, Value value, ValueBoundsConstraintSet::StopConditionFn stopCondition=nullptr, bool closedUB=false)
Reify a bound for the given index-typed value in terms of SSA values for which stopCondition is met.
FailureOr< OpFoldResult > reifyShapedValueDimBound(OpBuilder &b, Location loc, presburger::BoundType type, Value value, int64_t dim, ValueBoundsConstraintSet::StopConditionFn stopCondition=nullptr, bool closedUB=false)
Reify a bound for the specified dimension of the given shaped value in terms of SSA values for which ...
BoundType
The type of bound: equal, lower bound or upper bound.
Include the generated interface declarations.
@ CeilDiv
RHS of ceildiv is always a constant or a symbolic expression.
@ Mul
RHS of mul is always a constant or a symbolic expression.
@ Mod
RHS of mod is always a constant or a symbolic expression with a positive value.
@ DimId
Dimensional identifier.
@ FloorDiv
RHS of floordiv is always a constant or a symbolic expression.
@ Constant
Constant integer.
@ SymbolId
Symbolic identifier.
SmallVector< std::pair< Value, std::optional< int64_t > >> ValueDimList