Browse Source

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.
pull/2231/head
Benjamin Bouvier 4 years ago
parent
commit
e2c286deeb
  1. 4
      cranelift/Cargo.toml
  2. 2
      cranelift/filetests/Cargo.toml
  3. 16
      cranelift/filetests/filetests/isa/x64/basic.clif
  4. 13
      cranelift/filetests/filetests/isa/x64/run-const.clif
  5. 52
      cranelift/filetests/src/runone.rs
  6. 4
      cranelift/reader/Cargo.toml
  7. 27
      cranelift/reader/src/parser.rs
  8. 1
      cranelift/tests/filetests.rs

4
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"]

2
cranelift/filetests/Cargo.toml

@ -29,3 +29,5 @@ anyhow = "1.0.32"
[features]
enable-peepmatic = []
experimental_arm32 = []
experimental_x64 = []

16
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
}

13
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

52
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());
}

4
cranelift/reader/Cargo.toml

@ -17,3 +17,7 @@ thiserror = "1.0.15"
[badges]
maintenance = { status = "experimental" }
[features]
default = []
experimental_x64 = []

27
cranelift/reader/src/parser.rs

@ -90,6 +90,33 @@ pub fn parse_test<'a>(text: &'a str, options: ParseOptions<'a>) -> ParseResult<T
};
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
// host's calling convention--if any tests are to be run on the host we should default to the
// host's calling convention.

1
cranelift/tests/filetests.rs

@ -1,5 +1,4 @@
#[test]
#[cfg_attr(feature = "experimental_x64", should_panic)] // TODO #2079
fn filetests() {
// Run all the filetests in the following directories.
cranelift_filetests::run(false, false, &["filetests".into(), "docs".into()])

Loading…
Cancel
Save