cranelift_filetests/
test_alias_analysis.rs1use crate::subtest::{run_filecheck, Context, SubTest};
10use cranelift_codegen::ir::Function;
11use cranelift_reader::TestCommand;
12use std::borrow::Cow;
13
14struct TestAliasAnalysis;
15
16pub fn subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn SubTest>> {
17 assert_eq!(parsed.command, "alias-analysis");
18 if !parsed.options.is_empty() {
19 anyhow::bail!("No options allowed on {}", parsed);
20 }
21 Ok(Box::new(TestAliasAnalysis))
22}
23
24impl SubTest for TestAliasAnalysis {
25 fn name(&self) -> &'static str {
26 "alias-analysis"
27 }
28
29 fn is_mutating(&self) -> bool {
30 true
31 }
32
33 fn run(&self, func: Cow<Function>, context: &Context) -> anyhow::Result<()> {
34 let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());
35
36 comp_ctx.flowgraph();
37 comp_ctx
38 .replace_redundant_loads()
39 .map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, Into::into(e)))?;
40
41 let text = comp_ctx.func.display().to_string();
42 run_filecheck(&text, context)
43 }
44}