Hi folks,
I was wondering if anyone knows of a C/LLVM IR frontend for cranelift? So far I've found an LLVM IR to Cranelift MIR translator, which would've been perfect but it's abandoned.
For context, I'm a cpython core dev and I'm experimenting with JIT compilers for cpython. I can't claim that whatever I try will end up in cpython, mostly just doing this for fun and experimentation!
Thanks for your help!
There's https://github.com/jyn514/saltwater/, but it's using a very old version of Cranelift and is archived/not active. It might help (to avoid the X-Y problem) to say what you're trying to do -- what is the C code you're trying to compile, and what problem is it solving?
Thanks! I'll try to condense things to save your time:
CPython is written in C and so are its bytecode definitions. We use the bytecode definitions to generate multiple things, among them a baseline template (copy and patch) JIT.
I was thinking of how a higher-tier JIT (a somewhat-optimizing one) would look like. I'm trying to take straight-line sequences of bytecode, as either C source, or LLVM IR, concatenate them together, and pass them to something like Cranelift. This would (in theory) produce better code than our baseline JIT right now.
ah, so copy-and-patch style, interesting!
The short answer is that I don't think there's a fully mature and complete C compiler that would serve that need right now. I thought briefly about whether it might be possible to chain together stages e.g. through Wasm, but that introduces other issues -- you want the code to have the same target/ABI as the native runtime code it shares data structures with. So probably you're reduced to handwriting CLIF at the moment...
Alright, makes sense. Thank you for your advice!
Last updated: Dec 23 2024 at 13:07 UTC