MLIR: lib/Dialect/Arith/Transforms/ReifyValueBounds.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
15
16 using namespace mlir;
18
19
22 assert(map.getNumResults() == 1 && "multiple results not supported yet");
24 switch (e.getKind()) {
27 cast(e).getValue());
29 return operands[cast(e).getPosition()];
31 return operands[cast(e).getPosition() +
34 auto binaryExpr = cast(e);
35 return b.create(loc, buildExpr(binaryExpr.getLHS()),
36 buildExpr(binaryExpr.getRHS()));
37 }
39 auto binaryExpr = cast(e);
40 return b.create(loc, buildExpr(binaryExpr.getLHS()),
41 buildExpr(binaryExpr.getRHS()));
42 }
44 auto binaryExpr = cast(e);
45 return b.create(loc, buildExpr(binaryExpr.getLHS()),
46 buildExpr(binaryExpr.getRHS()));
47 }
49 auto binaryExpr = cast(e);
50 return b.create(loc, buildExpr(binaryExpr.getLHS()),
51 buildExpr(binaryExpr.getRHS()));
52 }
54 auto binaryExpr = cast(e);
55 return b.create(loc, buildExpr(binaryExpr.getLHS()),
56 buildExpr(binaryExpr.getRHS()));
57 }
58 }
59 llvm_unreachable("unsupported AffineExpr kind");
60 };
61 return buildExpr(map.getResult(0));
62 }
63
68
72 boundMap, mapOperands, type, var, stopCondition, closedUB)))
73 return failure();
74
75
77 for (auto valueDim : mapOperands) {
78 Value value = valueDim.first;
79 std::optional<int64_t> dim = valueDim.second;
80
81 if (!dim.has_value()) {
82
83 assert(value.getType().isIndex() && "expected index type");
84 operands.push_back(value);
85 continue;
86 }
87
88 assert(cast(value.getType()).isDynamicDim(*dim) &&
89 "expected dynamic dim");
90 if (isa(value.getType())) {
91
92 operands.push_back(b.createtensor::DimOp(loc, value, *dim));
93 } else if (isa(value.getType())) {
94
95 operands.push_back(b.creatememref::DimOp(loc, value, *dim));
96 } else {
97 llvm_unreachable("cannot generate DimOp for unsupported shaped type");
98 }
99 }
100
101
103
106 }
107
108 if (auto expr = dyn_cast(boundMap.getResult(0)))
109 return static_cast<OpFoldResult>(operands[expr.getPosition()]);
110 if (auto expr = dyn_cast(boundMap.getResult(0)))
112 operands[expr.getPosition() + boundMap.getNumDims()]);
113
115 }
116
120 bool closedUB) {
121 auto reifyToOperands = [&](Value v, std::optional<int64_t> d,
123
124
125
126
127
128 return v != value;
129 };
131 stopCondition ? stopCondition : reifyToOperands,
132 closedUB);
133 }
134
138 auto reifyToOperands = [&](Value v, std::optional<int64_t> d,
140 return v != value;
141 };
143 stopCondition ? stopCondition : reifyToOperands,
144 closedUB);
145 }
static Value buildArithValue(OpBuilder &b, Location loc, AffineMap map, ValueRange operands)
Build Arith IR for the given affine map and its operands.
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