Remove DefAlloc -- no longer needed.

This commit is contained in:
Chris Fallin
2022-01-19 23:57:31 -08:00
parent 3b037f3c9e
commit ccd6b4fc2c
4 changed files with 8 additions and 127 deletions

View File

@@ -743,7 +743,6 @@ impl<'a, F: Function> Checker<'a, F> {
.unwrap() .unwrap()
.push(CheckerInst::Move { into: to, from }); .push(CheckerInst::Move { into: to, from });
} }
_ => {}
} }
} }

View File

@@ -1017,60 +1017,29 @@ impl<'a, F: Function> Env<'a, F> {
} }
if self.allocation_is_stack(src) && self.allocation_is_stack(dst) { if self.allocation_is_stack(src) && self.allocation_is_stack(dst) {
if !scratch_used_yet { if !scratch_used_yet {
self.add_move_edit( self.add_move_edit(pos_prio, src, Allocation::reg(scratch));
pos_prio, self.add_move_edit(pos_prio, Allocation::reg(scratch), dst);
src,
Allocation::reg(scratch),
to_vreg,
);
self.add_move_edit(
pos_prio,
Allocation::reg(scratch),
dst,
to_vreg,
);
} else { } else {
debug_assert!(extra_slot.is_some()); debug_assert!(extra_slot.is_some());
self.add_move_edit( self.add_move_edit(
pos_prio, pos_prio,
Allocation::reg(scratch), Allocation::reg(scratch),
extra_slot.unwrap(), extra_slot.unwrap(),
None,
);
self.add_move_edit(
pos_prio,
src,
Allocation::reg(scratch),
to_vreg,
);
self.add_move_edit(
pos_prio,
Allocation::reg(scratch),
dst,
to_vreg,
); );
self.add_move_edit(pos_prio, src, Allocation::reg(scratch));
self.add_move_edit(pos_prio, Allocation::reg(scratch), dst);
self.add_move_edit( self.add_move_edit(
pos_prio, pos_prio,
extra_slot.unwrap(), extra_slot.unwrap(),
Allocation::reg(scratch), Allocation::reg(scratch),
None,
); );
} }
} else { } else {
self.add_move_edit(pos_prio, src, dst, to_vreg); self.add_move_edit(pos_prio, src, dst);
} }
} else { } else {
trace!(" -> redundant move elided"); trace!(" -> redundant move elided");
} }
#[cfg(feature = "checker")]
if let Some((alloc, vreg)) = action.def_alloc {
trace!(
" -> converted to DefAlloc: alloc {} vreg {}",
alloc,
vreg
);
self.edits.push((pos_prio, Edit::DefAlloc { alloc, vreg }));
}
} }
} }
@@ -1086,48 +1055,6 @@ impl<'a, F: Function> Env<'a, F> {
); );
let action = redundant_moves.process_move(m.from_alloc, m.to_alloc, m.to_vreg); let action = redundant_moves.process_move(m.from_alloc, m.to_alloc, m.to_vreg);
debug_assert!(action.elide); debug_assert!(action.elide);
if let Some((alloc, vreg)) = action.def_alloc {
trace!(" -> DefAlloc: alloc {} vreg {}", alloc, vreg);
self.edits.push((pos_prio, Edit::DefAlloc { alloc, vreg }));
}
}
}
#[cfg(feature = "checker")]
{
// Add edits to describe blockparam locations too. This is
// required by the checker. This comes after any edge-moves.
use crate::ion::data_structures::u64_key;
self.blockparam_allocs
.sort_unstable_by_key(|&(block, idx, _, _)| u64_key(block.raw_u32(), idx));
self.stats.blockparam_allocs_count = self.blockparam_allocs.len();
let mut i = 0;
while i < self.blockparam_allocs.len() {
let start = i;
let block = self.blockparam_allocs[i].0;
while i < self.blockparam_allocs.len() && self.blockparam_allocs[i].0 == block {
i += 1;
}
let params = &self.blockparam_allocs[start..i];
let vregs = params
.iter()
.map(|(_, _, vreg_idx, _)| self.vreg_regs[vreg_idx.index()])
.collect::<Vec<_>>();
let allocs = params
.iter()
.map(|(_, _, _, alloc)| *alloc)
.collect::<Vec<_>>();
debug_assert_eq!(vregs.len(), self.func.block_params(block).len());
debug_assert_eq!(allocs.len(), self.func.block_params(block).len());
for (vreg, alloc) in vregs.into_iter().zip(allocs.into_iter()) {
self.edits.push((
PosWithPrio {
pos: self.cfginfo.block_entry[block.index()],
prio: InsertMovePrio::BlockParam as u32,
},
Edit::DefAlloc { alloc, vreg },
));
}
} }
} }
@@ -1146,38 +1073,17 @@ impl<'a, F: Function> Env<'a, F> {
&Edit::Move { from, to } => { &Edit::Move { from, to } => {
self.annotate(pos_prio.pos, format!("move {} -> {})", from, to)); self.annotate(pos_prio.pos, format!("move {} -> {})", from, to));
} }
&Edit::DefAlloc { alloc, vreg } => {
let s = format!("defalloc {:?} := {:?}", alloc, vreg);
self.annotate(pos_prio.pos, s);
}
} }
} }
} }
} }
pub fn add_move_edit( pub fn add_move_edit(&mut self, pos_prio: PosWithPrio, from: Allocation, to: Allocation) {
&mut self,
pos_prio: PosWithPrio,
from: Allocation,
to: Allocation,
_to_vreg: Option<VReg>,
) {
if from != to { if from != to {
if from.is_reg() && to.is_reg() { if from.is_reg() && to.is_reg() {
debug_assert_eq!(from.as_reg().unwrap().class(), to.as_reg().unwrap().class()); debug_assert_eq!(from.as_reg().unwrap().class(), to.as_reg().unwrap().class());
} }
self.edits.push((pos_prio, Edit::Move { from, to })); self.edits.push((pos_prio, Edit::Move { from, to }));
} }
#[cfg(feature = "checker")]
if let Some(to_vreg) = _to_vreg {
self.edits.push((
pos_prio,
Edit::DefAlloc {
alloc: to,
vreg: to_vreg,
},
));
}
} }
} }

