Merge vcode filetest mode into compile.
I hadn't realized before that the filetest backend for `test vcode` is doing essentially what `compile` is doing, but for new (`MachInst`) backends: it is just getting a disassembly and running it through filecheck. There's no reason not to reuse `test compile` for the AArch64 tests as well. This was motivated by the desire to have "this IR compiles successfully" tests work on both x86 and AArch64. It seems this should work fine by adding multiple `target` directives when a test case should be compile-tested on multiple architectures.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f1(i64, i64) -> i64 {
|
function %f1(i64, i64) -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f(i32, i32) -> i32 {
|
function %f(i32, i32) -> i32 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %a(i8) -> i8 {
|
function %a(i8) -> i8 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f(i64, i64) -> i64 {
|
function %f(i64, i64) -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f(i64) -> i64 {
|
function %f(i64) -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f(i64, i64) -> b1 {
|
function %f(i64, i64) -> b1 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f(i8, i64, i64) -> i64 {
|
function %f(i8, i64, i64) -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f() -> b8 {
|
function %f() -> b8 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f(i8) -> i64 {
|
function %f(i8) -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f1(f32, f32) -> f32 {
|
function %f1(f32, f32) -> f32 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f(i64) -> i64 {
|
function %f(i64) -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %add8(i8, i8) -> i8 {
|
function %add8(i8, i8) -> i8 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %uaddsat64(i64, i64) -> i64 {
|
function %uaddsat64(i64, i64) -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f(i64) -> i64 {
|
function %f(i64) -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %foo() {
|
function %foo() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %stack_addr_small() -> i64 {
|
function %stack_addr_small() -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f() -> i64 {
|
function %f() -> i64 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f() {
|
function %f() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
test vcode
|
test compile
|
||||||
target aarch64
|
target aarch64
|
||||||
|
|
||||||
function %f_u_8_64(i8) -> i64 {
|
function %f_u_8_64(i8) -> i64 {
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ mod test_shrink;
|
|||||||
mod test_simple_gvn;
|
mod test_simple_gvn;
|
||||||
mod test_simple_preopt;
|
mod test_simple_preopt;
|
||||||
mod test_unwind;
|
mod test_unwind;
|
||||||
mod test_vcode;
|
|
||||||
mod test_verifier;
|
mod test_verifier;
|
||||||
|
|
||||||
/// The result of running the test in a file.
|
/// The result of running the test in a file.
|
||||||
@@ -141,7 +140,6 @@ fn new_subtest(parsed: &TestCommand) -> subtest::SubtestResult<Box<dyn subtest::
|
|||||||
"simple-gvn" => test_simple_gvn::subtest(parsed),
|
"simple-gvn" => test_simple_gvn::subtest(parsed),
|
||||||
"simple_preopt" => test_simple_preopt::subtest(parsed),
|
"simple_preopt" => test_simple_preopt::subtest(parsed),
|
||||||
"unwind" => test_unwind::subtest(parsed),
|
"unwind" => test_unwind::subtest(parsed),
|
||||||
"vcode" => test_vcode::subtest(parsed),
|
|
||||||
"verifier" => test_verifier::subtest(parsed),
|
"verifier" => test_verifier::subtest(parsed),
|
||||||
_ => Err(format!("unknown test command '{}'", parsed.command)),
|
_ => Err(format!("unknown test command '{}'", parsed.command)),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ impl SubTest for TestCompile {
|
|||||||
let isa = context.isa.expect("compile needs an ISA");
|
let isa = context.isa.expect("compile needs an ISA");
|
||||||
let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
|
let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
|
||||||
|
|
||||||
|
if isa.get_mach_backend().is_some() {
|
||||||
|
// With `MachBackend`s, we need to explicitly request dissassembly results.
|
||||||
|
comp_ctx.set_disasm(true);
|
||||||
|
}
|
||||||
|
|
||||||
let CodeInfo { total_size, .. } = comp_ctx
|
let CodeInfo { total_size, .. } = comp_ctx
|
||||||
.compile(isa)
|
.compile(isa)
|
||||||
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, e))?;
|
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, e))?;
|
||||||
@@ -50,6 +55,7 @@ impl SubTest for TestCompile {
|
|||||||
comp_ctx.func.display(isa)
|
comp_ctx.func.display(isa)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if !isa.get_mach_backend().is_some() {
|
||||||
// Verify that the returned code size matches the emitted bytes.
|
// Verify that the returned code size matches the emitted bytes.
|
||||||
let mut sink = SizeSink { offset: 0 };
|
let mut sink = SizeSink { offset: 0 };
|
||||||
binemit::emit_function(
|
binemit::emit_function(
|
||||||
@@ -69,6 +75,16 @@ impl SubTest for TestCompile {
|
|||||||
// Run final code through filecheck.
|
// Run final code through filecheck.
|
||||||
let text = comp_ctx.func.display(Some(isa)).to_string();
|
let text = comp_ctx.func.display(Some(isa)).to_string();
|
||||||
run_filecheck(&text, context)
|
run_filecheck(&text, context)
|
||||||
|
} else {
|
||||||
|
let disasm = comp_ctx
|
||||||
|
.mach_compile_result
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.disasm
|
||||||
|
.as_ref()
|
||||||
|
.unwrap();
|
||||||
|
run_filecheck(&disasm, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
use crate::subtest::{run_filecheck, Context, SubTest, SubtestResult};
|
|
||||||
use cranelift_codegen::ir::Function;
|
|
||||||
use cranelift_codegen::isa::lookup;
|
|
||||||
use cranelift_codegen::settings;
|
|
||||||
use cranelift_codegen::Context as CodegenContext;
|
|
||||||
use cranelift_reader::{TestCommand, TestOption};
|
|
||||||
|
|
||||||
use log::info;
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::string::String;
|
|
||||||
|
|
||||||
struct TestVCode {
|
|
||||||
arch: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn subtest(parsed: &TestCommand) -> SubtestResult<Box<dyn SubTest>> {
|
|
||||||
assert_eq!(parsed.command, "vcode");
|
|
||||||
|
|
||||||
let mut arch = "arm64".to_string();
|
|
||||||
for option in &parsed.options {
|
|
||||||
match option {
|
|
||||||
TestOption::Value(k, v) if k == &"arch" => {
|
|
||||||
arch = v.to_string();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Box::new(TestVCode { arch }))
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubTest for TestVCode {
|
|
||||||
fn name(&self) -> &'static str {
|
|
||||||
"vcode"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_mutating(&self) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn needs_isa(&self) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run(&self, func: Cow<Function>, context: &Context) -> SubtestResult<()> {
|
|
||||||
let triple = context.isa.unwrap().triple().clone();
|
|
||||||
let func = func.into_owned();
|
|
||||||
|
|
||||||
let mut isa = lookup(triple)
|
|
||||||
.map_err(|_| format!("Could not look up backend for arch '{}'", self.arch))?
|
|
||||||
.finish(settings::Flags::new(settings::builder()));
|
|
||||||
|
|
||||||
let mut codectx = CodegenContext::for_function(func);
|
|
||||||
codectx.set_disasm(true);
|
|
||||||
|
|
||||||
codectx
|
|
||||||
.compile(&mut *isa)
|
|
||||||
.map_err(|e| format!("Could not compile with arch '{}': {:?}", self.arch, e))?;
|
|
||||||
|
|
||||||
let result = codectx.mach_compile_result.take().unwrap();
|
|
||||||
let text = result.disasm.unwrap();
|
|
||||||
|
|
||||||
info!("text input to filecheck is:\n{}\n", text);
|
|
||||||
|
|
||||||
run_filecheck(&text, context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user