⚠️ 🚧 TODO / WIP
This page contains a short tutorial on MLIR, focusing on what is needed to understand cairo-native’s codebase and usage of MLIR, and a collection of resources.
It's better to use opaque pointers for the returned alloca data instead of specifying the full pointer type. Also LLVM is switching to those and deprecating non-opaque pointers.
To create a constant array, you need to use the llvm.mlir.constant
operation.
The way to represent the array data is by using a dense element attribute, for example:
// The attribute should look like this:
dense<[3, 1, 4, 1, 5]> : tensor<5 x i8>
// Full example
%alloca_size = llvm.mlir.constant(5 : i64) : i64
%array_ptr = llvm.alloca %alloca_size x i8 : (i64) -> !llvm.ptr
%array_data = llvm.mlir.constant(dense<[37, 48, 56, 88, 0]> : tensor<5xi8>) : !llvm.array<5 x i8>
llvm.store %array_data, %array_ptr : !llvm.array<5 x i8>, !llvm.ptr