Skip to content

Commit 2821d03

Browse files
authored
Merge pull request #12 from cfallin/remove-old-backend
RFC to remove old Cranelift x86 backend.
2 parents 12930ed + 7026b20 commit 2821d03

1 file changed

Lines changed: 160 additions & 0 deletions

File tree

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Summary
2+
[summary]: #summary
3+
4+
This RFC proposes to remove the old x86-64 backend from Cranelift, and
5+
subsequently clean up various bits of the IR, other compiler data
6+
structures, and metaprogramming / codegen infrastructure that are only
7+
used by old-style backends. The RFC represents two main decision
8+
points: (i) whether it is now time to remove the old backend, and (ii)
9+
what else in the codebase we will now be able to remove as a
10+
consequence of this action.
11+
12+
# Motivation
13+
[motivation]: #motivation
14+
15+
In RFC #10, we proposed switching the default Cranelift backend to the
16+
new implementation, based on the `MachInst` framework. This new
17+
framework is also in use by the aarch64 backend, which was natively
18+
developed for the new APIs, and the recently-added s390x backend as
19+
well.
20+
21+
To our knowledge, no significant consumers of Cranelift or Wasmtime
22+
are still relying on the old backend, and it has been included as a
23+
non-default option for two releases (0.27.x and 0.28.0) now. All
24+
ongoing development effort is targetted to the new backends.
25+
26+
Alongside this, retaining the old backend as an option has several
27+
ongoing costs. First, because we have decided thus far to ensure it
28+
continues to pass tests, it imposes additional requirements on any new
29+
features we might add. While we have sometimes adopted a more
30+
fine-grained attitude of "this won't work on the old backend, and
31+
that's OK" (see: newer Wasm instructions), it is still a decision that
32+
has to be made in each case.
33+
34+
Second, and more significantly, the old backend is the sole factor
35+
that keeps a number of other pieces of infrastructure alive. The core
36+
IR data structures contain some abstractions that are relevant only
37+
for the old backend, and this occasionally causes confusion. For
38+
example, someone looking for information on stackslots, or regalloc
39+
results, or code-layout information, will not find the information on
40+
the CLIF after compilation is done: the new backends produce the
41+
information in a separate IR (VCode). There is thus a cognitive
42+
overhead involved in maintaining "old and deprecated" vs. "new and
43+
supported" status in one's head for bits of the compiler, and a
44+
significant source of confusion for newcomers in particular.
45+
46+
# Proposal
47+
[proposal]: #proposal
48+
49+
We thus propose to (i) remove the old x86 backend, making the x64
50+
backend based on the `MachInst` framework the only supported option
51+
for x86-64 in the future; and (ii) then performing "dead-code
52+
elimination" as far as it will take us.
53+
54+
## Part 1: Deciding to Remove the Old Backend
55+
56+
The main question here is whether it is now the proper time to remove
57+
the backend. In #10, we suggested maintaining its functionality while
58+
"mak[ing] several releases with the new backend as default". We have
59+
now done so for two releases (0.27.x and 0.28). We can also directly
60+
consider several known users of Cranelift:
61+
62+
* Wasmtime: transitioned to new backend in
63+
bytecodealliance/wasmtime#2718. Feature flag to continue to use old
64+
backend.
65+
66+
* Lucet: transitioned to new backend in
67+
bytecodealliance/lucet#646. Feature flag to continue to use old
68+
backend.
69+
70+
* cg\_clif: transitioned to new backend in
71+
bjorn3/rustc_codegen_cranelift#1127 and removed ability to use old
72+
backend.
73+
74+
* Firefox/SpiderMonkey: most up-to-date integration (Baldrdash) used
75+
new backend only.
76+
77+
* VeriWasm: updated to support new x64 backend in PlSysSec/veriwasm#2.
78+
79+
Question 1: Are there any other known use-cases that remain on the old
80+
backend?
81+
82+
Question 2: Is there any functionality in the old backend that we have
83+
not yet adequately replicated in the new backend?
84+
85+
Question 3: given the above, is it acceptable to remove the old
86+
backend?
87+
88+
This RFC proposes answering "yes" to Question 3 above, contingent on
89+
receiving no answers to Question 1 or Question 2 that would change our
90+
path.
91+
92+
## Part 2: Logistics
93+
94+
There are several steps that we can take, in order, to remove the old
95+
backend and then carry out some clean-up work afterward.
96+
97+
Much of this work, especially the work to snip out the backend itself
98+
and replace legalizations where needed, has already been drafted by
99+
@bjorn3 in bytecodealliance/wasmtime#3009 (thanks!). This RFC's goal
100+
is to gain consensus on a process around merging this work, and
101+
outline the steps to carry it through with the appropriate cleanup
102+
afterward.
103+
104+
1. Remove the `BackendVariant::Legacy` enum option. This is an
105+
API-breaking change that will force embedders who were explicitly
106+
selecting the old backend to see that the old backend is no longer
107+
available.
108+
109+
2. Remove the `old-x86-backend` Cargo build flag.
110+
111+
3. Remove the x86 backend itself: recipes and encodings in
112+
`cranelift/codegen/isa/x86/`.
113+
114+
4. Remove any remaining backend-specific CDSL / meta-crate code except
115+
for that which remains necessary. We believe this should include at
116+
least register definitions and platform-specific legalizations. We
117+
will need to replace some of the legalizations that the new backend
118+
relies on with handwritten versions in the `simple_legalize`
119+
framework.
120+
121+
5. Remove old code in the rest of the compiler.
122+
123+
- Support for generating unwind info from the old backend's
124+
compilation result.
125+
- Support for generating debuginfo from the old backend's
126+
compilation result.
127+
- Compiler components only used when compiling with the old
128+
backend:
129+
- The register allocator.
130+
- The ABI legalization code.
131+
- The branch relaxation and binary emission pipeline.
132+
- Compiler data structures that are no longer used:
133+
- `encodings`, `locations`, `entry_diversions`, `offsets`,
134+
`jt_offsets`, prologue and epilogue info, etc., on
135+
`ir::Function`.
136+
- Any code that still generates/maintains/uses any of the above
137+
can and should be removed as well.
138+
139+
6. Begin to consider how the pipeline could be simplified in other
140+
ways now that some constraints are gone.
141+
- CodeSink: return machine code in some format more similar to the
142+
`MachBuffer`'s output, i.e., a single monolithic buffer rather
143+
than the `put1`/`put2`/... fine-grained API calling into the
144+
embedder repeatedly?
145+
146+
# Rationale and alternatives
147+
[rationale-and-alternatives]: #rationale-and-alternatives
148+
149+
As described above, this is the end of a long journey of refactoring
150+
and transition to a cleaner design; there is no reason to keep the old
151+
backend around once we've migrated all use-cases away from it and are
152+
no longer spending effort maintaining it.
153+
154+
# Open questions
155+
[open-questions]: #open-questions
156+
157+
1. Are there any significant users of the old backend that we have missed?
158+
159+
2. Is there any functionality in the old backend that we have not yet
160+
adequately replicated in the new backend?

0 commit comments

Comments
 (0)