View File

@@ -18,8 +18,6 @@ pub struct RedundantMoveEliminator {
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct RedundantMoveAction { pub struct RedundantMoveAction {
pub elide: bool, pub elide: bool,
#[cfg(feature = "checker")]
pub def_alloc: Option<(Allocation, VReg)>,
} }
impl RedundantMoveEliminator { impl RedundantMoveEliminator {
@@ -57,11 +55,7 @@ impl RedundantMoveEliminator {
self.clear_alloc(to); self.clear_alloc(to);
self.allocs self.allocs
.insert(to, RedundantMoveState::Orig(to_vreg.unwrap())); .insert(to, RedundantMoveState::Orig(to_vreg.unwrap()));
return RedundantMoveAction { return RedundantMoveAction { elide: true };
elide: true,
#[cfg(feature = "checker")]
def_alloc: Some((to, to_vreg.unwrap())),
};
} }
let src_vreg = match from_state { let src_vreg = match from_state {
@@ -86,13 +80,6 @@ impl RedundantMoveEliminator {
}; };
trace!(" -> elide {}", elide); trace!(" -> elide {}", elide);
let def_alloc = if dst_vreg != existing_dst_vreg && dst_vreg.is_some() {
Some((to, dst_vreg.unwrap()))
} else {
None
};
trace!(" -> def_alloc {:?}", def_alloc);
// Invalidate all existing copies of `to` if `to` actually changed value. // Invalidate all existing copies of `to` if `to` actually changed value.
if !elide { if !elide {
self.clear_alloc(to); self.clear_alloc(to);
@@ -113,11 +100,7 @@ impl RedundantMoveEliminator {
.push(to); .push(to);
} }
RedundantMoveAction { RedundantMoveAction { elide }
elide,
#[cfg(feature = "checker")]
def_alloc,
}
} }
pub fn clear(&mut self) { pub fn clear(&mut self) {

View File

@@ -1119,13 +1119,6 @@ pub enum Edit {
/// are the same if the vreg changes; this allows proper metadata /// are the same if the vreg changes; this allows proper metadata
/// tracking even when moves are elided. /// tracking even when moves are elided.
Move { from: Allocation, to: Allocation }, Move { from: Allocation, to: Allocation },
/// Define a particular Allocation to contain a particular VReg. Useful
/// for the checker.
///
/// `DefAlloc` edits are only emitted when the `"checker"` Cargo feature is
/// enabled.
DefAlloc { alloc: Allocation, vreg: VReg },
} }
/// Wrapper around either an original instruction or an inserted edit. /// Wrapper around either an original instruction or an inserted edit.