Skip to content

Commit

Permalink
Switch default to new x86_64 backend.
Browse files Browse the repository at this point in the history
This PR switches the default backend on x86, for both the
`cranelift-codegen` crate and for Wasmtime, to the new
(`MachInst`-style, `VCode`-based) backend that has been under
development and testing for some time now.

The old backend is still available by default in builds with the
`old-x86-backend` feature, or by requesting `BackendVariant::Legacy`
from the appropriate APIs.

As part of that switch, it adds some more runtime-configurable plumbing
to the testing infrastructure so that tests can be run using the
appropriate backend. `clif-util test` is now capable of parsing a
backend selector option from filetests and instantiating the correct
backend.

CI has been updated so that the old x86 backend continues to run its
tests, just as we used to run the new x64 backend separately.

At some point, we will remove the old x86 backend entirely, once we are
satisfied that the new backend has not caused any unforeseen issues and
we do not need to revert.
  • Loading branch information
cfallin committed Mar 11, 2021
1 parent 07c6ca1 commit 153cca2
Show file tree
Hide file tree
Showing 242 changed files with 303 additions and 442 deletions.
47 changes: 6 additions & 41 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ jobs:
# Test debug (DWARF) related functionality on new backend.
- run: |
sudo apt-get update && sudo apt-get install -y gdb
cargo test --features experimental_x64 test_debug_dwarf -- --ignored --test-threads 1 --test debug::
cargo test test_debug_dwarf -- --ignored --test-threads 1 --test debug::
if: matrix.os == 'ubuntu-latest'
env:
RUST_BACKTRACE: 1
Expand All @@ -319,12 +319,10 @@ jobs:
RUST_BACKTRACE: 1

# Perform all tests (debug mode) for `wasmtime` with the experimental x64
# backend. This runs on an older nightly of Rust (because of issues with
# unifying Cargo features on stable) on Ubuntu such that it's new enough
# to build Wasmtime, but old enough where the -Z options being used
# haven't been stabilized yet.
test_x64:
name: Test x64 new backend
# backend. This runs on the nightly channel of Rust (because of issues with
# unifying Cargo features on stable) on Ubuntu.
test_old_x86_backend:
name: Test old x86 backend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -341,40 +339,7 @@ jobs:
- run: rustup target add wasm32-unknown-unknown

# Run the x64 CI script.
- run: ./ci/run-experimental-x64-ci.sh
env:
CARGO_VERSION: "+nightly-2020-12-26"
RUST_BACKTRACE: 1

# Perform tests on the new x64 backend on Windows as well.
test_x64_win:
name: Test x64 new backend on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: ./.github/actions/install-rust
with:
toolchain: nightly-2020-11-29
- uses: ./.github/actions/define-llvm-env

- name: Install libclang
# Note: libclang is pre-installed on the macOS and linux images.
if: matrix.os == 'windows-latest'
run: |
curl https://releases.llvm.org/9.0.0/LLVM-9.0.0-win64.exe -o llvm-installer.exe
7z x llvm-installer.exe -oC:/llvm-binary
echo LIBCLANG_PATH=C:/llvm-binary/bin/libclang.dll >> $GITHUB_ENV
echo C:/llvm-binary/bin >> $GITHUB_PATH
# Install wasm32 targets in order to build various tests throughout the
# repo.
- run: rustup target add wasm32-wasi
- run: rustup target add wasm32-unknown-unknown

# Run the x64 CI script.
- run: ./ci/run-experimental-x64-ci.sh
- run: ./ci/run-old-x86-ci.sh
env:
CARGO_VERSION: "+nightly-2020-11-29"
RUST_BACKTRACE: 1
Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ wasi-crypto = ["wasmtime-wasi-crypto"]
wasi-nn = ["wasmtime-wasi-nn"]
uffd = ["wasmtime/uffd"]

# Try the experimental, work-in-progress new x86_64 backend. This is not stable
# as of June 2020.
experimental_x64 = ["wasmtime-jit/experimental_x64"]
# Use the old x86 backend.
old-x86-backend = ["wasmtime-jit/old-x86-backend"]

