diff --git a/cranelift/Cargo.toml b/cranelift/Cargo.toml index bf788bf691..3635f5d065 100644 --- a/cranelift/Cargo.toml +++ b/cranelift/Cargo.toml @@ -50,6 +50,6 @@ 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"] -experimental_arm32 = ["cranelift-codegen/arm32"] +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"] diff --git a/cranelift/filetests/Cargo.toml b/cranelift/filetests/Cargo.toml index e251b477a0..be4ce7051d 100644 --- a/cranelift/filetests/Cargo.toml +++ b/cranelift/filetests/Cargo.toml @@ -29,3 +29,5 @@ anyhow = "1.0.32" [features] enable-peepmatic = [] +experimental_arm32 = [] +experimental_x64 = [] diff --git a/cranelift/filetests/filetests/isa/x64/basic.clif b/cranelift/filetests/filetests/isa/x64/basic.clif new file mode 100644 index 0000000000..17897d2bb5 --- /dev/null +++ b/cranelift/filetests/filetests/isa/x64/basic.clif @@ -0,0 +1,16 @@ +test compile +target x86_64 +feature "experimental_x64" + +function %f(i32, i32) -> i32 { +block0(v0: i32, v1: i32): + ; check: pushq %rbp + ; check: movq %rsp, %rbp + v2 = iadd v0, v1 + ; check: addl %esi, %edi + return v2 + ; check: movq %rdi, %rax + ; check: movq %rbp, %rsp + ; check: popq %rbp + ; check: ret +} diff --git a/cranelift/filetests/filetests/isa/x64/run-const.clif b/cranelift/filetests/filetests/isa/x64/run-const.clif new file mode 100644 index 0000000000..af0a85353c --- /dev/null +++ b/cranelift/filetests/filetests/isa/x64/run-const.clif @@ -0,0 +1,13 @@ +test run +target x86_64 +feature "experimental_x64" + +function %test_compare_i32() -> b1 { +block0: + v0 = iconst.i32 42 + v1 = iconst.i32 42 + v2 = icmp eq v0, v1 + return v2 +} + +; run diff --git a/cranelift/filetests/src/runone.rs b/cranelift/filetests/src/runone.rs index 310b173cf0..c38315568c 100644 --- a/cranelift/filetests/src/runone.rs +++ b/cranelift/filetests/src/runone.rs @@ -9,13 +9,55 @@ use cranelift_codegen::print_errors::pretty_verifier_error; use cranelift_codegen::settings::Flags; use cranelift_codegen::timing; use cranelift_codegen::verify_function; -use cranelift_reader::{parse_test, Feature, IsaSpec, ParseOptions}; +use cranelift_reader::{parse_test, Feature, IsaSpec, ParseOptions, TestFile}; use log::info; use std::borrow::Cow; use std::fs; use std::path::Path; use std::time; +/// Skip the tests which define features and for which there's a feature mismatch. +/// +/// When a test must be skipped, returns an Option with a string containing an explanation why; +/// otherwise, return None. +fn skip_feature_mismatches(testfile: &TestFile) -> Option<&'static str> { + let mut has_experimental_x64 = false; + let mut has_experimental_arm32 = false; + + for feature in &testfile.features { + if let Feature::With(name) = feature { + match *name { + "experimental_x64" => has_experimental_x64 = true, + "experimental_arm32" => has_experimental_arm32 = true, + _ => {} + } + } + } + + // On the experimental x64 backend, skip tests which are not marked with the feature and + // that want to run on the x86_64 target isa. + #[cfg(feature = "experimental_x64")] + if let IsaSpec::Some(ref isas) = testfile.isa_spec { + if isas.iter().any(|isa| isa.name() == "x64") && !has_experimental_x64 { + return Some("test requiring x86_64 not marked with experimental_x64"); + } + } + + // On other targets, ignore tests marked as experimental_x64 only. + #[cfg(not(feature = "experimental_x64"))] + if has_experimental_x64 { + return Some("missing support for experimental_x64"); + } + + // Don't run tests if the experimental support for arm32 is disabled. + #[cfg(not(feature = "experimental_arm32"))] + if has_experimental_arm32 { + return Some("missing support for experimental_arm32"); + } + + None +} + /// Load `path` and run the test in it. /// /// If running this test causes a panic, it will propagate as normal. @@ -51,12 +93,8 @@ pub fn run( } }; - #[cfg(not(feature = "experimental_arm32"))] - if testfile - .features - .contains(&Feature::With("experimental_arm32")) - { - println!("skipped {:?}: no experimental_arm32 feature", path); + if let Some(msg) = skip_feature_mismatches(&testfile) { + println!("skipped {:?}: {}", path, msg); return Ok(started.elapsed()); } diff --git a/cranelift/reader/Cargo.toml b/cranelift/reader/Cargo.toml index 02131d890f..2b75bb32b9 100644 --- a/cranelift/reader/Cargo.toml +++ b/cranelift/reader/Cargo.toml @@ -17,3 +17,7 @@ thiserror = "1.0.15" [badges] maintenance = { status = "experimental" } + +[features] +default = [] +experimental_x64 = [] diff --git a/cranelift/reader/src/parser.rs b/cranelift/reader/src/parser.rs index 230d1b83d3..3d6f3da1e5 100644 --- a/cranelift/reader/src/parser.rs +++ b/cranelift/reader/src/parser.rs @@ -90,6 +90,33 @@ pub fn parse_test<'a>(text: &'a str, options: ParseOptions<'a>) -> ParseResult