C extensions to support JIT #174
Replies: 6 comments 5 replies
-
Any good JIT for a dynamic programming language requires implementation of speculated and de-optimized code generation. For the current MIR implementation, this would require for a JIT developer to generate MIR code which collect profile information (e.g. value type profiling) by himself and then generate speculative MIR code based on this information. It is a tedious work common for all dynamic language JITs. So I'd like to implement it in a general way. First, it requires to implement speculative MIR branch insns which collect profile information about taken paths. Then using this profile information, MIR generator in a special mode would generate a speculative code assuming that only one path will be taken. If the assumption is violated, an unoptimized code could be generated. Second, this could implemented as a C extension (something analogous to builtin_expect) informing c2mir where to generate speculative MIR branch insns. So that is the plan. Probably I can start this work in June-July after finishing Apple Silicon port. |
Beta Was this translation helpful? Give feedback.
-
Above makes sense. I don't know how feasible this is, but here is something that I would like to be able to do. When I JIT compile a piece of Ravi code, it essentially serializes the byte code instructions. This results in duplication of code as bytecodes are generally inlined. What would be nice if the common blocks could be shared without requiring them to be converted to functions with function call overhead. Almost like some form of fast call via local jump. This would be of huge benifit (if it can be done) to bytecode JIT compilers. Don't know if it makes sense - and also this my be too hard to do. |
Beta Was this translation helpful? Give feedback.
-
Above article describes the type of JIT I was referring to. I was thinking that easiest option might be have some internal fast call method - C function annotated by something - and certain assumptions - e.g local jump, maybe allow shared variables between the function and the owning function. That is the called chunk should be able to access variables in the caller. |
Beta Was this translation helpful? Give feedback.
-
BTW The reason I use the C front-end to MIR is that otherwise I would have to worry about manipulating aggregate objects such as structs and arrays myself. Moreover this needs to be portable and compatible with C conventions. If MIR IR can be extended to support definition of arrays, structs and unions, then this complication would disappear, and it would be relatively easy to generate MIR IR code. |
Beta Was this translation helpful? Give feedback.
-
Hi @vnmakarov I would suggest improving MIR rather than starting a new project. MIR is still not 1.0 so you have some freedom with regards to changing the IR to make it higher performance. Regards |
Beta Was this translation helpful? Give feedback.
-
Another thought I have is that currently the C front-end is ISO C11. However, this may not be optimum for JIT - it maybe that a subset/superset can be more useful. For instance, the MIR C front-end could prohibit certain C features such as pointer aliasing. Or allow fast call functions where certain limitations are imposed - e.g.. static local functions with register arguments and returns. |
Beta Was this translation helpful? Give feedback.
-
Hi @vnmakarov
Your recent Redhat blogpost made me wonder if it would be beneficial to have some C extensions in c2mir that help with better performing JIT code.
Regards
Beta Was this translation helpful? Give feedback.
All reactions