[badges]
maintenance = { status = "actively-developed" }
Expand Down
41 changes: 11 additions & 30 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,8 @@ fn write_testsuite_tests(
let testname = extract_name(path);

writeln!(out, "#[test]")?;
if experimental_x64_should_panic(testsuite, &testname, strategy) {
writeln!(
out,
r#"#[cfg_attr(feature = "experimental_x64", should_panic)]"#
)?;
if x64_should_panic(testsuite, &testname, strategy) {
writeln!(out, r#"#[should_panic]"#)?;
} else if ignore(testsuite, &testname, strategy) {
writeln!(out, "#[ignore]")?;
} else if pooling {
Expand All @@ -186,10 +183,10 @@ fn write_testsuite_tests(
Ok(())
}

/// For experimental_x64 backend features that are not supported yet, mark tests as panicking, so
/// For x64 backend features that are not supported yet, mark tests as panicking, so
/// they stop "passing" once the features are properly implemented.
fn experimental_x64_should_panic(testsuite: &str, testname: &str, strategy: &str) -> bool {
if !cfg!(feature = "experimental_x64") || strategy != "Cranelift" {
fn x64_should_panic(testsuite: &str, testname: &str, strategy: &str) -> bool {
if !platform_is_x64() || strategy != "Cranelift" {
return false;
}

Expand Down Expand Up @@ -222,15 +219,11 @@ fn ignore(testsuite: &str, testname: &str, strategy: &str) -> bool {
_ => (),
},
"Cranelift" => match (testsuite, testname) {
// TODO(#1886): Ignore reference types tests if this isn't x64,
// because Cranelift only supports reference types on x64.
("reference_types", _) => {
return env::var("CARGO_CFG_TARGET_ARCH").unwrap() != "x86_64";
}

("simd", _) if cfg!(feature = "old-x86-backend") => return true, // skip all SIMD tests on old backend.
// These are new instructions that are not really implemented in any backend.
("simd", "simd_i8x16_arith2")
| ("simd", "simd_conversions")
| ("simd", "simd_boolean")
| ("simd", "simd_i16x8_extadd_pairwise_i8x16")
| ("simd", "simd_i16x8_extmul_i8x16")
| ("simd", "simd_i16x8_q15mulr_sat_s")
Expand All @@ -240,26 +233,14 @@ fn ignore(testsuite: &str, testname: &str, strategy: &str) -> bool {
| ("simd", "simd_i64x2_extmul_i32x4")
| ("simd", "simd_int_to_int_extend") => return true,

// These are only implemented on x64.
("simd", "simd_i64x2_arith2") | ("simd", "simd_boolean") => {
return !cfg!(feature = "experimental_x64")
}

// These are only implemented on aarch64 and x64.
("simd", "simd_i64x2_cmp")
| ("simd", "simd_f32x4_pmin_pmax")
| ("simd", "simd_f64x2_pmin_pmax")
| ("simd", "simd_f32x4_rounding")
| ("simd", "simd_f64x2_rounding")
| ("simd", "simd_i32x4_dot_i16x8") => {
return !(cfg!(feature = "experimental_x64")
|| env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "aarch64")
}

_ => {}
},
_ => panic!("unrecognized strategy"),
}

false
}

fn platform_is_x64() -> bool {
env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "x86_64"
}
4 changes: 2 additions & 2 deletions ci/run-experimental-x64-ci.sh → ci/run-old-x86-ci.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Use the Nightly variant of the compiler to properly unify the
# experimental_x64 feature across all crates. Once the feature has stabilized
# across all crates. Once the feature has stabilized
# and become the default, we can remove this.
CARGO_VERSION=${CARGO_VERSION:-"+nightly"}

Expand All @@ -20,7 +20,7 @@ cargo $CARGO_VERSION \
-Zfeatures=all -Zpackage-features \
test \
--features test-programs/test_programs \
--features experimental_x64 \
--features old-x86-backend \
--all \
--exclude wasmtime-lightbeam \
--exclude wasmtime-wasi-nn \
Expand Down
1 change: 0 additions & 1 deletion cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ default = ["disas", "wasm", "cranelift-codegen/all-arch", "peepmatic-souper", "s
disas = ["capstone"]
enable-peepmatic = ["cranelift-codegen/enable-peepmatic", "cranelift-filetests/enable-peepmatic"]
wasm = ["wat", "cranelift-wasm"]
experimental_x64 = ["cranelift-codegen/x64", "cranelift-filetests/experimental_x64", "cranelift-reader/experimental_x64"]
experimental_arm32 = ["cranelift-codegen/arm32", "cranelift-filetests/experimental_arm32"]
souper-harvest = ["cranelift-codegen/souper-harvest", "rayon"]
4 changes: 3 additions & 1 deletion cranelift/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ unwind = ["gimli"]
x86 = []
arm64 = []
riscv = []
x64 = [] # New work-in-progress codegen backend for x86_64 based on the new isel.
arm32 = [] # Work-in-progress codegen backend for ARM.

# Make the old x86 backend the default.
old-x86-backend = []

# Option to enable all architectures.
all-arch = [
"x86",
Expand Down
28 changes: 16 additions & 12 deletions cranelift/codegen/src/isa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ use thiserror::Error;
#[cfg(feature = "riscv")]
mod riscv;

// N.B.: the old x86-64 backend (`x86`) and the new one (`x64`) can both be
// included; if the new backend is included, then it is the default backend
// returned for an x86-64 triple, but a specific option can request the old
// backend. It is important to have the ability to instantiate *both* backends
// in the same build so that we can do things like differential fuzzing between
// backends, or perhaps offer a runtime configuration flag in the future.
// N.B.: the old x86-64 backend (`x86`) and the new one (`x64`) are both
// included whenever building with x86 support. The new backend is the default,
// but the old can be requested with `BackendVariant::Legacy`. However, if this
// crate is built with the `old-x86-backend` feature, then the old backend is
// default instead.
#[cfg(feature = "x86")]
mod x86;

#[cfg(feature = "x64")]
#[cfg(feature = "x86")]
mod x64;

#[cfg(feature = "arm32")]
Expand Down Expand Up @@ -123,7 +122,7 @@ macro_rules! isa_builder {
/// The "variant" for a given target. On one platform (x86-64), we have two
/// backends, the "old" and "new" one; the new one is the default if included
/// in the build configuration and not otherwise specified.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum BackendVariant {
/// Any backend available.
Any,
Expand All @@ -150,13 +149,13 @@ pub fn lookup_variant(triple: Triple, variant: BackendVariant) -> Result<Builder
isa_builder!(x86, (feature = "x86"), triple)
}
(Architecture::X86_64, BackendVariant::MachInst) => {
isa_builder!(x64, (feature = "x64"), triple)
isa_builder!(x64, (feature = "x86"), triple)
}
#[cfg(feature = "x64")]
#[cfg(not(feature = "old-x86-backend"))]
(Architecture::X86_64, BackendVariant::Any) => {
isa_builder!(x64, (feature = "x64"), triple)
isa_builder!(x64, (feature = "x86"), triple)
}
#[cfg(not(feature = "x64"))]
#[cfg(feature = "old-x86-backend")]
(Architecture::X86_64, BackendVariant::Any) => {
isa_builder!(x86, (feature = "x86"), triple)
}
Expand Down Expand Up @@ -265,6 +264,11 @@ pub trait TargetIsa: fmt::Display + Send + Sync {
/// Get the ISA-independent flags that were used to make this trait object.
fn flags(&self) -> &settings::Flags;

/// Get the variant of this ISA (Legacy or MachInst).
fn variant(&self) -> BackendVariant {
BackendVariant::Legacy
}

/// Hashes all flags, both ISA-independent and ISA-specific, into the
/// specified hasher.
fn hash_all_flags(&self, hasher: &mut dyn Hasher);
Expand Down
2 changes: 2 additions & 0 deletions cranelift/codegen/src/isa/x64/inst/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

//! Instruction operand sub-components (aka "parts"): definitions and printing.

use super::regs::{self, show_ireg_sized};
Expand Down
2 changes: 2 additions & 0 deletions cranelift/codegen/src/isa/x64/inst/unwind/systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ mod tests {
use target_lexicon::triple;

#[test]
#[cfg_attr(feature = "old-x86-backend", ignore)]
fn test_simple_func() {
let isa = lookup(triple!("x86_64"))
.expect("expect x86 ISA")
Expand Down Expand Up @@ -151,6 +152,7 @@ mod tests {
}

#[test]
#[cfg_attr(feature = "old-x86-backend", ignore)]
fn test_multi_return_func() {
let isa = lookup(triple!("x86_64"))
.expect("expect x86 ISA")
Expand Down
1 change: 1 addition & 0 deletions cranelift/codegen/src/isa/x64/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ fn input_to_reg_mem<C: LowerCtx<I = Inst>>(ctx: &mut C, spec: InsnInput) -> RegM
}

/// An extension specification for `extend_input_to_reg`.
#[allow(dead_code)]
#[derive(Clone, Copy)]
enum ExtSpec {
ZeroExtendTo32,
Expand Down
8 changes: 7 additions & 1 deletion cranelift/codegen/src/machinst/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

use crate::binemit;
use crate::ir;
use crate::isa::{EncInfo, Encoding, Encodings, Legalize, RegClass, RegInfo, TargetIsa};
use crate::isa::{
BackendVariant, EncInfo, Encoding, Encodings, Legalize, RegClass, RegInfo, TargetIsa,
};
use crate::machinst::*;
use crate::regalloc::RegisterSet;
use crate::settings::Flags;
Expand Down Expand Up @@ -59,6 +61,10 @@ impl TargetIsa for TargetIsaAdapter {
self.backend.flags()
}

fn variant(&self) -> BackendVariant {
BackendVariant::MachInst
}

fn hash_all_flags(&self, hasher: &mut dyn Hasher) {
self.backend.hash_all_flags(hasher)
}
Expand Down
1 change: 0 additions & 1 deletion cranelift/filetests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ anyhow = "1.0.32"
[features]
enable-peepmatic = []
experimental_arm32 = []
experimental_x64 = []
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/amode-opt.clif
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
test compile
set unwind_info=false
target x86_64
feature "experimental_x64"
target x86_64 machinst

function %amode_add(i64, i64) -> i64 {
block0(v0: i64, v1: i64):
Expand Down
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/b1.clif
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
test compile
set unwind_info=false
target x86_64
feature "experimental_x64"
target x86_64 machinst

function %f0(b1, i32, i32) -> i32 {
; check: pushq %rbp
Expand Down
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/basic.clif
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
test compile
set unwind_info=false
target x86_64
feature "experimental_x64"
target x86_64 machinst

function %f(i32, i32) -> i32 {
block0(v0: i32, v1: i32):
Expand Down
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/bitops-i128-run.clif
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
test run
target x86_64
feature "experimental_x64"
target x86_64 machinst

function %ctz(i64, i64) -> i8 {
block0(v0: i64, v1: i64):
Expand Down
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/bitrev-i128-run.clif
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
test run
target x86_64
feature "experimental_x64"
target x86_64 machinst

function %reverse_bits_zero() -> b1 {
block0:
Expand Down
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/branches.clif
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
test compile
set unwind_info=false
target x86_64
feature "experimental_x64"
target x86_64 machinst

function %f0(i32, i32) -> i32 {
block0(v0: i32, v1: i32):
Expand Down
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/clz-lzcnt.clif
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
test compile
set unwind_info=false
target x86_64 has_lzcnt
feature "experimental_x64"
target x86_64 machinst has_lzcnt

function %clz(i64) -> i64 {
block0(v0: i64):
Expand Down
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/cmp-mem-bug.clif
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
test compile
set unwind_info=false
target x86_64
feature "experimental_x64"
target x86_64 machinst

function %f0(i64, i64) -> i64, i64 {
block0(v0: i64, v1: i64):
Expand Down
3 changes: 1 addition & 2 deletions cranelift/filetests/filetests/isa/x64/ctz-bmi1.clif
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
test compile
set unwind_info=false
target x86_64 has_bmi1
feature "experimental_x64"
target x86_64 machinst has_bmi1

function %ctz(i64) -> i64 {
block0(v0: i64):
Expand Down
Loading

0 comments on commit 153cca2

Please sign in to comment.