Add fixed stack slots to the fuzzer

This commit is contained in:
Amanieu d'Antras
2021-11-28 17:52:50 +00:00
parent 8f435243e0
commit 870e4729e1
2 changed files with 22 additions and 9 deletions

View File

@@ -426,12 +426,22 @@ impl CheckerState {
match op.constraint() { match op.constraint() {
OperandConstraint::Any => {} OperandConstraint::Any => {}
OperandConstraint::Reg => { OperandConstraint::Reg => {
if alloc.kind() != AllocationKind::Reg { // Reject pregs that represent a fixed stack slot.
return Err(CheckerError::AllocationIsNotReg { inst, op, alloc }); if let Some(preg) = alloc.as_reg() {
if preg.class() == RegClass::Int && (0..32).contains(&preg.hw_enc()) {
return Ok(());
}
} }
return Err(CheckerError::AllocationIsNotReg { inst, op, alloc });
} }
OperandConstraint::Stack => { OperandConstraint::Stack => {
if alloc.kind() != AllocationKind::Stack { if alloc.kind() != AllocationKind::Stack {
// Accept pregs that represent a fixed stack slot.
if let Some(preg) = alloc.as_reg() {
if preg.class() == RegClass::Int && (32..63).contains(&preg.hw_enc()) {
return Ok(());
}
}
return Err(CheckerError::AllocationIsNotStack { inst, op, alloc }); return Err(CheckerError::AllocationIsNotStack { inst, op, alloc });
} }
} }

View File

@@ -465,7 +465,7 @@ impl Func {
let mut fixed = vec![]; let mut fixed = vec![];
for _ in 0..u.int_in_range(0..=operands.len() - 1)? { for _ in 0..u.int_in_range(0..=operands.len() - 1)? {
// Pick an operand and make it a fixed reg. // Pick an operand and make it a fixed reg.
let fixed_reg = PReg::new(u.int_in_range(0..=30)?, RegClass::Int); let fixed_reg = PReg::new(u.int_in_range(0..=62)?, RegClass::Int);
if fixed.contains(&fixed_reg) { if fixed.contains(&fixed_reg) {
break; break;
} }
@@ -602,15 +602,18 @@ impl std::fmt::Debug for Func {
} }
pub fn machine_env() -> MachineEnv { pub fn machine_env() -> MachineEnv {
// Reg 31 is the scratch reg. // Reg 63 is the scratch reg.
let regs: Vec<PReg> = (0..31).map(|i| PReg::new(i, RegClass::Int)).collect(); fn regs(r: std::ops::Range<usize>) -> Vec<PReg> {
let preferred_regs_by_class: [Vec<PReg>; 2] = [regs.iter().cloned().take(24).collect(), vec![]]; r.map(|i| PReg::new(i, RegClass::Int)).collect()
let non_preferred_regs_by_class: [Vec<PReg>; 2] = }
[regs.iter().cloned().skip(24).collect(), vec![]]; let preferred_regs_by_class: [Vec<PReg>; 2] = [regs(0..24), vec![]];
let scratch_by_class: [PReg; 2] = [PReg::new(31, RegClass::Int), PReg::new(0, RegClass::Float)]; let non_preferred_regs_by_class: [Vec<PReg>; 2] = [regs(24..32), vec![]];
let scratch_by_class: [PReg; 2] = [PReg::new(63, RegClass::Int), PReg::new(0, RegClass::Float)];
let fixed_stack_slots = regs(32..63);
MachineEnv { MachineEnv {
preferred_regs_by_class, preferred_regs_by_class,
non_preferred_regs_by_class, non_preferred_regs_by_class,
scratch_by_class, scratch_by_class,
fixed_stack_slots,
} }
} }