[Mlir-commits] [mlir] [mlir][affine] Add static basis support to affine.delinearize (PR #113846)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Mon Oct 28 14:47:56 PDT 2024


================
@@ -1970,6 +1982,32 @@ mlir::affine::delinearizeIndex(OpBuilder &b, Location loc, Value linearIndex,
   return results;
 }
 
+FailureOr<SmallVector<Value>>
+mlir::affine::delinearizeIndex(OpBuilder &b, Location loc, Value linearIndex,
+                               ArrayRef<OpFoldResult> basis) {
+  unsigned numDims = basis.size();
+
+  SmallVector<Value> divisors;
+  for (unsigned i = 1; i < numDims; i++) {
+    ArrayRef<OpFoldResult> slice = basis.drop_front(i);
+    FailureOr<OpFoldResult> prod = getIndexProduct(b, loc, slice);
+    if (failed(prod))
+      return failure();
+    divisors.push_back(getValueOrCreateConstantIndexOp(b, loc, *prod));
+  }
----------------
ftynse wrote:

It would be more efficient to do a scan and collect intermediate products than rerun the product every time.

https://github.com/llvm/llvm-project/pull/113846


More information about the Mlir-commits mailing list