[Mlir-commits] [mlir] [mlir][EmitC] Add rank-0 MemRef conversion (PR #205774)

Gil Rapaport llvmlistbot at llvm.org
Sat Jun 27 10:44:30 PDT 2026


================
@@ -73,6 +72,11 @@ struct ConvertAlloca final : public OpConversionPattern<memref::AllocaOp> {
           op.getLoc(), "cannot transform alloca with dynamic shape");
     }
 
+    if (op.getType().getRank() == 0) {
+      return rewriter.notifyMatchFailure(
+          op.getLoc(), "cannot transform alloca with zero rank");
+    }
+
----------------
aniragil wrote:

It would be good to have an implementation for this case, to make sure we have a full model for lowering zero-dim memrefs.
For other memrefs we create an `emic.variable` with the converted array type and return it. Here, we can create an `emitc.variable` of the element type, then create an `emitc.address_of` the returned lvalue and use the pointer we get.
This seems quite analogous to MemRefToLLVM's, which:
- creates an `llvm::alloca`.
- uses the returned pointer in the memref descriptor it creates.
If and when we switch to memref descriptors in emitc this would also align with llvm's implementation.
WDYT?

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


More information about the Mlir-commits mailing list