|
| 1 | +--- |
| 2 | +title: 2020-04-03 Cranelift backend for rustc |
| 3 | +type: docs |
| 4 | +--- |
| 5 | + |
| 6 | +# Cranelift backend for rustc |
| 7 | + |
| 8 | +You can also read the [complete discussion in our zulip-archive](https://zulip-archive.rust-lang.org/131828tcompiler/01241designmeeting20200403compilerteam257.html). |
| 9 | + |
| 10 | +[Meeting Proposal](https://github.com/rust-lang/compiler-team/issues/257) |
| 11 | + |
| 12 | +[Pre-meeting details and agenda outline](https://hackmd.io/@bjorn3/HJL5ryFS8) |
| 13 | + |
| 14 | +## Overview of the Cranelift backend |
| 15 | + |
| 16 | +[Cranelift](https://github.com/bytecodealliance/wasmtime/tree/master/cranelift) is a code generation backend written in Rust which is under development for use in WebAssembly compilers. |
| 17 | +As such, it could potentially improve compilation times in `rustc` because it is optimized for efficiently generating code rather than generating efficient code. |
| 18 | + |
| 19 | +Over the past ~1.5 years, [@bjorn3](https://github.com/bjorn3) has been working on writing a Cranelift-based code generation backend for `rustc`: [`rustc_codegen_cranelift`](https://github.com/bjorn3/rustc_codegen_cranelift) or `cg_cranelift` for short. |
| 20 | +It is currently complete enough to compile many programs and is usually faster at compiling them than the regular LLVM backend. |
| 21 | + |
| 22 | +The main goal of this project is to build an alternative codegen backend that can be used for faster, non-optimized (debug) builds. |
| 23 | + |
| 24 | +`rustc` has support for runtime-pluggable backends via the unstable `-Zcodegen-backend=/path/to/dylib` flag. |
| 25 | +`cg_cranelift` is developed in a separate repository from the Rust project, so it uses this flag to plug into `rustc`. |
| 26 | +`cg_cranelift` also takes advantage of an internal `rustc` library called `rustc_codegen_ssa` which tries to be a backend-agnostic code generation support library but some parts of it are still very LLVM-like. |
| 27 | + |
| 28 | +## Next steps |
| 29 | + |
| 30 | +At this time, we want to help increase the support `cg_cranelift` gets but it isn't a top priority for us currently. |
| 31 | +The eventual goal seems to be first-class support for `cg_cranelift` alongside our existing LLVM backend but that won't happen for a while so we can afford to take small, measured steps in the meantime. |
| 32 | + |
| 33 | +A few things we would like to do now: |
| 34 | + |
| 35 | +- Continue refactoring `rustc_codegen_ssa` to be less LLVM-like and allow `cg_cranelift` to re-use more of the code. |
| 36 | + |
| 37 | +- Bring in `cg_cranelift` to the `rust` repo (probably via `git-subtree`) and require it to build during CI. |
| 38 | + - This is similar to the support we give to tools like clippy or miri. |
| 39 | + |
| 40 | +- Add a way in our testing infrastructure to mark tests as reliant on a specific codegen backend and annotate existing tests that require LLVM. |
| 41 | + |
| 42 | +- Add a way to manually run tests with `cg_cranelift` to Rustbuild (aka `x.py`). |
| 43 | + |
| 44 | +We may also want to do these soon but we need additional discussion: |
| 45 | + |
| 46 | +- Run tests in `cg_cranelift` mode and notify if they failed (but don't gate CI on it). |
| 47 | + |
| 48 | +- Form a working group related to `cg_cranelift`. |
0 commit comments