Red Hat develops MIR JIT compiler

At Red Hat development in progress new lightweight JIT compiler MIR, which provides execution of code previously converted to an intermediate representation MIR (Medium Internal Representation, not to be confused with another intermediate representation MIR (mid-level IR) used in the Rust compiler). The project aims to provide a framework for implementing fast and compact interpreters and JIT. The project code is written in C language and spreads under the MIT license.

At the current stage of development, translators to the MIR intermediate representation are prepared for C language and bitcode LLVM (Bitcode), but in the future it is planned to implement the ability to generate MIR for WebAssembly, Java bytecode, CIL (Common Intermediate Language), Rust and C++. The project is being developed by one of the developers of the JIT engine MJIT, used in Ruby. First of all, JIT based on MIR is planned to be implemented for CRuby ΠΈ MRuby. In the future, the possibility of porting GCC to use MIR is also not excluded.

Red Hat develops MIR JIT compiler

The intermediate MIR code can be represented in binary and text (readable) form. This code can be executed in an interpreter, generating machine code based on it (x86_64, in ARM64, PPC64 and MIPS64 plans). It is also possible to perform the reverse conversion - from MIR to CIL, Java bytecode, WebAssembly and C code.

Among the features of MIR stand out strong typing, support for modules and functions, providing a set of instructions for type conversion, comparison, arithmetic and logical operations, branching, etc. Modules that include a set of functions converted to MIR format can be loaded in the form of libraries, as well as loading external C code.

Red Hat develops MIR JIT compilerRed Hat develops MIR JIT compiler

The key advantage of executing intermediate code in JIT instead of compiling into native executable files is the ability to generate compact files that can be executed without rebuilding on different hardware architectures (x86, ARM, PPC, MIPS). For unsupported architectures, an interpretation mode is available, which in the case of MIR is 6-10 times slower than JIT.

Of the shortcomings of existing JIT compilers
GCC and LLVM are cited for their excessive bloat, slow compilation speed, and difficulty in implementing combined optimizations for different programming languages. MIR developers tried to solve these
problems and set goals:

  • Compiling to MIR should be at least 100 times faster than compiling to GCC;
  • The JIT for executing MIR must be very compact, around 15 lines of code;
  • Execution of MIR using JIT should be no more than 30% slower than the performance of an executable compiled from the same C code in GCC (with "-O2" optimizations);
  • The initialization stages before actual execution should take 100 times less time;
  • The MIR representation for JIT should be 100 times smaller than the executable built in GCC.

In its current form, the implementation of MIR is in many ways ahead of its originally set goals: tests have shown that compilation performance in MIR is 2 times faster than "GCC -O178", execution performance lags behind native code by 6%, code size is 144 times smaller, MIR implementation JIT is 16 thousand lines of code.

Red Hat develops MIR JIT compiler

Source: opennet.ru

Add a comment