Add early-stage optimization crate (#556)
* Add simple constant folding and folding tests
This commit is contained in:
committed by
Dan Gohman
parent
bdcc06eb15
commit
3409af7c07
44
lib/filetests/src/test_simple_preopt.rs
Normal file
44
lib/filetests/src/test_simple_preopt.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
//! Test command for testing the preopt pass.
|
||||
//!
|
||||
//! The resulting function is sent to `filecheck`.
|
||||
|
||||
use cranelift_codegen;
|
||||
use cranelift_codegen::ir::Function;
|
||||
use cranelift_codegen::print_errors::pretty_error;
|
||||
use cranelift_reader::TestCommand;
|
||||
use std::borrow::Cow;
|
||||
use subtest::{run_filecheck, Context, SubTest, SubtestResult};
|
||||
|
||||
struct TestSimplePreopt;
|
||||
|
||||
pub fn subtest(parsed: &TestCommand) -> SubtestResult<Box<SubTest>> {
|
||||
assert_eq!(parsed.command, "simple_preopt");
|
||||
if !parsed.options.is_empty() {
|
||||
Err(format!("No options allowed on {}", parsed))
|
||||
} else {
|
||||
Ok(Box::new(TestSimplePreopt))
|
||||
}
|
||||
}
|
||||
|
||||
impl SubTest for TestSimplePreopt {
|
||||
fn name(&self) -> &'static str {
|
||||
"simple_preopt"
|
||||
}
|
||||
|
||||
fn is_mutating(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn run(&self, func: Cow<Function>, context: &Context) -> SubtestResult<()> {
|
||||
let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
|
||||
let isa = context.isa.expect("preopt needs an ISA");
|
||||
|
||||
comp_ctx.flowgraph();
|
||||
comp_ctx
|
||||
.preopt(isa)
|
||||
.map_err(|e| pretty_error(&comp_ctx.func, context.isa, Into::into(e)))?;
|
||||
|
||||
let text = &comp_ctx.func.display(isa).to_string();
|
||||
run_filecheck(&text, context)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user