15 if (
map.isSingleConstant())
17 if (
map.getNumResults() != 1 ||
map.getNumInputs() != 1)
19 auto binop = dyn_cast<AffineBinaryOpExpr>(
map.getResult(0));
23 if (
auto cst = dyn_cast<AffineConstantExpr>(expr)) {
24 constant = cst.getValue();
31 auto lhs = binop.getLHS();
32 auto rhs = binop.getRHS();
33 if ((matchConstant(
lhs, cst) && isa<AffineSymbolExpr>(
rhs)) ||
34 (matchConstant(
rhs, cst) && isa<AffineSymbolExpr>(
lhs))) {
44 Value value, std::optional<int64_t> dim,
unsigned vscaleMin,
48 assert(vscaleMin <= vscaleMax);
52 auto defaultStopCondition = [&](
Value v, std::optional<int64_t> dim,
58 value.
getContext(), stopCondition ? stopCondition : defaultStopCondition,
59 vscaleMin, vscaleMax);
60 int64_t pos = scalableCstr.insert(value, dim,
false);
61 scalableCstr.processWorklist();
64 if (scalableCstr.cstr.isEmpty()) {
70 auto projectOutFn = [&](ValueDim p) {
71 bool isStartingPoint =
74 return p.first != scalableCstr.
getVscaleValue() && !isStartingPoint;
76 scalableCstr.projectOut(projectOutFn);
77 scalableCstr.projectOutAnonymous(pos);
80 for (
unsigned i = 0, e = scalableCstr.cstr.getNumLocalVars(); i < e; ++i) {
81 scalableCstr.cstr.projectOut(scalableCstr.cstr.getNumDimAndSymbolVars());
84 assert(scalableCstr.cstr.getNumDimAndSymbolVars() ==
85 scalableCstr.positionToValueDim.size() &&
86 "inconsistent mapping state");
89 for (
int64_t i = 0; i < scalableCstr.cstr.getNumDimAndSymbolVars(); ++i) {
92 if (scalableCstr.positionToValueDim[i] !=
100 scalableCstr.cstr.getSliceBounds(pos, 1, value.
getContext(), &lowerBound,
101 &upperBound, closedUB);
103 auto invalidBound = [](
auto &bound) {
104 return !bound[0] || bound[0].getNumResults() != 1;
108 if (boundType == BoundType::EQ && !invalidBound(lowerBound) &&
109 lowerBound[0] == upperBound[0]) {
110 return lowerBound[0];
112 if (boundType == BoundType::LB && !invalidBound(lowerBound)) {
113 return lowerBound[0];
114 }
else if (boundType == BoundType::UB && !invalidBound(upperBound)) {
115 return upperBound[0];
static FailureOr< ConstantOrScalableBound > computeScalableBound(Value value, std::optional< int64_t > dim, unsigned vscaleMin, unsigned vscaleMax, presburger::BoundType boundType, bool closedUB=true, const StopConditionFn &stopCondition=nullptr)
Computes a (possibly) scalable bound for a given value.