Path: blob/main/cranelift/filetests/src/test_alias_analysis.rs
1691 views
//! Test command for testing the alias analysis pass.1//!2//! The `alias-analysis` test command runs each function through GVN3//! and then alias analysis after ensuring that all instructions are4//! legal for the target.5//!6//! The resulting function is sent to `filecheck`.78use crate::subtest::{Context, SubTest, run_filecheck};9use cranelift_codegen::ir::Function;10use cranelift_reader::TestCommand;11use std::borrow::Cow;1213struct TestAliasAnalysis;1415pub fn subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn SubTest>> {16assert_eq!(parsed.command, "alias-analysis");17if !parsed.options.is_empty() {18anyhow::bail!("No options allowed on {}", parsed);19}20Ok(Box::new(TestAliasAnalysis))21}2223impl SubTest for TestAliasAnalysis {24fn name(&self) -> &'static str {25"alias-analysis"26}2728fn is_mutating(&self) -> bool {29true30}3132fn run(&self, func: Cow<Function>, context: &Context) -> anyhow::Result<()> {33let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned());3435comp_ctx.flowgraph();36comp_ctx37.replace_redundant_loads()38.map_err(|e| crate::pretty_anyhow_error(&comp_ctx.func, Into::into(e)))?;3940let text = comp_ctx.func.display().to_string();41run_filecheck(&text, context)42}43}444546