Hi there. For my final thesis, I’m currently working on a native code generator for MLIR that does not need to go through the llvm dialect.
TL;DR: Does anyone know another project that tries to lower MLIR, or another extensible IR to machine code directly?
There is currently not much to see in the repo, so let me tell you more about it: It defines target specific dialects containing ISA instructions (currently only for x86-64) to which users can lower their instructions, just like they can with the llvm
dialect. These instructions are fully qualified with regard to their opcode, so that the encoder can later take an op and know the exact opcode required to lower it. Some in-tree dialects have pre-defined patterns to do the lowering. This is in essence the instruction selection step of the code generation process. The MoNaCo back-end then takes care of SSA-destruction, register allocation and encoding using the fadec encoder, all in one second pass over the IR. As long as all instructions have been lowered to the target specific dialect, the back-end is completely agnostic to what happened during lowering.
Due to the time constraints of a thesis, the entire process is very basic, the instruction selection does not support many dialects yet (ironically the best supported one is probably llvm
at the moment, as its easiest to generate from C) and amounts to nothing more than macro expansion, the register allocator is basically purely stack based without any liveness, and at the moment, the only way to use external symbols or call external functions is in the JIT mode, which is the main focus of the code generator, i.e. relocations or object file writing isn’t implemented yet.
This of course leads to worse code quality compared to LLVM, the SPEC CPU 2017 mcf
benchmark takes about 4 times as long if compiled with monaco vs LLVM as the baseline(-O0, with fast isel enabled); Compile times are slightly better, monaco JIT compiles mcf
in about 75% of the time that LLVM needs (fast isel again).
Does anyone know of a similar project that is ongoing (classic “Related Work” question, I know)? The things that I would consider most similar are the armsve
, amx
, and x86vector
(and maybe nvgpu
?) dialects, as well as the intrinsics from llvm
, as they are closest to specifying an instruction/opcode. I also found this: https://arxiv.org/pdf/2101.11365.pdf, although I am very unfamiliar with quantum computing and quantum assembly languages, so I don’t know how close this really comes to monaco.
Also, all the dialects and representations I could find still rely on LLVM based code generation in the end, making them less direct than monaco.
So if anyone knows another attempt at lowering MLIR to machine code directly, or knows of another extensible intermediate representation employing direct code generation (‘direct’ meaning not through LLVM), I would greatly appreciate a link :).