Is there some test compiler that uses cranelift as a backend? Looking to see what it creates for what kind of instructions.
In my current case I'm trying to find out the use of vars in frontend. I'm using declare_var to create a new variable, and def_var to define it the first time, I'm using use_var's result to read it, but how to I change the value of a var ?
alternatively, can I use stackslots instead and does cranelift optimize those to ssa form?
You need to use def_var
every time you want to set a new value.
Stackslots are not optimized to SSA form.
Carlo Kok said:
Is there some test compiler that uses cranelift as a backend? Looking to see what it creates for what kind of instructions.
You can take a look at https://github.com/bytecodealliance/simplejit-demo and https://github.com/CraneStation/kaleidoscope-cranelift, which are made for learning purposes. If you want to see the wasm compilation part, you can look at cranelift-wasm
(the cranelift/wasm
dir of the wasmtime
repo). https://github.com/jyn514/rcc is a C compiler. https://github.com/bjorn3/rustc_codegen_cranelift is a Rust backend I made.
so def_var is block tied? Thanks!
that helped a lot.
rcc is perfect; that will let me see what to generate (I did the same when using llvm, see what clang does)
Is there any way to dump the before optimization and after optimization ir ?
You can use println!("{}", func);
or cranelift_codegen::write::write_function
. For the after optimization ir, as of right now the x86 backend just transforms the clif ir in several ways, while keeping it clif ir. This means that you can just take the context.func
after compilation and print it, preferably using write_function
.
The AArch64 backend and the future x86 backend use an extra layer, for which you need to set context.want_disasm
to true and then after compilation access context.mach_compile_result
.
Last updated: Nov 26 2024 at 01:30 UTC