Progress report on rustc_codegen_cranelift (Sep 2020)

Rustc_codegen_cranelift (cg_clif) is an alternative backend for rustc that I have been working on for the past two years. It uses the Cranelift code generator. Unlike LLVM which is optimized for output quality at the cost of compilation speed even when optimizations are disabled, Cranelift is optimized for compilation speed while producing executables that are almost as fast as LLVM with optimizations disabled. This has the potential to reduce the compilation times of rustc in debug mode.

I recently looked back at the notes for the design meeting (meeting proposal) about integrating cg_clif into rustc. I noticed that several of the challenges that needed to be solved have since been solved. Because of this I decided to give an overview of the achievements in the past six months and what the current challenges are.


@matthieum In reply to

First of all, thanks for your awesome work.


It may also open the door to further improvements -- I am curious as to the hints of in-place binary patching that Andrew Kelley dropped about his work on Zig, the idea being (apparently) to in-place substitute the new function code in the existing binary to completely skip linking again.

@lachlansneff pointed me to it by opening an issue. You may want to read my response there:

While there have been several PRs by other people like @osa1, @vi, @spastorino and @CohenArthur, I am the only person who has contributed more than a few changes to cg_clif.

Do you think it would be easier to draw contributors if your work was integrated in the rustc repository?

I have no idea.

Is there a clear view of when such integration would take place? #270 seems like a monster task on its own, but I don't see any mention of whether cg_clif is considered good enough already or if the compiler team would like to see some issues fixed first.

I already talked a bit about this in the git subtree section. To elaborate further: I already have a branch that makes it possible to build cg_clif as backend and even allows bootstrapping using cg_clif. It is a <1000 lines change. It doesn't extend the testing infrastructure as proposed yet though. The blocker for the past six months has been a bug in git subtree making it useless on the rust repo without using a patched git version.


I don't have anything to say other than to express my excitement. This is amazing work! Thank you!


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.