Error: type mismatch for bb argument #0 of successor #0

Hello.
Could you please help me. I receive “error: type mismatch for bb argument #0 of successor #0” when trying to lower to the LLVM dialect from the affine dialect. More exactly, I receive (when running mlir-opt with -debug-only=dialect-conversion):

Legalizing operation : ‘std.return’(0x5643b4ffa2c0) {
“std.return”(%1) : (memref<1000xf32>) → ()

  • Fold {
    } → FAILURE : unable to fold

  • Pattern : ‘std.return → ()’ {
    ** Insert : ‘llvm.return’(0x5643b5052320)
    ** Replace : ‘std.return’(0x5643b4ffa2c0)

    //===-------------------------------------------===//
    Legalizing operation : ‘llvm.return’(0x5643b5052320) {
    “llvm.return”(%2) : (!llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>) → ()

    } → SUCCESS : operation marked legal by the target
    //===-------------------------------------------===//
    } → SUCCESS : pattern applied successfully
    } → SUCCESS
    //===-------------------------------------------===//
    ** Insert : ‘builtin.unrealized_conversion_cast’(0x5643b50522a0)
    ** Insert : ‘builtin.unrealized_conversion_cast’(0x5643b50523b0)
    ** Insert : ‘builtin.unrealized_conversion_cast’(0x5643b5052440)
    convert_sw_layers_to_VPUIP_1c.mlir:6:10: error: type mismatch for bb argument #0 of successor #0

    I have difficulties reading the error message.
    Especially this part: “llvm.return”(%2) : (!llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>) → (). Please note that std.return looks like this exactly:
    return %0: memref<1000xf32>.

    Could you please help me. That is mainly please provide me some advice on how to avoid this error.
    Please note that I used the code from the Toy tutorial chapter 6 that deals with the LLVM dialect lowering.

    Thank you very much.
    Alex

Did you add a converter for the func op?

No, I didn’t. Could you please help me to implement one if it’s needed?
Thank you very much,
Alex

There is a pass for this https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h

Hello.
The pass is written with the latest version of the LLVM + MLIR API, while I need to use an older version of LLVM + MLIR, which doesn’t have the Func dialect, among others…
I will try to use part of the code from this Conversion subproject (https://github.com/llvm/llvm-project/blob/main/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp). I hope I will be able to do this.

Any advice is welcome.

Thank you very much,
  Alex

If you’re on an older version, StandardToLLVM should do the trick.