How to convert affine dialect -> llvm ir

I am new to mlir and I could not find which option to use with mlir-opt to lower affine dialect to llvm or
lower it to another dialect that I can convert to llvm after.


[quote=“messadki, post:1, topic:4710”]

I tried to use –lower-affine then –convert-scf-to-std then –convert-memref-to-llvm and –convert-memref-to-llvm. So I get a mlir with llvm dialect but also builtin.unrealized_conversion_cast, which can not be translated affeter that to llvm ir. I get the following error affter running mlir-translate -mlir-to-llvmir

 error: cannot be converted to LLVM IR: missing `LLVMTranslationDialectInterface` registration for dialect for op: builtin.unrealized_conversion_cast
    %8 = builtin.unrealized_conversion_cast %7 : !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)> to memref<4096x4096xf32>

You need to finalize the type conversion process by using the -reconcile-unrealized-casts pass. See PSA: run -reconcile-unrealized-casts after all -convert-*-to-llvm from now on and LLVM IR Target - MLIR for more details.

Also, I suspect that you may also need -convert-arith-to-llvm and -convert-std-to-llvm somewhere in pass pipeline before pass reconciliation, it is quite rare that these dialects are not in the mix after lowering from affine.

thanks @ftynse it works now with -reconcile-unrealized-casts pass and yes I used --convert-arith-to-llvm and --convert-std-to-llvm.