Skip to content

Commit 7f0d0b9

Browse files
authored
Expose ssa verification as a regalloc2 option (#102)
Adds the validate_ssa flag to the RegallocOptions struct, enabling ssa validation of inputs before register allocation takes place.
1 parent 25b08c6 commit 7f0d0b9

File tree

7 files changed

+16
-5
lines changed

7 files changed

+16
-5
lines changed

fuzz/fuzz_targets/ion.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ fuzz_target!(|func: Func| {
1111
let _ = env_logger::try_init();
1212
log::trace!("func:\n{:?}", func);
1313
let env = regalloc2::fuzzing::func::machine_env();
14-
let _out = regalloc2::fuzzing::ion::run(&func, &env, false).expect("regalloc did not succeed");
14+
let _out =
15+
regalloc2::fuzzing::ion::run(&func, &env, false, false).expect("regalloc did not succeed");
1516
});

fuzz/fuzz_targets/ion_checker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ fuzz_target!(|testcase: TestCase| {
4040
let _ = env_logger::try_init();
4141
log::trace!("func:\n{:?}", func);
4242
let env = regalloc2::fuzzing::func::machine_env();
43-
let out = regalloc2::fuzzing::ion::run(&func, &env, true).expect("regalloc did not succeed");
43+
let out =
44+
regalloc2::fuzzing::ion::run(&func, &env, true, false).expect("regalloc did not succeed");
4445

4546
let mut checker = Checker::new(&func, &env);
4647
checker.prepare(&out);

fuzz/fuzz_targets/ssagen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use regalloc2::fuzzing::arbitrary::{Arbitrary, Result, Unstructured};
88
use regalloc2::fuzzing::cfg::CFGInfo;
99
use regalloc2::fuzzing::func::{Func, Options};
1010
use regalloc2::fuzzing::fuzz_target;
11-
use regalloc2::fuzzing::ssa::validate_ssa;
11+
use regalloc2::ssa::validate_ssa;
1212

1313
#[derive(Debug)]
1414
struct TestCase {

src/fuzzing/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//! Utilities for fuzzing.
77
88
pub mod func;
9-
pub mod ssa;
109

1110
// Re-exports for fuzz targets.
1211

src/ion/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//! its design.
1515
1616
use crate::cfg::CFGInfo;
17+
use crate::ssa::validate_ssa;
1718
use crate::{Function, MachineEnv, Output, PReg, ProgPoint, RegAllocError, RegClass};
1819
use std::collections::HashMap;
1920

@@ -120,9 +121,14 @@ pub fn run<F: Function>(
120121
func: &F,
121122
mach_env: &MachineEnv,
122123
enable_annotations: bool,
124+
enable_ssa_checker: bool,
123125
) -> Result<Output, RegAllocError> {
124126
let cfginfo = CFGInfo::new(func)?;
125127

128+
if enable_ssa_checker {
129+
validate_ssa(func, &cfginfo)?;
130+
}
131+
126132
let mut env = Env::new(func, mach_env, cfginfo, enable_annotations);
127133
env.init()?;
128134

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod indexset;
3434
pub(crate) mod ion;
3535
pub(crate) mod moves;
3636
pub(crate) mod postorder;
37+
pub mod ssa;
3738

3839
#[macro_use]
3940
mod index;
@@ -1477,12 +1478,15 @@ pub fn run<F: Function>(
14771478
env: &MachineEnv,
14781479
options: &RegallocOptions,
14791480
) -> Result<Output, RegAllocError> {
1480-
ion::run(func, env, options.verbose_log)
1481+
ion::run(func, env, options.verbose_log, options.validate_ssa)
14811482
}
14821483

14831484
/// Options for allocation.
14841485
#[derive(Clone, Copy, Debug, Default)]
14851486
pub struct RegallocOptions {
14861487
/// Add extra verbosity to debug logs.
14871488
pub verbose_log: bool,
1489+
1490+
/// Run the SSA validator before allocating registers.
1491+
pub validate_ssa: bool,
14881492
}
File renamed without changes.

0 commit comments

Comments
 (0)