Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ component-async-tests = { path = "crates/misc/component-async-tests" }

# Bytecode Alliance maintained dependencies:
# ---------------------------
regalloc2 = "0.12.2"
regalloc2 = "0.13.1"

# cap-std family:
target-lexicon = "0.13.0"
Expand Down
8 changes: 3 additions & 5 deletions cranelift/codegen/meta/src/shared/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ pub(crate) fn define() -> SettingGroup {

- `backtracking`: A backtracking allocator with range splitting; more expensive
but generates better code.

Note that the `single_pass` option is currently disabled because it does not
have adequate support for the kinds of allocations required by exception
handling (https://github.com/bytecodealliance/regalloc2/issues/217).
- `single_pass`: A single-pass algorithm that yields quick compilation but
results in code with more register spills and moves.
"#,
vec!["backtracking"],
vec!["backtracking", "single_pass"],
);

settings.add_enum(
Expand Down
3 changes: 1 addition & 2 deletions cranelift/codegen/src/machinst/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ pub fn compile<B: LowerBackend + TargetIsa>(

options.algorithm = match b.flags().regalloc_algorithm() {
RegallocAlgorithm::Backtracking => Algorithm::Ion,
// Note: single-pass is currently disabled
// (https://github.com/bytecodealliance/regalloc2/issues/217).
RegallocAlgorithm::SinglePass => Algorithm::Fastalloc,
};

regalloc2::run(&vcode, vcode.abi.machine_env(), &options)
Expand Down
1 change: 1 addition & 0 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ mod tests {
// Regalloc algorithm
for (regalloc_value, expected) in [
("\"backtracking\"", Some(RegallocAlgorithm::Backtracking)),
("\"single-pass\"", Some(RegallocAlgorithm::SinglePass)),
("\"hello\"", None), // should fail
("3", None), // should fail
("true", None), // should fail
Expand Down
2 changes: 2 additions & 0 deletions crates/cli-flags/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ impl WasmtimeOptionValue for wasmtime::RegallocAlgorithm {
fn parse(val: Option<&str>) -> Result<Self> {
match String::parse(val)?.as_str() {
"backtracking" => Ok(wasmtime::RegallocAlgorithm::Backtracking),
"single-pass" => Ok(wasmtime::RegallocAlgorithm::SinglePass),
other => bail!(
"unknown regalloc algorithm`{}`, only backtracking,single-pass accepted",
other
Expand All @@ -495,6 +496,7 @@ impl WasmtimeOptionValue for wasmtime::RegallocAlgorithm {
fn display(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
wasmtime::RegallocAlgorithm::Backtracking => f.write_str("backtracking"),
wasmtime::RegallocAlgorithm::SinglePass => f.write_str("single-pass"),
_ => unreachable!(),
}
}
Expand Down
8 changes: 1 addition & 7 deletions crates/fuzzing/src/generators/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,13 +840,7 @@ impl RegallocAlgorithm {
fn to_wasmtime(&self) -> wasmtime::RegallocAlgorithm {
match self {
RegallocAlgorithm::Backtracking => wasmtime::RegallocAlgorithm::Backtracking,
// Note: we have disabled `single_pass` for now because of
// its limitations w.r.t. exception handling
// (https://github.com/bytecodealliance/regalloc2/issues/217). To
// avoid breaking all existing fuzzbugs by changing the
// `arbitrary` mappings, we keep the `RegallocAlgorithm`
// enum as it is and remap here to `Backtracking`.
RegallocAlgorithm::SinglePass => wasmtime::RegallocAlgorithm::Backtracking,
RegallocAlgorithm::SinglePass => wasmtime::RegallocAlgorithm::SinglePass,
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ impl Config {

// When running under MIRI try to optimize for compile time of wasm
// code itself as much as possible. Disable optimizations by
// default.
// default and use the fastest regalloc available to us.
if cfg!(miri) {
ret.cranelift_opt_level(OptLevel::None);
ret.cranelift_regalloc_algorithm(RegallocAlgorithm::SinglePass);
}
}

Expand Down Expand Up @@ -1299,6 +1300,7 @@ impl Config {
pub fn cranelift_regalloc_algorithm(&mut self, algo: RegallocAlgorithm) -> &mut Self {
let val = match algo {
RegallocAlgorithm::Backtracking => "backtracking",
RegallocAlgorithm::SinglePass => "single_pass",
};
self.compiler_config
.settings
Expand Down Expand Up @@ -2934,6 +2936,16 @@ pub enum RegallocAlgorithm {
/// results in better register utilization, producing fewer spills
/// and moves, but can cause super-linear compile runtime.
Backtracking,
/// Generates acceptable code very quickly.
///
/// This algorithm performs a single pass through the code,
/// guaranteed to work in linear time. (Note that the rest of
/// Cranelift is not necessarily guaranteed to run in linear time,
/// however.) It cannot undo earlier decisions, however, and it
/// cannot foresee constraints or issues that may occur further
/// ahead in the code, so the code may have more spills and moves as
/// a result.
SinglePass,
}

/// Select which profiling technique to support.
Expand Down
4 changes: 2 additions & 2 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ user-login = "dtolnay"
user-name = "David Tolnay"

[[publisher.regalloc2]]
version = "0.12.2"
when = "2025-05-07"
version = "0.13.1"
when = "2025-08-25"
user-id = 3726
user-login = "cfallin"
user-name = "Chris Fallin"
Expand Down
4 changes: 4 additions & 0 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2239,11 +2239,15 @@ fn config_cli_flag() -> Result<()> {
br#"
[optimize]
opt-level = 2
regalloc-algorithm = "single-pass"
signals-based-traps = false

[codegen]
collector = "null"

[debug]
debug-info = true

[wasm]
max-wasm-stack = 65536

Expand Down
1 change: 1 addition & 0 deletions tests/all/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ fn big_stack_works_ok(config: &mut Config) -> Result<()> {
// Disable cranelift optimizations to ensure that this test doesn't take too
// long in debug mode due to the large size of its code.
config.cranelift_opt_level(OptLevel::None);
config.cranelift_regalloc_algorithm(RegallocAlgorithm::SinglePass);
let engine = Engine::new(config)?;

let mut store = Store::new(&engine, ());
Expand Down