Stream: cranelift

Topic: testcompiler


view this post on Zulip Carlo Kok (May 15 2020 at 05:23):

Is there some test compiler that uses cranelift as a backend? Looking to see what it creates for what kind of instructions.

view this post on Zulip Carlo Kok (May 15 2020 at 05:25):

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 ?

view this post on Zulip Carlo Kok (May 15 2020 at 05:26):

alternatively, can I use stackslots instead and does cranelift optimize those to ssa form?

view this post on Zulip bjorn3 (May 15 2020 at 10:24):

You need to use def_var every time you want to set a new value.

view this post on Zulip bjorn3 (May 15 2020 at 10:25):

Stackslots are not optimized to SSA form.

view this post on Zulip bjorn3 (May 15 2020 at 10:28):

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.

JIT compiler and runtime for a toy language, using Cranelift - bytecodealliance/simplejit-demo
Tutorial to learn to use the cranelift compiler backend - CraneStation/kaleidoscope-cranelift
rcc: a Rust C compiler. Contribute to jyn514/rcc development by creating an account on GitHub.
Cranelift backend for rustc. Contribute to bjorn3/rustc_codegen_cranelift development by creating an account on GitHub.

view this post on Zulip Carlo Kok (May 15 2020 at 10:56):

so def_var is block tied? Thanks!

view this post on Zulip Carlo Kok (May 15 2020 at 10:56):

that helped a lot.

view this post on Zulip Carlo Kok (May 15 2020 at 11:02):

rcc is perfect; that will let me see what to generate (I did the same when using llvm, see what clang does)

view this post on Zulip Carlo Kok (May 15 2020 at 19:07):

Is there any way to dump the before optimization and after optimization ir ?

view this post on Zulip bjorn3 (May 15 2020 at 19:24):

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.

view this post on Zulip bjorn3 (May 15 2020 at 19:25):

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