mach backend: allow snapshotting IR graphs with the SNAPSHOT_REGALLOC env variable;

This also requires the serde feature, which isn't enabled by default,
thus it must be passed as a command-line argument to cargo.
This commit is contained in:
Benjamin Bouvier
2020-06-08 17:17:11 +02:00
parent 46093f6119
commit 5d01603390
3 changed files with 20 additions and 0 deletions

View File

@@ -44,6 +44,19 @@ where
}
};
#[cfg(feature = "regalloc-snapshot")]
{
use std::fs;
use std::path::Path;
if let Some(path) = std::env::var("SERIALIZE_REGALLOC").ok() {
let snapshot = regalloc::IRSnapshot::from_function(&vcode, b.reg_universe());
let serialized = bincode::serialize(&snapshot).expect("couldn't serialize snapshot");
let file_path = Path::new(&path).join(Path::new(&format!("ir{}.bin", f.name)));
fs::write(file_path, &serialized).expect("couldn't write IR snapshot file");
}
}
let result = {
let _tt = timing::regalloc();
allocate_registers_with_opts(