Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/cranelift/filetests/src/test_alias_analysis.rs
1691 views
1
//! Test command for testing the alias analysis pass.
2
//!
3
//! The `alias-analysis` test command runs each function through GVN
4
//! and then alias analysis after ensuring that all instructions are
5
//! legal for the target.
6
//!
7
//! The resulting function is sent to `filecheck`.
8
9
use crate::subtest::{Context, SubTest, run_filecheck};
10
use cranelift_codegen::ir::Function;
11
use cranelift_reader::TestCommand;
12
use std::borrow::Cow;
13
14
struct TestAliasAnalysis;
15
16
pub 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
24
impl 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
}
45
46