[Mlir-commits] [mlir] [mlir][Interfaces][NFC] `ValueBoundsConstraintSet`: Add columns for constant values/dims (PR #86097)
Matthias Springer
llvmlistbot at llvm.org
Tue Mar 26 01:23:50 PDT 2024
================
@@ -107,25 +107,47 @@ AffineExpr ValueBoundsConstraintSet::getExpr(Value value,
assertValidValueDim(value, dim);
#endif // NDEBUG
+ // Check if the value/dim is statically known. In that case, an affine
+ // constant expression should be returned. This allows us to support
+ // multiplications with constants. (Multiplications of two columns in the
+ // constraint set is not supported.)
+ std::optional<int64_t> constSize = std::nullopt;
auto shapedType = dyn_cast<ShapedType>(value.getType());
if (shapedType) {
- // Static dimension: return constant directly.
if (shapedType.hasRank() && !shapedType.isDynamicDim(*dim))
- return builder.getAffineConstantExpr(shapedType.getDimSize(*dim));
- } else {
- // Constant index value: return directly.
- if (auto constInt = ::getConstantIntValue(value))
- return builder.getAffineConstantExpr(*constInt);
+ constSize = shapedType.getDimSize(*dim);
----------------
matthias-springer wrote:
> any such analysis is relative to its context
On second thought, that's actually how it is implemented at the moment. We provide a `ValueBoundsConstraintSet::computeBound(Value)` API. That function will build a constraint set and add the given value as a dimension, everything else as a symbol. When computing a bound for a different value, we build a brand new constraint set, this time with the new value being the only dimension. So this analysis is actually relative to a context and rooted at a certain op.
Computing multiple bounds back-to-back is slow at the moment because we have to re-analyze the entire IR. If we improve this at some point in the future, we will have to take a closer look at what's a symbol and what's a dimension, as you suggested.
https://github.com/llvm/llvm-project/pull/86097
More information about the Mlir-commits
mailing list