[Mlir-commits] [mlir] [MLIR][EmitC] Add support for pointer-array types in the TypeConverter and related MemRef-to-EmitC operations, and update the C emitter. (PR #160159)

Gil Rapaport llvmlistbot at llvm.org
Sun Jan 18 04:42:44 PST 2026


aniragil wrote:

> @aniragil , @simon-camp For memref load and store, instead of using direct multi-dimensional subscripting on pointer<array<…>>, the access is rewritten to use a flattened pointer and flattened index.

Ouch, that seems unfortunate.
Trying to make sure I understand the problem:

>This is required due to EmitC semantics: taking address_of produces an lvalue, and lvalues cannot wrap or preserve array types.

`address_of` takes an `emitc.lvalue<>` and returns a `emitc.ptr<>`.

> As a result, the generated value cannot be represented as ptr<array<…>>, and emitc.subscript does not accept pointer operands directly.

`subscript` does take a pointer operand but allows only a single index for it, which forces you to flatten multi-dimensional access.

>To handle this consistently, the memref is treated as a flat contiguous buffer. The pointer is flattened to ptr, and the multi-dimensional indices are explicitly linearized using statically computed strides. Both load and store operate on this flattened representation

Would it help if we extend the `address_of` and `dereference` ops to support `emitc.array` directly, i.e.:
```mlir
%p = emitc.address_of %a: emitc.array<> -> emitc.ptr<emitc.array<>>
%a = emitc.dereference %p: emitc.ptr<emitc.array<>> -> emitc.array<>
```


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


More information about the Mlir-commits mailing list