24 assert(map.
getNumResults() == 1 &&
"multiple results not supported yet");
26 switch (e.getKind()) {
29 cast<AffineConstantExpr>(e).getValue());
31 return operands[cast<AffineDimExpr>(e).getPosition()];
33 return operands[cast<AffineSymbolExpr>(e).getPosition() +
36 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
37 return AddIOp::create(b, loc, buildExpr(binaryExpr.getLHS()),
38 buildExpr(binaryExpr.getRHS()));
41 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
42 return MulIOp::create(b, loc, buildExpr(binaryExpr.getLHS()),
43 buildExpr(binaryExpr.getRHS()));
46 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
47 return DivSIOp::create(b, loc, buildExpr(binaryExpr.getLHS()),
48 buildExpr(binaryExpr.getRHS()));
51 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
52 return CeilDivSIOp::create(b, loc, buildExpr(binaryExpr.getLHS()),
53 buildExpr(binaryExpr.getRHS()));
56 auto binaryExpr = cast<AffineBinaryOpExpr>(e);
57 return RemSIOp::create(b, loc, buildExpr(binaryExpr.getLHS()),
58 buildExpr(binaryExpr.getRHS()));
61 llvm_unreachable(
"unsupported AffineExpr kind");
74 boundMap, mapOperands, type, var, std::move(stopCondition),
80 for (
auto valueDim : mapOperands) {
81 Value value = valueDim.first;
82 std::optional<int64_t> dim = valueDim.second;
84 if (!dim.has_value()) {
87 operands.push_back(value);
91 assert(cast<ShapedType>(value.
getType()).isDynamicDim(*dim) &&
92 "expected dynamic dim");
93 if (isa<RankedTensorType>(value.
getType())) {
95 operands.push_back(tensor::DimOp::create(b, loc, value, *dim));
96 }
else if (isa<MemRefType>(value.
getType())) {
98 operands.push_back(memref::DimOp::create(b, loc, value, *dim));
100 llvm_unreachable(
"cannot generate DimOp for unsupported shaped type");
111 if (
auto expr = dyn_cast<AffineDimExpr>(boundMap.
getResult(0)))
112 return static_cast<OpFoldResult>(operands[expr.getPosition()]);
113 if (
auto expr = dyn_cast<AffineSymbolExpr>(boundMap.
getResult(0)))
115 operands[expr.getPosition() + boundMap.
getNumDims()]);
124 auto reifyToOperands = [&](
Value v, std::optional<int64_t> d,
134 stopCondition ? stopCondition : reifyToOperands,
142 auto reifyToOperands = [&](
Value v, std::optional<int64_t> d,
147 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.
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.
static ConstantIndexOp create(OpBuilder &builder, Location location, int64_t value)
FailureOr< OpFoldResult > reifyShapedValueDimBound(OpBuilder &b, Location loc, presburger::BoundType type, Value value, int64_t dim, const 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 ...
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, const 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.
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