[Mlir-commits] [mlir] [mlir][sparse] connect MapRef's lvl2dim with latest AffineMap computation (PR #69540)

Peiming Liu llvmlistbot at llvm.org
Wed Oct 18 17:56:27 PDT 2023


================
@@ -751,6 +744,35 @@ Value sparse_tensor::genMapBuffers(OpBuilder &builder, Location loc,
     }
     lvlSizesValues[l] = lvlSz;
   }
+  // Generate lvl2dim.
+  assert(dimRank == lvlToDim.getNumResults());
+  for (Dimension d = 0; d < dimRank; d++) {
+    AffineExpr exp = lvlToDim.getResult(d);
+    // We expect:
+    //    (1) d = l
+    //    (2) d = l' * c + l
+    Level l = 0, ll = 0;
+    uint64_t c = 0;
+    switch (exp.getKind()) {
+    case AffineExprKind::DimId: {
+      l = exp.cast<AffineDimExpr>().getPosition();
+      break;
+    }
+    case AffineExprKind::Add: {
+      // Always mul on lhs, symbol/constant on rhs.
+      auto add = exp.cast<AffineBinaryOpExpr>();
+      assert(add.getLHS().getKind() == AffineExprKind::Mul);
----------------
PeimingLiu wrote:

is it always `l' * c + l`? could it be `l + c * l'`? 

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


More information about the Mlir-commits mailing list