Skip to content
New issue

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

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

Already on GitHub? # to your account

Cranelift: add option to use new single-pass register allocator. #9611

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

cfallin
Copy link
Member

@cfallin cfallin commented Nov 15, 2024

In bytecodealliance/regalloc2#181, @d-sonuga added a fast single-pass algorithm option to regalloc2, in addition to its existing backtracking allocator. This produces code much more quickly, at the expense of code quality. Sometimes this tradeoff is desirable (e.g. when performing a debug build in a fast-iteration development situation, or in an initial JIT tier).

This PR adds a Cranelift option to select the RA2 algorithm, plumbs it through to a Wasmtime option, and adds the option to Wasmtime fuzzing as well.

An initial compile-time measurement in Wasmtime: spidermonkey.wasm builds in 1.383s with backtracking (existing algorithm), and 1.065s with single-pass. The resulting binary runs a simple Fibonacci benchmark in 2.060s with backtracking vs. 3.455s with single-pass.

Hence, the single-pass algorithm yields a 23% compile-time reduction, at the cost of a 67% runtime increase.

Fixes #9596.

@cfallin cfallin requested review from a team as code owners November 15, 2024 07:40
@cfallin cfallin requested review from alexcrichton and abrown and removed request for a team November 15, 2024 07:40
@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:meta Everything related to the meta-language. fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime labels Nov 15, 2024
@Amanieu
Copy link
Contributor

Amanieu commented Nov 15, 2024

Should this selection be automatic with opt_level=none?

Copy link

Subscribe to Label Action

cc @fitzgen

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

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.

@bjorn3
Copy link
Contributor

bjorn3 commented Nov 15, 2024

In that case we should probably get an opt level between none and speed which uses the better regalloc but keeps egraph optimizations disabled given that the better regalloc has a significantly higher improvement to runtime performance than egraph optimizations.

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.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

🎉 nice!

I'm ambivalent myself on the defaults for O0 and could go either way.

@cfallin cfallin force-pushed the single-pass-regalloc branch 2 times, most recently from d60e04c to 8b89853 Compare November 15, 2024 17:38
@cfallin
Copy link
Member Author

cfallin commented Nov 15, 2024

For now at least, I think I'd prefer to keep it an opt-in default -- let's let it bake in wasmtime's continuous fuzzing for a little longer. We can always switch the default later.

@alexcrichton updated to add cargo-vet, could you rubber-stamp the new commit? Also fixed silly issues in fuzz build (which I never test beforehand because Ocaml; I should fix my setup!).

In bytecodealliance/regalloc2#181, @d-sonuga added a fast single-pass
algorithm option to regalloc2, in addition to its existing backtracking
allocator. This produces code much more quickly, at the expense of code
quality. Sometimes this tradeoff is desirable (e.g. when performing a
debug build in a fast-iteration development situation, or in an initial
JIT tier).

This PR adds a Cranelift option to select the RA2 algorithm, plumbs it
through to a Wasmtime option, and adds the option to Wasmtime fuzzing as
well.

An initial compile-time measurement in Wasmtime: `spidermonkey.wasm`
builds in 1.383s with backtracking (existing algorithm), and 1.065s with
single-pass. The resulting binary runs a simple Fibonacci benchmark in
2.060s with backtracking vs. 3.455s with single-pass.

Hence, the single-pass algorithm yields a 23% compile-time reduction, at
the cost of a 67% runtime increase.
@cfallin cfallin force-pushed the single-pass-regalloc branch from 8b89853 to 1ac7de1 Compare November 15, 2024 17:47
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks good!

For fuzzing you can also build the fuzzers with --no-default-features to turn off the ocaml integration.

@cfallin cfallin added this pull request to the merge queue Nov 15, 2024
Merged via the queue into bytecodealliance:main with commit 1e3e5fc Nov 15, 2024
40 checks passed
@cfallin cfallin deleted the single-pass-regalloc branch November 15, 2024 18:15
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:meta Everything related to the meta-language. cranelift Issues related to the Cranelift code generator fuzzing Issues related to our fuzzing infrastructure 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.

Add flag to select the fast regalloc impl
4 participants