cranelift/rustc.md
One goal for Cranelift is to be usable as a backend suitable for compiling Rust in debug mode. This mode doesn't require a lot of mid-level optimization, and it does want very fast compile times, and this matches up fairly well with what we expect Cranelift's initial strengths and weaknesses will be. Cranelift is being designed to take aggressive advantage of multiple cores, and to be very efficient with its use of memory.
Another goal is a "pretty good" backend. The idea here is to do the work to get MIR-level inlining enabled, do some basic optimizations in Cranelift to capture the low-hanging fruit, and then use that along with good low-level optimizations to produce code which has a chance of being decently fast, with quite fast compile times. It obviously wouldn't compete with LLVM-based release builds in terms of optimization, but for some users, completely unoptimized code is too slow to test with, so a "pretty good" mode might be good enough.
There's plenty of work to do to achieve these goals, and if we achieve them, we'll have enabled a Rust compiler written entirely in Rust, and enabled faster Rust compile times for important use cases.
See issues tagged "rustc" for a list of some of the things that will be needed.
With all that said, there is a potential goal beyond that, which is to build a full optimizing release-capable backend. We can't predict how far Cranelift will go yet, but we do have some crazy ideas about what such a thing might look like, including:
Vec, it may be possible to recover what the optimizer
needs to know.SecondaryMaps), or
possibly an independent IR that could be translated to/from the base
IR. Either way, this overall architecture would keep the optimizer
out of the way of the non-optimizing build path, which keeps that
path fast and simple, and gives the optimizer more flexibility. If we
then want to base the IR on a powerful data structure like the
Value State Dependence Graph (VSDG), we can do so with fewer
compromises.And, these ideas build on each other. For example, one of the challenges for dependence-graph-oriented IRs like the VSDG is getting good enough memory dependence information. But if we can get high-quality aliasing information directly from the Rust front-end, we should be in great shape. As another example, it's often harder for superoptimizers to reason about control flow than expression graphs. But, graph-oriented IRs like the VSDG represent control flow as control dependencies. It's difficult to say how powerful this combination will be until we try it, but if nothing else, it should be very convenient to express pattern-matching over a single graph that includes both data and control dependencies.