How to execute MLIR without lowing to LLVM?

Currently, the class “ExecutionEngine” assumes “the module can be converted to LLVM IR”.

Is there any existing infrastruction so I can execute my Dialect without lowing to LLVM?

I need this feature because I want to execute my IR after every pass,
to ensure the pass is correctly implemented.

No, and it is impossible in principle. MLIR doesn’t have a fixed set of operations, so it wouldn’t know how to execute the operations from your dialect.

If you set up a pipeline that can lower your mix of dialects to the LLVM dialect, you can clone the module after each pass, use the pipeline to convert the cloned module to the LLVM dialect and use the ExecutionEngine to run it. In many cases, you can target a higher-level dialect for which the lowering to the LLVM dialect already exist so you won’t need to test it yourself (it’s unlikely, though not impossible, that the in-tree lowerings are buggy).

Alternatively, you can implement an interpreter for your mix of dialects.

You missed the talk yesterday about EmitC though :wink:! It proposes an alternative to be able to take an IR and lower it to execution without going through LLVM IR directly. (We should have the slides and recording up soon.)

If you compile that C with clang, it still goes through LLVM IR :wink:

1 Like
  1. Will MLIR get an infrastrure to execute a dialect (dialect interpreter)

  2. Any recommendation how to make an interpreter for a high level dialect (no register/stack/memory address/load/store), similar to XLO dialect?

I’m not aware of any generic interpreter infrastructure. PDL dialect has an interpreter, but the dialect has been specifically designed to be interpreted. Maybe look into generalizing that.