Merge pull request #1741 from cfallin/filetest-vcode-compile
Merge `vcode` filetest mode into `compile`.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f1(i64, i64) -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f(i32, i32) -> i32 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %a(i8) -> i8 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f(i64, i64) -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f(i64) -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f(i64, i64) -> b1 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f(i8, i64, i64) -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f() -> b8 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f(i8) -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f1(f32, f32) -> f32 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f(i64) -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %add8(i8, i8) -> i8 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %uaddsat64(i64, i64) -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f(i64) -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %foo() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %stack_addr_small() -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f() -> i64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test vcode
|
||||
test compile
|
||||
target aarch64
|
||||
|
||||
function %f_u_8_64(i8) -> i64 {
|
||||
|
||||
@@ -57,7 +57,6 @@ mod test_shrink;
|
||||
mod test_simple_gvn;
|
||||
mod test_simple_preopt;
|
||||
mod test_unwind;
|
||||
mod test_vcode;
|
||||
mod test_verifier;
|
||||
|
||||
/// 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_preopt" => test_simple_preopt::subtest(parsed),
|
||||
"unwind" => test_unwind::subtest(parsed),
|
||||
"vcode" => test_vcode::subtest(parsed),
|
||||
"verifier" => test_verifier::subtest(parsed),
|
||||
_ => 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 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
|
||||
.compile(isa)
|
||||
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, e))?;
|
||||
@@ -50,25 +55,36 @@ impl SubTest for TestCompile {
|
||||
comp_ctx.func.display(isa)
|
||||
);
|
||||
|
||||
// Verify that the returned code size matches the emitted bytes.
|
||||
let mut sink = SizeSink { offset: 0 };
|
||||
binemit::emit_function(
|
||||
&comp_ctx.func,
|
||||
|func, inst, div, sink, isa| isa.emit_inst(func, inst, div, sink),
|
||||
&mut sink,
|
||||
isa,
|
||||
);
|
||||
if !isa.get_mach_backend().is_some() {
|
||||
// Verify that the returned code size matches the emitted bytes.
|
||||
let mut sink = SizeSink { offset: 0 };
|
||||
binemit::emit_function(
|
||||
&comp_ctx.func,
|
||||
|func, inst, div, sink, isa| isa.emit_inst(func, inst, div, sink),
|
||||
&mut sink,
|
||||
isa,
|
||||
);
|
||||
|
||||
if sink.offset != total_size {
|
||||
return Err(format!(
|
||||
"Expected code size {}, got {}",
|
||||
total_size, sink.offset
|
||||
));
|
||||
if sink.offset != total_size {
|
||||
return Err(format!(
|
||||
"Expected code size {}, got {}",
|
||||
total_size, sink.offset
|
||||
));
|
||||
}
|
||||
|
||||
// Run final code through filecheck.
|
||||
let text = comp_ctx.func.display(Some(isa)).to_string();
|
||||
run_filecheck(&text, context)
|
||||
} else {
|
||||
let disasm = comp_ctx
|
||||
.mach_compile_result
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.disasm
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
run_filecheck(&disasm, context)
|
||||
}
|
||||
|
||||
// Run final code through filecheck.
|
||||
let text = comp_ctx.func.display(Some(isa)).to_string();
|
||||
run_filecheck(&text, 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