Skip to content

Add option to use regalloc3 as the register allocator #11213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Amanieu
Copy link
Contributor

@Amanieu Amanieu commented Jul 10, 2025

This is based on bytecodealliance/regalloc2#230 which adds regalloc3 as a back-end to regalloc2.

Only one change had to be made to codegen: tail calls were reserving r11 as a scratch register by making it a def on the return instruction. This is not supported by regalloc3, which allows it extends all live ranges to the end of ret instruction so that the live range segment can merge with the next one. Since a def on a return instruction is meaningless, I've changed it to a hard-coded register in the emit stage instead.

@Amanieu Amanieu requested review from a team as code owners July 10, 2025 16:52
@Amanieu Amanieu requested review from cfallin and alexcrichton and removed request for a team July 10, 2025 16:52
@Amanieu Amanieu marked this pull request as draft July 10, 2025 16:53
Regalloc3 doesn't support def operands on return instructions and this
doesn't interact with register allocation anyways, so hard-code the use
of r11 directly in `emit_return_call_common_sequence`.
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift:meta Everything related to the meta-language. isle Related to the ISLE domain-specific language wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime labels Jul 10, 2025
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:area:machinst", "cranelift:area:x64", "cranelift:meta", "isle", "wasmtime:api", "wasmtime:config"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

  • If you added a new Config method, you wrote extensive documentation for
    it.

    Our documentation should be of the following form:

    Short, simple summary sentence.
    
    More details. These details can be multiple paragraphs. There should be
    information about not just the method, but its parameters and results as
    well.
    
    Is this method fallible? If so, when can it return an error?
    
    Can this method panic? If so, when does it panic?
    
    # Example
    
    Optional example here.
    
  • If you added a new Config method, or modified an existing one, you
    ensured that this configuration is exercised by the fuzz targets.

    For example, if you expose a new strategy for allocating the next instance
    slot inside the pooling allocator, you should ensure that at least one of our
    fuzz targets exercises that new strategy.

    Often, all that is required of you is to ensure that there is a knob for this
    configuration option in wasmtime_fuzzing::Config (or one
    of its nested structs).

    Rarely, this may require authoring a new fuzz target to specifically test this
    configuration. See our docs on fuzzing for more details.

  • If you are enabling a configuration option by default, make sure that it
    has been fuzzed for at least two weeks before turning it on by default.


To modify this label's message, edit the .github/label-messager/wasmtime-config.md file.

To add new label messages or remove existing label messages, edit the
.github/label-messager.json configuration file.

Learn more.

@github-actions github-actions bot added the fuzzing Issues related to our fuzzing infrastructure label Jul 11, 2025
Copy link

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "fuzzing"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo comment below, removing the [patch.crates-io] bits when upstream is ready, and getting CI passing.

@Amanieu
Copy link
Contributor Author

Amanieu commented Jul 16, 2025

Regarding CI, there are currently 3 issues:

  • regalloc3 depends on brie-tree (fast B-Tree implementation) which has an MSRV of 1.88.
  • brie-tree uses allocator-api 0.3 but other dependencies of wasmtime use allocator-api 0.2. This fails cargo deny due to the duplicate dependency.
  • regalloc3/brie-tree probably need to be vetted. But this can wait until the crate is actually published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift:meta Everything related to the meta-language. cranelift Issues related to the Cranelift code generator fuzzing Issues related to our fuzzing infrastructure isle Related to the ISLE domain-specific language wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants