LLVM Discussion Forums

Can we read data from input file to fill the content of an alloc object?


Does MLIR support read data from input file? Can the data be used to fill the content of an “alloc” object, e.g. %1 = alloc() : memref<5xi32>. Can the values in %1 be read from file?

Thank you for your help in advance.

Have you gone through the tutorial yet?
MLIR is an extensible framework, there is little that you can’t do in MLIR (CIRCT is a good example).

Loading data from a file and populating memory is trivially implement through calling a runtime function (that you implement in C) though.
In general, you get into IR design when you want to model something where the semantics is important for further transformations on the IR.

There is a way to print memrefs in MLIR (a call to print_memref via its runtime utils) - you could similarly design a way to scan in memrefs from a file. Allocate the memref and have a similar interface/ABI scan_memref.

Hi Uday,

Thank you so much! I make it. it works.


Hi Mehdi,

Thank you for your information. It helps me!