Importing LLVM .bc into MLIR and raising it

Hi,

In the recent past, I have worked on some very difficult data problems where I have a clear aim of what I wish to achieve but no existing algorithm to achieve the goal.
The problems were eventually cracked, but only because I did a bit of lateral thinking and thought of ways to manipulate the data such that it becomes a different problem to solve, for which algorithms existed.
I would like to automate this process a bit.
To start with I have LLVM .bc and then wish to covert that to MLIR, and then raise it and then extract different representations of the data from that. So one can then understand the manipulations one can do to the data.
This is sort of decompiling, but the intention is not to get back from say LLVM IR to C++, but instead get back to different representation of the data, such that one might then think of better ways to approach the problem.
To this end, can anyone point me towards how best to convert LLVM IR to MLIR.
I guess a first step would be the LLVM dialect in MLIR, but then also the conversion of PHI to MLIR’s approach.
In this activity, you can see that I am not particularly interested in things like compile speed etc. I am more interested in progressive methods to raise MLIR, as opposed to the common approach of progressively lowering as MLIR was designed for.

mlir-translate --import-llvm sample.ll should be helpful. It still isn’t a complete tool and doesn’t accept all cases, but you can give it a try.

Slightly tangent: I have been fixing this translator recently and composed quite a few (~12) patches including bug fixes and enhancements. About half of them are still in my local tree, I’ll send them into review ASAP so that if anyone is interested in fixing it we won’t step on each other’s foot.

Also related, @chelini and friends worked on the progressive raising idea in MLIR context for this paper Progressive Raising in Multi-level IR | IEEE Conference Publication | IEEE Xplore. The code is likely bitrotten and won’t work with modern MLIR, but the ideas are worth reading.

3 Likes