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

2
Cargo.lock generated
View File

@@ -368,6 +368,7 @@ dependencies = [
name = "cranelift-codegen"
version = "0.64.0"
dependencies = [
"bincode",
"byteorder",
"cranelift-bforest",
"cranelift-codegen-meta",
@@ -1669,6 +1670,7 @@ checksum = "7c03092d79e0fd610932d89ed53895a38c0dd3bcd317a0046e69940de32f1d95"
dependencies = [
"log",
"rustc-hash",
"serde",
"smallvec",
]

View File

@@ -20,6 +20,7 @@ hashbrown = { version = "0.7", optional = true }
target-lexicon = "0.10"
log = { version = "0.4.6", default-features = false }
serde = { version = "1.0.94", features = ["derive"], optional = true }
bincode = { version = "1.2.1", optional = true }
gimli = { version = "0.21.0", default-features = false, features = ["write"], optional = true }
smallvec = { version = "1.0.0" }
thiserror = "1.0.4"
@@ -74,6 +75,10 @@ all-arch = [
# For dependent crates that want to serialize some parts of cranelift
enable-serde = ["serde"]
# Allow snapshotting regalloc test cases. Useful only to report bad register
# allocation failures, or for regalloc.rs developers.
regalloc-snapshot = ["bincode", "regalloc/enable-serde"]
# Recompile our optimizations that are written in the `peepmatic` DSL into a
# compact finite-state transducer automaton.
rebuild-peephole-optimizers = ["peepmatic"]

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(