Convert LLVM IR to LLVM dialect?

Hi I am new to MLIR. I have looked at the documents of MLIR and could not find an answer, so I am posting this question here. I am just wondering can I convert existing LLVM IR to LLVM dialect?

You can run mlir-translate -import-llvm, but the coverage is quite limited.


Thank you @ftynse ! Can I ask a follow-up question? In my project I need to raise abstractions, so I am also considering converting LLVM dialect to some high-level dialect, for example, scf dialect. I saw there is a dialect conversion framework in MLIR. Does it have good support for convert LLVM dialect to scf dialect? Thanks!

MLIR is predominantly lowering-oriented, so no, there is no raising support from the LLVM IR dialect, nor there are any substantial transformations on this dialect. This doesn’t mean raising conversions are not accepted in the source tree, but nobody was motivated enough to contribute them.

You may want to look into the Polygeist project that @wsmoses, @lorenzo_chelini and @kumasento are running. There are some aspects of raising from instruction-level IR there. There is also work on raising from loops to higher-level abstraction in MLIR, and on detecting (affine) loops in LLVM IR (Polly).

I might be more helpful if you describe your use case in some detail.

1 Like

Hi @ftynse , thank you so much. Let me give some details of my need: in my project, I have some low-level LLVM IR. The only control flow in the LLVM IR is branches. And I want to convert the LLVM IR to high-level abstractions, for example, detect loops in the LLVM IR and express them with explicit loops.

I have read the Polygeist paper. It seems to me it does not discover loops, but rely on explicit control flow structs. So maybe it does not help. I know Polly can discover loops and convert them to polyhedral form(e.g., in JSCoP), but I am not aware if Polly(or any other tool) can convert the polyhedral form to explicit code, e.g. C. Do you know if there is any tool can do this?