vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.29k stars 145 forks source link

lazy gen in foreground and parallel gen in background #280

Open Itay2805 opened 2 years ago

Itay2805 commented 2 years ago

Let's say I want to have parallel gen in the background at say O3, and while that heavy jitting runs I would love to start running code let's say at O1 with the lazy gen. That way I can have the best of both lazy for faster startups but also parallel in the background for better code gen in the long run.

Is something like this possible with the current code? Or would I need to setup my own jit interface?

vnmakarov commented 2 years ago

I guess it is possible. The way I look at possible solution is to have two ctx and an additional thread for background compilation and then when background generation is done, move the generated module to main thread where lazy code generation is done.
Although I did not check will it work.

There is no big difference in code generation time when -O1, -O2, and -O3 are used. Although the difference can be bigger if/when new optimizations will be added to MIR-generator.

FYI work of more one generator in one context is currently buggy. There are races in code working with context string (name) table when different generators create temporary registers (they have names) in parallel. I don't know yet how to fix it the best way (w/o losing generation speed).