Skip to content

Commit 753ee92

Browse files
committed
Add regalloc3 as an option for Cranelift's register allocator
1 parent 41dc1b0 commit 753ee92

File tree

8 files changed

+68
-5
lines changed

8 files changed

+68
-5
lines changed

Cargo.lock

Lines changed: 53 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,3 +619,6 @@ debug = "line-tables-only"
619619
inherits = "release"
620620
codegen-units = 1
621621
lto = true
622+
623+
[patch.crates-io]
624+
regalloc2 = { git = "https://github.com/Amanieu/regalloc2.git", branch = "regalloc3" }

cranelift/codegen/meta/src/shared/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(crate) fn define() -> SettingGroup {
4343
have adequate support for the kinds of allocations required by exception
4444
handling (https://github.com/bytecodealliance/regalloc2/issues/217).
4545
"#,
46-
vec!["backtracking"],
46+
vec!["backtracking", "regalloc3"],
4747
);
4848

4949
settings.add_enum(

cranelift/codegen/src/isa/x64/inst/emit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,9 @@ fn emit_return_call_common_sequence<T>(
19871987
// Hard-coded register which doesn't conflict with function arguments or
19881988
// callee-saved registers.
19891989
let tmp = Writable::from_reg(regs::r11());
1990+
for pair in &call_info.uses {
1991+
debug_assert_ne!(pair.preg, regs::r11());
1992+
}
19901993

19911994
for inst in
19921995
X64ABIMachineSpec::gen_clobber_restore(CallConv::Tail, &info.flags, state.frame_layout())

cranelift/codegen/src/machinst/compile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub fn compile<B: LowerBackend + TargetIsa>(
6666

6767
options.algorithm = match b.flags().regalloc_algorithm() {
6868
RegallocAlgorithm::Backtracking => Algorithm::Ion,
69+
RegallocAlgorithm::Regalloc3 => Algorithm::Regalloc3,
6970
// Note: single-pass is currently disabled
7071
// (https://github.com/bytecodealliance/regalloc2/issues/217).
7172
};

crates/cli-flags/src/opt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ impl WasmtimeOptionValue for wasmtime::RegallocAlgorithm {
482482
fn parse(val: Option<&str>) -> Result<Self> {
483483
match String::parse(val)?.as_str() {
484484
"backtracking" => Ok(wasmtime::RegallocAlgorithm::Backtracking),
485+
"regalloc3" => Ok(wasmtime::RegallocAlgorithm::Regalloc3),
485486
other => bail!(
486487
"unknown regalloc algorithm`{}`, only backtracking,single-pass accepted",
487488
other

crates/fuzzing/src/generators/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ impl OptLevel {
806806
enum RegallocAlgorithm {
807807
Backtracking,
808808
SinglePass,
809+
Regalloc3,
809810
}
810811

811812
impl RegallocAlgorithm {
@@ -819,6 +820,7 @@ impl RegallocAlgorithm {
819820
// `arbitrary` mappings, we keep the `RegallocAlgorithm`
820821
// enum as it is and remap here to `Backtracking`.
821822
RegallocAlgorithm::SinglePass => wasmtime::RegallocAlgorithm::Backtracking,
823+
RegallocAlgorithm::Regalloc3 => wasmtime::RegallocAlgorithm::Regalloc3,
822824
}
823825
}
824826
}

crates/wasmtime/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ impl Config {
12961296
pub fn cranelift_regalloc_algorithm(&mut self, algo: RegallocAlgorithm) -> &mut Self {
12971297
let val = match algo {
12981298
RegallocAlgorithm::Backtracking => "backtracking",
1299+
RegallocAlgorithm::Regalloc3 => "regalloc3",
12991300
};
13001301
self.compiler_config
13011302
.settings
@@ -2873,6 +2874,9 @@ pub enum RegallocAlgorithm {
28732874
/// results in better register utilization, producing fewer spills
28742875
/// and moves, but can cause super-linear compile runtime.
28752876
Backtracking,
2877+
2878+
/// New experimental register allocator.
2879+
Regalloc3,
28762880
}
28772881

28782882
/// Select which profiling technique to support.

0 commit comments

Comments
 (0)