machinst x64: enable clif testing
This adds a new feature experimental_x64 for CLIF tests. A test is run in the new x64 backend iff: - either the test doesn't have an x86_64 target requirement, signaling it must be target agnostic or not run on this target. - or the test does require the x86_64 target, and the test is marked with the `experimental_x64` feature. This required one workaround in the parser. The reason is that the parser will try to use information not provided by the TargetIsa adapter for the Mach backends, like register names. In particular, parsing test may fail before the test runner realizes that the test must not be run. In this case, we early return an almost-empty TestFile from the parser, under the same conditions as above, so that the caller may filter out the test properly. This also copies two tests from the test suite using the new backend, for demonstration purposes.
This commit is contained in:
@@ -50,6 +50,6 @@ default = ["disas", "wasm", "cranelift-codegen/all-arch", "peepmatic-souper", "s
|
|||||||
disas = ["capstone"]
|
disas = ["capstone"]
|
||||||
enable-peepmatic = ["cranelift-codegen/enable-peepmatic", "cranelift-filetests/enable-peepmatic"]
|
enable-peepmatic = ["cranelift-codegen/enable-peepmatic", "cranelift-filetests/enable-peepmatic"]
|
||||||
wasm = ["wat", "cranelift-wasm"]
|
wasm = ["wat", "cranelift-wasm"]
|
||||||
experimental_x64 = ["cranelift-codegen/x64"]
|
experimental_x64 = ["cranelift-codegen/x64", "cranelift-filetests/experimental_x64", "cranelift-reader/experimental_x64"]
|
||||||
experimental_arm32 = ["cranelift-codegen/arm32"]
|
experimental_arm32 = ["cranelift-codegen/arm32", "cranelift-filetests/experimental_arm32"]
|
||||||
souper-harvest = ["cranelift-codegen/souper-harvest", "rayon"]
|
souper-harvest = ["cranelift-codegen/souper-harvest", "rayon"]
|
||||||
|
|||||||
@@ -29,3 +29,5 @@ anyhow = "1.0.32"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
enable-peepmatic = []
|
enable-peepmatic = []
|
||||||
|
experimental_arm32 = []
|
||||||
|
experimental_x64 = []
|
||||||
|
|||||||
16
cranelift/filetests/filetests/isa/x64/basic.clif
Normal file
16
cranelift/filetests/filetests/isa/x64/basic.clif
Normal file
@@ -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
|
||||||
|
}
|
||||||
13
cranelift/filetests/filetests/isa/x64/run-const.clif
Normal file
13
cranelift/filetests/filetests/isa/x64/run-const.clif
Normal file
@@ -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
|
||||||
@@ -9,13 +9,55 @@ use cranelift_codegen::print_errors::pretty_verifier_error;
|
|||||||
use cranelift_codegen::settings::Flags;
|
use cranelift_codegen::settings::Flags;
|
||||||
use cranelift_codegen::timing;
|
use cranelift_codegen::timing;
|
||||||
use cranelift_codegen::verify_function;
|
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 log::info;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time;
|
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.
|
/// Load `path` and run the test in it.
|
||||||
///
|
///
|
||||||
/// If running this test causes a panic, it will propagate as normal.
|
/// 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 let Some(msg) = skip_feature_mismatches(&testfile) {
|
||||||
if testfile
|
println!("skipped {:?}: {}", path, msg);
|
||||||
.features
|
|
||||||
.contains(&Feature::With("experimental_arm32"))
|
|
||||||
{
|
|
||||||
println!("skipped {:?}: no experimental_arm32 feature", path);
|
|
||||||
return Ok(started.elapsed());
|
return Ok(started.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,3 +17,7 @@ thiserror = "1.0.15"
|
|||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
maintenance = { status = "experimental" }
|
maintenance = { status = "experimental" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
experimental_x64 = []
|
||||||
|
|||||||
@@ -90,6 +90,33 @@ pub fn parse_test<'a>(text: &'a str, options: ParseOptions<'a>) -> ParseResult<T
|
|||||||
};
|
};
|
||||||
let features = parser.parse_cranelift_features()?;
|
let features = parser.parse_cranelift_features()?;
|
||||||
|
|
||||||
|
#[cfg(feature = "experimental_x64")]
|
||||||
|
{
|
||||||
|
// If the test mentioned that it must run on x86_64, and the experimental_x64 feature is
|
||||||
|
// not present, we might run into parsing errors, because some TargetIsa information is
|
||||||
|
// left unimplemented in the new backend (e.g. register names).
|
||||||
|
//
|
||||||
|
// Users of this function must do some special treatment when the test requires to run on
|
||||||
|
// x86_64 without the experimental_x64 feature, until we switch to using the new x64
|
||||||
|
// backend by default.
|
||||||
|
//
|
||||||
|
// In the meanwhile, return a minimal TestFile containing the features/isa_spec, so the
|
||||||
|
// caller can ignore this.
|
||||||
|
if let isaspec::IsaSpec::Some(ref isas) = isa_spec {
|
||||||
|
if isas.iter().any(|isa| isa.name() == "x64")
|
||||||
|
&& !features.contains(&Feature::With("experimental_x64"))
|
||||||
|
{
|
||||||
|
return Ok(TestFile {
|
||||||
|
commands,
|
||||||
|
isa_spec,
|
||||||
|
features,
|
||||||
|
preamble_comments: Vec::new(),
|
||||||
|
functions: Vec::new(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Decide between using the calling convention passed in the options or using the
|
// Decide between using the calling convention passed in the options or using the
|
||||||
// host's calling convention--if any tests are to be run on the host we should default to the
|
// host's calling convention--if any tests are to be run on the host we should default to the
|
||||||
// host's calling convention.
|
// host's calling convention.
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(feature = "experimental_x64", should_panic)] // TODO #2079
|
|
||||||
fn filetests() {
|
fn filetests() {
|
||||||
// Run all the filetests in the following directories.
|
// Run all the filetests in the following directories.
|
||||||
cranelift_filetests::run(false, false, &["filetests".into(), "docs".into()])
|
cranelift_filetests::run(false, false, &["filetests".into(), "docs".into()])
|
||||||
|
|||||||
Reference in New Issue
Block a user