[Mlir-commits] [mlir] [mlir] Add affine.delinearize_index and affine.linearize_index ValueBoundsOpInterfaceImpl (PR #118829)
Krzysztof Drewniak
llvmlistbot at llvm.org
Mon Dec 16 20:54:08 PST 2024
================
@@ -49,6 +49,67 @@ struct AffineApplyOpInterface
}
};
+struct AffineDelinearizeIndexOpInterface
+ : public ValueBoundsOpInterface::ExternalModel<
+ AffineDelinearizeIndexOpInterface, AffineDelinearizeIndexOp> {
+ void populateBoundsForIndexValue(Operation *op, Value value,
+ ValueBoundsConstraintSet &cstr) const {
+ auto delinearizeOp = cast<AffineDelinearizeIndexOp>(op);
+ auto result = cast<OpResult>(value);
+ int64_t resultIdx = result.getResultNumber();
+ assert(result.getOwner() == delinearizeOp && "invalid value");
+
+ AffineExpr linearIdxExpr = cstr.getExpr(delinearizeOp.getLinearIndex());
+ SmallVector<OpFoldResult> basis = delinearizeOp.getMixedBasis();
+ SmallVector<AffineExpr> basisExprs;
+ AffineExpr modExpr = getAffineConstantExpr(1, op->getContext());
+ AffineExpr strideExpr = getAffineConstantExpr(1, op->getContext());
+ for (int i = basis.size() - 1; i >= resultIdx; --i) {
+ AffineExpr basisExpr = cstr.getExpr(basis[i]);
+ modExpr = modExpr * basisExpr;
+ if (i > resultIdx)
----------------
krzysz00 wrote:
It feels like an equivalent way to phrase this is to walk up to the index _before_ `resultIdx`, take the product of those, and then go one step further to get the final `mod`.
However, I'm not going to insist too much on that
https://github.com/llvm/llvm-project/pull/118829
More information about the Mlir-commits
mailing list