-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Wasmtime: Add (optional) bottom-up function inlining to Wasm compilation #11283
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
base: main
Are you sure you want to change the base?
Conversation
We copy *all* callee blocks into the caller's layout, but were then only copying the callee instructions in *reachable* callee blocks into the caller. Therefore, any *unreachable* blocks would remain empty in the caller, which is invalid CLIF because all blocks must end in a terminator, so this commit adds a quick pass over the inlined blocks to remove any empty blocks from the caller's layout.
0276ad6
to
eb34ad4
Compare
This commit plumbs together two pieces of recently-added infrastructure: 1. function inlining in Cranelift, and 2. the parallel bottom-up inlining scheduler in Wasmtime. Sprinkle some very simple inlining heuristics on top, and this gives us function inlining in Wasm compilation. The default Wasmtime configuration does not enable inlining, and when we do enable it, we only enable it for cross-component calls by default (since presumably the toolchain that produced a particular core Wasm module, like LLVM, already performed any inlining that was beneficial within that module, but that toolchain couldn't know how that Wasm module would be getting linked together with other modules via component composition, and so it could not have done any cross-component inlining). For what it is worth, there is a config knob to enable intra-module function inlining, but this is primarily for use by our fuzzers, so that they can easily excercise and explore this new inlining functionality. All this plumbing required some changes to the `wasmtime_environ::Compiler` trait, since Winch cannot do inlining but Cranelift can. This is mostly encapsulated in the new `wasmtime_environ::InliningCompiler` trait, for the most part. Additionally, we take care not to construct the call graph, or any other data structures required only by the inliner and not regular compilation, both when using Winch and when using Cranelift with inlining disabled. Finally, we add a `disas` test to verify that we successfully inline a series of calls from a function in one component, to a cross-component adapter function, to a function in another component. Most test coverage is expected to come from our fuzzing, however.
eb34ad4
to
7079aed
Compare
Subscribe to Label Action
This issue or pull request has been labeled: "cranelift", "fuzzing", "wasmtime:api", "wasmtime:config", "winch"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
Label Messager: wasmtime:configIt looks like you are changing Wasmtime's configuration options. Make sure to
To modify this label's message, edit the To add new label messages or remove existing label messages, edit the |
This commit plumbs together two pieces of recently-added infrastructure:
Sprinkle some very simple inlining heuristics on top, and this gives us function
inlining in Wasm compilation.
The default Wasmtime configuration does not enable inlining, and when we do
enable it, we only enable it for cross-component calls by default (since
presumably the toolchain that produced a particular core Wasm module, like LLVM,
already performed any inlining that was beneficial within that module, but that
toolchain couldn't know how that Wasm module would be getting linked together
with other modules via component composition, and so it could not have done any
cross-component inlining). For what it is worth, there is a config knob to
enable intra-module function inlining, but this is primarily for use by our
fuzzers, so that they can easily excercise and explore this new inlining
functionality.
All this plumbing required some changes to the
wasmtime_environ::Compiler
trait, since Winch cannot do inlining but Cranelift can. This is mostly
encapsulated in the new
wasmtime_environ::InliningCompiler
trait, for the mostpart. Additionally, we take care not to construct the call graph, or any other
data structures required only by the inliner and not regular compilation, both
when using Winch and when using Cranelift with inlining disabled.
Finally, we add a
disas
test to verify that we successfully inline a series ofcalls from a function in one component, to a cross-component adapter function,
to a function in another component. Most test coverage is expected to come from
our fuzzing, however.
Depends on #11282