rustc_codegen_cranelift icon indicating copy to clipboard operation
rustc_codegen_cranelift copied to clipboard

Using rustc_codegen_cranelift as dependency?

Open playXE opened this issue 4 years ago • 6 comments

I would like to create meta-tracing JIT library that will work like holyjit or RPython and there was a way of interpreting Rust MIR but now I think that it will be much simpler to interpret Cranelift IR so I'm wondering if it is possible to use rustc_codegen_cranelift to translate some Rust function MIR into Cranelift IR and then somehow obtain this IR? I've tried to look at source code but haven't found API for this

playXE avatar Apr 03 '21 10:04 playXE

Currently codegen_fn, codegen_static, CodegenCx and driver::predefine_mono_items are private. I think those should be enough for what you want. I can make them public if you want, but I won't make any api guarantees, so make sure to pin a specific commit using rustc_codegen_cranelift = { git = "...", rev = "..." }.

bjorn3 avatar Apr 03 '21 10:04 bjorn3

What I've thought of is to write rustc plugin which will invoke rustc_codegen_cranelift on specified function and then save Cranelift IR in some of data sections to be interpreted and traced at runtime , is this possible?

playXE avatar Apr 03 '21 11:04 playXE

That would also be possible. Except for the keeping it available at runtime at runtime part that would be pretty much equivalent to how cg_llvm embeds LLVM bitcode into object files.

By the way have you seen https://github.com/softdevteam/yk?

bjorn3 avatar Apr 03 '21 11:04 bjorn3

I have seen ykrustc, yes. It uses Intel hardware tracing which is not portable across CPUs. I belive that interpreting Cranelift IR is much easier and more portable way of doing meta-tracing JIT

playXE avatar Apr 03 '21 11:04 playXE

I can try to implement this in a couple of days.

bjorn3 avatar Apr 03 '21 12:04 bjorn3

That would be awesome! Thanks!

playXE avatar Apr 03 '21 17:04 playXE